@@ -85,7 +85,7 @@ discard block  | 
                                                    ||
| 85 | 85 |        ->groupBy('date, user_id') | 
                                                        
| 86 | 86 |        ->having('user_id = :user_id'); | 
                                                        
| 87 | 87 | $temp_dates = $query->all();  | 
                                                        
| 88 | -    foreach($temp_dates as $temp_date) { | 
                                                        |
| 88 | +    foreach ($temp_dates as $temp_date) { | 
                                                        |
| 89 | 89 | $past_checkin_dates[] = $this->time->convertUTCToLocal($temp_date['date']);  | 
                                                        
| 90 | 90 | }  | 
                                                        
| 91 | 91 | |
@@ -114,7 +114,7 @@ discard block  | 
                                                    ||
| 114 | 114 | |
| 115 | 115 |    public function getDailyScore($date = null) { | 
                                                        
| 116 | 116 | // default to today's score  | 
                                                        
| 117 | - if(is_null($date)) $date = $this->time->getLocalDate();  | 
                                                        |
| 117 | + if (is_null($date)) $date = $this->time->getLocalDate();  | 
                                                        |
| 118 | 118 | |
| 119 | 119 | list($start, $end) = $this->time->getUTCBookends($date);  | 
                                                        
| 120 | 120 | $score = $this->calculateScoreByUTCRange($start, $end);  | 
                                                        
@@ -147,9 +147,9 @@ discard block  | 
                                                    ||
| 147 | 147 | }  | 
                                                        
| 148 | 148 | |
| 149 | 149 |    public function calculateScoresOfLastMonth() { | 
                                                        
| 150 | - $key = "scores_of_last_month_".Yii::$app->user->id."_".$this->time->getLocalDate();  | 
                                                        |
| 150 | + $key = "scores_of_last_month_" . Yii::$app->user->id . "_" . $this->time->getLocalDate();  | 
                                                        |
| 151 | 151 | $scores = Yii::$app->cache->get($key);  | 
                                                        
| 152 | -    if($scores === false) { | 
                                                        |
| 152 | +    if ($scores === false) { | 
                                                        |
| 153 | 153 | $scores = [];  | 
                                                        
| 154 | 154 | |
| 155 | 155 |        $dt = new DateTime("now", new DateTimeZone("UTC")); | 
                                                        
@@ -166,8 +166,8 @@ discard block  | 
                                                    ||
| 166 | 166 | }  | 
                                                        
| 167 | 167 | |
| 168 | 168 |    public function calculateScore($usr_bhvrs, $all_cats = null) { | 
                                                        
| 169 | - if(!!!$usr_bhvrs) return [];  | 
                                                        |
| 170 | - if(!!!$all_cats) $all_cats = $this->behavior->getCategories();  | 
                                                        |
| 169 | + if (!!!$usr_bhvrs) return [];  | 
                                                        |
| 170 | + if (!!!$all_cats) $all_cats = $this->behavior->getCategories();  | 
                                                        |
| 171 | 171 | |
| 172 | 172 |      $usr_bhvrs = array_reduce($usr_bhvrs, function($carry, $bhvr) { | 
                                                        
| 173 | 173 | $date = $this->time->convertUTCToLocal($bhvr['date']);  | 
                                                        
@@ -176,7 +176,7 @@ discard block  | 
                                                    ||
| 176 | 176 | }, []);  | 
                                                        
| 177 | 177 | |
| 178 | 178 | $scores = [];  | 
                                                        
| 179 | -    foreach($usr_bhvrs as $date => $bhvrs) { | 
                                                        |
| 179 | +    foreach ($usr_bhvrs as $date => $bhvrs) { | 
                                                        |
| 180 | 180 |        $picked = array_reduce($bhvrs, function($carry, $bhvr) { | 
                                                        
| 181 | 181 | $carry[$bhvr['category_id']][] = $bhvr['id'];  | 
                                                        
| 182 | 182 | return $carry;  | 
                                                        
@@ -190,14 +190,14 @@ discard block  | 
                                                    ||
| 190 | 190 | }  | 
                                                        
| 191 | 191 | |
| 192 | 192 |    private function _getCatGrades($picked, $all_cats = null) { | 
                                                        
| 193 | - if(!!!$all_cats) $all_cats = $this->behavior->getCategories();  | 
                                                        |
| 193 | + if (!!!$all_cats) $all_cats = $this->behavior->getCategories();  | 
                                                        |
| 194 | 194 | |
| 195 | 195 |      return array_reduce($all_cats, function($carry, $cat) use($picked) { | 
                                                        
| 196 | -      if(array_key_exists($cat['category_id'], $picked)) { | 
                                                        |
| 196 | +      if (array_key_exists($cat['category_id'], $picked)) { | 
                                                        |
| 197 | 197 | $count = count($picked[$cat['category_id']]);  | 
                                                        
| 198 | - $prcnt_2x = ($count / $cat['behavior_count']) * 2;  | 
                                                        |
| 198 | + $prcnt_2x = ($count/$cat['behavior_count'])*2;  | 
                                                        |
| 199 | 199 | // because we're doubling the % we want to ensure we don't take more than 100%  | 
                                                        
| 200 | - $carry[$cat['category_id']] = $cat['weight'] * min($prcnt_2x, 1);  | 
                                                        |
| 200 | + $carry[$cat['category_id']] = $cat['weight']*min($prcnt_2x, 1);  | 
                                                        |
| 201 | 201 |        } else { | 
                                                        
| 202 | 202 | $carry[$cat['category_id']] = 0;  | 
                                                        
| 203 | 203 | }  | 
                                                        
@@ -219,7 +219,7 @@ discard block  | 
                                                    ||
| 219 | 219 |    public function getBehaviorsByCategory() { | 
                                                        
| 220 | 220 |      return array_values(array_reduce(self::decorateWithCategory($this->getBehaviorsWithCounts()), function($acc, $row) { | 
                                                        
| 221 | 221 | $cat_id = $row['behavior']['category']['id'];  | 
                                                        
| 222 | -      if(array_key_exists($cat_id, $acc)) { | 
                                                        |
| 222 | +      if (array_key_exists($cat_id, $acc)) { | 
                                                        |
| 223 | 223 | $acc[$cat_id]['count'] += $row['count'];  | 
                                                        
| 224 | 224 |        } else { | 
                                                        
| 225 | 225 | $acc[$cat_id] = [  | 
                                                        
@@ -232,10 +232,10 @@ discard block  | 
                                                    ||
| 232 | 232 | }  | 
                                                        
| 233 | 233 | |
| 234 | 234 |    public static function decorate(Array $uo, $with_category = false) { | 
                                                        
| 235 | -    foreach($uo as &$o) { | 
                                                        |
| 236 | -      if($behavior = \common\models\Behavior::getBehavior('id', $o['behavior_id'])) { | 
                                                        |
| 235 | +    foreach ($uo as &$o) { | 
                                                        |
| 236 | +      if ($behavior = \common\models\Behavior::getBehavior('id', $o['behavior_id'])) { | 
                                                        |
| 237 | 237 | $o['behavior'] = $behavior;  | 
                                                        
| 238 | -        if($with_category) { | 
                                                        |
| 238 | +        if ($with_category) { | 
                                                        |
| 239 | 239 |            $o['behavior']['category'] = \common\models\Category::getCategory('id', $o['behavior']['category_id']); | 
                                                        
| 240 | 240 | }  | 
                                                        
| 241 | 241 | }  | 
                                                        
@@ -255,7 +255,7 @@ discard block  | 
                                                    ||
| 255 | 255 |        ->groupBy('behavior_id, user_id') | 
                                                        
| 256 | 256 |        ->having('user_id = :user_id') | 
                                                        
| 257 | 257 |        ->orderBy('count DESC'); | 
                                                        
| 258 | -    if($limit) { | 
                                                        |
| 258 | +    if ($limit) { | 
                                                        |
| 259 | 259 | $query->limit($limit);  | 
                                                        
| 260 | 260 | }  | 
                                                        
| 261 | 261 | |