| @@ -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 | |
| @@ -39,7 +39,7 @@ discard block | ||
| 39 | 39 |      if ($form->load(Yii::$app->request->post()) && $form->validate()) { | 
| 40 | 40 | $form->compiled_behaviors = $form->compileBehaviors(); | 
| 41 | 41 | |
| 42 | -      if(sizeof($form->compiled_behaviors) === 0) { | |
| 42 | +      if (sizeof($form->compiled_behaviors) === 0) { | |
| 43 | 43 | return $this->redirect(['view']); | 
| 44 | 44 | } | 
| 45 | 45 | |
| @@ -49,14 +49,14 @@ discard block | ||
| 49 | 49 | |
| 50 | 50 | // delete cached scores | 
| 51 | 51 |        $time = Yii::$container->get('common\interfaces\TimeInterface'); | 
| 52 | - $key = "scores_of_last_month_".Yii::$app->user->id."_".$time->getLocalDate(); | |
| 52 | + $key = "scores_of_last_month_" . Yii::$app->user->id . "_" . $time->getLocalDate(); | |
| 53 | 53 | Yii::$app->cache->delete($key); | 
| 54 | 54 | |
| 55 | 55 | // if the user has publicised their score graph, create the image | 
| 56 | -      if(Yii::$app->user->identity->expose_graph) { | |
| 56 | +      if (Yii::$app->user->identity->expose_graph) { | |
| 57 | 57 |          $user_behavior = Yii::$container->get('common\interfaces\UserBehaviorInterface'); | 
| 58 | 58 | $scores_last_month = $user_behavior->calculateScoresOfLastMonth(); | 
| 59 | -        if($scores_last_month) { | |
| 59 | +        if ($scores_last_month) { | |
| 60 | 60 | Yii::$container | 
| 61 | 61 |              ->get('common\components\Graph') | 
| 62 | 62 | ->create($scores_last_month, true); | 
| @@ -81,7 +81,7 @@ discard block | ||
| 81 | 81 |      $date = Yii::$container->get('common\interfaces\TimeInterface')->getLocalDate(); | 
| 82 | 82 | |
| 83 | 83 | $user_behaviors = $user_behavior->getUserBehaviorsWithCategory($date); | 
| 84 | -    if(count($user_behaviors) === 0) { | |
| 84 | +    if (count($user_behaviors) === 0) { | |
| 85 | 85 | return $this->redirect(['view']); | 
| 86 | 86 | } | 
| 87 | 87 | |
| @@ -91,10 +91,10 @@ discard block | ||
| 91 | 91 | $form->deleteToday(); | 
| 92 | 92 | |
| 93 | 93 | $behaviors = $user_behavior->findAll($form->getUserBehaviorIds()); | 
| 94 | -      if($result = $form->saveAnswers($behaviors)) { | |
| 94 | +      if ($result = $form->saveAnswers($behaviors)) { | |
| 95 | 95 | |
| 96 | 96 | $score = $user_behavior->getDailyScore(); | 
| 97 | -        if(Yii::$app->user->identity->isOverThreshold($score)) { | |
| 97 | +        if (Yii::$app->user->identity->isOverThreshold($score)) { | |
| 98 | 98 | Yii::$app->user->identity->sendEmailReport($date); | 
| 99 | 99 |            Yii::$app->session->setFlash('warning', 'Your check-in is complete. A notification has been sent to your report partners because of your high score. Reach out to them!'); | 
| 100 | 100 |          } else { | 
| @@ -114,7 +114,7 @@ discard block | ||
| 114 | 114 | public function actionView($date = null) | 
| 115 | 115 |    { | 
| 116 | 116 |      $time = Yii::$container->get('common\interfaces\TimeInterface'); | 
| 117 | -    if(is_null($date)) { | |
| 117 | +    if (is_null($date)) { | |
| 118 | 118 | $date = $time->getLocalDate(); | 
| 119 | 119 | } | 
| 120 | 120 | |
| @@ -41,7 +41,7 @@ discard block | ||
| 41 | 41 | ]; | 
| 42 | 42 | |
| 43 | 43 | $tmp_pie = []; | 
| 44 | -foreach($answer_pie as $key => $category) { | |
| 44 | +foreach ($answer_pie as $key => $category) { | |
| 45 | 45 | $json = [ | 
| 46 | 46 | "value" => (int)$category['count'], | 
| 47 | 47 | "color" => $pie_colors[$key]["color"], | 
| @@ -79,12 +79,12 @@ discard block | ||
| 79 | 79 | <th>Behavior</th> | 
| 80 | 80 | <th>Category</th> | 
| 81 | 81 | </tr> | 
| 82 | -<?php foreach($top_behaviors as $key => $row) { | |
| 82 | +<?php foreach ($top_behaviors as $key => $row) { | |
| 83 | 83 | $num = $key + 1; | 
| 84 | -print "<tr>". | |
| 85 | -  "<td>{$row['count']}</td>". | |
| 86 | -  "<td>{$row['behavior']['name']}</td>". | |
| 87 | -  "<td>{$row['behavior']['category']['name']}</td>". | |
| 84 | +print "<tr>" . | |
| 85 | +  "<td>{$row['count']}</td>" . | |
| 86 | +  "<td>{$row['behavior']['name']}</td>" . | |
| 87 | +  "<td>{$row['behavior']['category']['name']}</td>" . | |
| 88 | 88 | "</tr>"; | 
| 89 | 89 | |
| 90 | 90 | } |