Skip to content

Commit 35c5f35

Browse files
committed
A bit more tweaking.
1 parent a2b94a9 commit 35c5f35

File tree

3 files changed

+99
-3
lines changed

3 files changed

+99
-3
lines changed

src/Conf/CodeTables.php

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,28 @@ public function getCodeTable($codetable)
3030
return json_decode($this->client->get($this->urlBase()."/$codetable"));
3131
}
3232

33+
34+
/**
35+
* Return a single row referring to the code table.
36+
*
37+
* @param $codetable - Code Table to pull from.
38+
* @param $code - The code in the Table we want to pull.
39+
*
40+
* @return object - the row in the code table.
41+
*/
42+
public function getCodeTableRowByCode($codetable,$code)
43+
{
44+
echo "CodeTable: $codetable\n";
45+
echo "Code: $code\n";
46+
$count = 0;
47+
foreach ($this->getCodeTable($codetable) as $row) {
48+
$count++;
49+
}
50+
print "Total Rows in $codetable: $count\n";
51+
return;
52+
}
53+
54+
3355
/**
3456
* Return a object containing a list of code tables.
3557
*

src/Users/Statistic.php

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
<?php
2+
3+
namespace Scriptotek\Alma\Users;
4+
5+
use Scriptotek\Alma\Model\SettableModel;
6+
7+
8+
/* Note: Not sure this is needed yet. */
9+
10+
11+
class Statistic extends SettableModel
12+
{
13+
14+
15+
}

src/Users/UserStatistics.php

Lines changed: 62 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ class UserStatistics extends Model
1313
/**
1414
* Get the user's statistics.
1515
*
16-
* @return Statistic
16+
* @return Array of Statistics.
1717
*/
1818
public function getStatistics()
1919
{
@@ -27,6 +27,9 @@ public function getStatistics()
2727
/**
2828
* Get a statistic.
2929
*
30+
* @param $typeCode code of the category type.
31+
* @param $categoryCode code of the statistical category.
32+
*
3033
* @return Statistic.
3134
*/
3235
public function getStatistic($typeCode,$categoryCode)
@@ -42,10 +45,18 @@ public function getStatistic($typeCode,$categoryCode)
4245
}
4346

4447
/**
45-
* Add a user statistic.
48+
* Add a user statistic with no regard to existing Types and Categories.
49+
*
50+
* @param string $typeCode code of the category type.
51+
* @param string $typeDesc description of the category type.
52+
* @param string $categoryCode code of the statistical category.
53+
* @param string $categoryDesc description of the statistical category.
54+
* @param string $note free text description of the statistic.
55+
* @param string $segment_type (Internal|External)
4656
*
57+
* @return Statistic
4758
*/
48-
public function addStatistic($typeCode,$typeDesc,$categoryCode,$categoryDesc,$note,$segment_type)
59+
public function addStatisticRaw($typeCode,$typeDesc,$categoryCode,$categoryDesc,$note,$segment_type)
4960
{
5061
# Create the new statistic object
5162
$stat_obj = (object) [
@@ -61,16 +72,59 @@ public function addStatistic($typeCode,$typeDesc,$categoryCode,$categoryDesc,$no
6172
'segment_type' => $segment_type,
6273
];
6374

75+
76+
//* TODO HERE *//
77+
6478
# Add the object to the user
6579
$this->data->user_statistic[] = $stat_obj;
80+
81+
/* Not Sure this is quite right or needed. */
82+
return Statistic::make($this->client,$stat_obj);
83+
}
84+
85+
/**
86+
* Add a user statistic based upon existing Types and Categories.
87+
*
88+
* @param string $typeCode code of the category type.
89+
* @param string $categoryCode code of the statistical category.
90+
*
91+
* @return Statistic
92+
*/
93+
public function addStatistic($typeCode,$categoryCode)
94+
{
95+
//* TODO HERE *//
96+
97+
/* Logic: */
98+
/* Lookup both $typeCode and $categoryCode in codetable */
99+
/* Obtain information (code/description) from both code tables. */
100+
/* If found and ok, add the statistic to the user */
101+
102+
/* Code Tables used:
103+
Code Table; UserStatisticalTypes
104+
Code Table: UserStatCategories
105+
*/
106+
107+
/* Seems to be an issue with # of categoryCodes that can be pulled at once (max:10) */
108+
/* But performing via curl returns all (???). */
109+
/* May need to open a case to allow resumption on pulling code tables regarding 'limit' and 'offset'? */
66110
}
67111

68112
/**
69113
* Delete a user statistic.
70114
*
115+
* @param string $typeCode code of the category type.
116+
* @param string $categoryCode code of the statistical category.
71117
*/
72118
public function removeStatistic($typeCode,$categoryCode)
73119
{
120+
foreach ($this->data->user_statistic as $statistic) {
121+
if (($statistic->category_type->value == $typeCode ) && ($statistic->statistic_category->value == $categoryCode )) {
122+
123+
//* TODO HERE *//
124+
125+
return;
126+
}
127+
}
74128
}
75129

76130
/**
@@ -79,6 +133,11 @@ public function removeStatistic($typeCode,$categoryCode)
79133
*/
80134
public function updateStatistic($fromTypeCode,$fromCategoryCode,$toTypeCode,$toCategoryCode)
81135
{
136+
137+
//* TODO HERE *//
138+
139+
/* Remove "from" statistic, then add "to" statistic */
140+
82141
$this->removeStatistic($fromTypeCode,$categoryCode);
83142
$this->addStatistic($toTypeCode,$toCategoryCode);
84143
}

0 commit comments

Comments
 (0)