@@ -106,9 +106,9 @@ |
||
106 | 106 | ], [ |
107 | 107 | 'class' => 'kartik\grid\ActionColumn', |
108 | 108 | 'buttons' => [ |
109 | - 'view' => function ($url, $model) { return ''; }, |
|
110 | - 'update' => function ($url, $model) { return ''; }, |
|
111 | - 'delete' => function ($url, $model) { |
|
109 | + 'view' => function($url, $model) { return ''; }, |
|
110 | + 'update' => function($url, $model) { return ''; }, |
|
111 | + 'delete' => function($url, $model) { |
|
112 | 112 | return yii\helpers\Html::a('<span class="glyphicon glyphicon-remove"></span>', "/custom-behavior/delete?id={$model->id}", [ |
113 | 113 | 'title' => 'Delete', |
114 | 114 | 'data-pjax' => true, |
@@ -11,8 +11,8 @@ discard block |
||
11 | 11 | 'common\interfaces\BehaviorInterface' => \common\models\Behavior::class, |
12 | 12 | 'common\interfaces\CategoryInterface' => \common\models\Category::class, |
13 | 13 | 'common\interfaces\CustomBehaviorInterface' => \common\models\CustomBehavior::class, |
14 | - 'common\interfaces\TimeInterface' => function () { |
|
15 | - if(Yii::$app->user->getIsGuest()) { |
|
14 | + 'common\interfaces\TimeInterface' => function() { |
|
15 | + if (Yii::$app->user->getIsGuest()) { |
|
16 | 16 | return new \common\components\Time('UTC'); |
17 | 17 | } else { |
18 | 18 | return new \common\components\Time(Yii::$app->user->identity->timezone); |
@@ -30,7 +30,7 @@ discard block |
||
30 | 30 | ], |
31 | 31 | 'components' => [ |
32 | 32 | // by default, sessions are stored in a local file |
33 | - 'cache' => [ // DummyCache never actually caches anything |
|
33 | + 'cache' => [// DummyCache never actually caches anything |
|
34 | 34 | 'class'=> yii\caching\DummyCache::class, |
35 | 35 | ], |
36 | 36 | 'mailer' => [ |
@@ -58,7 +58,7 @@ discard block |
||
58 | 58 | public function setBehaviors($behaviors) { |
59 | 59 | foreach($behaviors as $category_id => $bhvr_set) { |
60 | 60 | $attribute = "behaviors$category_id"; |
61 | - $this->$attribute = []; |
|
61 | + $this->$attribute = []; |
|
62 | 62 | foreach($bhvr_set as $behavior) { |
63 | 63 | $this->{$attribute}[] = $behavior['id']; |
64 | 64 | } |
@@ -89,12 +89,12 @@ discard block |
||
89 | 89 | */ |
90 | 90 | public function compileBehaviors() { |
91 | 91 | $behaviors = array_merge((array)$this->behaviors1, |
92 | - (array)$this->behaviors2, |
|
93 | - (array)$this->behaviors3, |
|
94 | - (array)$this->behaviors4, |
|
95 | - (array)$this->behaviors5, |
|
96 | - (array)$this->behaviors6, |
|
97 | - (array)$this->behaviors7); |
|
92 | + (array)$this->behaviors2, |
|
93 | + (array)$this->behaviors3, |
|
94 | + (array)$this->behaviors4, |
|
95 | + (array)$this->behaviors5, |
|
96 | + (array)$this->behaviors6, |
|
97 | + (array)$this->behaviors7); |
|
98 | 98 | |
99 | 99 | $clean_behaviors = array_filter($behaviors); // strip out false values |
100 | 100 |
@@ -56,10 +56,10 @@ discard block |
||
56 | 56 | } |
57 | 57 | |
58 | 58 | public function setBehaviors($behaviors) { |
59 | - foreach($behaviors as $category_id => $bhvr_set) { |
|
59 | + foreach ($behaviors as $category_id => $bhvr_set) { |
|
60 | 60 | $attribute = "behaviors$category_id"; |
61 | 61 | $this->$attribute = []; |
62 | - foreach($bhvr_set as $behavior) { |
|
62 | + foreach ($bhvr_set as $behavior) { |
|
63 | 63 | $this->{$attribute}[] = $behavior['id']; |
64 | 64 | } |
65 | 65 | } |
@@ -67,8 +67,8 @@ discard block |
||
67 | 67 | |
68 | 68 | public function validateBehaviors($attribute, $params) { |
69 | 69 | if (!$this->hasErrors()) { |
70 | - foreach($this->$attribute as $behavior) { |
|
71 | - if(!is_numeric($behavior) && !preg_match('/[0-9]{1,2}-custom/', $behavior)) { |
|
70 | + foreach ($this->$attribute as $behavior) { |
|
71 | + if (!is_numeric($behavior) && !preg_match('/[0-9]{1,2}-custom/', $behavior)) { |
|
72 | 72 | $this->addError($attribute, 'One of your behaviors is not an integer!'); |
73 | 73 | } |
74 | 74 | } |
@@ -99,11 +99,11 @@ discard block |
||
99 | 99 | $clean_behaviors = array_filter($behaviors); // strip out false values |
100 | 100 | |
101 | 101 | // if there are no selected behaviors just return false now |
102 | - if(sizeof($clean_behaviors) === 0) return false; |
|
102 | + if (sizeof($clean_behaviors) === 0) return false; |
|
103 | 103 | |
104 | 104 | $self = $this; |
105 | 105 | array_walk($clean_behaviors, function($bhvr) use (&$self) { |
106 | - if(preg_match('/.*-custom/', $bhvr)) { |
|
106 | + if (preg_match('/.*-custom/', $bhvr)) { |
|
107 | 107 | $self->custom_behaviors[] = $bhvr; |
108 | 108 | } else { |
109 | 109 | $self->compiled_behaviors[] = $bhvr; |
@@ -132,7 +132,7 @@ discard block |
||
132 | 132 | |
133 | 133 | // delete cached behaviors |
134 | 134 | array_map(function($period) use ($time) { |
135 | - $key = "checkins_".Yii::$app->user->id."_{$period}_".$time->getLocalDate(); |
|
135 | + $key = "checkins_" . Yii::$app->user->id . "_{$period}_" . $time->getLocalDate(); |
|
136 | 136 | Yii::$app->cache->delete($key); |
137 | 137 | }, [30, 90, 180]); |
138 | 138 | } |
@@ -146,7 +146,7 @@ discard block |
||
146 | 146 | public function mergeWithDefault(array $user_behaviors) { |
147 | 147 | $behaviors = AH::index(Yii::$container->get(BehaviorInterface::class)::$behaviors, 'name', "category_id"); |
148 | 148 | array_walk($behaviors, function(&$bhvrs, $cat_id) use ($user_behaviors) { |
149 | - if(array_key_exists($cat_id, $user_behaviors)) { |
|
149 | + if (array_key_exists($cat_id, $user_behaviors)) { |
|
150 | 150 | $bhvrs = AH::merge($bhvrs, $user_behaviors[$cat_id]); |
151 | 151 | } |
152 | 152 | }); |
@@ -169,10 +169,10 @@ discard block |
||
169 | 169 | } |
170 | 170 | |
171 | 171 | public function save() { |
172 | - if(empty($this->compiled_behaviors) && empty($this->custom_behaviors)) { |
|
172 | + if (empty($this->compiled_behaviors) && empty($this->custom_behaviors)) { |
|
173 | 173 | // maybe we haven't compiled the behaviors yet |
174 | 174 | $exit = !!!$this->compileBehaviors(); |
175 | - if($exit) return false; |
|
175 | + if ($exit) return false; |
|
176 | 176 | } |
177 | 177 | |
178 | 178 | $custom_bhvrs = \common\models\CustomBehavior::find() |
@@ -187,7 +187,7 @@ discard block |
||
187 | 187 | |
188 | 188 | $rows = []; |
189 | 189 | // this can be condensed....but we are optimizing for readability |
190 | - foreach($this->compiled_behaviors as $behavior_id) { |
|
190 | + foreach ($this->compiled_behaviors as $behavior_id) { |
|
191 | 191 | $behavior_id = (int)$behavior_id; |
192 | 192 | $behavior = \common\models\Behavior::getBehavior('id', $behavior_id); |
193 | 193 | $category_id = $behavior['category_id']; |
@@ -202,7 +202,7 @@ discard block |
||
202 | 202 | $rows[] = $temp; |
203 | 203 | } |
204 | 204 | |
205 | - foreach($custom_bhvrs as $cb) { |
|
205 | + foreach ($custom_bhvrs as $cb) { |
|
206 | 206 | $temp = [ |
207 | 207 | Yii::$app->user->id, |
208 | 208 | null, |
@@ -225,10 +225,10 @@ discard block |
||
225 | 225 | )->execute(); |
226 | 226 | |
227 | 227 | // if the user has publicised their check-in graph, create the image |
228 | - if(Yii::$app->user->identity->expose_graph) { |
|
228 | + if (Yii::$app->user->identity->expose_graph) { |
|
229 | 229 | $checkins_last_month = $user_behavior->getCheckInBreakdown(); |
230 | 230 | |
231 | - if($checkins_last_month) { |
|
231 | + if ($checkins_last_month) { |
|
232 | 232 | Yii::$container |
233 | 233 | ->get(\common\components\Graph::class, [Yii::$app->user->identity]) |
234 | 234 | ->create($checkins_last_month, true); |
@@ -99,7 +99,9 @@ discard block |
||
99 | 99 | $clean_behaviors = array_filter($behaviors); // strip out false values |
100 | 100 | |
101 | 101 | // if there are no selected behaviors just return false now |
102 | - if(sizeof($clean_behaviors) === 0) return false; |
|
102 | + if(sizeof($clean_behaviors) === 0) { |
|
103 | + return false; |
|
104 | + } |
|
103 | 105 | |
104 | 106 | $self = $this; |
105 | 107 | array_walk($clean_behaviors, function($bhvr) use (&$self) { |
@@ -172,7 +174,9 @@ discard block |
||
172 | 174 | if(empty($this->compiled_behaviors) && empty($this->custom_behaviors)) { |
173 | 175 | // maybe we haven't compiled the behaviors yet |
174 | 176 | $exit = !!!$this->compileBehaviors(); |
175 | - if($exit) return false; |
|
177 | + if($exit) { |
|
178 | + return false; |
|
179 | + } |
|
176 | 180 | } |
177 | 181 | |
178 | 182 | $custom_bhvrs = \common\models\CustomBehavior::find() |
@@ -42,16 +42,16 @@ discard block |
||
42 | 42 | |
43 | 43 | public function actions() { |
44 | 44 | return array_replace_recursive(parent::actions(), [ |
45 | - 'update' => [ // identifier for your editable column action |
|
45 | + 'update' => [// identifier for your editable column action |
|
46 | 46 | 'class' => EditableColumnAction::className(), // action class name |
47 | - 'modelClass' => CustoMBehavior::className(), // the model for the record being edited |
|
48 | - 'scenario' => CustomBehavior::SCENARIO_DEFAULT, // model scenario assigned before validation & update |
|
49 | - 'showModelErrors' => true, // show model validation errors after save |
|
50 | - 'errorOptions' => ['header' => ''], // error summary HTML options |
|
47 | + 'modelClass' => CustoMBehavior::className(), // the model for the record being edited |
|
48 | + 'scenario' => CustomBehavior::SCENARIO_DEFAULT, // model scenario assigned before validation & update |
|
49 | + 'showModelErrors' => true, // show model validation errors after save |
|
50 | + 'errorOptions' => ['header' => ''], // error summary HTML options |
|
51 | 51 | 'postOnly' => true, |
52 | 52 | 'ajaxOnly' => true, |
53 | 53 | 'findModel' => function($id, $action) { |
54 | - if(($model = CustomBehavior::findOne(['id' => $id, 'user_id' => Yii::$app->user->identity->id])) !== null) { |
|
54 | + if (($model = CustomBehavior::findOne(['id' => $id, 'user_id' => Yii::$app->user->identity->id])) !== null) { |
|
55 | 55 | return $model; |
56 | 56 | } |
57 | 57 | throw new NotFoundHttpException('The specified behavior does not exist.'); |
@@ -64,13 +64,13 @@ discard block |
||
64 | 64 | public function actionCreate() { |
65 | 65 | $form = Yii::$container->get(\site\models\CustomBehaviorForm::class, [Yii::$app->user->identity]); |
66 | 66 | |
67 | - if($form->load(Yii::$app->request->post()) && $form->validate()) { |
|
67 | + if ($form->load(Yii::$app->request->post()) && $form->validate()) { |
|
68 | 68 | $form->save(); |
69 | 69 | return $this->redirect(['profile/index']); |
70 | 70 | } |
71 | 71 | |
72 | 72 | \Yii::$app->response->format = \yii\web\Response::FORMAT_JSON; |
73 | - if($errors = $form->getErrorSummary(true)) { |
|
73 | + if ($errors = $form->getErrorSummary(true)) { |
|
74 | 74 | return $errors; |
75 | 75 | } else { |
76 | 76 | return ["success" => false, "message" => "Unknown Error"]; |
@@ -84,7 +84,7 @@ discard block |
||
84 | 84 | } |
85 | 85 | |
86 | 86 | protected function findModel($id) { |
87 | - if(($model = CustomBehavior::findOne(['id' => $id, 'user_id' => Yii::$app->user->identity->id])) !== null) { |
|
87 | + if (($model = CustomBehavior::findOne(['id' => $id, 'user_id' => Yii::$app->user->identity->id])) !== null) { |
|
88 | 88 | return $model; |
89 | 89 | } |
90 | 90 |
@@ -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(); |
@@ -123,7 +123,7 @@ |
||
123 | 123 | <p>If you're really <em>really</em> sure about this, enter your password below and click the Delete button. You will be logged out, your account and all your stored data will be immediately deleted, and a notification email will be sent to you and your partners.</p> |
124 | 124 | <?php $form = ActiveForm::begin([ |
125 | 125 | 'id' => 'form-delete-account', |
126 | - 'action' => ['profile/delete-account'], |
|
126 | + 'action' => ['profile/delete-account'], |
|
127 | 127 | 'method' => 'post', |
128 | 128 | 'enableClientValidation' => true, |
129 | 129 | 'options' => ['validateOnSubmit' => true] |
@@ -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) { |
@@ -158,7 +158,9 @@ discard block |
||
158 | 158 | */ |
159 | 159 | public function findByVerifyEmailToken($token) |
160 | 160 | { |
161 | - if($this->isTokenConfirmed($token)) return null; |
|
161 | + if($this->isTokenConfirmed($token)) { |
|
162 | + return null; |
|
163 | + } |
|
162 | 164 | |
163 | 165 | $user = $this->findOne([ |
164 | 166 | 'verify_email_token' => [$token, $token . self::CONFIRMED_STRING], |
@@ -222,7 +224,9 @@ discard block |
||
222 | 224 | * @param string $match the needle to search for |
223 | 225 | */ |
224 | 226 | public function isTokenConfirmed($token = null, String $match = self::CONFIRMED_STRING) { |
225 | - if(is_null($token)) $token = $this->verify_email_token; |
|
227 | + if(is_null($token)) { |
|
228 | + $token = $this->verify_email_token; |
|
229 | + } |
|
226 | 230 | return substr($token, -strlen($match)) === $match; |
227 | 231 | } |
228 | 232 | |
@@ -366,7 +370,10 @@ discard block |
||
366 | 370 | * partner email address the user has set. |
367 | 371 | */ |
368 | 372 | public function sendEmailReport($date) { |
369 | - if(!$this->send_email) return false; // no partner emails set |
|
373 | + if(!$this->send_email) { |
|
374 | + return false; |
|
375 | + } |
|
376 | + // no partner emails set |
|
370 | 377 | list($start, $end) = $this->time->getUTCBookends($date); |
371 | 378 | |
372 | 379 | $user_behavior = Yii::$container->get(UserBehaviorInterface::class); |
@@ -375,14 +382,22 @@ discard block |
||
375 | 382 | // we should only proceed with sending the email if the user |
376 | 383 | // scored above their set email threshold (User::email_category) |
377 | 384 | $this_checkin = $checkins_last_month[$date]; // gets the check-in |
378 | - if(!$this_checkin) return false; // sanity check |
|
385 | + if(!$this_checkin) { |
|
386 | + return false; |
|
387 | + } |
|
388 | + // sanity check |
|
379 | 389 | $highest_cat_data = end($this_checkin); // gets the data for the highest category from the check-in |
380 | - if(!$highest_cat_data) return false; // another sanity check |
|
390 | + if(!$highest_cat_data) { |
|
391 | + return false; |
|
392 | + } |
|
393 | + // another sanity check |
|
381 | 394 | $highest_cat_idx = key($this_checkin); // gets the key of the highest category |
382 | 395 | |
383 | 396 | // if the highest category they reached today was less than |
384 | 397 | // the category threshold they have set, don't send the email |
385 | - if($highest_cat_idx < $this->email_category) return false; |
|
398 | + if($highest_cat_idx < $this->email_category) { |
|
399 | + return false; |
|
400 | + } |
|
386 | 401 | |
387 | 402 | $user_behaviors = $user_behavior->getByDate(Yii::$app->user->id, $date); |
388 | 403 |
@@ -149,7 +149,7 @@ discard block |
||
149 | 149 | */ |
150 | 150 | public function findByPasswordResetToken($token) |
151 | 151 | { |
152 | - if(!$this->isTokenCurrent($token)) { |
|
152 | + if (!$this->isTokenCurrent($token)) { |
|
153 | 153 | return null; |
154 | 154 | } |
155 | 155 | |
@@ -167,15 +167,15 @@ discard block |
||
167 | 167 | */ |
168 | 168 | public function findByVerifyEmailToken($token) |
169 | 169 | { |
170 | - if($this->isTokenConfirmed($token)) return null; |
|
170 | + if ($this->isTokenConfirmed($token)) return null; |
|
171 | 171 | |
172 | 172 | $user = $this->findOne([ |
173 | 173 | 'verify_email_token' => [$token, $token . self::CONFIRMED_STRING], |
174 | 174 | 'status' => self::STATUS_ACTIVE, |
175 | 175 | ]); |
176 | 176 | |
177 | - if($user) { |
|
178 | - if(!$this->isTokenConfirmed($token) && |
|
177 | + if ($user) { |
|
178 | + if (!$this->isTokenConfirmed($token) && |
|
179 | 179 | !$this->isTokenCurrent($token, 'user.verifyAccountTokenExpire')) { |
180 | 180 | return null; |
181 | 181 | } |
@@ -197,8 +197,8 @@ discard block |
||
197 | 197 | 'status' => self::STATUS_ACTIVE, |
198 | 198 | ]); |
199 | 199 | |
200 | - if($user) { |
|
201 | - if(!$user->isTokenCurrent($token, 'user.verifyAccountTokenExpire')) { |
|
200 | + if ($user) { |
|
201 | + if (!$user->isTokenCurrent($token, 'user.verifyAccountTokenExpire')) { |
|
202 | 202 | return null; |
203 | 203 | } |
204 | 204 | } |
@@ -216,7 +216,7 @@ discard block |
||
216 | 216 | public function isTokenCurrent($token, String $paramPath = 'user.passwordResetTokenExpire') { |
217 | 217 | $expire = \Yii::$app->params[$paramPath]; |
218 | 218 | $parts = explode('_', $token); |
219 | - $timestamp = (int) end($parts); |
|
219 | + $timestamp = (int)end($parts); |
|
220 | 220 | if ($timestamp + $expire < time()) { |
221 | 221 | // token expired |
222 | 222 | return false; |
@@ -231,7 +231,7 @@ discard block |
||
231 | 231 | * @param string $match the needle to search for |
232 | 232 | */ |
233 | 233 | public function isTokenConfirmed($token = null, String $match = self::CONFIRMED_STRING) { |
234 | - if(is_null($token)) $token = $this->verify_email_token; |
|
234 | + if (is_null($token)) $token = $this->verify_email_token; |
|
235 | 235 | return substr($token, -strlen($match)) === $match; |
236 | 236 | } |
237 | 237 | |
@@ -256,7 +256,7 @@ discard block |
||
256 | 256 | } |
257 | 257 | |
258 | 258 | public function isVerified() { |
259 | - if(is_null($this->verify_email_token)) { |
|
259 | + if (is_null($this->verify_email_token)) { |
|
260 | 260 | // for old users who verified their accounts before the addition of |
261 | 261 | // '_confirmed' to the token |
262 | 262 | return true; |
@@ -375,7 +375,7 @@ discard block |
||
375 | 375 | * partner email address the user has set. |
376 | 376 | */ |
377 | 377 | public function sendEmailReport($date) { |
378 | - if(!$this->send_email) return false; // no partner emails set |
|
378 | + if (!$this->send_email) return false; // no partner emails set |
|
379 | 379 | list($start, $end) = $this->time->getUTCBookends($date); |
380 | 380 | |
381 | 381 | $user_behavior = Yii::$container->get(UserBehaviorInterface::class); |
@@ -384,14 +384,14 @@ discard block |
||
384 | 384 | // we should only proceed with sending the email if the user |
385 | 385 | // scored above their set email threshold (User::email_category) |
386 | 386 | $this_checkin = $checkins_last_month[$date]; // gets the check-in |
387 | - if(!$this_checkin) return false; // sanity check |
|
388 | - $highest_cat_data = end($this_checkin); // gets the data for the highest category from the check-in |
|
389 | - if(!$highest_cat_data) return false; // another sanity check |
|
390 | - $highest_cat_idx = key($this_checkin); // gets the key of the highest category |
|
387 | + if (!$this_checkin) return false; // sanity check |
|
388 | + $highest_cat_data = end($this_checkin); // gets the data for the highest category from the check-in |
|
389 | + if (!$highest_cat_data) return false; // another sanity check |
|
390 | + $highest_cat_idx = key($this_checkin); // gets the key of the highest category |
|
391 | 391 | |
392 | 392 | // if the highest category they reached today was less than |
393 | 393 | // the category threshold they have set, don't send the email |
394 | - if($highest_cat_idx < $this->email_category) return false; |
|
394 | + if ($highest_cat_idx < $this->email_category) return false; |
|
395 | 395 | |
396 | 396 | $user_behaviors = $user_behavior->getByDate(Yii::$app->user->id, $date); |
397 | 397 | |
@@ -403,8 +403,8 @@ discard block |
||
403 | 403 | ->create($checkins_last_month); |
404 | 404 | |
405 | 405 | $messages = []; |
406 | - foreach($this->getPartnerEmails() as $email) { |
|
407 | - if($email) { |
|
406 | + foreach ($this->getPartnerEmails() as $email) { |
|
407 | + if ($email) { |
|
408 | 408 | $messages[] = Yii::$app->mailer->compose('checkinReport', [ |
409 | 409 | 'user' => $this, |
410 | 410 | 'email' => $email, |
@@ -416,7 +416,7 @@ discard block |
||
416 | 416 | 'behaviors_list' => \common\models\Behavior::$behaviors, |
417 | 417 | ])->setFrom([Yii::$app->params['supportEmail'] => Yii::$app->name]) |
418 | 418 | ->setReplyTo($this->email) |
419 | - ->setSubject($this->email." has completed a Faster Scale check-in") |
|
419 | + ->setSubject($this->email . " has completed a Faster Scale check-in") |
|
420 | 420 | ->setTo($email); |
421 | 421 | } |
422 | 422 | } |
@@ -493,7 +493,7 @@ discard block |
||
493 | 493 | return \Yii::$app->mailer->compose('signupNotification') |
494 | 494 | ->setFrom([\Yii::$app->params['supportEmail'] => \Yii::$app->name]) |
495 | 495 | ->setTo(\Yii::$app->params['adminEmail']) |
496 | - ->setSubject('A new user has signed up for '.\Yii::$app->name) |
|
496 | + ->setSubject('A new user has signed up for ' . \Yii::$app->name) |
|
497 | 497 | ->send(); |
498 | 498 | } |
499 | 499 | |
@@ -501,20 +501,20 @@ discard block |
||
501 | 501 | return \Yii::$app->mailer->compose('verifyEmail', ['user' => $this]) |
502 | 502 | ->setFrom([\Yii::$app->params['supportEmail'] => \Yii::$app->name]) |
503 | 503 | ->setTo($this->email) |
504 | - ->setSubject('Please verify your '.\Yii::$app->name .' account') |
|
504 | + ->setSubject('Please verify your ' . \Yii::$app->name . ' account') |
|
505 | 505 | ->send(); |
506 | 506 | } |
507 | 507 | |
508 | 508 | public function sendDeleteNotificationEmail() { |
509 | 509 | $messages = []; |
510 | - foreach(array_merge([$this->email], $this->getPartnerEmails()) as $email) { |
|
511 | - if($email) { |
|
510 | + foreach (array_merge([$this->email], $this->getPartnerEmails()) as $email) { |
|
511 | + if ($email) { |
|
512 | 512 | $messages[] = Yii::$app->mailer->compose('deleteNotification', [ |
513 | 513 | 'user' => $this, |
514 | 514 | 'email' => $email |
515 | 515 | ])->setFrom([Yii::$app->params['supportEmail'] => Yii::$app->name]) |
516 | 516 | ->setReplyTo($this->email) |
517 | - ->setSubject($this->email." has deleted their The Faster Scale App account") |
|
517 | + ->setSubject($this->email . " has deleted their The Faster Scale App account") |
|
518 | 518 | ->setTo($email); |
519 | 519 | } |
520 | 520 | } |
@@ -528,7 +528,7 @@ discard block |
||
528 | 528 | |
529 | 529 | // clean up things we don't need |
530 | 530 | $row['category'] = $row['category']['name']; |
531 | - if(array_key_exists('behavior', $row)) { |
|
531 | + if (array_key_exists('behavior', $row)) { |
|
532 | 532 | $row['behavior'] = $row['behavior']['name']; |
533 | 533 | } else { |
534 | 534 | $row['behavior'] = $row['custom_behavior']; |
@@ -564,7 +564,7 @@ discard block |
||
564 | 564 | return rtrim( |
565 | 565 | strtr( |
566 | 566 | base64_encode( |
567 | - hash('sha256', $this->id."::".$this->created_at, true) |
|
567 | + hash('sha256', $this->id . "::" . $this->created_at, true) |
|
568 | 568 | ), |
569 | 569 | '+/', '-_'), |
570 | 570 | '='); |
@@ -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 | /* |