@@ -513,29 +513,29 @@ |
||
| 513 | 513 | public function cleanExportData($data) { |
| 514 | 514 | var_dump( $data); |
| 515 | 515 | exit(); |
| 516 | - $order = array_flip(["date", "behavior", "category", "question1", "question2", "question3"]); |
|
| 516 | + $order = array_flip(["date", "behavior", "category", "question1", "question2", "question3"]); |
|
| 517 | 517 | |
| 518 | - $ret = array_map( |
|
| 519 | - function($row) use ($order) { |
|
| 520 | - // change timestamp to local time (for the user) |
|
| 521 | - $row['date'] = $this->time->convertUTCToLocal($row['date'], false); |
|
| 518 | + $ret = array_map( |
|
| 519 | + function($row) use ($order) { |
|
| 520 | + // change timestamp to local time (for the user) |
|
| 521 | + $row['date'] = $this->time->convertUTCToLocal($row['date'], false); |
|
| 522 | 522 | |
| 523 | - // clean up things we don't need |
|
| 524 | - $row['category'] = $row['category']['name']; |
|
| 525 | - $row['behavior'] = $row['behavior']['name']; |
|
| 526 | - unset($row['id']); |
|
| 527 | - unset($row['behavior_id']); |
|
| 528 | - unset($row['category_id']); |
|
| 529 | - |
|
| 530 | - // sort the array into a sensible order |
|
| 531 | - uksort($row, function($a, $b) use ($order) { |
|
| 523 | + // clean up things we don't need |
|
| 524 | + $row['category'] = $row['category']['name']; |
|
| 525 | + $row['behavior'] = $row['behavior']['name']; |
|
| 526 | + unset($row['id']); |
|
| 527 | + unset($row['behavior_id']); |
|
| 528 | + unset($row['category_id']); |
|
| 529 | + |
|
| 530 | + // sort the array into a sensible order |
|
| 531 | + uksort($row, function($a, $b) use ($order) { |
|
| 532 | 532 | return $order[$a] <=> $order[$b]; |
| 533 | - }); |
|
| 534 | - return $row; |
|
| 535 | - }, |
|
| 536 | - $data |
|
| 537 | - ); |
|
| 538 | - return $ret; |
|
| 533 | + }); |
|
| 534 | + return $row; |
|
| 535 | + }, |
|
| 536 | + $data |
|
| 537 | + ); |
|
| 538 | + return $ret; |
|
| 539 | 539 | } |
| 540 | 540 | |
| 541 | 541 | /* |
@@ -140,7 +140,7 @@ discard block |
||
| 140 | 140 | */ |
| 141 | 141 | public function findByPasswordResetToken($token) |
| 142 | 142 | { |
| 143 | - if(!$this->isTokenCurrent($token)) { |
|
| 143 | + if (!$this->isTokenCurrent($token)) { |
|
| 144 | 144 | return null; |
| 145 | 145 | } |
| 146 | 146 | |
@@ -158,15 +158,15 @@ discard block |
||
| 158 | 158 | */ |
| 159 | 159 | public function findByVerifyEmailToken($token) |
| 160 | 160 | { |
| 161 | - if($this->isTokenConfirmed($token)) return null; |
|
| 161 | + if ($this->isTokenConfirmed($token)) return null; |
|
| 162 | 162 | |
| 163 | 163 | $user = $this->findOne([ |
| 164 | 164 | 'verify_email_token' => [$token, $token . self::CONFIRMED_STRING], |
| 165 | 165 | 'status' => self::STATUS_ACTIVE, |
| 166 | 166 | ]); |
| 167 | 167 | |
| 168 | - if($user) { |
|
| 169 | - if(!$this->isTokenConfirmed($token) && |
|
| 168 | + if ($user) { |
|
| 169 | + if (!$this->isTokenConfirmed($token) && |
|
| 170 | 170 | !$this->isTokenCurrent($token, 'user.verifyAccountTokenExpire')) { |
| 171 | 171 | return null; |
| 172 | 172 | } |
@@ -188,8 +188,8 @@ discard block |
||
| 188 | 188 | 'status' => self::STATUS_ACTIVE, |
| 189 | 189 | ]); |
| 190 | 190 | |
| 191 | - if($user) { |
|
| 192 | - if(!$user->isTokenCurrent($token, 'user.verifyAccountTokenExpire')) { |
|
| 191 | + if ($user) { |
|
| 192 | + if (!$user->isTokenCurrent($token, 'user.verifyAccountTokenExpire')) { |
|
| 193 | 193 | return null; |
| 194 | 194 | } |
| 195 | 195 | } |
@@ -207,7 +207,7 @@ discard block |
||
| 207 | 207 | public function isTokenCurrent($token, String $paramPath = 'user.passwordResetTokenExpire') { |
| 208 | 208 | $expire = \Yii::$app->params[$paramPath]; |
| 209 | 209 | $parts = explode('_', $token); |
| 210 | - $timestamp = (int) end($parts); |
|
| 210 | + $timestamp = (int)end($parts); |
|
| 211 | 211 | if ($timestamp + $expire < time()) { |
| 212 | 212 | // token expired |
| 213 | 213 | return false; |
@@ -222,7 +222,7 @@ discard block |
||
| 222 | 222 | * @param string $match the needle to search for |
| 223 | 223 | */ |
| 224 | 224 | public function isTokenConfirmed($token = null, String $match = self::CONFIRMED_STRING) { |
| 225 | - if(is_null($token)) $token = $this->verify_email_token; |
|
| 225 | + if (is_null($token)) $token = $this->verify_email_token; |
|
| 226 | 226 | return substr($token, -strlen($match)) === $match; |
| 227 | 227 | } |
| 228 | 228 | |
@@ -247,7 +247,7 @@ discard block |
||
| 247 | 247 | } |
| 248 | 248 | |
| 249 | 249 | public function isVerified() { |
| 250 | - if(is_null($this->verify_email_token)) { |
|
| 250 | + if (is_null($this->verify_email_token)) { |
|
| 251 | 251 | // for old users who verified their accounts before the addition of |
| 252 | 252 | // '_confirmed' to the token |
| 253 | 253 | return true; |
@@ -366,7 +366,7 @@ discard block |
||
| 366 | 366 | * partner email address the user has set. |
| 367 | 367 | */ |
| 368 | 368 | public function sendEmailReport($date) { |
| 369 | - if(!$this->send_email) return false; // no partner emails set |
|
| 369 | + if (!$this->send_email) return false; // no partner emails set |
|
| 370 | 370 | list($start, $end) = $this->time->getUTCBookends($date); |
| 371 | 371 | |
| 372 | 372 | $user_behavior = Yii::$container->get(UserBehaviorInterface::class); |
@@ -375,14 +375,14 @@ discard block |
||
| 375 | 375 | // we should only proceed with sending the email if the user |
| 376 | 376 | // scored above their set email threshold (User::email_category) |
| 377 | 377 | $this_checkin = $checkins_last_month[$date]; // gets the check-in |
| 378 | - if(!$this_checkin) return false; // sanity check |
|
| 379 | - $highest_cat_data = end($this_checkin); // gets the data for the highest category from the check-in |
|
| 380 | - if(!$highest_cat_data) return false; // another sanity check |
|
| 381 | - $highest_cat_idx = key($this_checkin); // gets the key of the highest category |
|
| 378 | + if (!$this_checkin) return false; // sanity check |
|
| 379 | + $highest_cat_data = end($this_checkin); // gets the data for the highest category from the check-in |
|
| 380 | + if (!$highest_cat_data) return false; // another sanity check |
|
| 381 | + $highest_cat_idx = key($this_checkin); // gets the key of the highest category |
|
| 382 | 382 | |
| 383 | 383 | // if the highest category they reached today was less than |
| 384 | 384 | // the category threshold they have set, don't send the email |
| 385 | - if($highest_cat_idx < $this->email_category) return false; |
|
| 385 | + if ($highest_cat_idx < $this->email_category) return false; |
|
| 386 | 386 | |
| 387 | 387 | $user_behaviors = $user_behavior->getByDate(Yii::$app->user->id, $date); |
| 388 | 388 | |
@@ -394,8 +394,8 @@ discard block |
||
| 394 | 394 | ->create($checkins_last_month); |
| 395 | 395 | |
| 396 | 396 | $messages = []; |
| 397 | - foreach($this->getPartnerEmails() as $email) { |
|
| 398 | - if($email) { |
|
| 397 | + foreach ($this->getPartnerEmails() as $email) { |
|
| 398 | + if ($email) { |
|
| 399 | 399 | $messages[] = Yii::$app->mailer->compose('checkinReport', [ |
| 400 | 400 | 'user' => $this, |
| 401 | 401 | 'email' => $email, |
@@ -407,7 +407,7 @@ discard block |
||
| 407 | 407 | 'behaviors_list' => \common\models\Behavior::$behaviors, |
| 408 | 408 | ])->setFrom([Yii::$app->params['supportEmail'] => Yii::$app->name]) |
| 409 | 409 | ->setReplyTo($this->email) |
| 410 | - ->setSubject($this->email." has completed a Faster Scale check-in") |
|
| 410 | + ->setSubject($this->email . " has completed a Faster Scale check-in") |
|
| 411 | 411 | ->setTo($email); |
| 412 | 412 | } |
| 413 | 413 | } |
@@ -481,7 +481,7 @@ discard block |
||
| 481 | 481 | return \Yii::$app->mailer->compose('signupNotification') |
| 482 | 482 | ->setFrom([\Yii::$app->params['supportEmail'] => \Yii::$app->name]) |
| 483 | 483 | ->setTo(\Yii::$app->params['adminEmail']) |
| 484 | - ->setSubject('A new user has signed up for '.\Yii::$app->name) |
|
| 484 | + ->setSubject('A new user has signed up for ' . \Yii::$app->name) |
|
| 485 | 485 | ->send(); |
| 486 | 486 | } |
| 487 | 487 | |
@@ -489,20 +489,20 @@ discard block |
||
| 489 | 489 | return \Yii::$app->mailer->compose('verifyEmail', ['user' => $this]) |
| 490 | 490 | ->setFrom([\Yii::$app->params['supportEmail'] => \Yii::$app->name]) |
| 491 | 491 | ->setTo($this->email) |
| 492 | - ->setSubject('Please verify your '.\Yii::$app->name .' account') |
|
| 492 | + ->setSubject('Please verify your ' . \Yii::$app->name . ' account') |
|
| 493 | 493 | ->send(); |
| 494 | 494 | } |
| 495 | 495 | |
| 496 | 496 | public function sendDeleteNotificationEmail() { |
| 497 | 497 | $messages = []; |
| 498 | - foreach(array_merge([$this->email], $this->getPartnerEmails()) as $email) { |
|
| 499 | - if($email) { |
|
| 498 | + foreach (array_merge([$this->email], $this->getPartnerEmails()) as $email) { |
|
| 499 | + if ($email) { |
|
| 500 | 500 | $messages[] = Yii::$app->mailer->compose('deleteNotification', [ |
| 501 | 501 | 'user' => $this, |
| 502 | 502 | 'email' => $email |
| 503 | 503 | ])->setFrom([Yii::$app->params['supportEmail'] => Yii::$app->name]) |
| 504 | 504 | ->setReplyTo($this->email) |
| 505 | - ->setSubject($this->email." has deleted their The Faster Scale App account") |
|
| 505 | + ->setSubject($this->email . " has deleted their The Faster Scale App account") |
|
| 506 | 506 | ->setTo($email); |
| 507 | 507 | } |
| 508 | 508 | } |
@@ -511,7 +511,7 @@ discard block |
||
| 511 | 511 | } |
| 512 | 512 | |
| 513 | 513 | public function cleanExportData($data) { |
| 514 | - var_dump( $data); |
|
| 514 | + var_dump($data); |
|
| 515 | 515 | exit(); |
| 516 | 516 | $order = array_flip(["date", "behavior", "category", "question1", "question2", "question3"]); |
| 517 | 517 | |
@@ -557,7 +557,7 @@ discard block |
||
| 557 | 557 | return rtrim( |
| 558 | 558 | strtr( |
| 559 | 559 | base64_encode( |
| 560 | - hash('sha256', $this->id."::".$this->created_at, true) |
|
| 560 | + hash('sha256', $this->id . "::" . $this->created_at, true) |
|
| 561 | 561 | ), |
| 562 | 562 | '+/', '-_'), |
| 563 | 563 | '='); |
@@ -158,7 +158,9 @@ discard block |
||
| 158 | 158 | */ |
| 159 | 159 | public function findByVerifyEmailToken($token) |
| 160 | 160 | { |
| 161 | - if($this->isTokenConfirmed($token)) return null; |
|
| 161 | + if($this->isTokenConfirmed($token)) { |
|
| 162 | + return null; |
|
| 163 | + } |
|
| 162 | 164 | |
| 163 | 165 | $user = $this->findOne([ |
| 164 | 166 | 'verify_email_token' => [$token, $token . self::CONFIRMED_STRING], |
@@ -222,7 +224,9 @@ discard block |
||
| 222 | 224 | * @param string $match the needle to search for |
| 223 | 225 | */ |
| 224 | 226 | public function isTokenConfirmed($token = null, String $match = self::CONFIRMED_STRING) { |
| 225 | - if(is_null($token)) $token = $this->verify_email_token; |
|
| 227 | + if(is_null($token)) { |
|
| 228 | + $token = $this->verify_email_token; |
|
| 229 | + } |
|
| 226 | 230 | return substr($token, -strlen($match)) === $match; |
| 227 | 231 | } |
| 228 | 232 | |
@@ -366,7 +370,10 @@ discard block |
||
| 366 | 370 | * partner email address the user has set. |
| 367 | 371 | */ |
| 368 | 372 | public function sendEmailReport($date) { |
| 369 | - if(!$this->send_email) return false; // no partner emails set |
|
| 373 | + if(!$this->send_email) { |
|
| 374 | + return false; |
|
| 375 | + } |
|
| 376 | + // no partner emails set |
|
| 370 | 377 | list($start, $end) = $this->time->getUTCBookends($date); |
| 371 | 378 | |
| 372 | 379 | $user_behavior = Yii::$container->get(UserBehaviorInterface::class); |
@@ -375,14 +382,22 @@ discard block |
||
| 375 | 382 | // we should only proceed with sending the email if the user |
| 376 | 383 | // scored above their set email threshold (User::email_category) |
| 377 | 384 | $this_checkin = $checkins_last_month[$date]; // gets the check-in |
| 378 | - if(!$this_checkin) return false; // sanity check |
|
| 385 | + if(!$this_checkin) { |
|
| 386 | + return false; |
|
| 387 | + } |
|
| 388 | + // sanity check |
|
| 379 | 389 | $highest_cat_data = end($this_checkin); // gets the data for the highest category from the check-in |
| 380 | - if(!$highest_cat_data) return false; // another sanity check |
|
| 390 | + if(!$highest_cat_data) { |
|
| 391 | + return false; |
|
| 392 | + } |
|
| 393 | + // another sanity check |
|
| 381 | 394 | $highest_cat_idx = key($this_checkin); // gets the key of the highest category |
| 382 | 395 | |
| 383 | 396 | // if the highest category they reached today was less than |
| 384 | 397 | // the category threshold they have set, don't send the email |
| 385 | - if($highest_cat_idx < $this->email_category) return false; |
|
| 398 | + if($highest_cat_idx < $this->email_category) { |
|
| 399 | + return false; |
|
| 400 | + } |
|
| 386 | 401 | |
| 387 | 402 | $user_behaviors = $user_behavior->getByDate(Yii::$app->user->id, $date); |
| 388 | 403 | |
@@ -73,7 +73,7 @@ discard block |
||
| 73 | 73 | 'whenClient' => "function(attribute, value) { return false; }", // lame, but acceptable |
| 74 | 74 | "message" => "You must select a behavior your responses apply to."], |
| 75 | 75 | |
| 76 | - [['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'] |
|
| 76 | + [['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'] |
|
| 77 | 77 | ]; |
| 78 | 78 | } |
| 79 | 79 | |
@@ -91,10 +91,10 @@ discard block |
||
| 91 | 91 | |
| 92 | 92 | public function getBhvrValidator() { |
| 93 | 93 | return function($model, $attr) { |
| 94 | - $attrNum = $attr[strlen($attr)-1]; |
|
| 95 | - foreach(['a', 'b', 'c'] as $l) { |
|
| 94 | + $attrNum = $attr[strlen($attr) - 1]; |
|
| 95 | + foreach (['a', 'b', 'c'] as $l) { |
|
| 96 | 96 | $attr = "answer_{$attrNum}{$l}"; |
| 97 | - if($model->$attr) return true; |
|
| 97 | + if ($model->$attr) return true; |
|
| 98 | 98 | } |
| 99 | 99 | return false; |
| 100 | 100 | }; |
@@ -125,7 +125,7 @@ discard block |
||
| 125 | 125 | |
| 126 | 126 | public function getPrefixProps($prefix) { |
| 127 | 127 | return array_filter(get_object_vars($this), function($v, $k) use($prefix) { |
| 128 | - if(strpos($k, $prefix) === 0 && strlen($v)) { |
|
| 128 | + if (strpos($k, $prefix) === 0 && strlen($v)) { |
|
| 129 | 129 | return true; |
| 130 | 130 | } |
| 131 | 131 | }, ARRAY_FILTER_USE_BOTH); |
@@ -143,9 +143,9 @@ discard block |
||
| 143 | 143 | public function getAnswers($bhvrs) { |
| 144 | 144 | $answers = []; |
| 145 | 145 | $user_bhvrs = array_combine($this->getUserBehaviorProps(), $bhvrs); |
| 146 | - foreach($user_bhvrs as $property => $user_bhvr) { |
|
| 146 | + foreach ($user_bhvrs as $property => $user_bhvr) { |
|
| 147 | 147 | $behavior_id = intval(substr($property, -1, 1)); |
| 148 | - foreach($this->behaviorToAnswers($behavior_id) as $answer_letter => $answer) { |
|
| 148 | + foreach ($this->behaviorToAnswers($behavior_id) as $answer_letter => $answer) { |
|
| 149 | 149 | $question_id = \common\models\Question::$TYPES[$answer_letter]; |
| 150 | 150 | array_push($answers, [ |
| 151 | 151 | 'behavior_id' => $user_bhvr->behavior_id, |
@@ -161,7 +161,7 @@ discard block |
||
| 161 | 161 | |
| 162 | 162 | public function saveAnswers($bhvrs) { |
| 163 | 163 | $result = true; |
| 164 | - foreach($this->getAnswers($bhvrs) as $answer) { |
|
| 164 | + foreach ($this->getAnswers($bhvrs) as $answer) { |
|
| 165 | 165 | $model = new \common\models\Question; |
| 166 | 166 | $model->user_id = Yii::$app->user->id; |
| 167 | 167 | $model->behavior_id = $answer['behavior_id']; |
@@ -170,9 +170,9 @@ discard block |
||
| 170 | 170 | $model->date = new Expression("now()::timestamp"); |
| 171 | 171 | $model->question = $answer['question_id']; |
| 172 | 172 | $model->answer = $answer['answer']; |
| 173 | - if(!$model->save()) { |
|
| 173 | + if (!$model->save()) { |
|
| 174 | 174 | $result = false; |
| 175 | - var_dump( $model->errors); |
|
| 175 | + var_dump($model->errors); |
|
| 176 | 176 | exit(); |
| 177 | 177 | } |
| 178 | 178 | } |
@@ -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"); |
@@ -68,15 +68,15 @@ discard block |
||
| 68 | 68 | </div> |
| 69 | 69 | </div> |
| 70 | 70 | |
| 71 | - <?php if($questions) { |
|
| 72 | - foreach($questions as $behavior_id => $behavior_questions) { |
|
| 71 | + <?php if ($questions) { |
|
| 72 | + foreach ($questions as $behavior_id => $behavior_questions) { |
|
| 73 | 73 | print "<div class='well well-sm'>"; |
| 74 | 74 | print "<button type='button' class='btn btn-primary' disabled='disabled'>{$behavior_questions['question']['behavior_name']}</button>"; |
| 75 | 75 | print "<div class='row'>"; |
| 76 | - foreach($behavior_questions['answers'] as $question) { |
|
| 76 | + foreach ($behavior_questions['answers'] as $question) { |
|
| 77 | 77 | print "<div class='col-md-4'>"; |
| 78 | 78 | print "<p><strong>{$question['title']}</strong></p>"; |
| 79 | - print "<p>".Html::encode($question['answer'])."</p>"; |
|
| 79 | + print "<p>" . Html::encode($question['answer']) . "</p>"; |
|
| 80 | 80 | print "</div>"; |
| 81 | 81 | } |
| 82 | 82 | print "</div></div>"; |
@@ -88,7 +88,7 @@ discard block |
||
| 88 | 88 | 'options' => ['class' => 'form-horizontal'], |
| 89 | 89 | ]); |
| 90 | 90 | |
| 91 | - foreach($categories as $category) { |
|
| 91 | + foreach ($categories as $category) { |
|
| 92 | 92 | $behaviors = AH::map($behaviorsList[$category['id']], 'id', 'name'); |
| 93 | 93 | print $form |
| 94 | 94 | ->field($model, "behaviors{$category['id']}") |