@@ -95,8 +95,8 @@ discard block |
||
| 95 | 95 | parent::setUp(); |
| 96 | 96 | } |
| 97 | 97 | |
| 98 | - public function testAttributeLabels() |
|
| 99 | - { |
|
| 98 | + public function testAttributeLabels() |
|
| 99 | + { |
|
| 100 | 100 | $this->specify('attributeLabels should function properly', function () { |
| 101 | 101 | $model = $this->container->get('\site\models\CheckinForm'); |
| 102 | 102 | expect('attributeLabels should be correct', $this->assertEquals([ |
@@ -116,7 +116,7 @@ discard block |
||
| 116 | 116 | $this->specify('setBehaviors should function properly', function () { |
| 117 | 117 | $model = $this->container->get('\site\models\CheckinForm'); |
| 118 | 118 | |
| 119 | - $model->setBehaviors($this->behaviors); |
|
| 119 | + $model->setBehaviors($this->behaviors); |
|
| 120 | 120 | expect('behaviors1 should be correct', $this->assertEquals([ 0 => 7 ], $model->behaviors1)); |
| 121 | 121 | expect('behaviors2 should be correct', $this->assertEquals([ 0 => 12, 1 => 13, 2 => 17, 3 => 18 ], $model->behaviors2)); |
| 122 | 122 | expect('behaviors3 should be correct', $this->assertEquals([ 0 => 28, 1 => 38, 2 => 46 ], $model->behaviors3)); |
@@ -125,7 +125,7 @@ discard block |
||
| 125 | 125 | expect('behaviors6 should be correct', $this->assertEquals([ 0 => 104 ], $model->behaviors6)); |
| 126 | 126 | expect('behaviors7 should be correct', $this->assertEquals([ 0 => 128 ], $model->behaviors7)); |
| 127 | 127 | |
| 128 | - $model->setBehaviors($this->behaviors); |
|
| 128 | + $model->setBehaviors($this->behaviors); |
|
| 129 | 129 | expect('setBehaviors should not append behaviors to existing ones', $this->assertEquals([ 0 => 7 ], $model->behaviors1)); |
| 130 | 130 | expect('setBehaviors should not append behaviors to existing ones', $this->assertEquals([ 0 => 12, 1 => 13, 2 => 17, 3 => 18 ], $model->behaviors2)); |
| 131 | 131 | expect('setBehaviors should not append behaviors to existing ones', $this->assertEquals([ 0 => 28, 1 => 38, 2 => 46 ], $model->behaviors3)); |
@@ -136,19 +136,19 @@ discard block |
||
| 136 | 136 | }); |
| 137 | 137 | } |
| 138 | 138 | |
| 139 | - public function testValidateBehaviors() |
|
| 140 | - { |
|
| 139 | + public function testValidateBehaviors() |
|
| 140 | + { |
|
| 141 | 141 | $this->specify('validateBehaviors should function properly', function () { |
| 142 | 142 | $model = $this->container->get('\site\models\CheckinForm'); |
| 143 | - $model->setBehaviors($this->behaviors); |
|
| 143 | + $model->setBehaviors($this->behaviors); |
|
| 144 | 144 | expect('validation should be good', $this->assertTrue($model->validate())); |
| 145 | 145 | |
| 146 | 146 | $model->behaviors1[0] = 'bad'; |
| 147 | 147 | expect('validation should be bad', $this->assertFalse($model->validate())); |
| 148 | 148 | }); |
| 149 | - } |
|
| 149 | + } |
|
| 150 | 150 | |
| 151 | - public function testCompileBehaviors() |
|
| 151 | + public function testCompileBehaviors() |
|
| 152 | 152 | { |
| 153 | 153 | $model = $this->container->get('\site\models\CheckinForm'); |
| 154 | 154 | $model->setBehaviors($this->behaviors); |
@@ -164,8 +164,8 @@ discard block |
||
| 164 | 164 | $model->behaviors3[0] = null; |
| 165 | 165 | $model->compileBehaviors(); |
| 166 | 166 | expect('compiling behaviors should strip out any falsy values', $this->assertEquals([ |
| 167 | - 13, 17, 18, 38, 46, 47, 56, 62, 78, 79, 104, 128, |
|
| 168 | - ], $model->compiled_behaviors)); |
|
| 167 | + 13, 17, 18, 38, 46, 47, 56, 62, 78, 79, 104, 128, |
|
| 168 | + ], $model->compiled_behaviors)); |
|
| 169 | 169 | |
| 170 | 170 | $model = $this->container->get('\site\models\CheckinForm'); |
| 171 | 171 | $model->setBehaviors([]); |
@@ -189,6 +189,6 @@ discard block |
||
| 189 | 189 | $expected_behaviors = $base_behaviors; |
| 190 | 190 | $expected_behaviors[7] += $other_behaviors; |
| 191 | 191 | |
| 192 | - expect('mergeWithDefault should return the given behaviors merged in with the base behaviors', $this->assertEquals($base_behaviors, $model->mergeWithDefault($other_behaviors))); |
|
| 192 | + expect('mergeWithDefault should return the given behaviors merged in with the base behaviors', $this->assertEquals($base_behaviors, $model->mergeWithDefault($other_behaviors))); |
|
| 193 | 193 | } |
| 194 | 194 | } |
@@ -117,7 +117,7 @@ discard block |
||
| 117 | 117 | protected function setUp() { |
| 118 | 118 | $this->container = new \yii\di\Container; |
| 119 | 119 | $this->container->set('common\interfaces\UserBehaviorInterface', '\site\tests\_support\MockUserBehavior'); |
| 120 | - $this->container->set('common\interfaces\TimeInterface', function () { |
|
| 120 | + $this->container->set('common\interfaces\TimeInterface', function() { |
|
| 121 | 121 | return new \common\components\Time('America/Los_Angeles'); |
| 122 | 122 | }); |
| 123 | 123 | parent::setUp(); |
@@ -125,7 +125,7 @@ discard block |
||
| 125 | 125 | |
| 126 | 126 | public function testAttributeLabels() |
| 127 | 127 | { |
| 128 | - $this->specify('attributeLabels should function properly', function () { |
|
| 128 | + $this->specify('attributeLabels should function properly', function() { |
|
| 129 | 129 | $model = $this->container->get('\site\models\CheckinForm'); |
| 130 | 130 | expect('attributeLabels should be correct', $this->assertEquals([ |
| 131 | 131 | 'behaviors1' => 'Restoration', |
@@ -141,32 +141,32 @@ discard block |
||
| 141 | 141 | |
| 142 | 142 | public function testSetBehaviors() |
| 143 | 143 | { |
| 144 | - $this->specify('setBehaviors should function properly', function () { |
|
| 144 | + $this->specify('setBehaviors should function properly', function() { |
|
| 145 | 145 | $model = $this->container->get('\site\models\CheckinForm'); |
| 146 | 146 | |
| 147 | 147 | $model->setBehaviors($this->behaviors); |
| 148 | - expect('behaviors1 should be correct', $this->assertEquals([ 0 => 7 ], $model->behaviors1)); |
|
| 149 | - expect('behaviors2 should be correct', $this->assertEquals([ 0 => 12, 1 => 13, 2 => 17, 3 => 18 ], $model->behaviors2)); |
|
| 150 | - expect('behaviors3 should be correct', $this->assertEquals([ 0 => 28, 1 => 38, 2 => 46 ], $model->behaviors3)); |
|
| 151 | - expect('behaviors4 should be correct', $this->assertEquals([ 0 => 47, 1 => 56, 2 => 62 ], $model->behaviors4)); |
|
| 152 | - expect('behaviors5 should be correct', $this->assertEquals([ 0 => 78, 1 => 79 ], $model->behaviors5)); |
|
| 153 | - expect('behaviors6 should be correct', $this->assertEquals([ 0 => 104 ], $model->behaviors6)); |
|
| 154 | - expect('behaviors7 should be correct', $this->assertEquals([ 0 => 128 ], $model->behaviors7)); |
|
| 148 | + expect('behaviors1 should be correct', $this->assertEquals([0 => 7], $model->behaviors1)); |
|
| 149 | + expect('behaviors2 should be correct', $this->assertEquals([0 => 12, 1 => 13, 2 => 17, 3 => 18], $model->behaviors2)); |
|
| 150 | + expect('behaviors3 should be correct', $this->assertEquals([0 => 28, 1 => 38, 2 => 46], $model->behaviors3)); |
|
| 151 | + expect('behaviors4 should be correct', $this->assertEquals([0 => 47, 1 => 56, 2 => 62], $model->behaviors4)); |
|
| 152 | + expect('behaviors5 should be correct', $this->assertEquals([0 => 78, 1 => 79], $model->behaviors5)); |
|
| 153 | + expect('behaviors6 should be correct', $this->assertEquals([0 => 104], $model->behaviors6)); |
|
| 154 | + expect('behaviors7 should be correct', $this->assertEquals([0 => 128], $model->behaviors7)); |
|
| 155 | 155 | |
| 156 | 156 | $model->setBehaviors($this->behaviors); |
| 157 | - expect('setBehaviors should not append behaviors to existing ones', $this->assertEquals([ 0 => 7 ], $model->behaviors1)); |
|
| 158 | - expect('setBehaviors should not append behaviors to existing ones', $this->assertEquals([ 0 => 12, 1 => 13, 2 => 17, 3 => 18 ], $model->behaviors2)); |
|
| 159 | - expect('setBehaviors should not append behaviors to existing ones', $this->assertEquals([ 0 => 28, 1 => 38, 2 => 46 ], $model->behaviors3)); |
|
| 160 | - expect('setBehaviors should not append behaviors to existing ones', $this->assertEquals([ 0 => 47, 1 => 56, 2 => 62 ], $model->behaviors4)); |
|
| 161 | - expect('setBehaviors should not append behaviors to existing ones', $this->assertEquals([ 0 => 78, 1 => 79 ], $model->behaviors5)); |
|
| 162 | - expect('setBehaviors should not append behaviors to existing ones', $this->assertEquals([ 0 => 104 ], $model->behaviors6)); |
|
| 163 | - expect('setBehaviors should not append behaviors to existing ones', $this->assertEquals([ 0 => 128 ], $model->behaviors7)); |
|
| 157 | + expect('setBehaviors should not append behaviors to existing ones', $this->assertEquals([0 => 7], $model->behaviors1)); |
|
| 158 | + expect('setBehaviors should not append behaviors to existing ones', $this->assertEquals([0 => 12, 1 => 13, 2 => 17, 3 => 18], $model->behaviors2)); |
|
| 159 | + expect('setBehaviors should not append behaviors to existing ones', $this->assertEquals([0 => 28, 1 => 38, 2 => 46], $model->behaviors3)); |
|
| 160 | + expect('setBehaviors should not append behaviors to existing ones', $this->assertEquals([0 => 47, 1 => 56, 2 => 62], $model->behaviors4)); |
|
| 161 | + expect('setBehaviors should not append behaviors to existing ones', $this->assertEquals([0 => 78, 1 => 79], $model->behaviors5)); |
|
| 162 | + expect('setBehaviors should not append behaviors to existing ones', $this->assertEquals([0 => 104], $model->behaviors6)); |
|
| 163 | + expect('setBehaviors should not append behaviors to existing ones', $this->assertEquals([0 => 128], $model->behaviors7)); |
|
| 164 | 164 | }); |
| 165 | 165 | } |
| 166 | 166 | |
| 167 | 167 | public function testValidateBehaviors() |
| 168 | 168 | { |
| 169 | - $this->specify('validateBehaviors should function properly', function () { |
|
| 169 | + $this->specify('validateBehaviors should function properly', function() { |
|
| 170 | 170 | $model = $this->container->get('\site\models\CheckinForm'); |
| 171 | 171 | $model->setBehaviors($this->behaviors); |
| 172 | 172 | expect('validation should be good', $this->assertTrue($model->validate())); |
@@ -213,7 +213,7 @@ discard block |
||
| 213 | 213 | |
| 214 | 214 | $model = $this->container->get('\site\models\CheckinForm'); |
| 215 | 215 | $model->custom_behaviors = []; |
| 216 | - $model->compiled_behaviors = [ 1, 2, 3]; |
|
| 216 | + $model->compiled_behaviors = [1, 2, 3]; |
|
| 217 | 217 | expect('to return an empty array if no custom behaviors are set', $this->assertEquals([], $model->getCustomBehaviors())); |
| 218 | 218 | } |
| 219 | 219 | |
@@ -10,8 +10,7 @@ discard block |
||
| 10 | 10 | $this->title = "The Faster Scale App | Check-in"; |
| 11 | 11 | |
| 12 | 12 | function checkboxItemTemplate($index, $label, $name, $checked, $value) { |
| 13 | - return Html::checkbox |
|
| 14 | - ( |
|
| 13 | + return Html::checkbox( |
|
| 15 | 14 | $name, |
| 16 | 15 | $checked, |
| 17 | 16 | [ |
@@ -35,10 +34,10 @@ discard block |
||
| 35 | 34 | 'options' => ['class' => 'form-horizontal'], |
| 36 | 35 | ]); |
| 37 | 36 | |
| 38 | -foreach($categories as $category) { |
|
| 37 | +foreach ($categories as $category) { |
|
| 39 | 38 | $behaviors = AH::map($behaviorsList[$category['id']], 'id', 'name'); |
| 40 | 39 | $custom = []; |
| 41 | - if(array_key_exists($category['id'], $customList)) { |
|
| 40 | + if (array_key_exists($category['id'], $customList)) { |
|
| 42 | 41 | $custom = AH::map($customList[$category['id']], function($cbhvr) { |
| 43 | 42 | return $cbhvr['id'] . '-custom'; |
| 44 | 43 | }, 'name'); |
@@ -46,7 +46,7 @@ |
||
| 46 | 46 | print $form |
| 47 | 47 | ->field($model, "behaviors{$category['id']}") |
| 48 | 48 | ->checkboxList($behaviors + $custom, |
| 49 | - ['data-toggle' => 'buttons', 'item' => "checkboxItemTemplate"]); |
|
| 49 | + ['data-toggle' => 'buttons', 'item' => "checkboxItemTemplate"]); |
|
| 50 | 50 | } |
| 51 | 51 | print Html::submitButton('Submit', ['class' => 'btn btn-success']); |
| 52 | 52 | ActiveForm::end(); |
@@ -98,7 +98,7 @@ discard block |
||
| 98 | 98 | |
| 99 | 99 | public function getByUser(int $user_id, $local_date = null) { |
| 100 | 100 | $time = Yii::$container->get(\common\interfaces\TimeInterface::class); |
| 101 | - if(is_null($local_date)) $local_date = $time->getLocalDate(); |
|
| 101 | + if (is_null($local_date)) $local_date = $time->getLocalDate(); |
|
| 102 | 102 | list($start, $end) = $time->getUTCBookends($local_date); |
| 103 | 103 | |
| 104 | 104 | $questions = $this->find() |
@@ -117,10 +117,10 @@ discard block |
||
| 117 | 117 | } |
| 118 | 118 | |
| 119 | 119 | public function parseQuestionData($questions) { |
| 120 | - if(!$questions) return []; |
|
| 120 | + if (!$questions) return []; |
|
| 121 | 121 | |
| 122 | 122 | $question_answers = []; |
| 123 | - foreach($questions as $question) { |
|
| 123 | + foreach ($questions as $question) { |
|
| 124 | 124 | $user_behavior_id = $question->user_behavior_id; |
| 125 | 125 | |
| 126 | 126 | $behavior_name = $question->behavior_id |
@@ -98,7 +98,9 @@ discard block |
||
| 98 | 98 | |
| 99 | 99 | public function getByUser(int $user_id, $local_date = null) { |
| 100 | 100 | $time = Yii::$container->get(\common\interfaces\TimeInterface::class); |
| 101 | - if(is_null($local_date)) $local_date = $time->getLocalDate(); |
|
| 101 | + if(is_null($local_date)) { |
|
| 102 | + $local_date = $time->getLocalDate(); |
|
| 103 | + } |
|
| 102 | 104 | list($start, $end) = $time->getUTCBookends($local_date); |
| 103 | 105 | |
| 104 | 106 | $questions = $this->find() |
@@ -117,7 +119,9 @@ discard block |
||
| 117 | 119 | } |
| 118 | 120 | |
| 119 | 121 | public function parseQuestionData($questions) { |
| 120 | - if(!$questions) return []; |
|
| 122 | + if(!$questions) { |
|
| 123 | + return []; |
|
| 124 | + } |
|
| 121 | 125 | |
| 122 | 126 | $question_answers = []; |
| 123 | 127 | foreach($questions as $question) { |
@@ -125,14 +125,14 @@ discard block |
||
| 125 | 125 | <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"> |
| 126 | 126 | |
| 127 | 127 | <?php |
| 128 | -if($questions) { |
|
| 129 | - foreach($questions as $behavior_id => $behavior_questions) { |
|
| 128 | +if ($questions) { |
|
| 129 | + foreach ($questions as $behavior_id => $behavior_questions) { |
|
| 130 | 130 | ?> |
| 131 | 131 | |
| 132 | 132 | <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"> <?= Html::encode($behavior_questions['question']['behavior_name']) ?> </h4> |
| 133 | 133 | |
| 134 | 134 | <?php |
| 135 | - foreach($behavior_questions['answers'] as $key => $question) { ?> |
|
| 135 | + foreach ($behavior_questions['answers'] as $key => $question) { ?> |
|
| 136 | 136 | <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><?= Html::encode($question['title']) ?></strong> <?= Html::encode($question['answer']) ?></p> |
| 137 | 137 | <?php |
| 138 | 138 | } |
@@ -189,12 +189,12 @@ discard block |
||
| 189 | 189 | <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"> |
| 190 | 190 | |
| 191 | 191 | <?php |
| 192 | -if($user_behaviors) { |
|
| 193 | - foreach($user_behaviors as $cat_key => $behaviors) { ?> |
|
| 192 | +if ($user_behaviors) { |
|
| 193 | + foreach ($user_behaviors as $cat_key => $behaviors) { ?> |
|
| 194 | 194 | <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"> |
| 195 | 195 | <strong style="color:#37b98f"><?= Html::encode($categories[$cat_key]) ?></strong> |
| 196 | 196 | <?php |
| 197 | - foreach($behaviors as $behavior) { ?> |
|
| 197 | + foreach ($behaviors as $behavior) { ?> |
|
| 198 | 198 | <br><?= Html::encode($behavior['name']) ?> |
| 199 | 199 | <?php |
| 200 | 200 | } |
@@ -88,7 +88,7 @@ discard block |
||
| 88 | 88 | $this->container = new \yii\di\Container; |
| 89 | 89 | $this->container->set('common\interfaces\UserInterface', '\site\tests\_support\MockUser'); |
| 90 | 90 | $this->container->set('common\interfaces\UserBehaviorInterface', '\site\tests\_support\MockUserBehavior'); |
| 91 | - $this->container->set('common\interfaces\TimeInterface', function () { |
|
| 91 | + $this->container->set('common\interfaces\TimeInterface', function() { |
|
| 92 | 92 | return new \common\components\Time('America/Los_Angeles'); |
| 93 | 93 | }); |
| 94 | 94 | |
@@ -134,7 +134,7 @@ discard block |
||
| 134 | 134 | } |
| 135 | 135 | |
| 136 | 136 | public function testIsTokenCurrent() { |
| 137 | - $this->specify('isTokenCurrent should function correctly', function () { |
|
| 137 | + $this->specify('isTokenCurrent should function correctly', function() { |
|
| 138 | 138 | $good_token = \Yii::$app |
| 139 | 139 | ->getSecurity() |
| 140 | 140 | ->generateRandomString() . '_' . time(); |
@@ -168,7 +168,7 @@ discard block |
||
| 168 | 168 | public function testConfirmVerifyEmailToken() { |
| 169 | 169 | $this->user->verify_email_token = 'hello_world'; |
| 170 | 170 | $this->user->confirmVerifyEmailToken(); |
| 171 | - expect('confirmVerifyEmailToken should append User::CONFIRMED_STRING to the end of the verify_email_token property', $this->assertEquals($this->user->verify_email_token, 'hello_world'.$this->user::CONFIRMED_STRING)); |
|
| 171 | + expect('confirmVerifyEmailToken should append User::CONFIRMED_STRING to the end of the verify_email_token property', $this->assertEquals($this->user->verify_email_token, 'hello_world' . $this->user::CONFIRMED_STRING)); |
|
| 172 | 172 | } |
| 173 | 173 | |
| 174 | 174 | public function testIsVerified() { |
@@ -262,7 +262,7 @@ discard block |
||
| 262 | 262 | ->disableOriginalConstructor() |
| 263 | 263 | ->setMethods(['save', 'attributes', 'getCheckinBreakdown']) |
| 264 | 264 | ->getMock(); |
| 265 | - $expected = require(__DIR__.'/../data/expected_getCheckinBreakdown.php'); |
|
| 265 | + $expected = require(__DIR__ . '/../data/expected_getCheckinBreakdown.php'); |
|
| 266 | 266 | $user_behavior->method('getCheckinBreakdown')->willReturn($expected); |
| 267 | 267 | |
| 268 | 268 | $user = $this->getMockBuilder(User::class) |
@@ -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; |
@@ -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 | |
@@ -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'], |