@@ -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 | } |
@@ -221,7 +221,7 @@ discard block |
||
| 221 | 221 | |
| 222 | 222 | $arr = array_reduce($behaviors, function($acc, $row) { |
| 223 | 223 | $cat_id = $row['behavior']['category']['id']; |
| 224 | - if(array_key_exists($cat_id, $acc)) { |
|
| 224 | + if (array_key_exists($cat_id, $acc)) { |
|
| 225 | 225 | $acc[$cat_id]['count'] += $row['count']; |
| 226 | 226 | } else { |
| 227 | 227 | $acc[$cat_id] = [ |
@@ -238,10 +238,10 @@ discard block |
||
| 238 | 238 | } |
| 239 | 239 | |
| 240 | 240 | public static function decorate(Array $uo, $with_category = false) { |
| 241 | - foreach($uo as &$o) { |
|
| 242 | - if($behavior = \common\models\Behavior::getBehavior('id', $o['behavior_id'])) { |
|
| 241 | + foreach ($uo as &$o) { |
|
| 242 | + if ($behavior = \common\models\Behavior::getBehavior('id', $o['behavior_id'])) { |
|
| 243 | 243 | $o['behavior'] = $behavior; |
| 244 | - if($with_category) { |
|
| 244 | + if ($with_category) { |
|
| 245 | 245 | $o['behavior']['category'] = \common\models\Category::getCategory('id', $o['behavior']['category_id']); |
| 246 | 246 | } |
| 247 | 247 | } |
@@ -262,11 +262,11 @@ discard block |
||
| 262 | 262 | ->having('user_id = :user_id') |
| 263 | 263 | ->orderBy('count DESC'); |
| 264 | 264 | |
| 265 | - if($limit instanceof \DateTime) { |
|
| 265 | + if ($limit instanceof \DateTime) { |
|
| 266 | 266 | list($start, $end) = $this->time->getUTCBookends($limit->format('Y-m-d')); |
| 267 | 267 | $query->params += [':start_date' => $start, ':end_date' => $end]; |
| 268 | 268 | $query->where('user_id=:user_id AND date > :start_date AND date <= :end_date'); |
| 269 | - } else if(is_int($limit)) { |
|
| 269 | + } else if (is_int($limit)) { |
|
| 270 | 270 | $query->limit($limit); |
| 271 | 271 | } |
| 272 | 272 | |
@@ -27,7 +27,7 @@ discard block |
||
| 27 | 27 | $plus_week = $time->alterLocalDate($actual_date, "+1 week"); |
| 28 | 28 | |
| 29 | 29 | $pie_data = []; |
| 30 | -if($answer_pie) { |
|
| 30 | +if ($answer_pie) { |
|
| 31 | 31 | $values = array_map('intval', array_column($answer_pie, "count")); |
| 32 | 32 | $labels = array_column($answer_pie, "name"); |
| 33 | 33 | $colors = array_column($answer_pie, "color"); |
@@ -64,7 +64,7 @@ discard block |
||
| 64 | 64 | </div> |
| 65 | 65 | |
| 66 | 66 | <?php |
| 67 | - switch(true) { |
|
| 67 | + switch (true) { |
|
| 68 | 68 | case ($score < 30): |
| 69 | 69 | $alert_level = "success"; |
| 70 | 70 | $alert_msg = "You're doing well! Keep on doing whatever it is you're doing!"; |
@@ -96,15 +96,15 @@ discard block |
||
| 96 | 96 | </div> |
| 97 | 97 | </div> |
| 98 | 98 | |
| 99 | - <?php if($questions) { |
|
| 100 | - foreach($questions as $behavior_id => $behavior_questions) { |
|
| 99 | + <?php if ($questions) { |
|
| 100 | + foreach ($questions as $behavior_id => $behavior_questions) { |
|
| 101 | 101 | print "<div class='well well-sm'>"; |
| 102 | 102 | print "<button type='button' class='btn btn-primary' disabled='disabled'>{$behavior_questions['question']['title']}</button>"; |
| 103 | 103 | print "<div class='row'>"; |
| 104 | - foreach($behavior_questions['answers'] as $question) { |
|
| 104 | + foreach ($behavior_questions['answers'] as $question) { |
|
| 105 | 105 | print "<div class='col-md-4'>"; |
| 106 | 106 | print "<p><strong>{$question['title']}</strong></p>"; |
| 107 | - print "<p>".Html::encode($question['answer'])."</p>"; |
|
| 107 | + print "<p>" . Html::encode($question['answer']) . "</p>"; |
|
| 108 | 108 | print "</div>"; |
| 109 | 109 | } |
| 110 | 110 | print "</div></div>"; |
@@ -116,7 +116,7 @@ discard block |
||
| 116 | 116 | 'options' => ['class' => 'form-horizontal'], |
| 117 | 117 | ]); |
| 118 | 118 | |
| 119 | - foreach($categories as $category) { |
|
| 119 | + foreach ($categories as $category) { |
|
| 120 | 120 | $behaviors = AH::map($behaviorsList[$category['id']], 'id', 'name'); |
| 121 | 121 | print $form |
| 122 | 122 | ->field($model, "behaviors{$category['id']}") |
@@ -15,7 +15,7 @@ discard block |
||
| 15 | 15 | $this->title = "The Faster Scale App | Previous Check-ins"; |
| 16 | 16 | $time = Yii::$container->get('common\interfaces\TimeInterface'); |
| 17 | 17 | $this->registerJsFile('/js/checkin/view.js', ['depends' => [\site\assets\AppAsset::class]]); |
| 18 | -if($answer_pie) { |
|
| 18 | +if ($answer_pie) { |
|
| 19 | 19 | $this->registerJsFile('/js/checkin/charts/pie.js', ['depends' => [\site\assets\AppAsset::class]]); |
| 20 | 20 | } |
| 21 | 21 | |
@@ -25,7 +25,7 @@ discard block |
||
| 25 | 25 | } |
| 26 | 26 | |
| 27 | 27 | $pie_data = []; |
| 28 | -if($answer_pie) { |
|
| 28 | +if ($answer_pie) { |
|
| 29 | 29 | $values = array_map('intval', array_column($answer_pie, "count")); |
| 30 | 30 | $labels = array_column($answer_pie, "name"); |
| 31 | 31 | $colors = array_column($answer_pie, "color"); |
@@ -51,7 +51,7 @@ discard block |
||
| 51 | 51 | <h1>View Previous Check-ins</h1> |
| 52 | 52 | |
| 53 | 53 | <?php |
| 54 | - switch(true) { |
|
| 54 | + switch (true) { |
|
| 55 | 55 | case ($score < 30): |
| 56 | 56 | $alert_level = "success"; |
| 57 | 57 | $alert_msg = "You're doing well! Keep on doing whatever it is you're doing!"; |
@@ -112,16 +112,16 @@ discard block |
||
| 112 | 112 | </div> |
| 113 | 113 | |
| 114 | 114 | |
| 115 | - <?php if($questions) { |
|
| 115 | + <?php if ($questions) { |
|
| 116 | 116 | print "<h3>Processing Questions:</h3>"; |
| 117 | - foreach($questions as $behavior_id => $behavior_questions) { |
|
| 117 | + foreach ($questions as $behavior_id => $behavior_questions) { |
|
| 118 | 118 | print "<div class='well well-sm'>"; |
| 119 | 119 | print "<button type='button' class='btn btn-primary' disabled='disabled'>{$behavior_questions['question']['title']}</button>"; |
| 120 | 120 | print "<div class='row'>"; |
| 121 | - foreach($behavior_questions['answers'] as $question) { |
|
| 121 | + foreach ($behavior_questions['answers'] as $question) { |
|
| 122 | 122 | print "<div class='col-md-4'>"; |
| 123 | 123 | print "<p><strong>{$question['title']}</strong></p>"; |
| 124 | - print "<p>".Html::encode($question['answer'])."</p>"; |
|
| 124 | + print "<p>" . Html::encode($question['answer']) . "</p>"; |
|
| 125 | 125 | print "</div>"; |
| 126 | 126 | } |
| 127 | 127 | print "</div></div>"; |
@@ -136,7 +136,7 @@ discard block |
||
| 136 | 136 | 'options' => ['class' => 'form-horizontal'], |
| 137 | 137 | ]); |
| 138 | 138 | |
| 139 | - foreach($categories as $category) { |
|
| 139 | + foreach ($categories as $category) { |
|
| 140 | 140 | $behaviors = AH::map($behaviorsList[$category['id']], 'id', 'name'); |
| 141 | 141 | print $form |
| 142 | 142 | ->field($model, "behaviors{$category['id']}") |
@@ -146,7 +146,7 @@ discard block |
||
| 146 | 146 | ActiveForm::end(); |
| 147 | 147 | |
| 148 | 148 | $this->registerJson($past_checkin_dates, "past-checkin-dates"); |
| 149 | -if($answer_pie) { |
|
| 149 | +if ($answer_pie) { |
|
| 150 | 150 | $this->registerJson($pie_data, "pie_data"); |
| 151 | 151 | } |
| 152 | 152 | ?> |
@@ -102,9 +102,12 @@ |
||
| 102 | 102 | <div class='card-text'> |
| 103 | 103 | <?php if ($pie_data): ?> |
| 104 | 104 | <canvas id='category-pie-chart'></canvas> |
| 105 | - <?php else: ?> |
|
| 105 | + <?php else { |
|
| 106 | + : ?> |
|
| 106 | 107 | <p>no data</p> |
| 107 | - <?php endif; ?> |
|
| 108 | + <?php endif; |
|
| 109 | +} |
|
| 110 | +?> |
|
| 108 | 111 | </div> |
| 109 | 112 | </div> |
| 110 | 113 | </div> |