@@ -19,7 +19,21 @@ public function getStatistics()
19
19
{
20
20
$ stats = array ();
21
21
foreach ($ this ->data as $ statistic ) {
22
- array_push ($ stats ,$ statistic );
22
+ $ stats [] = $ statistic ;
23
+ }
24
+ return $ stats ;
25
+ }
26
+
27
+ /**
28
+ * Get the user's statistics.
29
+ *
30
+ * @return array of statistics.
31
+ */
32
+ public function get ()
33
+ {
34
+ $ stats = array ();
35
+ foreach ($ this ->data as $ statistic ) {
36
+ $ stats [] = $ statistic ;
23
37
}
24
38
return $ stats ;
25
39
}
@@ -38,7 +52,7 @@ public function getStatistic($typeCode,$categoryCode)
38
52
foreach ($ this ->data as $ statistic ) {
39
53
if (($ statistic ->category_type ->value == $ typeCode ) &&
40
54
($ statistic ->statistic_category ->value == $ categoryCode )) {
41
- array_push ( $ stats, $ statistic) ;
55
+ $ stats[] = $ statistic ;
42
56
}
43
57
}
44
58
return $ stats ;
@@ -130,15 +144,22 @@ public function addStatistic($typeCode,$categoryCode,$segmentType,$note)
130
144
*/
131
145
public function removeStatistic ($ typeCode ,$ categoryCode )
132
146
{
133
- $ max = sizeof ($ this ->data );
134
- $ ret = false ;
135
- for ($ i = 0 ; $ i < $ max ; $ i ++) {
136
- if (($ this ->data [$ i ]->category_type ->value == $ typeCode ) && ($ this ->data [$ i ]->statistic_category ->value == $ categoryCode )) {
137
- unset($ this ->data [$ i ]);
138
- $ ret = true ;
147
+ # Old way:
148
+ #$max = sizeof($this->data);
149
+ #for($i = 0; $i < $max; $i++) {
150
+ # if (($this->data[$i]->category_type->value == $typeCode) && ($this->data[$i]->statistic_category->value == $categoryCode)) {
151
+ # unset($this->data[$i]);
152
+ # $ret = true;
153
+ # }
154
+ #}
155
+
156
+ # New way: (Thanks Rick!)
157
+ foreach ($ this ->data as $ key => $ row ) {
158
+ if (($ row ->category_type ->value == $ typeCode ) && ($ row ->statistic_category ->value == $ categoryCode )) {
159
+ array_splice ($ this ->data , $ key , 1 );
139
160
}
140
161
}
141
- return ( $ ret ) ;
162
+ return ;
142
163
}
143
164
144
165
/**
0 commit comments