@@ -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,12 +151,12 @@ 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')); // to be sure we have everything |
|
| 154 | + ->add(new \DateInterval('PT2M')); // to be sure we have everything |
|
| 155 | 155 | $start = $dt2->add(new \DateInterval('PT2M')); // to be sure we have everything |
| 156 | 156 | $start = $start->sub(new \DateInterval("P${period}D")); |
| 157 | 157 | $periods = new \DatePeriod($start, new \DateInterval('P1D'), $end, \DatePeriod::EXCLUDE_START_DATE); |
| 158 | 158 | $local_tz = new \DateTimeZone($this->timezone); |
| 159 | - foreach($periods as $period) { |
|
| 159 | + foreach ($periods as $period) { |
|
| 160 | 160 | $period->setTimezone($local_tz); |
| 161 | 161 | } |
| 162 | 162 | return $periods; |
@@ -14,8 +14,8 @@ discard block |
||
| 14 | 14 | use \Codeception\Specify; |
| 15 | 15 | |
| 16 | 16 | private $user; |
| 17 | - private $filepath = __DIR__.'/../../_output/test_graph.png'; |
|
| 18 | - private $filepath_extra = __DIR__.'/../../_output/charts/test_graph.png'; |
|
| 17 | + private $filepath = __DIR__ . '/../../_output/test_graph.png'; |
|
| 18 | + private $filepath_extra = __DIR__ . '/../../_output/charts/test_graph.png'; |
|
| 19 | 19 | |
| 20 | 20 | public function setUp() { |
| 21 | 21 | $this->user = $this->getMockBuilder('\site\tests\_support\MockUser') |
@@ -36,7 +36,7 @@ discard block |
||
| 36 | 36 | ->willReturn('random1DH4sh'); |
| 37 | 37 | $graph = new Graph($this->user); |
| 38 | 38 | |
| 39 | - expect('the expected graph image filepath will be returned', $this->assertEquals(dirname(dirname(dirname(dirname(__DIR__)))).'/site/web/charts/random1DH4sh.png', $graph->getFilepath())); |
|
| 39 | + expect('the expected graph image filepath will be returned', $this->assertEquals(dirname(dirname(dirname(dirname(__DIR__)))) . '/site/web/charts/random1DH4sh.png', $graph->getFilepath())); |
|
| 40 | 40 | } |
| 41 | 41 | |
| 42 | 42 | public function testGetUrl() { |
@@ -57,7 +57,7 @@ discard block |
||
| 57 | 57 | ->method('getFilepath') |
| 58 | 58 | ->willReturn($this->filepath); |
| 59 | 59 | |
| 60 | - if(!file_exists($this->filepath) && preg_match('%/_output/test_graph.png$%', $this->filepath)) { |
|
| 60 | + if (!file_exists($this->filepath) && preg_match('%/_output/test_graph.png$%', $this->filepath)) { |
|
| 61 | 61 | touch($this->filepath); |
| 62 | 62 | expect('just a check to be sure $filepath is sane', $this->assertStringEndsWith('/_output/test_graph.png', $this->filepath)); |
| 63 | 63 | expect('the generated file should exist', $this->assertFileExists($this->filepath)); |
@@ -89,7 +89,7 @@ discard block |
||
| 89 | 89 | expect('the generated file should be readable', $this->assertFileExists($this->filepath_extra)); |
| 90 | 90 | |
| 91 | 91 | // cleanup |
| 92 | - if(file_exists($this->filepath_extra) && preg_match('%/_output/charts/test_graph.png%', $this->filepath_extra)) { |
|
| 92 | + if (file_exists($this->filepath_extra) && preg_match('%/_output/charts/test_graph.png%', $this->filepath_extra)) { |
|
| 93 | 93 | // just in case something is weird, we don't want to straight rm this file |
| 94 | 94 | unlink($this->filepath_extra); |
| 95 | 95 | rmdir(dirname($this->filepath_extra)); |
@@ -97,7 +97,7 @@ discard block |
||
| 97 | 97 | } |
| 98 | 98 | } |
| 99 | 99 | |
| 100 | -function checkinBreakdown () { |
|
| 100 | +function checkinBreakdown() { |
|
| 101 | 101 | return [ |
| 102 | 102 | '2019-01-31' => [], |
| 103 | 103 | '2019-02-01' => [], |
@@ -230,7 +230,7 @@ discard block |
||
| 230 | 230 | '2019-02-27' => [], |
| 231 | 231 | '2019-02-28' => [], |
| 232 | 232 | '2019-03-01' => [ |
| 233 | - 2 => [ 'name' => 'Forgetting Priorities', |
|
| 233 | + 2 => ['name' => 'Forgetting Priorities', |
|
| 234 | 234 | 'count' => 6, |
| 235 | 235 | 'color' => '#4CA100', |
| 236 | 236 | 'highlight' => '#61B219', |
@@ -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 |
@@ -91,7 +91,7 @@ discard block |
||
| 91 | 91 | // if they haven't done a check-in in the last month this |
| 92 | 92 | // will explode because $checkinss_last_month is an empty |
| 93 | 93 | // array |
| 94 | - if($checkins_last_month) { |
|
| 94 | + if ($checkins_last_month) { |
|
| 95 | 95 | $graph->create($checkins_last_month, true); |
| 96 | 96 | } |
| 97 | 97 | } else { |
@@ -99,12 +99,12 @@ discard block |
||
| 99 | 99 | // remove scores graph image |
| 100 | 100 | $graph->destroy(); |
| 101 | 101 | } |
| 102 | - if($this->send_email) { |
|
| 102 | + if ($this->send_email) { |
|
| 103 | 103 | $user->send_email = true; |
| 104 | 104 | } else { |
| 105 | 105 | $user->send_email = false; |
| 106 | 106 | } |
| 107 | - if($this->send_email) { |
|
| 107 | + if ($this->send_email) { |
|
| 108 | 108 | $user->partner_email1 = $this->partner_email1; |
| 109 | 109 | $user->partner_email2 = $this->partner_email2; |
| 110 | 110 | $user->partner_email3 = $this->partner_email3; |
@@ -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 |
| 91 | 91 | // will explode because $checkinss_last_month is an empty |
@@ -6,22 +6,22 @@ discard block |
||
| 6 | 6 | use \site\models\EditProfileForm; |
| 7 | 7 | |
| 8 | 8 | class EditProfileFormTest extends \Codeception\Test\Unit { |
| 9 | - public $graph; |
|
| 10 | - public $values = [ |
|
| 11 | - 'timezone' => 'America/Los_Angeles', |
|
| 9 | + public $graph; |
|
| 10 | + public $values = [ |
|
| 11 | + 'timezone' => 'America/Los_Angeles', |
|
| 12 | 12 | 'send_email' => true, |
| 13 | - 'partner_email1' => '[email protected]', |
|
| 14 | - 'partner_email2' => '[email protected]', |
|
| 15 | - 'partner_email3' => '[email protected]', |
|
| 16 | - 'expose_graph' => true, |
|
| 17 | - ]; |
|
| 13 | + 'partner_email1' => '[email protected]', |
|
| 14 | + 'partner_email2' => '[email protected]', |
|
| 15 | + 'partner_email3' => '[email protected]', |
|
| 16 | + 'expose_graph' => true, |
|
| 17 | + ]; |
|
| 18 | 18 | |
| 19 | - public function setUp() { |
|
| 20 | - $this->graph = $this->getMockBuilder(common\components\Graph::class) |
|
| 21 | - ->setMethods(['create', 'destroy']) |
|
| 22 | - ->getMock(); |
|
| 23 | - parent::setUp(); |
|
| 24 | - } |
|
| 19 | + public function setUp() { |
|
| 20 | + $this->graph = $this->getMockBuilder(common\components\Graph::class) |
|
| 21 | + ->setMethods(['create', 'destroy']) |
|
| 22 | + ->getMock(); |
|
| 23 | + parent::setUp(); |
|
| 24 | + } |
|
| 25 | 25 | |
| 26 | 26 | public function testLoadUser() { |
| 27 | 27 | $user = $this->getUser(); |
@@ -51,20 +51,20 @@ discard block |
||
| 51 | 51 | $form->attributes = $this->values; |
| 52 | 52 | expect('saveProfile should return the user', $this->assertEquals($user, $form->saveProfile())); |
| 53 | 53 | return true; |
| 54 | - expect('saveProfile should set the user\'s attributes to be the form values', $this->assertEquals($this->values, $user->attributes)); |
|
| 54 | + expect('saveProfile should set the user\'s attributes to be the form values', $this->assertEquals($this->values, $user->attributes)); |
|
| 55 | 55 | |
| 56 | 56 | $form->send_email = 'not_a_boolean'; |
| 57 | 57 | expect('saveProfile should return the user with the partner-related settings equal to null', $this->assertNull($form->saveProfile())); |
| 58 | 58 | |
| 59 | - $null_vals = [ |
|
| 60 | - 'partner_email1' => null, |
|
| 61 | - 'partner_email2' => null, |
|
| 62 | - 'partner_email3' => null, |
|
| 59 | + $null_vals = [ |
|
| 60 | + 'partner_email1' => null, |
|
| 61 | + 'partner_email2' => null, |
|
| 62 | + 'partner_email3' => null, |
|
| 63 | 63 | 'send_email' => null, |
| 64 | - 'timezone' => 'America/Los_Angeles', |
|
| 65 | - ]; |
|
| 64 | + 'timezone' => 'America/Los_Angeles', |
|
| 65 | + ]; |
|
| 66 | 66 | $form->send_email = false; |
| 67 | - $ret = $form->saveProfile(); |
|
| 67 | + $ret = $form->saveProfile(); |
|
| 68 | 68 | expect('saveProfile should return the user with the partner-related settings equal to null', $this->assertEquals($null_vals, $user->attributes)); |
| 69 | 69 | |
| 70 | 70 | $form->send_email = 'not_a_boolean'; |
@@ -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'); ?> |
@@ -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, |
@@ -139,10 +139,10 @@ discard block |
||
| 139 | 139 | )->execute(); |
| 140 | 140 | |
| 141 | 141 | // if the user has publicised their score graph, create the image |
| 142 | - if(Yii::$app->user->identity->expose_graph) { |
|
| 142 | + if (Yii::$app->user->identity->expose_graph) { |
|
| 143 | 143 | $checkins_last_month = $this->user_behavior->getCheckInBreakdown(); |
| 144 | 144 | |
| 145 | - if($checkins_last_month) { |
|
| 145 | + if ($checkins_last_month) { |
|
| 146 | 146 | Yii::$container |
| 147 | 147 | ->get(\common\components\Graph::class, [Yii::$app->user->identity]) |
| 148 | 148 | ->create($checkins_last_month, true); |
@@ -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'], |
@@ -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 | |
@@ -127,12 +127,12 @@ discard block |
||
| 127 | 127 | |
| 128 | 128 | public function getCheckinBreakdown(int $period = 30) { |
| 129 | 129 | $datetimes = $this->time->getDateTimesInPeriod($period); |
| 130 | - $key = "scores_of_last_month_".Yii::$app->user->id."_".$this->time->getLocalDate(); |
|
| 130 | + $key = "scores_of_last_month_" . Yii::$app->user->id . "_" . $this->time->getLocalDate(); |
|
| 131 | 131 | $scores = Yii::$app->cache->get($key); |
| 132 | 132 | |
| 133 | - if($scores === false) { |
|
| 133 | + if ($scores === false) { |
|
| 134 | 134 | $scores = []; |
| 135 | - foreach($datetimes as $datetime) { |
|
| 135 | + foreach ($datetimes as $datetime) { |
|
| 136 | 136 | $behaviors = self::decorateWithCategory($this->getBehaviorsWithCounts($datetime)); |
| 137 | 137 | $scores[$datetime->format('Y-m-d')] = $this->getBehaviorsByCategory($behaviors); |
| 138 | 138 | } |
@@ -158,7 +158,7 @@ discard block |
||
| 158 | 158 | public function getBehaviorsByCategory(array $decorated_behaviors) { |
| 159 | 159 | $arr = array_reduce($decorated_behaviors, function($acc, $row) { |
| 160 | 160 | $cat_id = $row['behavior']['category']['id']; |
| 161 | - if(array_key_exists($cat_id, $acc)) { |
|
| 161 | + if (array_key_exists($cat_id, $acc)) { |
|
| 162 | 162 | $acc[$cat_id]['count'] += $row['count']; |
| 163 | 163 | } else { |
| 164 | 164 | $acc[$cat_id] = [ |
@@ -175,10 +175,10 @@ discard block |
||
| 175 | 175 | } |
| 176 | 176 | |
| 177 | 177 | public static function decorate(array $uo, $with_category = false) { |
| 178 | - foreach($uo as &$o) { |
|
| 179 | - if($behavior = \common\models\Behavior::getBehavior('id', $o['behavior_id'])) { |
|
| 178 | + foreach ($uo as &$o) { |
|
| 179 | + if ($behavior = \common\models\Behavior::getBehavior('id', $o['behavior_id'])) { |
|
| 180 | 180 | $o['behavior'] = $behavior; |
| 181 | - if($with_category) { |
|
| 181 | + if ($with_category) { |
|
| 182 | 182 | $o['behavior']['category'] = \common\models\Category::getCategory('id', $o['behavior']['category_id']); |
| 183 | 183 | } |
| 184 | 184 | } |
@@ -199,11 +199,11 @@ discard block |
||
| 199 | 199 | ->having('user_id = :user_id') |
| 200 | 200 | ->orderBy('count DESC'); |
| 201 | 201 | |
| 202 | - if($limit instanceof \DateTime) { |
|
| 202 | + if ($limit instanceof \DateTime) { |
|
| 203 | 203 | list($start, $end) = $this->time->getUTCBookends($limit->format('Y-m-d')); |
| 204 | 204 | $query->params += [':start_date' => $start, ':end_date' => $end]; |
| 205 | 205 | $query->where('user_id=:user_id AND date > :start_date AND date <= :end_date'); |
| 206 | - } else if(is_int($limit)) { |
|
| 206 | + } else if (is_int($limit)) { |
|
| 207 | 207 | $query->limit($limit); |
| 208 | 208 | } |
| 209 | 209 | |
@@ -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) { |