@@ -27,7 +27,7 @@ discard block |
||
| 27 | 27 | 'allow' => true, |
| 28 | 28 | 'roles' => ['@'], |
| 29 | 29 | ], [ |
| 30 | - 'actions' => [ 'change-email', ], |
|
| 30 | + 'actions' => ['change-email', ], |
|
| 31 | 31 | 'allow' => true, |
| 32 | 32 | ], |
| 33 | 33 | ], |
@@ -58,7 +58,7 @@ discard block |
||
| 58 | 58 | |
| 59 | 59 | if ($editProfileForm->load(Yii::$app->request->post())) { |
| 60 | 60 | $saved_user = $editProfileForm->saveProfile(); |
| 61 | - if($saved_user) { |
|
| 61 | + if ($saved_user) { |
|
| 62 | 62 | Yii::$app->session->setFlash('success', 'New profile data saved!'); |
| 63 | 63 | } |
| 64 | 64 | } |
@@ -78,7 +78,7 @@ discard block |
||
| 78 | 78 | $model = Yii::$container->get(\site\models\DeleteAccountForm::class, [Yii::$app->user->identity]); |
| 79 | 79 | |
| 80 | 80 | if ($model->load(Yii::$app->request->post()) && $model->validate()) { |
| 81 | - if($model->deleteAccount()) { |
|
| 81 | + if ($model->deleteAccount()) { |
|
| 82 | 82 | $this->redirect(['site/index']); |
| 83 | 83 | } else { |
| 84 | 84 | Yii::$app->session->setFlash('error', 'Wrong password!'); |
@@ -92,7 +92,7 @@ discard block |
||
| 92 | 92 | $model = Yii::$container->get(\site\models\ChangePasswordForm::class, [Yii::$app->user->identity]); |
| 93 | 93 | |
| 94 | 94 | if ($model->load(Yii::$app->request->post())) { |
| 95 | - if($model->validate() && $model->changePassword()) { |
|
| 95 | + if ($model->validate() && $model->changePassword()) { |
|
| 96 | 96 | Yii::$app->session->setFlash('success', 'Password successfully changed'); |
| 97 | 97 | } else { |
| 98 | 98 | Yii::$app->session->setFlash('error', 'Wrong password!'); |
@@ -116,14 +116,14 @@ discard block |
||
| 116 | 116 | public function actionChangeEmail(string $token) { |
| 117 | 117 | $user = Yii::$container->get(\common\interfaces\UserInterface::class)->findByChangeEmailToken($token); |
| 118 | 118 | |
| 119 | - if($user) { |
|
| 119 | + if ($user) { |
|
| 120 | 120 | $validator = new \yii\validators\EmailValidator(); |
| 121 | - if($validator->validate($user->desired_email, $error)) { |
|
| 121 | + if ($validator->validate($user->desired_email, $error)) { |
|
| 122 | 122 | $user->removeChangeEmailToken(); |
| 123 | 123 | $user->email = $user->desired_email; |
| 124 | 124 | $user->desired_email = null; |
| 125 | 125 | $user->save(); |
| 126 | - if(!Yii::$app->user->isGuest) { |
|
| 126 | + if (!Yii::$app->user->isGuest) { |
|
| 127 | 127 | Yii::$app->user->logout(); |
| 128 | 128 | Yii::$app->session->setFlash('success', 'Your email address was successfully changed. For security, we\'ve logged you out.'); |
| 129 | 129 | } else { |
@@ -143,7 +143,7 @@ discard block |
||
| 143 | 143 | |
| 144 | 144 | public function actionExport() { |
| 145 | 145 | header("Content-Type: text/csv"); |
| 146 | - header("Content-Disposition: attachment; filename=fsa-data-export-".Yii::$app->user->identity->email."-".date('Ymd').".csv"); |
|
| 146 | + header("Content-Disposition: attachment; filename=fsa-data-export-" . Yii::$app->user->identity->email . "-" . date('Ymd') . ".csv"); |
|
| 147 | 147 | |
| 148 | 148 | $reader = Yii::$app->user->identity->getExportData(); |
| 149 | 149 | $fp = fopen('php://output', 'w'); |
@@ -159,7 +159,7 @@ discard block |
||
| 159 | 159 | |
| 160 | 160 | fputcsv($fp, $header); |
| 161 | 161 | $user_behavior = Yii::$container->get(\common\interfaces\UserBehaviorInterface::class); |
| 162 | - while($row = $reader->read()) { |
|
| 162 | + while ($row = $reader->read()) { |
|
| 163 | 163 | $row = $user_behavior::decorate([$row]); |
| 164 | 164 | $row = Yii::$app->user->identity->cleanExportRow($row[0]); |
| 165 | 165 | fputcsv($fp, $row); |
@@ -157,15 +157,15 @@ |
||
| 157 | 157 | |
| 158 | 158 | public function setUp() { |
| 159 | 159 | $this->question = $this->getMockBuilder('\common\models\Question') |
| 160 | - ->setMethods(['save', 'attributes']) |
|
| 161 | - ->getMock(); |
|
| 160 | + ->setMethods(['save', 'attributes']) |
|
| 161 | + ->getMock(); |
|
| 162 | 162 | } |
| 163 | 163 | |
| 164 | 164 | public function testParseQuestionData() { |
| 165 | 165 | $questions = array_map(function ($d) { |
| 166 | 166 | $q = $this->getMockBuilder('\common\models\Question') |
| 167 | - ->setMethods(['save', 'attributes']) |
|
| 168 | - ->getMock(); |
|
| 167 | + ->setMethods(['save', 'attributes']) |
|
| 168 | + ->getMock(); |
|
| 169 | 169 | $q->method('save')->willReturn(true); |
| 170 | 170 | $q->method('attributes') |
| 171 | 171 | ->willReturn([ |
@@ -162,7 +162,7 @@ discard block |
||
| 162 | 162 | } |
| 163 | 163 | |
| 164 | 164 | public function testParseQuestionData() { |
| 165 | - $questions = array_map(function ($d) { |
|
| 165 | + $questions = array_map(function($d) { |
|
| 166 | 166 | $q = $this->getMockBuilder('\common\models\Question') |
| 167 | 167 | ->setMethods(['save', 'attributes']) |
| 168 | 168 | ->getMock(); |
@@ -179,8 +179,8 @@ discard block |
||
| 179 | 179 | 'date', |
| 180 | 180 | 'userBehavior', |
| 181 | 181 | ]); |
| 182 | - foreach($d as $k => $v) { |
|
| 183 | - if($k === 'behavior_id' && $v === null) { |
|
| 182 | + foreach ($d as $k => $v) { |
|
| 183 | + if ($k === 'behavior_id' && $v === null) { |
|
| 184 | 184 | $ub = new \StdClass(); |
| 185 | 185 | $ub->custom_behavior = 'some_custom_behavior'; |
| 186 | 186 | $q->userBehavior = $ub; |
@@ -92,7 +92,7 @@ discard block |
||
| 92 | 92 | ->groupBy('date, user_id') |
| 93 | 93 | ->having('user_id = :user_id'); |
| 94 | 94 | $temp_dates = $query->all(); |
| 95 | - foreach($temp_dates as $temp_date) { |
|
| 95 | + foreach ($temp_dates as $temp_date) { |
|
| 96 | 96 | $past_checkin_dates[] = $this->time->convertUTCToLocal($temp_date['date']); |
| 97 | 97 | } |
| 98 | 98 | |
@@ -121,12 +121,12 @@ discard block |
||
| 121 | 121 | |
| 122 | 122 | public function getCheckinBreakdown(int $period = 30) { |
| 123 | 123 | $datetimes = $this->time->getDateTimesInPeriod($period); |
| 124 | - $key = "checkins_".Yii::$app->user->id."_{$period}_".$this->time->getLocalDate(); |
|
| 124 | + $key = "checkins_" . Yii::$app->user->id . "_{$period}_" . $this->time->getLocalDate(); |
|
| 125 | 125 | $checkins = Yii::$app->cache->get($key); |
| 126 | 126 | |
| 127 | - if($checkins === false) { |
|
| 127 | + if ($checkins === false) { |
|
| 128 | 128 | $checkins = []; |
| 129 | - foreach($datetimes as $datetime) { |
|
| 129 | + foreach ($datetimes as $datetime) { |
|
| 130 | 130 | $behaviors = self::decorate($this->getBehaviorsWithCounts($datetime)); |
| 131 | 131 | $checkins[$datetime->format('Y-m-d')] = $this->getBehaviorsByCategory($behaviors); |
| 132 | 132 | } |
@@ -152,7 +152,7 @@ discard block |
||
| 152 | 152 | public function getBehaviorsByCategory(array $decorated_behaviors) { |
| 153 | 153 | $arr = array_reduce($decorated_behaviors, function($acc, $row) { |
| 154 | 154 | $cat_id = $row['category_id']; |
| 155 | - if(array_key_exists($cat_id, $acc)) { |
|
| 155 | + if (array_key_exists($cat_id, $acc)) { |
|
| 156 | 156 | $acc[$cat_id]['count'] += $row['count']; |
| 157 | 157 | } else { |
| 158 | 158 | $acc[$cat_id] = [ |
@@ -184,11 +184,11 @@ discard block |
||
| 184 | 184 | ->having('user_id = :user_id') |
| 185 | 185 | ->orderBy('count DESC'); |
| 186 | 186 | |
| 187 | - if($limit instanceof \DateTime) { |
|
| 187 | + if ($limit instanceof \DateTime) { |
|
| 188 | 188 | list($start, $end) = $this->time->getUTCBookends($limit->format('Y-m-d')); |
| 189 | 189 | $query->params += [':start_date' => $start, ':end_date' => $end]; |
| 190 | 190 | $query->where('user_id=:user_id AND date > :start_date AND date <= :end_date'); |
| 191 | - } else if(is_int($limit)) { |
|
| 191 | + } else if (is_int($limit)) { |
|
| 192 | 192 | $query->limit($limit); |
| 193 | 193 | } |
| 194 | 194 | return $query->all(); |
@@ -202,7 +202,7 @@ discard block |
||
| 202 | 202 | * @return array |
| 203 | 203 | */ |
| 204 | 204 | public function getByDate(int $user_id, $local_date = null) { |
| 205 | - if(is_null($local_date)) $local_date = $this->time->getLocalDate(); |
|
| 205 | + if (is_null($local_date)) $local_date = $this->time->getLocalDate(); |
|
| 206 | 206 | |
| 207 | 207 | $behaviors = $this->getBehaviorData($user_id, $local_date); |
| 208 | 208 | $behaviors = self::decorate($behaviors); |
@@ -215,13 +215,13 @@ discard block |
||
| 215 | 215 | * @return an array of decorated UserBehaviors, each with an added Category and Behavior |
| 216 | 216 | */ |
| 217 | 217 | public static function decorate(array $uo) { |
| 218 | - foreach($uo as &$o) { |
|
| 218 | + foreach ($uo as &$o) { |
|
| 219 | 219 | $behavior = \common\models\Behavior::getBehavior('id', $o['behavior_id']); |
| 220 | 220 | $category = \common\models\Category::getCategory('id', $o['category_id']); |
| 221 | - if($behavior) { |
|
| 221 | + if ($behavior) { |
|
| 222 | 222 | $o['behavior'] = $behavior; |
| 223 | 223 | } |
| 224 | - if($category) { |
|
| 224 | + if ($category) { |
|
| 225 | 225 | $o['category'] = $category; |
| 226 | 226 | } |
| 227 | 227 | } |
@@ -247,10 +247,10 @@ discard block |
||
| 247 | 247 | |
| 248 | 248 | // TODO: this should probably be a private method...but unit testing is hard |
| 249 | 249 | public function parseBehaviorData($behaviors) { |
| 250 | - if(!$behaviors) return []; |
|
| 250 | + if (!$behaviors) return []; |
|
| 251 | 251 | |
| 252 | 252 | $bhvrs_by_cat = []; |
| 253 | - foreach($behaviors as $behavior) { |
|
| 253 | + foreach ($behaviors as $behavior) { |
|
| 254 | 254 | $indx = $behavior['category_id']; |
| 255 | 255 | |
| 256 | 256 | $bname = AH::getValue($behavior, 'behavior.name', AH::getValue($behavior, 'custom_behavior')); |
@@ -523,26 +523,26 @@ |
||
| 523 | 523 | } |
| 524 | 524 | |
| 525 | 525 | public function cleanExportRow($row) { |
| 526 | - // change timestamp to local time (for the user) |
|
| 527 | - $row['date'] = $this->time->convertUTCToLocal($row['date'], false); |
|
| 528 | - |
|
| 529 | - // clean up things we don't need |
|
| 530 | - $row['category'] = $row['category']['name']; |
|
| 531 | - if(array_key_exists('behavior', $row)) { |
|
| 532 | - $row['behavior'] = $row['behavior']['name']; |
|
| 533 | - } else { |
|
| 534 | - $row['behavior'] = $row['custom_behavior']; |
|
| 535 | - } |
|
| 536 | - unset($row['id']); |
|
| 537 | - unset($row['behavior_id']); |
|
| 538 | - unset($row['category_id']); |
|
| 539 | - unset($row['custom_behavior']); |
|
| 540 | - |
|
| 541 | - // sort the array into a sensible order |
|
| 542 | - uksort($row, function($a, $b) { |
|
| 543 | - return $this->export_order[$a] <=> $this->export_order[$b]; |
|
| 544 | - }); |
|
| 545 | - return $row; |
|
| 526 | + // change timestamp to local time (for the user) |
|
| 527 | + $row['date'] = $this->time->convertUTCToLocal($row['date'], false); |
|
| 528 | + |
|
| 529 | + // clean up things we don't need |
|
| 530 | + $row['category'] = $row['category']['name']; |
|
| 531 | + if(array_key_exists('behavior', $row)) { |
|
| 532 | + $row['behavior'] = $row['behavior']['name']; |
|
| 533 | + } else { |
|
| 534 | + $row['behavior'] = $row['custom_behavior']; |
|
| 535 | + } |
|
| 536 | + unset($row['id']); |
|
| 537 | + unset($row['behavior_id']); |
|
| 538 | + unset($row['category_id']); |
|
| 539 | + unset($row['custom_behavior']); |
|
| 540 | + |
|
| 541 | + // sort the array into a sensible order |
|
| 542 | + uksort($row, function($a, $b) { |
|
| 543 | + return $this->export_order[$a] <=> $this->export_order[$b]; |
|
| 544 | + }); |
|
| 545 | + return $row; |
|
| 546 | 546 | } |
| 547 | 547 | |
| 548 | 548 | /* |
@@ -152,7 +152,7 @@ discard block |
||
| 152 | 152 | */ |
| 153 | 153 | public function findByPasswordResetToken($token) |
| 154 | 154 | { |
| 155 | - if(!$this->isTokenCurrent($token)) { |
|
| 155 | + if (!$this->isTokenCurrent($token)) { |
|
| 156 | 156 | return null; |
| 157 | 157 | } |
| 158 | 158 | |
@@ -170,15 +170,15 @@ discard block |
||
| 170 | 170 | */ |
| 171 | 171 | public function findByVerifyEmailToken($token) |
| 172 | 172 | { |
| 173 | - if($this->isTokenConfirmed($token)) return null; |
|
| 173 | + if ($this->isTokenConfirmed($token)) return null; |
|
| 174 | 174 | |
| 175 | 175 | $user = $this->find()->where([ |
| 176 | 176 | 'verify_email_token' => [$token, $token . self::CONFIRMED_STRING], |
| 177 | 177 | 'status' => self::STATUS_ACTIVE, |
| 178 | 178 | ])->one(); |
| 179 | 179 | |
| 180 | - if($user) { |
|
| 181 | - if(!$this->isTokenConfirmed($token) && |
|
| 180 | + if ($user) { |
|
| 181 | + if (!$this->isTokenConfirmed($token) && |
|
| 182 | 182 | !$this->isTokenCurrent($token, 'user.verifyAccountTokenExpire')) { |
| 183 | 183 | return null; |
| 184 | 184 | } |
@@ -200,8 +200,8 @@ discard block |
||
| 200 | 200 | 'status' => self::STATUS_ACTIVE, |
| 201 | 201 | ])->one(); |
| 202 | 202 | |
| 203 | - if($user) { |
|
| 204 | - if(!$user->isTokenCurrent($token, 'user.verifyAccountTokenExpire')) { |
|
| 203 | + if ($user) { |
|
| 204 | + if (!$user->isTokenCurrent($token, 'user.verifyAccountTokenExpire')) { |
|
| 205 | 205 | return null; |
| 206 | 206 | } |
| 207 | 207 | } |
@@ -219,7 +219,7 @@ discard block |
||
| 219 | 219 | public function isTokenCurrent($token, String $paramPath = 'user.passwordResetTokenExpire') { |
| 220 | 220 | $expire = \Yii::$app->params[$paramPath]; |
| 221 | 221 | $parts = explode('_', $token); |
| 222 | - $timestamp = (int) end($parts); |
|
| 222 | + $timestamp = (int)end($parts); |
|
| 223 | 223 | if ($timestamp + $expire < time()) { |
| 224 | 224 | // token expired |
| 225 | 225 | return false; |
@@ -234,7 +234,7 @@ discard block |
||
| 234 | 234 | * @param string $match the needle to search for |
| 235 | 235 | */ |
| 236 | 236 | public function isTokenConfirmed($token = null, String $match = self::CONFIRMED_STRING) { |
| 237 | - if(is_null($token)) $token = $this->verify_email_token; |
|
| 237 | + if (is_null($token)) $token = $this->verify_email_token; |
|
| 238 | 238 | return substr($token, -strlen($match)) === $match; |
| 239 | 239 | } |
| 240 | 240 | |
@@ -261,7 +261,7 @@ discard block |
||
| 261 | 261 | } |
| 262 | 262 | |
| 263 | 263 | public function isVerified() { |
| 264 | - if(is_null($this->verify_email_token)) { |
|
| 264 | + if (is_null($this->verify_email_token)) { |
|
| 265 | 265 | // for old users who verified their accounts before the addition of |
| 266 | 266 | // '_confirmed' to the token |
| 267 | 267 | return true; |
@@ -380,7 +380,7 @@ discard block |
||
| 380 | 380 | * partner email address the user has set. |
| 381 | 381 | */ |
| 382 | 382 | public function sendEmailReport($date) { |
| 383 | - if(!$this->send_email) return false; // no partner emails set |
|
| 383 | + if (!$this->send_email) return false; // no partner emails set |
|
| 384 | 384 | list($start, $end) = $this->time->getUTCBookends($date); |
| 385 | 385 | |
| 386 | 386 | $user_behavior = Yii::$container->get(UserBehaviorInterface::class); |
@@ -389,14 +389,14 @@ discard block |
||
| 389 | 389 | // we should only proceed with sending the email if the user |
| 390 | 390 | // scored above their set email threshold (User::email_category) |
| 391 | 391 | $this_checkin = $checkins_last_month[$date]; // gets the check-in |
| 392 | - if(!$this_checkin) return false; // sanity check |
|
| 393 | - $highest_cat_data = end($this_checkin); // gets the data for the highest category from the check-in |
|
| 394 | - if(!$highest_cat_data) return false; // another sanity check |
|
| 395 | - $highest_cat_idx = key($this_checkin); // gets the key of the highest category |
|
| 392 | + if (!$this_checkin) return false; // sanity check |
|
| 393 | + $highest_cat_data = end($this_checkin); // gets the data for the highest category from the check-in |
|
| 394 | + if (!$highest_cat_data) return false; // another sanity check |
|
| 395 | + $highest_cat_idx = key($this_checkin); // gets the key of the highest category |
|
| 396 | 396 | |
| 397 | 397 | // if the highest category they reached today was less than |
| 398 | 398 | // the category threshold they have set, don't send the email |
| 399 | - if($highest_cat_idx < $this->email_category) return false; |
|
| 399 | + if ($highest_cat_idx < $this->email_category) return false; |
|
| 400 | 400 | |
| 401 | 401 | $user_behaviors = $user_behavior->getByDate(Yii::$app->user->id, $date); |
| 402 | 402 | |
@@ -408,8 +408,8 @@ discard block |
||
| 408 | 408 | ->create($checkins_last_month); |
| 409 | 409 | |
| 410 | 410 | $messages = []; |
| 411 | - foreach($this->getPartnerEmails() as $email) { |
|
| 412 | - if($email) { |
|
| 411 | + foreach ($this->getPartnerEmails() as $email) { |
|
| 412 | + if ($email) { |
|
| 413 | 413 | $messages[] = Yii::$app->mailer->compose('checkinReport', [ |
| 414 | 414 | 'user' => $this, |
| 415 | 415 | 'email' => $email, |
@@ -421,7 +421,7 @@ discard block |
||
| 421 | 421 | 'behaviors_list' => \common\models\Behavior::$behaviors, |
| 422 | 422 | ])->setFrom([Yii::$app->params['supportEmail'] => Yii::$app->name]) |
| 423 | 423 | ->setReplyTo($this->email) |
| 424 | - ->setSubject($this->email." has completed a Faster Scale check-in") |
|
| 424 | + ->setSubject($this->email . " has completed a Faster Scale check-in") |
|
| 425 | 425 | ->setTo($email); |
| 426 | 426 | } |
| 427 | 427 | } |
@@ -498,7 +498,7 @@ discard block |
||
| 498 | 498 | return \Yii::$app->mailer->compose('signupNotification') |
| 499 | 499 | ->setFrom([\Yii::$app->params['supportEmail'] => \Yii::$app->name]) |
| 500 | 500 | ->setTo(\Yii::$app->params['adminEmail']) |
| 501 | - ->setSubject('A new user has signed up for '.\Yii::$app->name) |
|
| 501 | + ->setSubject('A new user has signed up for ' . \Yii::$app->name) |
|
| 502 | 502 | ->send(); |
| 503 | 503 | } |
| 504 | 504 | |
@@ -506,20 +506,20 @@ discard block |
||
| 506 | 506 | return \Yii::$app->mailer->compose('verifyEmail', ['user' => $this]) |
| 507 | 507 | ->setFrom([\Yii::$app->params['supportEmail'] => \Yii::$app->name]) |
| 508 | 508 | ->setTo($this->email) |
| 509 | - ->setSubject('Please verify your '.\Yii::$app->name .' account') |
|
| 509 | + ->setSubject('Please verify your ' . \Yii::$app->name . ' account') |
|
| 510 | 510 | ->send(); |
| 511 | 511 | } |
| 512 | 512 | |
| 513 | 513 | public function sendDeleteNotificationEmail() { |
| 514 | 514 | $messages = []; |
| 515 | - foreach(array_merge([$this->email], $this->getPartnerEmails()) as $email) { |
|
| 516 | - if($email) { |
|
| 515 | + foreach (array_merge([$this->email], $this->getPartnerEmails()) as $email) { |
|
| 516 | + if ($email) { |
|
| 517 | 517 | $messages[] = Yii::$app->mailer->compose('deleteNotification', [ |
| 518 | 518 | 'user' => $this, |
| 519 | 519 | 'email' => $email |
| 520 | 520 | ])->setFrom([Yii::$app->params['supportEmail'] => Yii::$app->name]) |
| 521 | 521 | ->setReplyTo($this->email) |
| 522 | - ->setSubject($this->email." has deleted their The Faster Scale App account") |
|
| 522 | + ->setSubject($this->email . " has deleted their The Faster Scale App account") |
|
| 523 | 523 | ->setTo($email); |
| 524 | 524 | } |
| 525 | 525 | } |
@@ -533,7 +533,7 @@ discard block |
||
| 533 | 533 | |
| 534 | 534 | // clean up things we don't need |
| 535 | 535 | $row['category'] = $row['category']['name']; |
| 536 | - if(array_key_exists('behavior', $row)) { |
|
| 536 | + if (array_key_exists('behavior', $row)) { |
|
| 537 | 537 | $row['behavior'] = $row['behavior']['name']; |
| 538 | 538 | } else { |
| 539 | 539 | $row['behavior'] = $row['custom_behavior']; |
@@ -569,7 +569,7 @@ discard block |
||
| 569 | 569 | return rtrim( |
| 570 | 570 | strtr( |
| 571 | 571 | base64_encode( |
| 572 | - hash('sha256', $this->id."::".$this->created_at, true) |
|
| 572 | + hash('sha256', $this->id . "::" . $this->created_at, true) |
|
| 573 | 573 | ), |
| 574 | 574 | '+/', '-_'), |
| 575 | 575 | '='); |
@@ -170,7 +170,9 @@ discard block |
||
| 170 | 170 | */ |
| 171 | 171 | public function findByVerifyEmailToken($token) |
| 172 | 172 | { |
| 173 | - if($this->isTokenConfirmed($token)) return null; |
|
| 173 | + if($this->isTokenConfirmed($token)) { |
|
| 174 | + return null; |
|
| 175 | + } |
|
| 174 | 176 | |
| 175 | 177 | $user = $this->find()->where([ |
| 176 | 178 | 'verify_email_token' => [$token, $token . self::CONFIRMED_STRING], |
@@ -234,7 +236,9 @@ discard block |
||
| 234 | 236 | * @param string $match the needle to search for |
| 235 | 237 | */ |
| 236 | 238 | public function isTokenConfirmed($token = null, String $match = self::CONFIRMED_STRING) { |
| 237 | - if(is_null($token)) $token = $this->verify_email_token; |
|
| 239 | + if(is_null($token)) { |
|
| 240 | + $token = $this->verify_email_token; |
|
| 241 | + } |
|
| 238 | 242 | return substr($token, -strlen($match)) === $match; |
| 239 | 243 | } |
| 240 | 244 | |
@@ -380,7 +384,10 @@ discard block |
||
| 380 | 384 | * partner email address the user has set. |
| 381 | 385 | */ |
| 382 | 386 | public function sendEmailReport($date) { |
| 383 | - if(!$this->send_email) return false; // no partner emails set |
|
| 387 | + if(!$this->send_email) { |
|
| 388 | + return false; |
|
| 389 | + } |
|
| 390 | + // no partner emails set |
|
| 384 | 391 | list($start, $end) = $this->time->getUTCBookends($date); |
| 385 | 392 | |
| 386 | 393 | $user_behavior = Yii::$container->get(UserBehaviorInterface::class); |
@@ -389,14 +396,22 @@ discard block |
||
| 389 | 396 | // we should only proceed with sending the email if the user |
| 390 | 397 | // scored above their set email threshold (User::email_category) |
| 391 | 398 | $this_checkin = $checkins_last_month[$date]; // gets the check-in |
| 392 | - if(!$this_checkin) return false; // sanity check |
|
| 399 | + if(!$this_checkin) { |
|
| 400 | + return false; |
|
| 401 | + } |
|
| 402 | + // sanity check |
|
| 393 | 403 | $highest_cat_data = end($this_checkin); // gets the data for the highest category from the check-in |
| 394 | - if(!$highest_cat_data) return false; // another sanity check |
|
| 404 | + if(!$highest_cat_data) { |
|
| 405 | + return false; |
|
| 406 | + } |
|
| 407 | + // another sanity check |
|
| 395 | 408 | $highest_cat_idx = key($this_checkin); // gets the key of the highest category |
| 396 | 409 | |
| 397 | 410 | // if the highest category they reached today was less than |
| 398 | 411 | // the category threshold they have set, don't send the email |
| 399 | - if($highest_cat_idx < $this->email_category) return false; |
|
| 412 | + if($highest_cat_idx < $this->email_category) { |
|
| 413 | + return false; |
|
| 414 | + } |
|
| 400 | 415 | |
| 401 | 416 | $user_behaviors = $user_behavior->getByDate(Yii::$app->user->id, $date); |
| 402 | 417 | |
@@ -52,7 +52,7 @@ discard block |
||
| 52 | 52 | |
| 53 | 53 | public function __construct(QuestionInterface $question, |
| 54 | 54 | $config = []) { |
| 55 | - $this->question = $question; |
|
| 55 | + $this->question = $question; |
|
| 56 | 56 | parent::__construct($config); |
| 57 | 57 | } |
| 58 | 58 | |
@@ -70,7 +70,7 @@ discard block |
||
| 70 | 70 | 'whenClient' => "function(attribute, value) { return false; }", // lame, but acceptable |
| 71 | 71 | "message" => "You must select a behavior your responses apply to."], |
| 72 | 72 | |
| 73 | - [['answer_1a','answer_1b','answer_1c','answer_2a','answer_2b','answer_2c','answer_3a','answer_3b','answer_3c','answer_4a','answer_4b','answer_4c','answer_5a', 'answer_5b','answer_5c','answer_6a', 'answer_6b','answer_6c','answer_7a','answer_7b','answer_7c'], 'safe'] |
|
| 73 | + [['answer_1a', 'answer_1b', 'answer_1c', 'answer_2a', 'answer_2b', 'answer_2c', 'answer_3a', 'answer_3b', 'answer_3c', 'answer_4a', 'answer_4b', 'answer_4c', 'answer_5a', 'answer_5b', 'answer_5c', 'answer_6a', 'answer_6b', 'answer_6c', 'answer_7a', 'answer_7b', 'answer_7c'], 'safe'] |
|
| 74 | 74 | ]; |
| 75 | 75 | } |
| 76 | 76 | |
@@ -88,10 +88,10 @@ discard block |
||
| 88 | 88 | |
| 89 | 89 | public function getBhvrValidator() { |
| 90 | 90 | return function($model, $attr) { |
| 91 | - $attrNum = $attr[strlen($attr)-1]; |
|
| 92 | - foreach(['a', 'b', 'c'] as $l) { |
|
| 91 | + $attrNum = $attr[strlen($attr) - 1]; |
|
| 92 | + foreach (['a', 'b', 'c'] as $l) { |
|
| 93 | 93 | $attr = "answer_{$attrNum}{$l}"; |
| 94 | - if($model->$attr) return true; |
|
| 94 | + if ($model->$attr) return true; |
|
| 95 | 95 | } |
| 96 | 96 | return false; |
| 97 | 97 | }; |
@@ -122,7 +122,7 @@ discard block |
||
| 122 | 122 | |
| 123 | 123 | public function getPrefixProps($prefix) { |
| 124 | 124 | return array_filter(get_object_vars($this), function($v, $k) use($prefix) { |
| 125 | - if(strpos($k, $prefix) === 0 && strlen($v)) { |
|
| 125 | + if (strpos($k, $prefix) === 0 && strlen($v)) { |
|
| 126 | 126 | return true; |
| 127 | 127 | } |
| 128 | 128 | }, ARRAY_FILTER_USE_BOTH); |
@@ -140,9 +140,9 @@ discard block |
||
| 140 | 140 | public function getAnswers($bhvrs) { |
| 141 | 141 | $answers = []; |
| 142 | 142 | $user_bhvrs = array_combine($this->getUserBehaviorProps(), $bhvrs); |
| 143 | - foreach($user_bhvrs as $property => $user_bhvr) { |
|
| 143 | + foreach ($user_bhvrs as $property => $user_bhvr) { |
|
| 144 | 144 | $behavior_id = intval(substr($property, -1, 1)); |
| 145 | - foreach($this->behaviorToAnswers($behavior_id) as $answer_letter => $answer) { |
|
| 145 | + foreach ($this->behaviorToAnswers($behavior_id) as $answer_letter => $answer) { |
|
| 146 | 146 | $question_id = \common\models\Question::$TYPES[$answer_letter]; |
| 147 | 147 | array_push($answers, [ |
| 148 | 148 | 'behavior_id' => $user_bhvr->behavior_id, |
@@ -159,7 +159,7 @@ discard block |
||
| 159 | 159 | public function saveAnswers(int $user_id, array $bhvrs) { |
| 160 | 160 | $result = true; |
| 161 | 161 | |
| 162 | - foreach($this->getAnswers($bhvrs) as $answer) { |
|
| 162 | + foreach ($this->getAnswers($bhvrs) as $answer) { |
|
| 163 | 163 | $model = Yii::$container->get(\common\interfaces\QuestionInterface::class); |
| 164 | 164 | $model->user_id = $user_id; |
| 165 | 165 | $model->behavior_id = $answer['behavior_id']; |
@@ -168,7 +168,7 @@ discard block |
||
| 168 | 168 | $model->date = new Expression("now()::timestamp"); |
| 169 | 169 | $model->question = $answer['question_id']; |
| 170 | 170 | $model->answer = $answer['answer']; |
| 171 | - if(!$model->save()) { |
|
| 171 | + if (!$model->save()) { |
|
| 172 | 172 | $result = false; |
| 173 | 173 | } |
| 174 | 174 | } |
@@ -37,7 +37,7 @@ discard block |
||
| 37 | 37 | public function actionIndex() { |
| 38 | 38 | $form = Yii::$container->get(\site\models\CheckinForm::class); |
| 39 | 39 | if ($form->load(Yii::$app->request->post()) && $form->validate()) { |
| 40 | - if(!$form->compileBehaviors()) { |
|
| 40 | + if (!$form->compileBehaviors()) { |
|
| 41 | 41 | return $this->redirect(['view']); |
| 42 | 42 | } |
| 43 | 43 | |
@@ -48,7 +48,7 @@ discard block |
||
| 48 | 48 | return $this->redirect(['questions']); |
| 49 | 49 | } |
| 50 | 50 | |
| 51 | - $behaviors = Yii::$container->get(BehaviorInterface::class)::$behaviors; |
|
| 51 | + $behaviors = Yii::$container->get(BehaviorInterface::class)::$behaviors; |
|
| 52 | 52 | $custom = \common\models\CustomBehavior::find()->where(['user_id' => Yii::$app->user->id])->asArray()->all(); |
| 53 | 53 | return $this->render('index', [ |
| 54 | 54 | 'categories' => Yii::$container->get(CategoryInterface::class)::$categories, |
@@ -63,7 +63,7 @@ discard block |
||
| 63 | 63 | $date = Yii::$container->get(TimeInterface::class)->getLocalDate(); |
| 64 | 64 | |
| 65 | 65 | $user_behaviors = $user_behavior->getUserBehaviorsWithCategory($date); |
| 66 | - if(count($user_behaviors) === 0) { |
|
| 66 | + if (count($user_behaviors) === 0) { |
|
| 67 | 67 | return $this->redirect(['view']); |
| 68 | 68 | } |
| 69 | 69 | |
@@ -73,10 +73,10 @@ discard block |
||
| 73 | 73 | $form->deleteToday(Yii::$app->user->id); |
| 74 | 74 | |
| 75 | 75 | $behaviors = $user_behavior->findAll($form->getUserBehaviorIds()); |
| 76 | - if($result = $form->saveAnswers(Yii::$app->user->id, $behaviors)) { |
|
| 76 | + if ($result = $form->saveAnswers(Yii::$app->user->id, $behaviors)) { |
|
| 77 | 77 | |
| 78 | - if(Yii::$app->user->identity->send_email) { |
|
| 79 | - if(Yii::$app->user->identity->sendEmailReport($date)) { |
|
| 78 | + if (Yii::$app->user->identity->send_email) { |
|
| 79 | + if (Yii::$app->user->identity->sendEmailReport($date)) { |
|
| 80 | 80 | Yii::$app->session->setFlash('success', 'Your check-in is complete. A notification has been sent to your report partners.'); |
| 81 | 81 | } else { |
| 82 | 82 | Yii::$app->session->setFlash('success', 'Your check-in is complete.'); |
@@ -132,7 +132,7 @@ discard block |
||
| 132 | 132 | $raw_pie_data = $user_behavior::decorate($user_behavior->getBehaviorsWithCounts()); |
| 133 | 133 | $answer_pie = $user_behavior->getBehaviorsByCategory($raw_pie_data); |
| 134 | 134 | |
| 135 | - $pie_data = [ |
|
| 135 | + $pie_data = [ |
|
| 136 | 136 | "labels" => array_column($answer_pie, "name"), |
| 137 | 137 | "datasets" => [[ |
| 138 | 138 | "data" => array_map('intval', array_column($answer_pie, "count")), |
@@ -167,14 +167,14 @@ discard block |
||
| 167 | 167 | $checkins = $user_behavior->getCheckInBreakdown($period); |
| 168 | 168 | |
| 169 | 169 | $accum = []; |
| 170 | - foreach($checkins as $date => $cats) { |
|
| 171 | - for($i = 1; $i <= 7; $i ++) { |
|
| 170 | + foreach ($checkins as $date => $cats) { |
|
| 171 | + for ($i = 1; $i <= 7; $i++) { |
|
| 172 | 172 | $accum[$i][] = array_key_exists($i, $cats) ? $cats[$i]['count'] : []; |
| 173 | 173 | } |
| 174 | 174 | } |
| 175 | 175 | |
| 176 | 176 | $bar_datasets = []; |
| 177 | - foreach($accum as $idx => $data) { |
|
| 177 | + foreach ($accum as $idx => $data) { |
|
| 178 | 178 | $bar_datasets[] = [ |
| 179 | 179 | 'label' => ($category::getCategories())[$idx], |
| 180 | 180 | 'backgroundColor' => $category::$colors[$idx]['color'], |
@@ -42,7 +42,7 @@ discard block |
||
| 42 | 42 | |
| 43 | 43 | public function actions() { |
| 44 | 44 | return array_replace_recursive(parent::actions(), [ |
| 45 | - 'update' => [ // identifier for your editable column action |
|
| 45 | + 'update' => [// identifier for your editable column action |
|
| 46 | 46 | 'class' => EditableColumnAction::className(), // action class name |
| 47 | 47 | 'modelClass' => CustoMBehavior::className(), // the model for the record being edited |
| 48 | 48 | 'scenario' => CustomBehavior::SCENARIO_DEFAULT, // model scenario assigned before validation & update |
@@ -52,7 +52,7 @@ discard block |
||
| 52 | 52 | 'ajaxOnly' => true, |
| 53 | 53 | 'findModel' => function($id, $action) { |
| 54 | 54 | $model = $this->findModel($id); |
| 55 | - if($model !== null) { |
|
| 55 | + if ($model !== null) { |
|
| 56 | 56 | return $model; |
| 57 | 57 | } |
| 58 | 58 | throw new NotFoundHttpException('The specified behavior does not exist.'); |
@@ -64,13 +64,13 @@ discard block |
||
| 64 | 64 | public function actionCreate() { |
| 65 | 65 | $form = Yii::$container->get(\site\models\CustomBehaviorForm::class, [Yii::$app->user->identity]); |
| 66 | 66 | |
| 67 | - if($form->load(Yii::$app->request->post()) && $form->validate()) { |
|
| 67 | + if ($form->load(Yii::$app->request->post()) && $form->validate()) { |
|
| 68 | 68 | $form->save(); |
| 69 | 69 | return $this->redirect(['profile/index']); |
| 70 | 70 | } |
| 71 | 71 | |
| 72 | 72 | \Yii::$app->response->format = \yii\web\Response::FORMAT_JSON; |
| 73 | - if($errors = $form->getErrorSummary(true)) { |
|
| 73 | + if ($errors = $form->getErrorSummary(true)) { |
|
| 74 | 74 | return $errors; |
| 75 | 75 | } else { |
| 76 | 76 | return ["success" => false, "message" => "Unknown Error"]; |
@@ -85,7 +85,7 @@ discard block |
||
| 85 | 85 | |
| 86 | 86 | protected function findModel($id) { |
| 87 | 87 | $model = CustomBehavior::find()->where(['id' => $id, 'user_id' => Yii::$app->user->id])->one(); |
| 88 | - if($model !== null) { |
|
| 88 | + if ($model !== null) { |
|
| 89 | 89 | return $model; |
| 90 | 90 | } |
| 91 | 91 | |