@@ -41,11 +41,11 @@ |
||
| 41 | 41 | |
| 42 | 42 | // Set up dependency injections |
| 43 | 43 | Yii::$container |
| 44 | - ->set(\common\interfaces\TimeInterface::class, function () { return new \common\components\Time('UTC'); }); |
|
| 44 | + ->set(\common\interfaces\TimeInterface::class, function() { return new \common\components\Time('UTC'); }); |
|
| 45 | 45 | Yii::$container |
| 46 | - ->set(\common\components\Graph::class, function () { return $this->graph; }); |
|
| 46 | + ->set(\common\components\Graph::class, function() { return $this->graph; }); |
|
| 47 | 47 | Yii::$container |
| 48 | - ->set(\common\interfaces\UserBehaviorInterface::class, function () { return new FakeUserBehavior(); }); |
|
| 48 | + ->set(\common\interfaces\UserBehaviorInterface::class, function() { return new FakeUserBehavior(); }); |
|
| 49 | 49 | |
| 50 | 50 | // Actually begin testing |
| 51 | 51 | $form->attributes = $this->values; |
@@ -70,11 +70,11 @@ |
||
| 70 | 70 | ]); ?> |
| 71 | 71 | <?= $form->field($profile, 'timezone')->dropDownList(array_combine($timezones, $timezones)); ?> |
| 72 | 72 | <?= $form->field($profile, 'expose_graph')->checkbox() ?> |
| 73 | - <?php if($profile->expose_graph): ?> |
|
| 73 | + <?php if ($profile->expose_graph): ?> |
|
| 74 | 74 | <div class='alert alert-success score-graph-info'>Your score graph can be found at:<br /> <a id="score-graph-link" target="_blank" href="<?=$graph_url?>"><?=$graph_url?></a></div> |
| 75 | 75 | <?php endif; ?> |
| 76 | 76 | <?= $form->field($profile, 'send_email')->checkbox() ?> |
| 77 | - <div id='send_email_fields' <?php if(!$profile->send_email) { ?>style="display: none;"<?php } ?>> |
|
| 77 | + <div id='send_email_fields' <?php if (!$profile->send_email) { ?>style="display: none;"<?php } ?>> |
|
| 78 | 78 | <?= $form->field($profile, 'partner_email1')->input('email'); ?> |
| 79 | 79 | <?= $form->field($profile, 'partner_email2')->input('email'); ?> |
| 80 | 80 | <?= $form->field($profile, 'partner_email3')->input('email'); ?> |
@@ -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")), |
@@ -165,14 +165,14 @@ discard block |
||
| 165 | 165 | $checkins = $user_behavior->getCheckInBreakdown($period); |
| 166 | 166 | |
| 167 | 167 | $accum = []; |
| 168 | - foreach($checkins as $date => $cats) { |
|
| 169 | - for($i = 1; $i <= 7; $i ++) { |
|
| 168 | + foreach ($checkins as $date => $cats) { |
|
| 169 | + for ($i = 1; $i <= 7; $i++) { |
|
| 170 | 170 | $accum[$i][] = array_key_exists($i, $cats) ? $cats[$i]['count'] : []; |
| 171 | 171 | } |
| 172 | 172 | } |
| 173 | 173 | |
| 174 | 174 | $bar_datasets = []; |
| 175 | - foreach($accum as $idx => $data) { |
|
| 175 | + foreach ($accum as $idx => $data) { |
|
| 176 | 176 | $bar_datasets[] = [ |
| 177 | 177 | 'label' => ($category::getCategories())[$idx], |
| 178 | 178 | 'backgroundColor' => $category::$colors[$idx]['color'], |
@@ -143,7 +143,7 @@ discard block |
||
| 143 | 143 | */ |
| 144 | 144 | public function findByPasswordResetToken($token) |
| 145 | 145 | { |
| 146 | - if(!$this->isTokenCurrent($token)) { |
|
| 146 | + if (!$this->isTokenCurrent($token)) { |
|
| 147 | 147 | return null; |
| 148 | 148 | } |
| 149 | 149 | |
@@ -161,15 +161,15 @@ discard block |
||
| 161 | 161 | */ |
| 162 | 162 | public function findByVerifyEmailToken($token) |
| 163 | 163 | { |
| 164 | - if($this->isTokenConfirmed($token)) return null; |
|
| 164 | + if ($this->isTokenConfirmed($token)) return null; |
|
| 165 | 165 | |
| 166 | 166 | $user = $this->findOne([ |
| 167 | 167 | 'verify_email_token' => [$token, $token . self::CONFIRMED_STRING], |
| 168 | 168 | 'status' => self::STATUS_ACTIVE, |
| 169 | 169 | ]); |
| 170 | 170 | |
| 171 | - if($user) { |
|
| 172 | - if(!$this->isTokenConfirmed($token) && |
|
| 171 | + if ($user) { |
|
| 172 | + if (!$this->isTokenConfirmed($token) && |
|
| 173 | 173 | !$this->isTokenCurrent($token, 'user.verifyAccountTokenExpire')) { |
| 174 | 174 | return null; |
| 175 | 175 | } |
@@ -191,8 +191,8 @@ discard block |
||
| 191 | 191 | 'status' => self::STATUS_ACTIVE, |
| 192 | 192 | ]); |
| 193 | 193 | |
| 194 | - if($user) { |
|
| 195 | - if(!$user->isTokenCurrent($token, 'user.verifyAccountTokenExpire')) { |
|
| 194 | + if ($user) { |
|
| 195 | + if (!$user->isTokenCurrent($token, 'user.verifyAccountTokenExpire')) { |
|
| 196 | 196 | return null; |
| 197 | 197 | } |
| 198 | 198 | } |
@@ -210,7 +210,7 @@ discard block |
||
| 210 | 210 | public function isTokenCurrent($token, String $paramPath = 'user.passwordResetTokenExpire') { |
| 211 | 211 | $expire = \Yii::$app->params[$paramPath]; |
| 212 | 212 | $parts = explode('_', $token); |
| 213 | - $timestamp = (int) end($parts); |
|
| 213 | + $timestamp = (int)end($parts); |
|
| 214 | 214 | if ($timestamp + $expire < time()) { |
| 215 | 215 | // token expired |
| 216 | 216 | return false; |
@@ -225,7 +225,7 @@ discard block |
||
| 225 | 225 | * @param string $match the needle to search for |
| 226 | 226 | */ |
| 227 | 227 | public function isTokenConfirmed($token = null, String $match = self::CONFIRMED_STRING) { |
| 228 | - if(is_null($token)) $token = $this->verify_email_token; |
|
| 228 | + if (is_null($token)) $token = $this->verify_email_token; |
|
| 229 | 229 | return substr($token, -strlen($match)) === $match; |
| 230 | 230 | } |
| 231 | 231 | |
@@ -250,7 +250,7 @@ discard block |
||
| 250 | 250 | } |
| 251 | 251 | |
| 252 | 252 | public function isVerified() { |
| 253 | - if(is_null($this->verify_email_token)) { |
|
| 253 | + if (is_null($this->verify_email_token)) { |
|
| 254 | 254 | // for old users who verified their accounts before the addition of |
| 255 | 255 | // '_confirmed' to the token |
| 256 | 256 | return true; |
@@ -358,7 +358,7 @@ discard block |
||
| 358 | 358 | } |
| 359 | 359 | |
| 360 | 360 | public function sendEmailReport($date) { |
| 361 | - if(!$this->send_email) return false; // no partner emails set |
|
| 361 | + if (!$this->send_email) return false; // no partner emails set |
|
| 362 | 362 | list($start, $end) = $this->time->getUTCBookends($date); |
| 363 | 363 | |
| 364 | 364 | $checkins_last_month = $this->user_behavior->getCheckInBreakdown(); |
@@ -366,12 +366,12 @@ discard block |
||
| 366 | 366 | ->get(\common\components\Graph::class) |
| 367 | 367 | ->create($checkins_last_month); |
| 368 | 368 | |
| 369 | - $user_behaviors = $this->getUserBehaviors($date); |
|
| 369 | + $user_behaviors = $this->getUserBehaviors($date); |
|
| 370 | 370 | $user_questions = $this->getUserQuestions($date); |
| 371 | 371 | |
| 372 | 372 | $messages = []; |
| 373 | - foreach($this->getPartnerEmails() as $email) { |
|
| 374 | - if($email) { |
|
| 373 | + foreach ($this->getPartnerEmails() as $email) { |
|
| 374 | + if ($email) { |
|
| 375 | 375 | $messages[] = Yii::$app->mailer->compose('checkinReport', [ |
| 376 | 376 | 'user' => $this, |
| 377 | 377 | 'email' => $email, |
@@ -383,7 +383,7 @@ discard block |
||
| 383 | 383 | 'behaviors_list' => \common\models\Behavior::$behaviors, |
| 384 | 384 | ])->setFrom([Yii::$app->params['supportEmail'] => Yii::$app->name]) |
| 385 | 385 | ->setReplyTo($this->email) |
| 386 | - ->setSubject($this->email." has completed a Faster Scale check-in") |
|
| 386 | + ->setSubject($this->email . " has completed a Faster Scale check-in") |
|
| 387 | 387 | ->setTo($email); |
| 388 | 388 | } |
| 389 | 389 | } |
@@ -456,7 +456,7 @@ discard block |
||
| 456 | 456 | return \Yii::$app->mailer->compose('signupNotification') |
| 457 | 457 | ->setFrom([\Yii::$app->params['supportEmail'] => \Yii::$app->name]) |
| 458 | 458 | ->setTo(\Yii::$app->params['adminEmail']) |
| 459 | - ->setSubject('A new user has signed up for '.\Yii::$app->name) |
|
| 459 | + ->setSubject('A new user has signed up for ' . \Yii::$app->name) |
|
| 460 | 460 | ->send(); |
| 461 | 461 | } |
| 462 | 462 | |
@@ -464,20 +464,20 @@ discard block |
||
| 464 | 464 | return \Yii::$app->mailer->compose('verifyEmail', ['user' => $this]) |
| 465 | 465 | ->setFrom([\Yii::$app->params['supportEmail'] => \Yii::$app->name]) |
| 466 | 466 | ->setTo($this->email) |
| 467 | - ->setSubject('Please verify your '.\Yii::$app->name .' account') |
|
| 467 | + ->setSubject('Please verify your ' . \Yii::$app->name . ' account') |
|
| 468 | 468 | ->send(); |
| 469 | 469 | } |
| 470 | 470 | |
| 471 | 471 | public function sendDeleteNotificationEmail() { |
| 472 | 472 | $messages = []; |
| 473 | - foreach(array_merge([$this->email], $this->getPartnerEmails()) as $email) { |
|
| 474 | - if($email) { |
|
| 473 | + foreach (array_merge([$this->email], $this->getPartnerEmails()) as $email) { |
|
| 474 | + if ($email) { |
|
| 475 | 475 | $messages[] = Yii::$app->mailer->compose('deleteNotification', [ |
| 476 | 476 | 'user' => $this, |
| 477 | 477 | 'email' => $email |
| 478 | 478 | ])->setFrom([Yii::$app->params['supportEmail'] => Yii::$app->name]) |
| 479 | 479 | ->setReplyTo($this->email) |
| 480 | - ->setSubject($this->email." has deleted their The Faster Scale App account") |
|
| 480 | + ->setSubject($this->email . " has deleted their The Faster Scale App account") |
|
| 481 | 481 | ->setTo($email); |
| 482 | 482 | } |
| 483 | 483 | } |
@@ -486,13 +486,13 @@ discard block |
||
| 486 | 486 | } |
| 487 | 487 | |
| 488 | 488 | public function getUserQuestions($local_date = null) { |
| 489 | - if(is_null($local_date)) $local_date = $this->time->getLocalDate(); |
|
| 489 | + if (is_null($local_date)) $local_date = $this->time->getLocalDate(); |
|
| 490 | 490 | $questions = $this->getQuestionData($local_date); |
| 491 | 491 | return $this->parseQuestionData($questions); |
| 492 | 492 | } |
| 493 | 493 | |
| 494 | 494 | public function getUserBehaviors($local_date = null) { |
| 495 | - if(is_null($local_date)) $local_date = $this->time->getLocalDate(); |
|
| 495 | + if (is_null($local_date)) $local_date = $this->time->getLocalDate(); |
|
| 496 | 496 | |
| 497 | 497 | $behaviors = $this->getBehaviorData($local_date); |
| 498 | 498 | $behaviors = $this->user_behavior::decorateWithCategory($behaviors); |
@@ -500,10 +500,10 @@ discard block |
||
| 500 | 500 | } |
| 501 | 501 | |
| 502 | 502 | public function parseQuestionData($questions) { |
| 503 | - if(!$questions) return []; |
|
| 503 | + if (!$questions) return []; |
|
| 504 | 504 | |
| 505 | 505 | $question_answers = []; |
| 506 | - foreach($questions as $question) { |
|
| 506 | + foreach ($questions as $question) { |
|
| 507 | 507 | $behavior = $question['behavior']; |
| 508 | 508 | |
| 509 | 509 | $question_answers[$behavior['id']]['question'] = [ |
@@ -521,10 +521,10 @@ discard block |
||
| 521 | 521 | } |
| 522 | 522 | |
| 523 | 523 | public function parseBehaviorData($behaviors) { |
| 524 | - if(!$behaviors) return []; |
|
| 524 | + if (!$behaviors) return []; |
|
| 525 | 525 | |
| 526 | 526 | $opts_by_cat = []; |
| 527 | - foreach($behaviors as $behavior) { |
|
| 527 | + foreach ($behaviors as $behavior) { |
|
| 528 | 528 | $indx = $behavior['behavior']['category_id']; |
| 529 | 529 | |
| 530 | 530 | $opts_by_cat[$indx]['category_name'] = $behavior['behavior']['category']['name']; |
@@ -616,7 +616,7 @@ discard block |
||
| 616 | 616 | return rtrim( |
| 617 | 617 | strtr( |
| 618 | 618 | base64_encode( |
| 619 | - hash('sha256', $this->id."::".$this->created_at, true) |
|
| 619 | + hash('sha256', $this->id . "::" . $this->created_at, true) |
|
| 620 | 620 | ), |
| 621 | 621 | '+/', '-_'), |
| 622 | 622 | '='); |
@@ -161,7 +161,9 @@ discard block |
||
| 161 | 161 | */ |
| 162 | 162 | public function findByVerifyEmailToken($token) |
| 163 | 163 | { |
| 164 | - if($this->isTokenConfirmed($token)) return null; |
|
| 164 | + if($this->isTokenConfirmed($token)) { |
|
| 165 | + return null; |
|
| 166 | + } |
|
| 165 | 167 | |
| 166 | 168 | $user = $this->findOne([ |
| 167 | 169 | 'verify_email_token' => [$token, $token . self::CONFIRMED_STRING], |
@@ -225,7 +227,9 @@ discard block |
||
| 225 | 227 | * @param string $match the needle to search for |
| 226 | 228 | */ |
| 227 | 229 | public function isTokenConfirmed($token = null, String $match = self::CONFIRMED_STRING) { |
| 228 | - if(is_null($token)) $token = $this->verify_email_token; |
|
| 230 | + if(is_null($token)) { |
|
| 231 | + $token = $this->verify_email_token; |
|
| 232 | + } |
|
| 229 | 233 | return substr($token, -strlen($match)) === $match; |
| 230 | 234 | } |
| 231 | 235 | |
@@ -358,7 +362,10 @@ discard block |
||
| 358 | 362 | } |
| 359 | 363 | |
| 360 | 364 | public function sendEmailReport($date) { |
| 361 | - if(!$this->send_email) return false; // no partner emails set |
|
| 365 | + if(!$this->send_email) { |
|
| 366 | + return false; |
|
| 367 | + } |
|
| 368 | + // no partner emails set |
|
| 362 | 369 | list($start, $end) = $this->time->getUTCBookends($date); |
| 363 | 370 | |
| 364 | 371 | $checkins_last_month = $this->user_behavior->getCheckInBreakdown(); |
@@ -486,13 +493,17 @@ discard block |
||
| 486 | 493 | } |
| 487 | 494 | |
| 488 | 495 | public function getUserQuestions($local_date = null) { |
| 489 | - if(is_null($local_date)) $local_date = $this->time->getLocalDate(); |
|
| 496 | + if(is_null($local_date)) { |
|
| 497 | + $local_date = $this->time->getLocalDate(); |
|
| 498 | + } |
|
| 490 | 499 | $questions = $this->getQuestionData($local_date); |
| 491 | 500 | return $this->parseQuestionData($questions); |
| 492 | 501 | } |
| 493 | 502 | |
| 494 | 503 | public function getUserBehaviors($local_date = null) { |
| 495 | - if(is_null($local_date)) $local_date = $this->time->getLocalDate(); |
|
| 504 | + if(is_null($local_date)) { |
|
| 505 | + $local_date = $this->time->getLocalDate(); |
|
| 506 | + } |
|
| 496 | 507 | |
| 497 | 508 | $behaviors = $this->getBehaviorData($local_date); |
| 498 | 509 | $behaviors = $this->user_behavior::decorateWithCategory($behaviors); |
@@ -500,7 +511,9 @@ discard block |
||
| 500 | 511 | } |
| 501 | 512 | |
| 502 | 513 | public function parseQuestionData($questions) { |
| 503 | - if(!$questions) return []; |
|
| 514 | + if(!$questions) { |
|
| 515 | + return []; |
|
| 516 | + } |
|
| 504 | 517 | |
| 505 | 518 | $question_answers = []; |
| 506 | 519 | foreach($questions as $question) { |
@@ -521,7 +534,9 @@ discard block |
||
| 521 | 534 | } |
| 522 | 535 | |
| 523 | 536 | public function parseBehaviorData($behaviors) { |
| 524 | - if(!$behaviors) return []; |
|
| 537 | + if(!$behaviors) { |
|
| 538 | + return []; |
|
| 539 | + } |
|
| 525 | 540 | |
| 526 | 541 | $opts_by_cat = []; |
| 527 | 542 | foreach($behaviors as $behavior) { |
@@ -337,7 +337,7 @@ |
||
| 337 | 337 | ], [ |
| 338 | 338 | ], [ |
| 339 | 339 | ], [ |
| 340 | - ], [ [ |
|
| 340 | + ], [[ |
|
| 341 | 341 | 'user_id' => 1, |
| 342 | 342 | 'behavior_id' => 117, |
| 343 | 343 | 'count' => 1, |
@@ -105,19 +105,19 @@ discard block |
||
| 105 | 105 | expect('decorate should add Behavior data and Category data to an array of UserBehaviors', |
| 106 | 106 | $this->assertEquals( |
| 107 | 107 | $this->user_behavior->decorateWithCategory($this->singleSimpleBehaviorNoBehavior), |
| 108 | - [['id' => 396, |
|
| 109 | - 'user_id' => 2, |
|
| 110 | - 'behavior_id' => 107, |
|
| 111 | - 'date' => '2016-06-17 04:12:43', |
|
| 112 | - 'behavior' => [ |
|
| 113 | - 'id' => 107, |
|
| 114 | - 'name' => 'numb', |
|
| 115 | - 'category_id' => 6, |
|
| 116 | - 'category' => [ |
|
| 117 | - 'id' => 6, |
|
| 118 | - 'name' => 'Exhausted', |
|
| 119 | - ] |
|
| 120 | - ]]])); |
|
| 108 | + [['id' => 396, |
|
| 109 | + 'user_id' => 2, |
|
| 110 | + 'behavior_id' => 107, |
|
| 111 | + 'date' => '2016-06-17 04:12:43', |
|
| 112 | + 'behavior' => [ |
|
| 113 | + 'id' => 107, |
|
| 114 | + 'name' => 'numb', |
|
| 115 | + 'category_id' => 6, |
|
| 116 | + 'category' => [ |
|
| 117 | + 'id' => 6, |
|
| 118 | + 'name' => 'Exhausted', |
|
| 119 | + ] |
|
| 120 | + ]]])); |
|
| 121 | 121 | } |
| 122 | 122 | |
| 123 | 123 | public function testGetBehaviorsByCategory() { |
@@ -198,6 +198,6 @@ discard block |
||
| 198 | 198 | $bhvrs = require(__DIR__.'/../data/behaviorsWithCounts.php'); |
| 199 | 199 | $expected = require(__DIR__.'/../data/expected_getCheckinBreakdown.php'); |
| 200 | 200 | $this->user_behavior->method('getBehaviorsWithCounts')->willReturn(...$bhvrs); |
| 201 | - expect('asdf', $this->assertEquals($expected, $this->user_behavior->getCheckinBreakdown())); |
|
| 201 | + expect('asdf', $this->assertEquals($expected, $this->user_behavior->getCheckinBreakdown())); |
|
| 202 | 202 | } |
| 203 | 203 | } |
@@ -33,7 +33,7 @@ discard block |
||
| 33 | 33 | ]; |
| 34 | 34 | public function setUp() { |
| 35 | 35 | // pull in test data |
| 36 | - $data = require(__DIR__.'/../data/checkinData.php'); |
|
| 36 | + $data = require(__DIR__ . '/../data/checkinData.php'); |
|
| 37 | 37 | $this->singleBhvr = $data['singleBhvr']; |
| 38 | 38 | $this->manyBhvrs = $data['manyBhvrs']; |
| 39 | 39 | $this->allBhvrs = $data['allBhvrs']; |
@@ -43,7 +43,7 @@ discard block |
||
| 43 | 43 | $this->container->set('common\interfaces\UserInterface', '\site\tests\_support\MockUser'); |
| 44 | 44 | $this->container->set('common\interfaces\QuestionInterface', '\site\tests\_support\MockQuestion'); |
| 45 | 45 | $this->container->set('common\interfaces\BehaviorInterface', 'common\models\Behavior'); |
| 46 | - $this->container->set('common\interfaces\TimeInterface', function () { |
|
| 46 | + $this->container->set('common\interfaces\TimeInterface', function() { |
|
| 47 | 47 | return new \common\components\Time('America/Los_Angeles'); |
| 48 | 48 | }); |
| 49 | 49 | |
@@ -195,8 +195,8 @@ discard block |
||
| 195 | 195 | ->setMethods(['getIsNewRecord', 'save', 'getBehaviorsByDate', 'getBehaviorsWithCounts']) |
| 196 | 196 | ->getMock(); |
| 197 | 197 | |
| 198 | - $bhvrs = require(__DIR__.'/../data/behaviorsWithCounts.php'); |
|
| 199 | - $expected = require(__DIR__.'/../data/expected_getCheckinBreakdown.php'); |
|
| 198 | + $bhvrs = require(__DIR__ . '/../data/behaviorsWithCounts.php'); |
|
| 199 | + $expected = require(__DIR__ . '/../data/expected_getCheckinBreakdown.php'); |
|
| 200 | 200 | $this->user_behavior->method('getBehaviorsWithCounts')->willReturn(...$bhvrs); |
| 201 | 201 | expect('asdf', $this->assertEquals($expected, $this->user_behavior->getCheckinBreakdown())); |
| 202 | 202 | } |
@@ -151,9 +151,9 @@ |
||
| 151 | 151 | $dt = new DateTime("now", new DateTimeZone($this->timezone)); |
| 152 | 152 | $dt2 = new DateTime("now", new DateTimeZone($this->timezone)); |
| 153 | 153 | $end = $dt ->add(new \DateInterval('P1D')) // add a day, so the end date gets included in the intervals |
| 154 | - ->add(new \DateInterval('PT2M')); // add two minutes, to be sure we have everything |
|
| 154 | + ->add(new \DateInterval('PT2M')); // add two minutes, to be sure we have everything |
|
| 155 | 155 | $start = $dt2->add(new \DateInterval('PT2M')) // add two minutes, to be sure we have everything |
| 156 | - ->sub(new \DateInterval("P${period}D")); // subtract `$period` number of days |
|
| 156 | + ->sub(new \DateInterval("P${period}D")); // subtract `$period` number of days |
|
| 157 | 157 | |
| 158 | 158 | $periods = new \DatePeriod($start, new \DateInterval('P1D'), $end, \DatePeriod::EXCLUDE_START_DATE); |
| 159 | 159 | $local_tz = new \DateTimeZone($this->timezone); |
@@ -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 = null) { |
| 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(); |
@@ -151,13 +151,13 @@ discard block |
||
| 151 | 151 | $dt = new DateTime("now", new DateTimeZone($this->timezone)); |
| 152 | 152 | $dt2 = new DateTime("now", new DateTimeZone($this->timezone)); |
| 153 | 153 | $end = $dt ->add(new \DateInterval('P1D')) // add a day, so the end date gets included in the intervals |
| 154 | - ->add(new \DateInterval('PT2M')); // add two minutes, to be sure we have everything |
|
| 154 | + ->add(new \DateInterval('PT2M')); // add two minutes, to be sure we have everything |
|
| 155 | 155 | $start = $dt2->add(new \DateInterval('PT2M')) // add two minutes, to be sure we have everything |
| 156 | 156 | ->sub(new \DateInterval("P${period}D")); // subtract `$period` number of days |
| 157 | 157 | |
| 158 | 158 | $periods = new \DatePeriod($start, new \DateInterval('P1D'), $end, \DatePeriod::EXCLUDE_START_DATE); |
| 159 | 159 | $local_tz = new \DateTimeZone($this->timezone); |
| 160 | - foreach($periods as $period) { |
|
| 160 | + foreach ($periods as $period) { |
|
| 161 | 161 | $period->setTimezone($local_tz); |
| 162 | 162 | } |
| 163 | 163 | return $periods; |
@@ -124,14 +124,14 @@ discard block |
||
| 124 | 124 | <th style="Margin:0;color:#0a0a0a;font-family:Arial,Verdana,Helvetica,sans-serif;font-size:16px;font-weight:400;line-height:1.3;margin:0;padding:0;text-align:left"> |
| 125 | 125 | |
| 126 | 126 | <?php |
| 127 | -if($questions) { |
|
| 128 | - foreach($questions as $behavior_id => $behavior_questions) { |
|
| 127 | +if ($questions) { |
|
| 128 | + foreach ($questions as $behavior_id => $behavior_questions) { |
|
| 129 | 129 | ?> |
| 130 | 130 | |
| 131 | 131 | <h4 style="Margin:0;Margin-bottom:10px;color:#37b98f;font-family:Arial,Verdana,Helvetica,sans-serif;font-size:24px;font-weight:400;line-height:1.3;margin:0;margin-bottom:5px;padding:0 8px;text-align:left;word-wrap:normal"> <?= $behavior_questions['question']['title'] ?> </h4> |
| 132 | 132 | |
| 133 | 133 | <?php |
| 134 | - foreach($behavior_questions['answers'] as $key => $question) { ?> |
|
| 134 | + foreach ($behavior_questions['answers'] as $key => $question) { ?> |
|
| 135 | 135 | <p style="Margin:0;Margin-bottom:10px;color:#0a0a0a;font-family:Arial,Verdana,Helvetica,sans-serif;font-size:16px;font-weight:400;line-height:1.3;margin:0;margin-bottom:10px;padding:0 8px 4px 8px;text-align:left"><strong><?=$question['title']?></strong> <?=$question['answer']?></p> |
| 136 | 136 | <?php |
| 137 | 137 | } |
@@ -188,12 +188,12 @@ discard block |
||
| 188 | 188 | <th style="Margin:0;color:#0a0a0a;font-family:Arial,Verdana,Helvetica,sans-serif;font-size:16px;font-weight:400;line-height:1.3;margin:0;padding:0;text-align:left"> |
| 189 | 189 | |
| 190 | 190 | <?php |
| 191 | -if($user_behaviors) { |
|
| 192 | - foreach($user_behaviors as $user_behavior) { ?> |
|
| 191 | +if ($user_behaviors) { |
|
| 192 | + foreach ($user_behaviors as $user_behavior) { ?> |
|
| 193 | 193 | <p style="Margin:0;Margin-bottom:10px;color:#0a0a0a;font-family:Arial,Verdana,Helvetica,sans-serif;font-size:16px;font-weight:400;line-height:1.3;margin:0;margin-bottom:10px;padding:0 8px 4px 8px;text-align:left"> |
| 194 | 194 | <strong style="color:#37b98f"><?= $user_behavior['category_name'] ?></strong> |
| 195 | 195 | <?php |
| 196 | - foreach($user_behavior['behaviors'] as $behavior) { ?> |
|
| 196 | + foreach ($user_behavior['behaviors'] as $behavior) { ?> |
|
| 197 | 197 | <br><?= $behavior['name'] ?> |
| 198 | 198 | <?php |
| 199 | 199 | } |
@@ -53,8 +53,8 @@ discard block |
||
| 53 | 53 | } |
| 54 | 54 | |
| 55 | 55 | /** |
| 56 | - * @codeCoverageIgnore |
|
| 57 | - */ |
|
| 56 | + * @codeCoverageIgnore |
|
| 57 | + */ |
|
| 58 | 58 | public function attributeLabels() { |
| 59 | 59 | return [ |
| 60 | 60 | 'partner_email1' => "Partner Email #1", |
@@ -85,7 +85,7 @@ discard block |
||
| 85 | 85 | |
| 86 | 86 | // generate scores graph image |
| 87 | 87 | $checkins_last_month = (Yii::$container->get(\common\interfaces\UserBehaviorInterface::class)) |
| 88 | - ->getCheckInBreakdown(); |
|
| 88 | + ->getCheckInBreakdown(); |
|
| 89 | 89 | |
| 90 | 90 | // if they haven't done a check-in in the last month this will explode |
| 91 | 91 | // because $checkins_last_month is an empty array |
@@ -77,10 +77,10 @@ discard block |
||
| 77 | 77 | $graph = Yii::$container |
| 78 | 78 | ->get(\common\components\Graph::class, [$this->user]); |
| 79 | 79 | |
| 80 | - if($this->timezone) { |
|
| 80 | + if ($this->timezone) { |
|
| 81 | 81 | $user->timezone = $this->timezone; |
| 82 | 82 | } |
| 83 | - if($this->expose_graph) { |
|
| 83 | + if ($this->expose_graph) { |
|
| 84 | 84 | $user->expose_graph = true; |
| 85 | 85 | |
| 86 | 86 | // generate scores graph image |
@@ -89,7 +89,7 @@ discard block |
||
| 89 | 89 | |
| 90 | 90 | // if they haven't done a check-in in the last month this will explode |
| 91 | 91 | // because $checkins_last_month is an empty array |
| 92 | - if($checkins_last_month) { |
|
| 92 | + if ($checkins_last_month) { |
|
| 93 | 93 | $graph->create($checkins_last_month, true); |
| 94 | 94 | } |
| 95 | 95 | } else { |
@@ -98,7 +98,7 @@ discard block |
||
| 98 | 98 | $graph->destroy(); |
| 99 | 99 | } |
| 100 | 100 | |
| 101 | - if($this->send_email) { |
|
| 101 | + if ($this->send_email) { |
|
| 102 | 102 | $user->send_email = true; |
| 103 | 103 | $user->partner_email1 = $this->partner_email1; |
| 104 | 104 | $user->partner_email2 = $this->partner_email2; |