@@ -6,13 +6,13 @@ discard block |
||
| 6 | 6 | use \site\models\EditProfileForm; |
| 7 | 7 | |
| 8 | 8 | class EditProfileFormTest extends \Codeception\Test\Unit { |
| 9 | - public $values = [ |
|
| 10 | - 'timezone' => 'America/Los_Angeles', |
|
| 9 | + public $values = [ |
|
| 10 | + 'timezone' => 'America/Los_Angeles', |
|
| 11 | 11 | 'send_email' => true, |
| 12 | - 'partner_email1' => '[email protected]', |
|
| 13 | - 'partner_email2' => '[email protected]', |
|
| 14 | - 'partner_email3' => '[email protected]', |
|
| 15 | - ]; |
|
| 12 | + 'partner_email1' => '[email protected]', |
|
| 13 | + 'partner_email2' => '[email protected]', |
|
| 14 | + 'partner_email3' => '[email protected]', |
|
| 15 | + ]; |
|
| 16 | 16 | |
| 17 | 17 | public function testLoadUser() { |
| 18 | 18 | $user = $this->getUser(); |
@@ -35,20 +35,20 @@ discard block |
||
| 35 | 35 | |
| 36 | 36 | $form->attributes = $this->values; |
| 37 | 37 | expect('saveProfile should return the user', $this->assertEquals($user, $form->saveProfile())); |
| 38 | - expect('saveProfile should set the user\'s attributes to be the form values', $this->assertEquals($this->values, $user->attributes)); |
|
| 38 | + expect('saveProfile should set the user\'s attributes to be the form values', $this->assertEquals($this->values, $user->attributes)); |
|
| 39 | 39 | |
| 40 | 40 | $form->send_email = 'not_a_boolean'; |
| 41 | 41 | expect('saveProfile should return the user with the partner-related settings equal to null', $this->assertNull($form->saveProfile())); |
| 42 | 42 | |
| 43 | - $null_vals = [ |
|
| 44 | - 'partner_email1' => null, |
|
| 45 | - 'partner_email2' => null, |
|
| 46 | - 'partner_email3' => null, |
|
| 43 | + $null_vals = [ |
|
| 44 | + 'partner_email1' => null, |
|
| 45 | + 'partner_email2' => null, |
|
| 46 | + 'partner_email3' => null, |
|
| 47 | 47 | 'send_email' => null, |
| 48 | - 'timezone' => 'America/Los_Angeles', |
|
| 49 | - ]; |
|
| 48 | + 'timezone' => 'America/Los_Angeles', |
|
| 49 | + ]; |
|
| 50 | 50 | $form->send_email = false; |
| 51 | - $ret = $form->saveProfile(); |
|
| 51 | + $ret = $form->saveProfile(); |
|
| 52 | 52 | expect('saveProfile should return the user with the partner-related settings equal to null', $this->assertEquals($null_vals, $user->attributes)); |
| 53 | 53 | |
| 54 | 54 | $form->send_email = 'not_a_boolean'; |
@@ -64,10 +64,10 @@ discard block |
||
| 64 | 64 | } |
| 65 | 65 | |
| 66 | 66 | public function setBehaviors($behaviors) { |
| 67 | - foreach($behaviors as $category_id => $category_data) { |
|
| 67 | + foreach ($behaviors as $category_id => $category_data) { |
|
| 68 | 68 | $attribute = "behaviors$category_id"; |
| 69 | 69 | $this->$attribute = []; |
| 70 | - foreach($category_data['behaviors'] as $behavior) { |
|
| 70 | + foreach ($category_data['behaviors'] as $behavior) { |
|
| 71 | 71 | $this->{$attribute}[] = $behavior['id']; |
| 72 | 72 | } |
| 73 | 73 | } |
@@ -75,8 +75,8 @@ discard block |
||
| 75 | 75 | |
| 76 | 76 | public function validateBehaviors($attribute, $params) { |
| 77 | 77 | if (!$this->hasErrors()) { |
| 78 | - foreach($this->$attribute as $behavior) { |
|
| 79 | - if(!is_numeric($behavior)) { |
|
| 78 | + foreach ($this->$attribute as $behavior) { |
|
| 79 | + if (!is_numeric($behavior)) { |
|
| 80 | 80 | $this->addError($attribute, 'One of your behaviors is not an integer!'); |
| 81 | 81 | } |
| 82 | 82 | } |
@@ -110,17 +110,17 @@ discard block |
||
| 110 | 110 | |
| 111 | 111 | // delete cached scores |
| 112 | 112 | $time = Yii::$container->get(\common\interfaces\TimeInterface::class); |
| 113 | - $key = "scores_of_last_month_".Yii::$app->user->id."_".$time->getLocalDate(); |
|
| 113 | + $key = "scores_of_last_month_" . Yii::$app->user->id . "_" . $time->getLocalDate(); |
|
| 114 | 114 | Yii::$app->cache->delete($key); |
| 115 | 115 | } |
| 116 | 116 | |
| 117 | 117 | public function save() { |
| 118 | - if(empty($this->compiled_behaviors)) { |
|
| 118 | + if (empty($this->compiled_behaviors)) { |
|
| 119 | 119 | $this->commpiled_behaviors = $this->compileBehaviors(); |
| 120 | 120 | } |
| 121 | 121 | |
| 122 | 122 | $rows = []; |
| 123 | - foreach($this->compiled_behaviors as $behavior_id) { |
|
| 123 | + foreach ($this->compiled_behaviors as $behavior_id) { |
|
| 124 | 124 | $temp = [ |
| 125 | 125 | Yii::$app->user->id, |
| 126 | 126 | (int)$behavior_id, |
@@ -69,17 +69,17 @@ |
||
| 69 | 69 | */ |
| 70 | 70 | public function saveProfile() { |
| 71 | 71 | if ($this->validate()) { |
| 72 | - $user = $this->user; |
|
| 72 | + $user = $this->user; |
|
| 73 | 73 | |
| 74 | - if($this->timezone) { |
|
| 74 | + if ($this->timezone) { |
|
| 75 | 75 | $user->timezone = $this->timezone; |
| 76 | 76 | } |
| 77 | - if($this->send_email) { |
|
| 77 | + if ($this->send_email) { |
|
| 78 | 78 | $user->send_email = true; |
| 79 | 79 | } else { |
| 80 | 80 | $user->send_email = false; |
| 81 | 81 | } |
| 82 | - if($this->send_email) { |
|
| 82 | + if ($this->send_email) { |
|
| 83 | 83 | $user->partner_email1 = $this->partner_email1; |
| 84 | 84 | $user->partner_email2 = $this->partner_email2; |
| 85 | 85 | $user->partner_email3 = $this->partner_email3; |
@@ -36,13 +36,13 @@ discard block |
||
| 36 | 36 | * @return \DateTime the parsed time or the default value |
| 37 | 37 | */ |
| 38 | 38 | public function parse($time, $default = false, string $format = 'Y-m-d') { |
| 39 | - if(is_string($time)) { |
|
| 39 | + if (is_string($time)) { |
|
| 40 | 40 | $dt = DateTime::createFromFormat($format, $time, new DateTimeZone($this->timezone)); |
| 41 | - if($dt) { |
|
| 41 | + if ($dt) { |
|
| 42 | 42 | // for some reason, using createFromFromat adds in the time. The regular DateTime constructor _does not_ do this. We manually zero out the time here to make the DateTime objects match. |
| 43 | 43 | $dt->setTime(0, 0, 0); |
| 44 | 44 | $formatted = $dt->format($format); |
| 45 | - if($formatted === $time && $this->inBounds($dt)) { |
|
| 45 | + if ($formatted === $time && $this->inBounds($dt)) { |
|
| 46 | 46 | return $dt; |
| 47 | 47 | } |
| 48 | 48 | } |
@@ -62,7 +62,7 @@ discard block |
||
| 62 | 62 | $test = strtotime($dt->format('Y-m-d')); |
| 63 | 63 | $now = strtotime($this->getLocalDate()); |
| 64 | 64 | |
| 65 | - if($first <= $test && $test <= $now) { |
|
| 65 | + if ($first <= $test && $test <= $now) { |
|
| 66 | 66 | return true; |
| 67 | 67 | } else { |
| 68 | 68 | return false; |
@@ -86,7 +86,7 @@ discard block |
||
| 86 | 86 | } |
| 87 | 87 | |
| 88 | 88 | public function getLocalTime($timezone = null) { |
| 89 | - if($timezone === null) |
|
| 89 | + if ($timezone === null) |
|
| 90 | 90 | $timezone = $this->timezone; |
| 91 | 91 | |
| 92 | 92 | $timestamp = new DateTime("now", new DateTimeZone($timezone)); |
@@ -94,7 +94,7 @@ discard block |
||
| 94 | 94 | } |
| 95 | 95 | |
| 96 | 96 | public function getLocalDate($timezone = null) { |
| 97 | - if($timezone === null) |
|
| 97 | + if ($timezone === null) |
|
| 98 | 98 | $timezone = $this->timezone; |
| 99 | 99 | |
| 100 | 100 | return (new DateTime("now", new DateTimeZone($timezone))) |
@@ -108,7 +108,7 @@ discard block |
||
| 108 | 108 | |
| 109 | 109 | public function getUTCBookends($local) { |
| 110 | 110 | $local = trim($local); |
| 111 | - if(strpos($local, " ")) { |
|
| 111 | + if (strpos($local, " ")) { |
|
| 112 | 112 | return false; |
| 113 | 113 | } |
| 114 | 114 | |
@@ -130,9 +130,9 @@ discard block |
||
| 130 | 130 | * @return string a date string |
| 131 | 131 | */ |
| 132 | 132 | public function validate($date) { |
| 133 | - if(is_null($date)) { |
|
| 133 | + if (is_null($date)) { |
|
| 134 | 134 | return $this->getLocalDate(); |
| 135 | - } else if($dt = $this->parse($date)) { |
|
| 135 | + } else if ($dt = $this->parse($date)) { |
|
| 136 | 136 | return $dt->format('Y-m-d'); |
| 137 | 137 | } else { |
| 138 | 138 | return $this->getLocalDate(); |
@@ -149,7 +149,7 @@ discard block |
||
| 149 | 149 | $start = $dt2->sub(new \DateInterval("P${period}D")); |
| 150 | 150 | $periods = new \DatePeriod($start, new \DateInterval('P1D'), $end); |
| 151 | 151 | $local_tz = new \DateTimeZone($this->timezone); |
| 152 | - foreach($periods as $period) { |
|
| 152 | + foreach ($periods as $period) { |
|
| 153 | 153 | $period->setTimezone($local_tz); |
| 154 | 154 | } |
| 155 | 155 | return $periods; |
@@ -84,7 +84,7 @@ discard block |
||
| 84 | 84 | ->groupBy('date, user_id') |
| 85 | 85 | ->having('user_id = :user_id'); |
| 86 | 86 | $temp_dates = $query->all(); |
| 87 | - foreach($temp_dates as $temp_date) { |
|
| 87 | + foreach ($temp_dates as $temp_date) { |
|
| 88 | 88 | $past_checkin_dates[] = $this->time->convertUTCToLocal($temp_date['date']); |
| 89 | 89 | } |
| 90 | 90 | |
@@ -126,16 +126,16 @@ discard block |
||
| 126 | 126 | } |
| 127 | 127 | |
| 128 | 128 | public function getCheckinBreakdown(\DatePeriod $datetimes) { |
| 129 | - $key = "scores_of_last_month_".Yii::$app->user->id."_".$this->time->getLocalDate(); |
|
| 129 | + $key = "scores_of_last_month_" . Yii::$app->user->id . "_" . $this->time->getLocalDate(); |
|
| 130 | 130 | $scores = Yii::$app->cache->get($key); |
| 131 | 131 | |
| 132 | 132 | /******* REMOVE THIS ********/ |
| 133 | 133 | $scores = false; |
| 134 | 134 | /******* END REMOVE THIS *******/ |
| 135 | 135 | |
| 136 | - if($scores === false) { |
|
| 136 | + if ($scores === false) { |
|
| 137 | 137 | $scores = []; |
| 138 | - foreach($datetimes as $datetime) { |
|
| 138 | + foreach ($datetimes as $datetime) { |
|
| 139 | 139 | $behaviors = self::decorateWithCategory($this->getBehaviorsWithCounts($datetime)); |
| 140 | 140 | $scores[$datetime->format('Y-m-d')] = $this->getBehaviorsByCategory($behaviors); |
| 141 | 141 | } |
@@ -161,7 +161,7 @@ discard block |
||
| 161 | 161 | public function getBehaviorsByCategory(array $decorated_behaviors) { |
| 162 | 162 | $arr = array_reduce($decorated_behaviors, function($acc, $row) { |
| 163 | 163 | $cat_id = $row['behavior']['category']['id']; |
| 164 | - if(array_key_exists($cat_id, $acc)) { |
|
| 164 | + if (array_key_exists($cat_id, $acc)) { |
|
| 165 | 165 | $acc[$cat_id]['count'] += $row['count']; |
| 166 | 166 | } else { |
| 167 | 167 | $acc[$cat_id] = [ |
@@ -178,10 +178,10 @@ discard block |
||
| 178 | 178 | } |
| 179 | 179 | |
| 180 | 180 | public static function decorate(array $uo, $with_category = false) { |
| 181 | - foreach($uo as &$o) { |
|
| 182 | - if($behavior = \common\models\Behavior::getBehavior('id', $o['behavior_id'])) { |
|
| 181 | + foreach ($uo as &$o) { |
|
| 182 | + if ($behavior = \common\models\Behavior::getBehavior('id', $o['behavior_id'])) { |
|
| 183 | 183 | $o['behavior'] = $behavior; |
| 184 | - if($with_category) { |
|
| 184 | + if ($with_category) { |
|
| 185 | 185 | $o['behavior']['category'] = \common\models\Category::getCategory('id', $o['behavior']['category_id']); |
| 186 | 186 | } |
| 187 | 187 | } |
@@ -202,11 +202,11 @@ discard block |
||
| 202 | 202 | ->having('user_id = :user_id') |
| 203 | 203 | ->orderBy('count DESC'); |
| 204 | 204 | |
| 205 | - if($limit instanceof \DateTime) { |
|
| 205 | + if ($limit instanceof \DateTime) { |
|
| 206 | 206 | list($start, $end) = $this->time->getUTCBookends($limit->format('Y-m-d')); |
| 207 | 207 | $query->params += [':start_date' => $start, ':end_date' => $end]; |
| 208 | 208 | $query->where('user_id=:user_id AND date > :start_date AND date <= :end_date'); |
| 209 | - } else if(is_int($limit)) { |
|
| 209 | + } else if (is_int($limit)) { |
|
| 210 | 210 | $query->limit($limit); |
| 211 | 211 | } |
| 212 | 212 | |
@@ -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,7 +49,7 @@ discard block |
||
| 49 | 49 | |
| 50 | 50 | return $this->redirect(['questions']); |
| 51 | 51 | } else { |
| 52 | - $behaviors = Yii::$container->get(BehaviorInterface::class)::$behaviors; |
|
| 52 | + $behaviors = Yii::$container->get(BehaviorInterface::class)::$behaviors; |
|
| 53 | 53 | return $this->render('index', [ |
| 54 | 54 | 'categories' => Yii::$container->get(CategoryInterface::class)::$categories, |
| 55 | 55 | 'model' => $form, |
@@ -64,7 +64,7 @@ discard block |
||
| 64 | 64 | $date = Yii::$container->get(TimeInterface::class)->getLocalDate(); |
| 65 | 65 | |
| 66 | 66 | $user_behaviors = $user_behavior->getUserBehaviorsWithCategory($date); |
| 67 | - if(count($user_behaviors) === 0) { |
|
| 67 | + if (count($user_behaviors) === 0) { |
|
| 68 | 68 | return $this->redirect(['view']); |
| 69 | 69 | } |
| 70 | 70 | |
@@ -74,9 +74,9 @@ discard block |
||
| 74 | 74 | $form->deleteToday(); |
| 75 | 75 | |
| 76 | 76 | $behaviors = $user_behavior->findAll($form->getUserBehaviorIds()); |
| 77 | - if($result = $form->saveAnswers($behaviors)) { |
|
| 77 | + if ($result = $form->saveAnswers($behaviors)) { |
|
| 78 | 78 | |
| 79 | - if(Yii::$app->user->identity->send_email) { |
|
| 79 | + if (Yii::$app->user->identity->send_email) { |
|
| 80 | 80 | Yii::$app->user->identity->sendEmailReport($date); |
| 81 | 81 | Yii::$app->session->setFlash('success', 'Your check-in is complete. A notification has been sent to your report partners.'); |
| 82 | 82 | } else { |
@@ -130,7 +130,7 @@ discard block |
||
| 130 | 130 | $raw_pie_data = $user_behavior::decorateWithCategory($user_behavior->getBehaviorsWithCounts()); |
| 131 | 131 | $answer_pie = $user_behavior->getBehaviorsByCategory($raw_pie_data); |
| 132 | 132 | |
| 133 | - $pie_data = [ |
|
| 133 | + $pie_data = [ |
|
| 134 | 134 | "labels" => array_column($answer_pie, "name"), |
| 135 | 135 | "datasets" => [[ |
| 136 | 136 | "data" => array_map('intval', array_column($answer_pie, "count")), |
@@ -166,14 +166,14 @@ discard block |
||
| 166 | 166 | $scores = $user_behavior->getCheckInBreakdown($time->getDateTimesInPeriod($period)); |
| 167 | 167 | |
| 168 | 168 | $accum = []; |
| 169 | - foreach($scores as $date => $cats) { |
|
| 170 | - for($i = 1; $i <= 7; $i ++) { |
|
| 169 | + foreach ($scores as $date => $cats) { |
|
| 170 | + for ($i = 1; $i <= 7; $i++) { |
|
| 171 | 171 | $accum[$i][] = array_key_exists($i, $cats) ? $cats[$i]['count'] : []; |
| 172 | 172 | } |
| 173 | 173 | } |
| 174 | 174 | |
| 175 | 175 | $bar_datasets = []; |
| 176 | - foreach($accum as $idx => $data) { |
|
| 176 | + foreach ($accum as $idx => $data) { |
|
| 177 | 177 | $bar_datasets[] = [ |
| 178 | 178 | 'label' => ($category::getCategories())[$idx], |
| 179 | 179 | 'backgroundColor' => $category::$colors[$idx]['color'], |
@@ -70,7 +70,7 @@ |
||
| 70 | 70 | ]); ?> |
| 71 | 71 | <?= $form->field($profile, 'timezone')->dropDownList(array_combine($timezones, $timezones)); ?> |
| 72 | 72 | <?= $form->field($profile, 'send_email')->checkbox() ?> |
| 73 | - <div id='send_email_fields' <?php if(!$profile->send_email) { ?>style="display: none;"<?php } ?>> |
|
| 73 | + <div id='send_email_fields' <?php if (!$profile->send_email) { ?>style="display: none;"<?php } ?>> |
|
| 74 | 74 | <?= $form->field($profile, 'partner_email1')->input('email'); ?> |
| 75 | 75 | <?= $form->field($profile, 'partner_email2')->input('email'); ?> |
| 76 | 76 | <?= $form->field($profile, 'partner_email3')->input('email'); ?> |