@@ -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, |
@@ -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(); |
74 | 74 | |
75 | 75 | $behaviors = $user_behavior->findAll($form->getUserBehaviorIds()); |
76 | - if($result = $form->saveAnswers($behaviors)) { |
|
76 | + if ($result = $form->saveAnswers($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.'); |
@@ -131,7 +131,7 @@ discard block |
||
131 | 131 | $raw_pie_data = $user_behavior::decorate($user_behavior->getBehaviorsWithCounts()); |
132 | 132 | $answer_pie = $user_behavior->getBehaviorsByCategory($raw_pie_data); |
133 | 133 | |
134 | - $pie_data = [ |
|
134 | + $pie_data = [ |
|
135 | 135 | "labels" => array_column($answer_pie, "name"), |
136 | 136 | "datasets" => [[ |
137 | 137 | "data" => array_map('intval', array_column($answer_pie, "count")), |
@@ -166,14 +166,14 @@ discard block |
||
166 | 166 | $checkins = $user_behavior->getCheckInBreakdown($period); |
167 | 167 | |
168 | 168 | $accum = []; |
169 | - foreach($checkins as $date => $cats) { |
|
170 | - for($i = 1; $i <= 7; $i ++) { |
|
169 | + foreach ($checkins as $date => $cats) { |
|
170 | + for ($i = 1; $i <= 7; $i++) { |
|
171 | 171 | $accum[$i][] = array_key_exists($i, $cats) ? $cats[$i]['count'] : []; |
172 | 172 | } |
173 | 173 | } |
174 | 174 | |
175 | 175 | $bar_datasets = []; |
176 | - foreach($accum as $idx => $data) { |
|
176 | + foreach ($accum as $idx => $data) { |
|
177 | 177 | $bar_datasets[] = [ |
178 | 178 | 'label' => ($category::getCategories())[$idx], |
179 | 179 | 'backgroundColor' => $category::$colors[$idx]['color'], |
@@ -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 | ], |
@@ -57,7 +57,7 @@ discard block |
||
57 | 57 | |
58 | 58 | if ($editProfileForm->load(Yii::$app->request->post())) { |
59 | 59 | $saved_user = $editProfileForm->saveProfile(); |
60 | - if($saved_user) { |
|
60 | + if ($saved_user) { |
|
61 | 61 | Yii::$app->session->setFlash('success', 'New profile data saved!'); |
62 | 62 | } |
63 | 63 | } |
@@ -76,7 +76,7 @@ discard block |
||
76 | 76 | $model = Yii::$container->get(\site\models\DeleteAccountForm::class, [Yii::$app->user->identity]); |
77 | 77 | |
78 | 78 | if ($model->load(Yii::$app->request->post()) && $model->validate()) { |
79 | - if($model->deleteAccount()) { |
|
79 | + if ($model->deleteAccount()) { |
|
80 | 80 | $this->redirect(['site/index']); |
81 | 81 | } else { |
82 | 82 | Yii::$app->session->setFlash('error', 'Wrong password!'); |
@@ -90,7 +90,7 @@ discard block |
||
90 | 90 | $model = Yii::$container->get(\site\models\ChangePasswordForm::class, [Yii::$app->user->identity]); |
91 | 91 | |
92 | 92 | if ($model->load(Yii::$app->request->post())) { |
93 | - if($model->validate() && $model->changePassword()) { |
|
93 | + if ($model->validate() && $model->changePassword()) { |
|
94 | 94 | Yii::$app->session->setFlash('success', 'Password successfully changed'); |
95 | 95 | } else { |
96 | 96 | Yii::$app->session->setFlash('error', 'Wrong password!'); |
@@ -114,14 +114,14 @@ discard block |
||
114 | 114 | public function actionChangeEmail(string $token) { |
115 | 115 | $user = Yii::$container->get(\common\interfaces\UserInterface::class)->findByChangeEmailToken($token); |
116 | 116 | |
117 | - if($user) { |
|
117 | + if ($user) { |
|
118 | 118 | $validator = new \yii\validators\EmailValidator(); |
119 | - if($validator->validate($user->desired_email, $error)) { |
|
119 | + if ($validator->validate($user->desired_email, $error)) { |
|
120 | 120 | $user->removeChangeEmailToken(); |
121 | 121 | $user->email = $user->desired_email; |
122 | 122 | $user->desired_email = null; |
123 | 123 | $user->save(); |
124 | - if(!Yii::$app->user->isGuest) { |
|
124 | + if (!Yii::$app->user->isGuest) { |
|
125 | 125 | Yii::$app->user->logout(); |
126 | 126 | Yii::$app->session->setFlash('success', 'Your email address was successfully changed. For security, we\'ve logged you out.'); |
127 | 127 | } else { |
@@ -141,7 +141,7 @@ discard block |
||
141 | 141 | |
142 | 142 | public function actionExport() { |
143 | 143 | header("Content-Type: text/csv"); |
144 | - header("Content-Disposition: attachment; filename=fsa-data-export-".Yii::$app->user->identity->email."-".date('Ymd').".csv"); |
|
144 | + header("Content-Disposition: attachment; filename=fsa-data-export-" . Yii::$app->user->identity->email . "-" . date('Ymd') . ".csv"); |
|
145 | 145 | |
146 | 146 | $reader = Yii::$app->user->identity->getExportData(); |
147 | 147 | $fp = fopen('php://output', 'w'); |
@@ -157,7 +157,7 @@ discard block |
||
157 | 157 | |
158 | 158 | fputcsv($fp, $header); |
159 | 159 | $user_behavior = Yii::$container->get(\common\interfaces\UserBehaviorInterface::class); |
160 | - while($row = $reader->read()) { |
|
160 | + while ($row = $reader->read()) { |
|
161 | 161 | $row = $user_behavior::decorate([$row]); |
162 | 162 | $row = Yii::$app->user->identity->cleanExportData($row); |
163 | 163 | fputcsv($fp, $row[0]); |
@@ -19,387 +19,387 @@ |
||
19 | 19 | private $time; |
20 | 20 | private $question; |
21 | 21 | |
22 | - public $questionData = [ |
|
23 | - [ |
|
24 | - 'id' => 641, |
|
25 | - 'user_id' => 2, |
|
26 | - 'behavior_id' => 13, |
|
27 | - 'user_behavior_id' => 821, |
|
28 | - 'question' => 1, |
|
29 | - 'answer' => 'alsgn', |
|
30 | - 'date' => '2016-09-10 19:27:43', |
|
31 | - 'behavior' => |
|
32 | - [ |
|
33 | - 'id' => 13, |
|
34 | - 'name' => 'less time/energy for God, meetings, and church', |
|
35 | - 'category_id' => 2, |
|
36 | - ], |
|
37 | - ], |
|
38 | - [ |
|
39 | - 'id' => 642, |
|
40 | - 'user_id' => 2, |
|
41 | - 'behavior_id' => 13, |
|
42 | - 'user_behavior_id' => 821, |
|
43 | - 'question' => 2, |
|
44 | - 'answer' => 'loiun', |
|
45 | - 'date' => '2016-09-10 19:27:43', |
|
46 | - 'behavior' => |
|
47 | - [ |
|
48 | - 'id' => 13, |
|
49 | - 'name' => 'less time/energy for God, meetings, and church', |
|
50 | - 'category_id' => 2, |
|
51 | - ], |
|
52 | - ], |
|
53 | - [ |
|
54 | - 'id' => 643, |
|
55 | - 'user_id' => 2, |
|
56 | - 'behavior_id' => 13, |
|
57 | - 'user_behavior_id' => 821, |
|
58 | - 'question' => 3, |
|
59 | - 'answer' => 'liun', |
|
60 | - 'date' => '2016-09-10 19:27:43', |
|
61 | - 'behavior' => |
|
62 | - [ |
|
63 | - 'id' => 13, |
|
64 | - 'name' => 'less time/energy for God, meetings, and church', |
|
65 | - 'category_id' => 2, |
|
66 | - ], |
|
67 | - ], |
|
68 | - [ |
|
69 | - 'id' => 644, |
|
70 | - 'user_id' => 2, |
|
71 | - 'behavior_id' => 29, |
|
72 | - 'user_behavior_id' => 823, |
|
73 | - 'question' => 1, |
|
74 | - 'answer' => 'ljnb', |
|
75 | - 'date' => '2016-09-10 19:27:43', |
|
76 | - 'behavior' => |
|
77 | - [ |
|
78 | - 'id' => 29, |
|
79 | - 'name' => 'using profanity', |
|
80 | - 'category_id' => 3, |
|
81 | - ], |
|
82 | - ], |
|
83 | - [ |
|
84 | - 'id' => 645, |
|
85 | - 'user_id' => 2, |
|
86 | - 'behavior_id' => 29, |
|
87 | - 'user_behavior_id' => 823, |
|
88 | - 'question' => 2, |
|
89 | - 'answer' => 'liunb', |
|
90 | - 'date' => '2016-09-10 19:27:43', |
|
91 | - 'behavior' => |
|
92 | - [ |
|
93 | - 'id' => 29, |
|
94 | - 'name' => 'using profanity', |
|
95 | - 'category_id' => 3, |
|
96 | - ], |
|
97 | - ], |
|
98 | - [ |
|
99 | - 'id' => 646, |
|
100 | - 'user_id' => 2, |
|
101 | - 'behavior_id' => 29, |
|
102 | - 'user_behavior_id' => 823, |
|
103 | - 'question' => 3, |
|
104 | - 'answer' => 'ilub ', |
|
105 | - 'date' => '2016-09-10 19:27:43', |
|
106 | - 'behavior' => |
|
107 | - [ |
|
108 | - 'id' => 29, |
|
109 | - 'name' => 'using profanity', |
|
110 | - 'category_id' => 3, |
|
111 | - ], |
|
112 | - ], |
|
113 | - [ |
|
114 | - 'id' => 647, |
|
115 | - 'user_id' => 2, |
|
116 | - 'behavior_id' => 48, |
|
117 | - 'user_behavior_id' => 825, |
|
118 | - 'question' => 1, |
|
119 | - 'answer' => 'liub', |
|
120 | - 'date' => '2016-09-10 19:27:43', |
|
121 | - 'behavior' => |
|
122 | - [ |
|
123 | - 'id' => 48, |
|
124 | - 'name' => 'workaholic', |
|
125 | - 'category_id' => 4, |
|
126 | - ], |
|
127 | - ], |
|
128 | - [ |
|
129 | - 'id' => 648, |
|
130 | - 'user_id' => 2, |
|
131 | - 'behavior_id' => 48, |
|
132 | - 'user_behavior_id' => 825, |
|
133 | - 'question' => 2, |
|
134 | - 'answer' => 'liub', |
|
135 | - 'date' => '2016-09-10 19:27:43', |
|
136 | - 'behavior' => |
|
137 | - [ |
|
138 | - 'id' => 48, |
|
139 | - 'name' => 'workaholic', |
|
140 | - 'category_id' => 4, |
|
141 | - ], |
|
142 | - ], |
|
143 | - [ |
|
144 | - 'id' => 649, |
|
145 | - 'user_id' => 2, |
|
146 | - 'behavior_id' => 48, |
|
147 | - 'user_behavior_id' => 825, |
|
148 | - 'question' => 3, |
|
149 | - 'answer' => 'liub ', |
|
150 | - 'date' => '2016-09-10 19:27:43', |
|
151 | - 'behavior' => |
|
152 | - [ |
|
153 | - 'id' => 48, |
|
154 | - 'name' => 'workaholic', |
|
155 | - 'category_id' => 4, |
|
156 | - ], |
|
157 | - ], |
|
158 | - [ |
|
159 | - 'id' => 650, |
|
160 | - 'user_id' => 2, |
|
161 | - 'behavior_id' => 89, |
|
162 | - 'user_behavior_id' => 828, |
|
163 | - 'question' => 1, |
|
164 | - 'answer' => 'liub', |
|
165 | - 'date' => '2016-09-10 19:27:43', |
|
166 | - 'behavior' => |
|
167 | - [ |
|
168 | - 'id' => 89, |
|
169 | - 'name' => 'obsessive (stuck) thoughts', |
|
170 | - 'category_id' => 5, |
|
171 | - ], |
|
172 | - ], |
|
173 | - [ |
|
174 | - 'id' => 651, |
|
175 | - 'user_id' => 2, |
|
176 | - 'behavior_id' => 89, |
|
177 | - 'user_behavior_id' => 828, |
|
178 | - 'question' => 2, |
|
179 | - 'answer' => 'liuby', |
|
180 | - 'date' => '2016-09-10 19:27:43', |
|
181 | - 'behavior' => |
|
182 | - [ |
|
183 | - 'id' => 89, |
|
184 | - 'name' => 'obsessive (stuck) thoughts', |
|
185 | - 'category_id' => 5, |
|
186 | - ], |
|
187 | - ], |
|
188 | - [ |
|
189 | - 'id' => 652, |
|
190 | - 'user_id' => 2, |
|
191 | - 'behavior_id' => 89, |
|
192 | - 'user_behavior_id' => 828, |
|
193 | - 'question' => 3, |
|
194 | - 'answer' => 'uiylb', |
|
195 | - 'date' => '2016-09-10 19:27:43', |
|
196 | - 'behavior' => |
|
197 | - [ |
|
198 | - 'id' => 89, |
|
199 | - 'name' => 'obsessive (stuck) thoughts', |
|
200 | - 'category_id' => 5, |
|
201 | - ], |
|
202 | - ], |
|
203 | - [ |
|
204 | - 'id' => 653, |
|
205 | - 'user_id' => 2, |
|
206 | - 'behavior_id' => 111, |
|
207 | - 'user_behavior_id' => 829, |
|
208 | - 'question' => 1, |
|
209 | - 'answer' => 'liub', |
|
210 | - 'date' => '2016-09-10 19:27:43', |
|
211 | - 'behavior' => |
|
212 | - [ |
|
213 | - 'id' => 111, |
|
214 | - 'name' => 'seeking out old unhealthy people and places', |
|
215 | - 'category_id' => 6, |
|
216 | - ], |
|
217 | - ], |
|
218 | - [ |
|
219 | - 'id' => 654, |
|
220 | - 'user_id' => 2, |
|
221 | - 'behavior_id' => 111, |
|
222 | - 'user_behavior_id' => 829, |
|
223 | - 'question' => 2, |
|
224 | - 'answer' => 'liuyb', |
|
225 | - 'date' => '2016-09-10 19:27:43', |
|
226 | - 'behavior' => |
|
227 | - [ |
|
228 | - 'id' => 111, |
|
229 | - 'name' => 'seeking out old unhealthy people and places', |
|
230 | - 'category_id' => 6, |
|
231 | - ], |
|
232 | - ], |
|
233 | - [ |
|
234 | - 'id' => 655, |
|
235 | - 'user_id' => 2, |
|
236 | - 'behavior_id' => 111, |
|
237 | - 'user_behavior_id' => 829, |
|
238 | - 'question' => 3, |
|
239 | - 'answer' => 'iuyb', |
|
240 | - 'date' => '2016-09-10 19:27:43', |
|
241 | - 'behavior' => |
|
242 | - [ |
|
243 | - 'id' => 111, |
|
244 | - 'name' => 'seeking out old unhealthy people and places', |
|
245 | - 'category_id' => 6, |
|
246 | - ], |
|
247 | - ], |
|
248 | - [ |
|
249 | - 'id' => 656, |
|
250 | - 'user_id' => 2, |
|
251 | - 'behavior_id' => 122, |
|
252 | - 'user_behavior_id' => 831, |
|
253 | - 'question' => 1, |
|
254 | - 'answer' => 'iuyb', |
|
255 | - 'date' => '2016-09-10 19:27:43', |
|
256 | - 'behavior' => |
|
257 | - [ |
|
258 | - 'id' => 122, |
|
259 | - 'name' => 'returning to the place you swore you would never go again', |
|
260 | - 'category_id' => 7, |
|
261 | - ], |
|
262 | - ], |
|
263 | - [ |
|
264 | - 'id' => 657, |
|
265 | - 'user_id' => 2, |
|
266 | - 'behavior_id' => 122, |
|
267 | - 'user_behavior_id' => 831, |
|
268 | - 'question' => 2, |
|
269 | - 'answer' => 'iuyb', |
|
270 | - 'date' => '2016-09-10 19:27:43', |
|
271 | - 'behavior' => |
|
272 | - [ |
|
273 | - 'id' => 122, |
|
274 | - 'name' => 'returning to the place you swore you would never go again', |
|
275 | - 'category_id' => 7, |
|
276 | - ], |
|
277 | - ], |
|
278 | - [ |
|
279 | - 'id' => 658, |
|
280 | - 'user_id' => 2, |
|
281 | - 'behavior_id' => 122, |
|
282 | - 'user_behavior_id' => 831, |
|
283 | - 'question' => 3, |
|
284 | - 'answer' => 'liuyb', |
|
285 | - 'date' => '2016-09-10 19:27:43', |
|
286 | - 'behavior' => |
|
287 | - [ |
|
288 | - 'id' => 122, |
|
289 | - 'name' => 'returning to the place you swore you would never go again', |
|
290 | - 'category_id' => 7, |
|
291 | - ], |
|
292 | - ], |
|
22 | + public $questionData = [ |
|
23 | + [ |
|
24 | + 'id' => 641, |
|
25 | + 'user_id' => 2, |
|
26 | + 'behavior_id' => 13, |
|
27 | + 'user_behavior_id' => 821, |
|
28 | + 'question' => 1, |
|
29 | + 'answer' => 'alsgn', |
|
30 | + 'date' => '2016-09-10 19:27:43', |
|
31 | + 'behavior' => |
|
32 | + [ |
|
33 | + 'id' => 13, |
|
34 | + 'name' => 'less time/energy for God, meetings, and church', |
|
35 | + 'category_id' => 2, |
|
36 | + ], |
|
37 | + ], |
|
38 | + [ |
|
39 | + 'id' => 642, |
|
40 | + 'user_id' => 2, |
|
41 | + 'behavior_id' => 13, |
|
42 | + 'user_behavior_id' => 821, |
|
43 | + 'question' => 2, |
|
44 | + 'answer' => 'loiun', |
|
45 | + 'date' => '2016-09-10 19:27:43', |
|
46 | + 'behavior' => |
|
47 | + [ |
|
48 | + 'id' => 13, |
|
49 | + 'name' => 'less time/energy for God, meetings, and church', |
|
50 | + 'category_id' => 2, |
|
51 | + ], |
|
52 | + ], |
|
53 | + [ |
|
54 | + 'id' => 643, |
|
55 | + 'user_id' => 2, |
|
56 | + 'behavior_id' => 13, |
|
57 | + 'user_behavior_id' => 821, |
|
58 | + 'question' => 3, |
|
59 | + 'answer' => 'liun', |
|
60 | + 'date' => '2016-09-10 19:27:43', |
|
61 | + 'behavior' => |
|
62 | + [ |
|
63 | + 'id' => 13, |
|
64 | + 'name' => 'less time/energy for God, meetings, and church', |
|
65 | + 'category_id' => 2, |
|
66 | + ], |
|
67 | + ], |
|
68 | + [ |
|
69 | + 'id' => 644, |
|
70 | + 'user_id' => 2, |
|
71 | + 'behavior_id' => 29, |
|
72 | + 'user_behavior_id' => 823, |
|
73 | + 'question' => 1, |
|
74 | + 'answer' => 'ljnb', |
|
75 | + 'date' => '2016-09-10 19:27:43', |
|
76 | + 'behavior' => |
|
77 | + [ |
|
78 | + 'id' => 29, |
|
79 | + 'name' => 'using profanity', |
|
80 | + 'category_id' => 3, |
|
81 | + ], |
|
82 | + ], |
|
83 | + [ |
|
84 | + 'id' => 645, |
|
85 | + 'user_id' => 2, |
|
86 | + 'behavior_id' => 29, |
|
87 | + 'user_behavior_id' => 823, |
|
88 | + 'question' => 2, |
|
89 | + 'answer' => 'liunb', |
|
90 | + 'date' => '2016-09-10 19:27:43', |
|
91 | + 'behavior' => |
|
92 | + [ |
|
93 | + 'id' => 29, |
|
94 | + 'name' => 'using profanity', |
|
95 | + 'category_id' => 3, |
|
96 | + ], |
|
97 | + ], |
|
98 | + [ |
|
99 | + 'id' => 646, |
|
100 | + 'user_id' => 2, |
|
101 | + 'behavior_id' => 29, |
|
102 | + 'user_behavior_id' => 823, |
|
103 | + 'question' => 3, |
|
104 | + 'answer' => 'ilub ', |
|
105 | + 'date' => '2016-09-10 19:27:43', |
|
106 | + 'behavior' => |
|
107 | + [ |
|
108 | + 'id' => 29, |
|
109 | + 'name' => 'using profanity', |
|
110 | + 'category_id' => 3, |
|
111 | + ], |
|
112 | + ], |
|
113 | + [ |
|
114 | + 'id' => 647, |
|
115 | + 'user_id' => 2, |
|
116 | + 'behavior_id' => 48, |
|
117 | + 'user_behavior_id' => 825, |
|
118 | + 'question' => 1, |
|
119 | + 'answer' => 'liub', |
|
120 | + 'date' => '2016-09-10 19:27:43', |
|
121 | + 'behavior' => |
|
122 | + [ |
|
123 | + 'id' => 48, |
|
124 | + 'name' => 'workaholic', |
|
125 | + 'category_id' => 4, |
|
126 | + ], |
|
127 | + ], |
|
128 | + [ |
|
129 | + 'id' => 648, |
|
130 | + 'user_id' => 2, |
|
131 | + 'behavior_id' => 48, |
|
132 | + 'user_behavior_id' => 825, |
|
133 | + 'question' => 2, |
|
134 | + 'answer' => 'liub', |
|
135 | + 'date' => '2016-09-10 19:27:43', |
|
136 | + 'behavior' => |
|
137 | + [ |
|
138 | + 'id' => 48, |
|
139 | + 'name' => 'workaholic', |
|
140 | + 'category_id' => 4, |
|
141 | + ], |
|
142 | + ], |
|
143 | + [ |
|
144 | + 'id' => 649, |
|
145 | + 'user_id' => 2, |
|
146 | + 'behavior_id' => 48, |
|
147 | + 'user_behavior_id' => 825, |
|
148 | + 'question' => 3, |
|
149 | + 'answer' => 'liub ', |
|
150 | + 'date' => '2016-09-10 19:27:43', |
|
151 | + 'behavior' => |
|
152 | + [ |
|
153 | + 'id' => 48, |
|
154 | + 'name' => 'workaholic', |
|
155 | + 'category_id' => 4, |
|
156 | + ], |
|
157 | + ], |
|
158 | + [ |
|
159 | + 'id' => 650, |
|
160 | + 'user_id' => 2, |
|
161 | + 'behavior_id' => 89, |
|
162 | + 'user_behavior_id' => 828, |
|
163 | + 'question' => 1, |
|
164 | + 'answer' => 'liub', |
|
165 | + 'date' => '2016-09-10 19:27:43', |
|
166 | + 'behavior' => |
|
167 | + [ |
|
168 | + 'id' => 89, |
|
169 | + 'name' => 'obsessive (stuck) thoughts', |
|
170 | + 'category_id' => 5, |
|
171 | + ], |
|
172 | + ], |
|
173 | + [ |
|
174 | + 'id' => 651, |
|
175 | + 'user_id' => 2, |
|
176 | + 'behavior_id' => 89, |
|
177 | + 'user_behavior_id' => 828, |
|
178 | + 'question' => 2, |
|
179 | + 'answer' => 'liuby', |
|
180 | + 'date' => '2016-09-10 19:27:43', |
|
181 | + 'behavior' => |
|
182 | + [ |
|
183 | + 'id' => 89, |
|
184 | + 'name' => 'obsessive (stuck) thoughts', |
|
185 | + 'category_id' => 5, |
|
186 | + ], |
|
187 | + ], |
|
188 | + [ |
|
189 | + 'id' => 652, |
|
190 | + 'user_id' => 2, |
|
191 | + 'behavior_id' => 89, |
|
192 | + 'user_behavior_id' => 828, |
|
193 | + 'question' => 3, |
|
194 | + 'answer' => 'uiylb', |
|
195 | + 'date' => '2016-09-10 19:27:43', |
|
196 | + 'behavior' => |
|
197 | + [ |
|
198 | + 'id' => 89, |
|
199 | + 'name' => 'obsessive (stuck) thoughts', |
|
200 | + 'category_id' => 5, |
|
201 | + ], |
|
202 | + ], |
|
203 | + [ |
|
204 | + 'id' => 653, |
|
205 | + 'user_id' => 2, |
|
206 | + 'behavior_id' => 111, |
|
207 | + 'user_behavior_id' => 829, |
|
208 | + 'question' => 1, |
|
209 | + 'answer' => 'liub', |
|
210 | + 'date' => '2016-09-10 19:27:43', |
|
211 | + 'behavior' => |
|
212 | + [ |
|
213 | + 'id' => 111, |
|
214 | + 'name' => 'seeking out old unhealthy people and places', |
|
215 | + 'category_id' => 6, |
|
216 | + ], |
|
217 | + ], |
|
218 | + [ |
|
219 | + 'id' => 654, |
|
220 | + 'user_id' => 2, |
|
221 | + 'behavior_id' => 111, |
|
222 | + 'user_behavior_id' => 829, |
|
223 | + 'question' => 2, |
|
224 | + 'answer' => 'liuyb', |
|
225 | + 'date' => '2016-09-10 19:27:43', |
|
226 | + 'behavior' => |
|
227 | + [ |
|
228 | + 'id' => 111, |
|
229 | + 'name' => 'seeking out old unhealthy people and places', |
|
230 | + 'category_id' => 6, |
|
231 | + ], |
|
232 | + ], |
|
233 | + [ |
|
234 | + 'id' => 655, |
|
235 | + 'user_id' => 2, |
|
236 | + 'behavior_id' => 111, |
|
237 | + 'user_behavior_id' => 829, |
|
238 | + 'question' => 3, |
|
239 | + 'answer' => 'iuyb', |
|
240 | + 'date' => '2016-09-10 19:27:43', |
|
241 | + 'behavior' => |
|
242 | + [ |
|
243 | + 'id' => 111, |
|
244 | + 'name' => 'seeking out old unhealthy people and places', |
|
245 | + 'category_id' => 6, |
|
246 | + ], |
|
247 | + ], |
|
248 | + [ |
|
249 | + 'id' => 656, |
|
250 | + 'user_id' => 2, |
|
251 | + 'behavior_id' => 122, |
|
252 | + 'user_behavior_id' => 831, |
|
253 | + 'question' => 1, |
|
254 | + 'answer' => 'iuyb', |
|
255 | + 'date' => '2016-09-10 19:27:43', |
|
256 | + 'behavior' => |
|
257 | + [ |
|
258 | + 'id' => 122, |
|
259 | + 'name' => 'returning to the place you swore you would never go again', |
|
260 | + 'category_id' => 7, |
|
261 | + ], |
|
262 | + ], |
|
263 | + [ |
|
264 | + 'id' => 657, |
|
265 | + 'user_id' => 2, |
|
266 | + 'behavior_id' => 122, |
|
267 | + 'user_behavior_id' => 831, |
|
268 | + 'question' => 2, |
|
269 | + 'answer' => 'iuyb', |
|
270 | + 'date' => '2016-09-10 19:27:43', |
|
271 | + 'behavior' => |
|
272 | + [ |
|
273 | + 'id' => 122, |
|
274 | + 'name' => 'returning to the place you swore you would never go again', |
|
275 | + 'category_id' => 7, |
|
276 | + ], |
|
277 | + ], |
|
278 | + [ |
|
279 | + 'id' => 658, |
|
280 | + 'user_id' => 2, |
|
281 | + 'behavior_id' => 122, |
|
282 | + 'user_behavior_id' => 831, |
|
283 | + 'question' => 3, |
|
284 | + 'answer' => 'liuyb', |
|
285 | + 'date' => '2016-09-10 19:27:43', |
|
286 | + 'behavior' => |
|
287 | + [ |
|
288 | + 'id' => 122, |
|
289 | + 'name' => 'returning to the place you swore you would never go again', |
|
290 | + 'category_id' => 7, |
|
291 | + ], |
|
292 | + ], |
|
293 | 293 | ]; |
294 | 294 | public $userQuestions = [ |
295 | - 13 => [ |
|
296 | - 'question' => [ |
|
297 | - 'id' => 13, |
|
298 | - 'title' => 'less time/energy for God, meetings, and church', |
|
299 | - ], |
|
300 | - 'answers' => [ |
|
301 | - [ |
|
302 | - 'title' => 'How does it affect me? How do I act and feel?', |
|
303 | - 'answer' => 'alsgn', |
|
304 | - ], [ |
|
305 | - 'title' => 'How does it affect the important people in my life?', |
|
306 | - 'answer' => 'loiun', |
|
307 | - ], [ |
|
308 | - 'title' => 'Why do I do this? What is the benefit for me?', |
|
309 | - 'answer' => 'liun', |
|
310 | - ], |
|
311 | - ], |
|
312 | - ], |
|
313 | - 29 => [ |
|
314 | - 'question' => [ |
|
315 | - 'id' => 29, |
|
316 | - 'title' => 'using profanity', |
|
317 | - ], |
|
318 | - 'answers' => [ |
|
319 | - [ |
|
320 | - 'title' => 'How does it affect me? How do I act and feel?', |
|
321 | - 'answer' => 'ljnb', |
|
322 | - ], [ |
|
323 | - 'title' => 'How does it affect the important people in my life?', |
|
324 | - 'answer' => 'liunb', |
|
325 | - ], [ |
|
326 | - 'title' => 'Why do I do this? What is the benefit for me?', |
|
327 | - 'answer' => 'ilub ', |
|
328 | - ], |
|
329 | - ], |
|
330 | - ], |
|
331 | - 48 => [ |
|
332 | - 'question' => [ |
|
333 | - 'id' => 48, |
|
334 | - 'title' => 'workaholic', |
|
335 | - ], |
|
336 | - 'answers' => [ |
|
337 | - [ |
|
338 | - 'title' => 'How does it affect me? How do I act and feel?', |
|
339 | - 'answer' => 'liub', |
|
340 | - ], [ |
|
341 | - 'title' => 'How does it affect the important people in my life?', |
|
342 | - 'answer' => 'liub', |
|
343 | - ], [ |
|
344 | - 'title' => 'Why do I do this? What is the benefit for me?', |
|
345 | - 'answer' => 'liub ', |
|
346 | - ], |
|
347 | - ], |
|
348 | - ], |
|
349 | - 89 => [ |
|
350 | - 'question' => [ |
|
351 | - 'id' => 89, |
|
352 | - 'title' => 'obsessive (stuck) thoughts', |
|
353 | - ], |
|
354 | - 'answers' => [ |
|
355 | - [ |
|
356 | - 'title' => 'How does it affect me? How do I act and feel?', |
|
357 | - 'answer' => 'liub', |
|
358 | - ], [ |
|
359 | - 'title' => 'How does it affect the important people in my life?', |
|
360 | - 'answer' => 'liuby', |
|
361 | - ], [ |
|
362 | - 'title' => 'Why do I do this? What is the benefit for me?', |
|
363 | - 'answer' => 'uiylb', |
|
364 | - ], |
|
365 | - ], |
|
366 | - ], |
|
367 | - 111 => [ |
|
368 | - 'question' => [ |
|
369 | - 'id' => 111, |
|
370 | - 'title' => 'seeking out old unhealthy people and places', |
|
371 | - ], |
|
372 | - 'answers' => [ |
|
373 | - [ |
|
374 | - 'title' => 'How does it affect me? How do I act and feel?', |
|
375 | - 'answer' => 'liub', |
|
376 | - ], [ |
|
377 | - 'title' => 'How does it affect the important people in my life?', |
|
378 | - 'answer' => 'liuyb', |
|
379 | - ], [ |
|
380 | - 'title' => 'Why do I do this? What is the benefit for me?', |
|
381 | - 'answer' => 'iuyb', |
|
382 | - ], |
|
383 | - ], |
|
384 | - ], |
|
385 | - 122 => [ |
|
386 | - 'question' => [ |
|
387 | - 'id' => 122, |
|
388 | - 'title' => 'returning to the place you swore you would never go again', |
|
389 | - ], |
|
390 | - 'answers' => [ |
|
391 | - [ |
|
392 | - 'title' => 'How does it affect me? How do I act and feel?', |
|
393 | - 'answer' => 'iuyb', |
|
394 | - ], [ |
|
395 | - 'title' => 'How does it affect the important people in my life?', |
|
396 | - 'answer' => 'iuyb', |
|
397 | - ], [ |
|
398 | - 'title' => 'Why do I do this? What is the benefit for me?', |
|
399 | - 'answer' => 'liuyb', |
|
400 | - ], |
|
401 | - ], |
|
402 | - ], |
|
295 | + 13 => [ |
|
296 | + 'question' => [ |
|
297 | + 'id' => 13, |
|
298 | + 'title' => 'less time/energy for God, meetings, and church', |
|
299 | + ], |
|
300 | + 'answers' => [ |
|
301 | + [ |
|
302 | + 'title' => 'How does it affect me? How do I act and feel?', |
|
303 | + 'answer' => 'alsgn', |
|
304 | + ], [ |
|
305 | + 'title' => 'How does it affect the important people in my life?', |
|
306 | + 'answer' => 'loiun', |
|
307 | + ], [ |
|
308 | + 'title' => 'Why do I do this? What is the benefit for me?', |
|
309 | + 'answer' => 'liun', |
|
310 | + ], |
|
311 | + ], |
|
312 | + ], |
|
313 | + 29 => [ |
|
314 | + 'question' => [ |
|
315 | + 'id' => 29, |
|
316 | + 'title' => 'using profanity', |
|
317 | + ], |
|
318 | + 'answers' => [ |
|
319 | + [ |
|
320 | + 'title' => 'How does it affect me? How do I act and feel?', |
|
321 | + 'answer' => 'ljnb', |
|
322 | + ], [ |
|
323 | + 'title' => 'How does it affect the important people in my life?', |
|
324 | + 'answer' => 'liunb', |
|
325 | + ], [ |
|
326 | + 'title' => 'Why do I do this? What is the benefit for me?', |
|
327 | + 'answer' => 'ilub ', |
|
328 | + ], |
|
329 | + ], |
|
330 | + ], |
|
331 | + 48 => [ |
|
332 | + 'question' => [ |
|
333 | + 'id' => 48, |
|
334 | + 'title' => 'workaholic', |
|
335 | + ], |
|
336 | + 'answers' => [ |
|
337 | + [ |
|
338 | + 'title' => 'How does it affect me? How do I act and feel?', |
|
339 | + 'answer' => 'liub', |
|
340 | + ], [ |
|
341 | + 'title' => 'How does it affect the important people in my life?', |
|
342 | + 'answer' => 'liub', |
|
343 | + ], [ |
|
344 | + 'title' => 'Why do I do this? What is the benefit for me?', |
|
345 | + 'answer' => 'liub ', |
|
346 | + ], |
|
347 | + ], |
|
348 | + ], |
|
349 | + 89 => [ |
|
350 | + 'question' => [ |
|
351 | + 'id' => 89, |
|
352 | + 'title' => 'obsessive (stuck) thoughts', |
|
353 | + ], |
|
354 | + 'answers' => [ |
|
355 | + [ |
|
356 | + 'title' => 'How does it affect me? How do I act and feel?', |
|
357 | + 'answer' => 'liub', |
|
358 | + ], [ |
|
359 | + 'title' => 'How does it affect the important people in my life?', |
|
360 | + 'answer' => 'liuby', |
|
361 | + ], [ |
|
362 | + 'title' => 'Why do I do this? What is the benefit for me?', |
|
363 | + 'answer' => 'uiylb', |
|
364 | + ], |
|
365 | + ], |
|
366 | + ], |
|
367 | + 111 => [ |
|
368 | + 'question' => [ |
|
369 | + 'id' => 111, |
|
370 | + 'title' => 'seeking out old unhealthy people and places', |
|
371 | + ], |
|
372 | + 'answers' => [ |
|
373 | + [ |
|
374 | + 'title' => 'How does it affect me? How do I act and feel?', |
|
375 | + 'answer' => 'liub', |
|
376 | + ], [ |
|
377 | + 'title' => 'How does it affect the important people in my life?', |
|
378 | + 'answer' => 'liuyb', |
|
379 | + ], [ |
|
380 | + 'title' => 'Why do I do this? What is the benefit for me?', |
|
381 | + 'answer' => 'iuyb', |
|
382 | + ], |
|
383 | + ], |
|
384 | + ], |
|
385 | + 122 => [ |
|
386 | + 'question' => [ |
|
387 | + 'id' => 122, |
|
388 | + 'title' => 'returning to the place you swore you would never go again', |
|
389 | + ], |
|
390 | + 'answers' => [ |
|
391 | + [ |
|
392 | + 'title' => 'How does it affect me? How do I act and feel?', |
|
393 | + 'answer' => 'iuyb', |
|
394 | + ], [ |
|
395 | + 'title' => 'How does it affect the important people in my life?', |
|
396 | + 'answer' => 'iuyb', |
|
397 | + ], [ |
|
398 | + 'title' => 'Why do I do this? What is the benefit for me?', |
|
399 | + 'answer' => 'liuyb', |
|
400 | + ], |
|
401 | + ], |
|
402 | + ], |
|
403 | 403 | ]; |
404 | 404 | |
405 | 405 | public $exportData = [ |
@@ -470,7 +470,7 @@ discard block |
||
470 | 470 | $this->container = new \yii\di\Container; |
471 | 471 | $this->container->set('common\interfaces\UserInterface', '\site\tests\_support\MockUser'); |
472 | 472 | $this->container->set('common\interfaces\UserBehaviorInterface', '\site\tests\_support\MockUserBehavior'); |
473 | - $this->container->set('common\interfaces\TimeInterface', function () { |
|
473 | + $this->container->set('common\interfaces\TimeInterface', function() { |
|
474 | 474 | return new \common\components\Time('America/Los_Angeles'); |
475 | 475 | }); |
476 | 476 | |
@@ -516,14 +516,14 @@ discard block |
||
516 | 516 | } |
517 | 517 | |
518 | 518 | public function testParseQuestionData() { |
519 | - $this->specify('parseQuestionData should function correctly', function () { |
|
519 | + $this->specify('parseQuestionData should function correctly', function() { |
|
520 | 520 | expect('parseQuestionData should return the correct structure with expected data', $this->assertEquals($this->user->parseQuestionData($this->questionData), $this->userQuestions)); |
521 | 521 | expect('parseQuestionData should return empty with the empty set', $this->assertEmpty($this->user->parseQuestionData([]))); |
522 | 522 | }); |
523 | 523 | } |
524 | 524 | |
525 | 525 | public function testIsTokenCurrent() { |
526 | - $this->specify('isTokenCurrent should function correctly', function () { |
|
526 | + $this->specify('isTokenCurrent should function correctly', function() { |
|
527 | 527 | $good_token = \Yii::$app |
528 | 528 | ->getSecurity() |
529 | 529 | ->generateRandomString() . '_' . time(); |
@@ -557,7 +557,7 @@ discard block |
||
557 | 557 | public function testConfirmVerifyEmailToken() { |
558 | 558 | $this->user->verify_email_token = 'hello_world'; |
559 | 559 | $this->user->confirmVerifyEmailToken(); |
560 | - 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)); |
|
560 | + 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)); |
|
561 | 561 | } |
562 | 562 | |
563 | 563 | public function testIsVerified() { |
@@ -651,7 +651,7 @@ discard block |
||
651 | 651 | ->disableOriginalConstructor() |
652 | 652 | ->setMethods(['save', 'attributes', 'getCheckinBreakdown']) |
653 | 653 | ->getMock(); |
654 | - $expected = require(__DIR__.'/../data/expected_getCheckinBreakdown.php'); |
|
654 | + $expected = require(__DIR__ . '/../data/expected_getCheckinBreakdown.php'); |
|
655 | 655 | $user_behavior->method('getCheckinBreakdown')->willReturn($expected); |
656 | 656 | |
657 | 657 | $user = $this->getMockBuilder('\common\models\User') |
@@ -449,6 +449,6 @@ |
||
449 | 449 | $bhvrs = require(__DIR__.'/../data/behaviorsWithCounts.php'); |
450 | 450 | $expected = require(__DIR__.'/../data/expected_getCheckinBreakdown.php'); |
451 | 451 | $this->user_behavior->method('getBehaviorsWithCounts')->willReturn(...$bhvrs); |
452 | - expect('asdf', $this->assertEquals($expected, $this->user_behavior->getCheckinBreakdown())); |
|
452 | + expect('asdf', $this->assertEquals($expected, $this->user_behavior->getCheckinBreakdown())); |
|
453 | 453 | } |
454 | 454 | } |
@@ -287,7 +287,7 @@ discard block |
||
287 | 287 | |
288 | 288 | public function setUp() { |
289 | 289 | // pull in test data |
290 | - $data = require(__DIR__.'/../data/checkinData.php'); |
|
290 | + $data = require(__DIR__ . '/../data/checkinData.php'); |
|
291 | 291 | $this->singleBhvr = $data['singleBhvr']; |
292 | 292 | $this->manyBhvrs = $data['manyBhvrs']; |
293 | 293 | $this->allBhvrs = $data['allBhvrs']; |
@@ -297,7 +297,7 @@ discard block |
||
297 | 297 | $this->container->set('common\interfaces\UserInterface', '\site\tests\_support\MockUser'); |
298 | 298 | $this->container->set('common\interfaces\QuestionInterface', '\site\tests\_support\MockQuestion'); |
299 | 299 | $this->container->set('common\interfaces\BehaviorInterface', 'common\models\Behavior'); |
300 | - $this->container->set('common\interfaces\TimeInterface', function () { |
|
300 | + $this->container->set('common\interfaces\TimeInterface', function() { |
|
301 | 301 | return new \common\components\Time('America/Los_Angeles'); |
302 | 302 | }); |
303 | 303 | |
@@ -446,8 +446,8 @@ discard block |
||
446 | 446 | ->setMethods(['getIsNewRecord', 'save', 'getBehaviorsWithCounts']) |
447 | 447 | ->getMock(); |
448 | 448 | |
449 | - $bhvrs = require(__DIR__.'/../data/behaviorsWithCounts.php'); |
|
450 | - $expected = require(__DIR__.'/../data/expected_getCheckinBreakdown.php'); |
|
449 | + $bhvrs = require(__DIR__ . '/../data/behaviorsWithCounts.php'); |
|
450 | + $expected = require(__DIR__ . '/../data/expected_getCheckinBreakdown.php'); |
|
451 | 451 | $this->user_behavior->method('getBehaviorsWithCounts')->willReturn(...$bhvrs); |
452 | 452 | expect('asdf', $this->assertEquals($expected, $this->user_behavior->getCheckinBreakdown())); |
453 | 453 | } |
@@ -560,29 +560,29 @@ |
||
560 | 560 | |
561 | 561 | |
562 | 562 | public function cleanExportData($data) { |
563 | - $order = array_flip(["date", "behavior", "category", "question1", "question2", "question3"]); |
|
563 | + $order = array_flip(["date", "behavior", "category", "question1", "question2", "question3"]); |
|
564 | 564 | |
565 | - $ret = array_map( |
|
566 | - function($row) use ($order) { |
|
567 | - // change timestamp to local time (for the user) |
|
568 | - $row['date'] = $this->time->convertUTCToLocal($row['date'], false); |
|
565 | + $ret = array_map( |
|
566 | + function($row) use ($order) { |
|
567 | + // change timestamp to local time (for the user) |
|
568 | + $row['date'] = $this->time->convertUTCToLocal($row['date'], false); |
|
569 | 569 | |
570 | - // clean up things we don't need |
|
571 | - $row['category'] = $row['category']['name']; |
|
572 | - $row['behavior'] = $row['behavior']['name']; |
|
573 | - unset($row['id']); |
|
574 | - unset($row['behavior_id']); |
|
575 | - unset($row['category_id']); |
|
576 | - |
|
577 | - // sort the array into a sensible order |
|
578 | - uksort($row, function($a, $b) use ($order) { |
|
570 | + // clean up things we don't need |
|
571 | + $row['category'] = $row['category']['name']; |
|
572 | + $row['behavior'] = $row['behavior']['name']; |
|
573 | + unset($row['id']); |
|
574 | + unset($row['behavior_id']); |
|
575 | + unset($row['category_id']); |
|
576 | + |
|
577 | + // sort the array into a sensible order |
|
578 | + uksort($row, function($a, $b) use ($order) { |
|
579 | 579 | return $order[$a] <=> $order[$b]; |
580 | - }); |
|
581 | - return $row; |
|
582 | - }, |
|
583 | - $data |
|
584 | - ); |
|
585 | - return $ret; |
|
580 | + }); |
|
581 | + return $row; |
|
582 | + }, |
|
583 | + $data |
|
584 | + ); |
|
585 | + return $ret; |
|
586 | 586 | } |
587 | 587 | |
588 | 588 | /* |
@@ -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; |
@@ -369,7 +369,7 @@ discard block |
||
369 | 369 | * partner email address the user has set. |
370 | 370 | */ |
371 | 371 | public function sendEmailReport($date) { |
372 | - if(!$this->send_email) return false; // no partner emails set |
|
372 | + if (!$this->send_email) return false; // no partner emails set |
|
373 | 373 | list($start, $end) = $this->time->getUTCBookends($date); |
374 | 374 | |
375 | 375 | $user_behavior = Yii::$container->get(UserBehaviorInterface::class); |
@@ -378,14 +378,14 @@ discard block |
||
378 | 378 | // we should only proceed with sending the email if the user |
379 | 379 | // scored above their set email threshold (User::email_category) |
380 | 380 | $this_checkin = $checkins_last_month[$date]; // gets the check-in |
381 | - if(!$this_checkin) return false; // sanity check |
|
382 | - $highest_cat_data = end($this_checkin); // gets the data for the highest category from the check-in |
|
383 | - if(!$highest_cat_data) return false; // another sanity check |
|
381 | + if (!$this_checkin) return false; // sanity check |
|
382 | + $highest_cat_data = end($this_checkin); // gets the data for the highest category from the check-in |
|
383 | + if (!$highest_cat_data) return false; // another sanity check |
|
384 | 384 | $highest_cat_idx = key($this_checkin); // gets the key of the highest category |
385 | 385 | |
386 | 386 | // if the highest category they reached today was less than |
387 | 387 | // the category threshold they have set, don't send the email |
388 | - if($highest_cat_idx < $this->email_category) return false; |
|
388 | + if ($highest_cat_idx < $this->email_category) return false; |
|
389 | 389 | |
390 | 390 | $graph = Yii::$container |
391 | 391 | ->get(\common\components\Graph::class) |
@@ -395,8 +395,8 @@ discard block |
||
395 | 395 | $user_questions = $this->getUserQuestions($date); |
396 | 396 | |
397 | 397 | $messages = []; |
398 | - foreach($this->getPartnerEmails() as $email) { |
|
399 | - if($email) { |
|
398 | + foreach ($this->getPartnerEmails() as $email) { |
|
399 | + if ($email) { |
|
400 | 400 | $messages[] = Yii::$app->mailer->compose('checkinReport', [ |
401 | 401 | 'user' => $this, |
402 | 402 | 'email' => $email, |
@@ -408,7 +408,7 @@ discard block |
||
408 | 408 | 'behaviors_list' => \common\models\Behavior::$behaviors, |
409 | 409 | ])->setFrom([Yii::$app->params['supportEmail'] => Yii::$app->name]) |
410 | 410 | ->setReplyTo($this->email) |
411 | - ->setSubject($this->email." has completed a Faster Scale check-in") |
|
411 | + ->setSubject($this->email . " has completed a Faster Scale check-in") |
|
412 | 412 | ->setTo($email); |
413 | 413 | } |
414 | 414 | } |
@@ -482,7 +482,7 @@ discard block |
||
482 | 482 | return \Yii::$app->mailer->compose('signupNotification') |
483 | 483 | ->setFrom([\Yii::$app->params['supportEmail'] => \Yii::$app->name]) |
484 | 484 | ->setTo(\Yii::$app->params['adminEmail']) |
485 | - ->setSubject('A new user has signed up for '.\Yii::$app->name) |
|
485 | + ->setSubject('A new user has signed up for ' . \Yii::$app->name) |
|
486 | 486 | ->send(); |
487 | 487 | } |
488 | 488 | |
@@ -490,20 +490,20 @@ discard block |
||
490 | 490 | return \Yii::$app->mailer->compose('verifyEmail', ['user' => $this]) |
491 | 491 | ->setFrom([\Yii::$app->params['supportEmail'] => \Yii::$app->name]) |
492 | 492 | ->setTo($this->email) |
493 | - ->setSubject('Please verify your '.\Yii::$app->name .' account') |
|
493 | + ->setSubject('Please verify your ' . \Yii::$app->name . ' account') |
|
494 | 494 | ->send(); |
495 | 495 | } |
496 | 496 | |
497 | 497 | public function sendDeleteNotificationEmail() { |
498 | 498 | $messages = []; |
499 | - foreach(array_merge([$this->email], $this->getPartnerEmails()) as $email) { |
|
500 | - if($email) { |
|
499 | + foreach (array_merge([$this->email], $this->getPartnerEmails()) as $email) { |
|
500 | + if ($email) { |
|
501 | 501 | $messages[] = Yii::$app->mailer->compose('deleteNotification', [ |
502 | 502 | 'user' => $this, |
503 | 503 | 'email' => $email |
504 | 504 | ])->setFrom([Yii::$app->params['supportEmail'] => Yii::$app->name]) |
505 | 505 | ->setReplyTo($this->email) |
506 | - ->setSubject($this->email." has deleted their The Faster Scale App account") |
|
506 | + ->setSubject($this->email . " has deleted their The Faster Scale App account") |
|
507 | 507 | ->setTo($email); |
508 | 508 | } |
509 | 509 | } |
@@ -512,16 +512,16 @@ discard block |
||
512 | 512 | } |
513 | 513 | |
514 | 514 | public function getUserQuestions($local_date = null) { |
515 | - if(is_null($local_date)) $local_date = $this->time->getLocalDate(); |
|
515 | + if (is_null($local_date)) $local_date = $this->time->getLocalDate(); |
|
516 | 516 | $questions = $this->getQuestionData($local_date); |
517 | 517 | return $this->parseQuestionData($questions); |
518 | 518 | } |
519 | 519 | |
520 | 520 | public function parseQuestionData($questions) { |
521 | - if(!$questions) return []; |
|
521 | + if (!$questions) return []; |
|
522 | 522 | |
523 | 523 | $question_answers = []; |
524 | - foreach($questions as $question) { |
|
524 | + foreach ($questions as $question) { |
|
525 | 525 | $behavior = $question['behavior']; |
526 | 526 | |
527 | 527 | $question_answers[$behavior['id']]['question'] = [ |
@@ -604,7 +604,7 @@ discard block |
||
604 | 604 | return rtrim( |
605 | 605 | strtr( |
606 | 606 | base64_encode( |
607 | - hash('sha256', $this->id."::".$this->created_at, true) |
|
607 | + hash('sha256', $this->id . "::" . $this->created_at, true) |
|
608 | 608 | ), |
609 | 609 | '+/', '-_'), |
610 | 610 | '='); |
@@ -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 | |
@@ -369,7 +373,10 @@ discard block |
||
369 | 373 | * partner email address the user has set. |
370 | 374 | */ |
371 | 375 | public function sendEmailReport($date) { |
372 | - if(!$this->send_email) return false; // no partner emails set |
|
376 | + if(!$this->send_email) { |
|
377 | + return false; |
|
378 | + } |
|
379 | + // no partner emails set |
|
373 | 380 | list($start, $end) = $this->time->getUTCBookends($date); |
374 | 381 | |
375 | 382 | $user_behavior = Yii::$container->get(UserBehaviorInterface::class); |
@@ -378,14 +385,22 @@ discard block |
||
378 | 385 | // we should only proceed with sending the email if the user |
379 | 386 | // scored above their set email threshold (User::email_category) |
380 | 387 | $this_checkin = $checkins_last_month[$date]; // gets the check-in |
381 | - if(!$this_checkin) return false; // sanity check |
|
388 | + if(!$this_checkin) { |
|
389 | + return false; |
|
390 | + } |
|
391 | + // sanity check |
|
382 | 392 | $highest_cat_data = end($this_checkin); // gets the data for the highest category from the check-in |
383 | - if(!$highest_cat_data) return false; // another sanity check |
|
393 | + if(!$highest_cat_data) { |
|
394 | + return false; |
|
395 | + } |
|
396 | + // another sanity check |
|
384 | 397 | $highest_cat_idx = key($this_checkin); // gets the key of the highest category |
385 | 398 | |
386 | 399 | // if the highest category they reached today was less than |
387 | 400 | // the category threshold they have set, don't send the email |
388 | - if($highest_cat_idx < $this->email_category) return false; |
|
401 | + if($highest_cat_idx < $this->email_category) { |
|
402 | + return false; |
|
403 | + } |
|
389 | 404 | |
390 | 405 | $graph = Yii::$container |
391 | 406 | ->get(\common\components\Graph::class) |
@@ -512,13 +527,17 @@ discard block |
||
512 | 527 | } |
513 | 528 | |
514 | 529 | public function getUserQuestions($local_date = null) { |
515 | - if(is_null($local_date)) $local_date = $this->time->getLocalDate(); |
|
530 | + if(is_null($local_date)) { |
|
531 | + $local_date = $this->time->getLocalDate(); |
|
532 | + } |
|
516 | 533 | $questions = $this->getQuestionData($local_date); |
517 | 534 | return $this->parseQuestionData($questions); |
518 | 535 | } |
519 | 536 | |
520 | 537 | public function parseQuestionData($questions) { |
521 | - if(!$questions) return []; |
|
538 | + if(!$questions) { |
|
539 | + return []; |
|
540 | + } |
|
522 | 541 | |
523 | 542 | $question_answers = []; |
524 | 543 | foreach($questions as $question) { |
@@ -86,7 +86,7 @@ discard block |
||
86 | 86 | ->groupBy('date, user_id') |
87 | 87 | ->having('user_id = :user_id'); |
88 | 88 | $temp_dates = $query->all(); |
89 | - foreach($temp_dates as $temp_date) { |
|
89 | + foreach ($temp_dates as $temp_date) { |
|
90 | 90 | $past_checkin_dates[] = $this->time->convertUTCToLocal($temp_date['date']); |
91 | 91 | } |
92 | 92 | |
@@ -115,12 +115,12 @@ discard block |
||
115 | 115 | |
116 | 116 | public function getCheckinBreakdown(int $period = 30) { |
117 | 117 | $datetimes = $this->time->getDateTimesInPeriod($period); |
118 | - $key = "checkins_".Yii::$app->user->id."_{$period}_".$this->time->getLocalDate(); |
|
118 | + $key = "checkins_" . Yii::$app->user->id . "_{$period}_" . $this->time->getLocalDate(); |
|
119 | 119 | $checkins = Yii::$app->cache->get($key); |
120 | 120 | |
121 | - if($checkins === false) { |
|
121 | + if ($checkins === false) { |
|
122 | 122 | $checkins = []; |
123 | - foreach($datetimes as $datetime) { |
|
123 | + foreach ($datetimes as $datetime) { |
|
124 | 124 | $behaviors = self::decorate($this->getBehaviorsWithCounts($datetime)); |
125 | 125 | $checkins[$datetime->format('Y-m-d')] = $this->getBehaviorsByCategory($behaviors); |
126 | 126 | } |
@@ -146,7 +146,7 @@ discard block |
||
146 | 146 | public function getBehaviorsByCategory(array $decorated_behaviors) { |
147 | 147 | $arr = array_reduce($decorated_behaviors, function($acc, $row) { |
148 | 148 | $cat_id = $row['category_id']; |
149 | - if(array_key_exists($cat_id, $acc)) { |
|
149 | + if (array_key_exists($cat_id, $acc)) { |
|
150 | 150 | $acc[$cat_id]['count'] += $row['count']; |
151 | 151 | } else { |
152 | 152 | $acc[$cat_id] = [ |
@@ -178,11 +178,11 @@ discard block |
||
178 | 178 | ->having('user_id = :user_id') |
179 | 179 | ->orderBy('count DESC'); |
180 | 180 | |
181 | - if($limit instanceof \DateTime) { |
|
181 | + if ($limit instanceof \DateTime) { |
|
182 | 182 | list($start, $end) = $this->time->getUTCBookends($limit->format('Y-m-d')); |
183 | 183 | $query->params += [':start_date' => $start, ':end_date' => $end]; |
184 | 184 | $query->where('user_id=:user_id AND date > :start_date AND date <= :end_date'); |
185 | - } else if(is_int($limit)) { |
|
185 | + } else if (is_int($limit)) { |
|
186 | 186 | $query->limit($limit); |
187 | 187 | } |
188 | 188 | return $query->all(); |
@@ -197,7 +197,7 @@ discard block |
||
197 | 197 | * @return array |
198 | 198 | */ |
199 | 199 | public function getByDate(int $user_id, $local_date = null) { |
200 | - if(is_null($local_date)) $local_date = $this->time->getLocalDate(); |
|
200 | + if (is_null($local_date)) $local_date = $this->time->getLocalDate(); |
|
201 | 201 | |
202 | 202 | $behaviors = $this->getBehaviorData($user_id, $local_date); |
203 | 203 | $behaviors = self::decorate($behaviors); |
@@ -210,12 +210,12 @@ discard block |
||
210 | 210 | * @return an array of decorated UserBehaviors, each with an added Category and Behavior |
211 | 211 | */ |
212 | 212 | public static function decorate(array $uo) { |
213 | - foreach($uo as &$o) { |
|
213 | + foreach ($uo as &$o) { |
|
214 | 214 | $behavior = \common\models\Behavior::getBehavior('id', $o['behavior_id']); |
215 | 215 | $category = \common\models\Category::getCategory('id', $o['category_id']); |
216 | 216 | // if this behavior does not have a valid behavior or category, something |
217 | 217 | // is weird and we don't want to do this halfway. |
218 | - if($behavior && $category) { |
|
218 | + if ($behavior && $category) { |
|
219 | 219 | $o['behavior'] = $behavior; |
220 | 220 | $o['category'] = $category; |
221 | 221 | } |
@@ -242,10 +242,10 @@ discard block |
||
242 | 242 | |
243 | 243 | // this should probably be a private method...but unit testing is hard |
244 | 244 | public function parseBehaviorData($behaviors) { |
245 | - if(!$behaviors) return []; |
|
245 | + if (!$behaviors) return []; |
|
246 | 246 | |
247 | 247 | $bhvrs_by_cat = []; |
248 | - foreach($behaviors as $behavior) { |
|
248 | + foreach ($behaviors as $behavior) { |
|
249 | 249 | $indx = $behavior['category_id']; |
250 | 250 | |
251 | 251 | $bhvrs_by_cat[$indx][$behavior['behavior']['name']] = [ |
@@ -197,7 +197,9 @@ discard block |
||
197 | 197 | * @return array |
198 | 198 | */ |
199 | 199 | public function getByDate(int $user_id, $local_date = null) { |
200 | - if(is_null($local_date)) $local_date = $this->time->getLocalDate(); |
|
200 | + if(is_null($local_date)) { |
|
201 | + $local_date = $this->time->getLocalDate(); |
|
202 | + } |
|
201 | 203 | |
202 | 204 | $behaviors = $this->getBehaviorData($user_id, $local_date); |
203 | 205 | $behaviors = self::decorate($behaviors); |
@@ -242,7 +244,9 @@ discard block |
||
242 | 244 | |
243 | 245 | // this should probably be a private method...but unit testing is hard |
244 | 246 | public function parseBehaviorData($behaviors) { |
245 | - if(!$behaviors) return []; |
|
247 | + if(!$behaviors) { |
|
248 | + return []; |
|
249 | + } |
|
246 | 250 | |
247 | 251 | $bhvrs_by_cat = []; |
248 | 252 | foreach($behaviors as $behavior) { |
@@ -22,20 +22,20 @@ |
||
22 | 22 | |
23 | 23 | // then populate the columns |
24 | 24 | $query = (new Query())->from('user_behavior_link'); |
25 | - foreach($query->batch() as $rows) { |
|
26 | - foreach($rows as $row) { |
|
25 | + foreach ($query->batch() as $rows) { |
|
26 | + foreach ($rows as $row) { |
|
27 | 27 | $bhvr = Behavior::getBehavior('id', $row['behavior_id']); |
28 | - if($bhvr) { |
|
28 | + if ($bhvr) { |
|
29 | 29 | $this->update('{{%user_behavior_link}}', ['category_id' => $bhvr['category_id']], ['id' => $row['id']]); |
30 | 30 | } |
31 | 31 | } |
32 | 32 | } |
33 | 33 | |
34 | 34 | $query = (new Query())->from('question'); |
35 | - foreach($query->batch() as $rows) { |
|
36 | - foreach($rows as $row) { |
|
35 | + foreach ($query->batch() as $rows) { |
|
36 | + foreach ($rows as $row) { |
|
37 | 37 | $bhvr = Behavior::getBehavior('id', $row['behavior_id']); |
38 | - if($bhvr) { |
|
38 | + if ($bhvr) { |
|
39 | 39 | $this->update('{{%question}}', ['category_id' => $bhvr['category_id']], ['id' => $row['id']]); |
40 | 40 | } |
41 | 41 | } |