@@ -19,7 +19,21 @@ public function getStatistics()
1919 {
2020 $ stats = array ();
2121 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 ;
2337 }
2438 return $ stats ;
2539 }
@@ -38,7 +52,7 @@ public function getStatistic($typeCode,$categoryCode)
3852 foreach ($ this ->data as $ statistic ) {
3953 if (($ statistic ->category_type ->value == $ typeCode ) &&
4054 ($ statistic ->statistic_category ->value == $ categoryCode )) {
41- array_push ( $ stats, $ statistic) ;
55+ $ stats[] = $ statistic ;
4256 }
4357 }
4458 return $ stats ;
@@ -130,15 +144,22 @@ public function addStatistic($typeCode,$categoryCode,$segmentType,$note)
130144 */
131145 public function removeStatistic ($ typeCode ,$ categoryCode )
132146 {
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 );
139160 }
140161 }
141- return ( $ ret ) ;
162+ return ;
142163 }
143164
144165 /**
0 commit comments