@@ -15,7 +15,7 @@ discard block |
||
15 | 15 | |
16 | 16 | $exception = Yii::$app->errorHandler->exception; |
17 | 17 | |
18 | -if($exception instanceof \yii\web\NotFoundHttpException): |
|
18 | +if ($exception instanceof \yii\web\NotFoundHttpException): |
|
19 | 19 | $this->title = "The Faster Scale App | Page Not Found"; |
20 | 20 | ?> |
21 | 21 | |
@@ -25,7 +25,7 @@ discard block |
||
25 | 25 | <p>Otherwise, please ensure your attempted url is correct.</p> |
26 | 26 | |
27 | 27 | <?php |
28 | -elseif($exception instanceof \yii\web\ServerErrorHttpException): |
|
28 | +elseif ($exception instanceof \yii\web\ServerErrorHttpException): |
|
29 | 29 | $this->title = "The Faster Scale App | Oops"; |
30 | 30 | ?> |
31 | 31 |
@@ -33,7 +33,8 @@ discard block |
||
33 | 33 | <div class="alert alert-danger"><?= nl2br(Html::encode($name)) ?></div> |
34 | 34 | <p>Well this is embarrassing...we're having an error on our side. So sorry for the annoyance. If you'd like to help, please send us a message on our <a href='<?=Url::to(['site/contact'])?>'>contact form</a>.</p> |
35 | 35 | |
36 | -<?php else: ?> |
|
36 | +<?php else { |
|
37 | + : ?> |
|
37 | 38 | |
38 | 39 | <div class="site-error"> |
39 | 40 | <h1><?= Html::encode($name) ?></h1> |
@@ -41,4 +42,6 @@ discard block |
||
41 | 42 | <p>The above error occurred while the Web server was processing your request.</p> |
42 | 43 | <p>Please contact us if you think this is a server error. Thank you.</p> |
43 | 44 | </div> |
44 | -<?php endif; ?> |
|
45 | +<?php endif; |
|
46 | +} |
|
47 | +?> |
@@ -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 | } |
@@ -75,7 +75,7 @@ discard block |
||
75 | 75 | $model = Yii::$container->get(\site\models\DeleteAccountForm::class, [Yii::$app->user->identity]); |
76 | 76 | |
77 | 77 | if ($model->load(Yii::$app->request->post()) && $model->validate()) { |
78 | - if($model->deleteAccount()) { |
|
78 | + if ($model->deleteAccount()) { |
|
79 | 79 | $this->redirect(['site/index']); |
80 | 80 | } else { |
81 | 81 | Yii::$app->session->setFlash('error', 'Wrong password!'); |
@@ -89,7 +89,7 @@ discard block |
||
89 | 89 | $model = Yii::$container->get(\site\models\ChangePasswordForm::class, [Yii::$app->user->identity]); |
90 | 90 | |
91 | 91 | if ($model->load(Yii::$app->request->post())) { |
92 | - if($model->validate() && $model->changePassword()) { |
|
92 | + if ($model->validate() && $model->changePassword()) { |
|
93 | 93 | Yii::$app->session->setFlash('success', 'Password successfully changed'); |
94 | 94 | } else { |
95 | 95 | Yii::$app->session->setFlash('error', 'Wrong password!'); |
@@ -113,14 +113,14 @@ discard block |
||
113 | 113 | public function actionChangeEmail(string $token) { |
114 | 114 | $user = Yii::$container->get(\common\interfaces\UserInterface::class)->findByChangeEmailToken($token); |
115 | 115 | |
116 | - if($user) { |
|
116 | + if ($user) { |
|
117 | 117 | $validator = new \yii\validators\EmailValidator(); |
118 | - if($validator->validate($user->desired_email, $error)) { |
|
118 | + if ($validator->validate($user->desired_email, $error)) { |
|
119 | 119 | $user->removeChangeEmailToken(); |
120 | 120 | $user->email = $user->desired_email; |
121 | 121 | $user->desired_email = null; |
122 | 122 | $user->save(); |
123 | - if(!Yii::$app->user->isGuest) { |
|
123 | + if (!Yii::$app->user->isGuest) { |
|
124 | 124 | Yii::$app->user->logout(); |
125 | 125 | Yii::$app->session->setFlash('success', 'Your email address was successfully changed. For security, we\'ve logged you out.'); |
126 | 126 | } else { |
@@ -140,7 +140,7 @@ discard block |
||
140 | 140 | |
141 | 141 | public function actionExport() { |
142 | 142 | header("Content-Type: text/csv"); |
143 | - header("Content-Disposition: attachment; filename=fsa-data-export-".Yii::$app->user->identity->email."-".date('Ymd').".csv"); |
|
143 | + header("Content-Disposition: attachment; filename=fsa-data-export-" . Yii::$app->user->identity->email . "-" . date('Ymd') . ".csv"); |
|
144 | 144 | |
145 | 145 | $reader = Yii::$app->user->identity->getExportData(); |
146 | 146 | $fp = fopen('php://output', 'w'); |
@@ -156,7 +156,7 @@ discard block |
||
156 | 156 | |
157 | 157 | fputcsv($fp, $header); |
158 | 158 | $user_behavior = Yii::$container->get(\common\interfaces\UserBehaviorInterface::class); |
159 | - while($row = $reader->read()) { |
|
159 | + while ($row = $reader->read()) { |
|
160 | 160 | $row = $user_behavior::decorateWithCategory([$row]); |
161 | 161 | $row = Yii::$app->user->identity->cleanExportData($row); |
162 | 162 | fputcsv($fp, $row[0]); |
@@ -55,9 +55,9 @@ discard block |
||
55 | 55 | public function actionBlog() |
56 | 56 | { |
57 | 57 | $time = Yii::$container->get(\common\interfaces\TimeInterface::class); |
58 | - $key = "index_blog_".$time->getLocalDate('UTC'); |
|
58 | + $key = "index_blog_" . $time->getLocalDate('UTC'); |
|
59 | 59 | $posts = Yii::$app->cache->get($key); |
60 | - if($posts === false) { |
|
60 | + if ($posts === false) { |
|
61 | 61 | $posts = \Yii::$app->getModule('blog') |
62 | 62 | ->fetch() |
63 | 63 | ->parse() |
@@ -90,7 +90,7 @@ discard block |
||
90 | 90 | { |
91 | 91 | $model = new \site\models\ContactForm(); |
92 | 92 | if ($model->load(Yii::$app->request->post()) && $model->validate()) { |
93 | - if($model->sendEmail(Yii::$app->params['adminEmail'])) { |
|
93 | + if ($model->sendEmail(Yii::$app->params['adminEmail'])) { |
|
94 | 94 | Yii::$app->session->setFlash('success', 'Thank you for contacting us. We will respond to you as soon as possible.'); |
95 | 95 | } else { |
96 | 96 | Yii::$app->session->setFlash('error', 'There was an error sending email.'); |
@@ -122,10 +122,10 @@ discard block |
||
122 | 122 | public function actionSignup() |
123 | 123 | { |
124 | 124 | $model = Yii::$container->get(\site\models\SignupForm::class); |
125 | - if($model->load(Yii::$app->request->post()) && $model->validate()) { |
|
125 | + if ($model->load(Yii::$app->request->post()) && $model->validate()) { |
|
126 | 126 | $model->signup(); |
127 | 127 | Yii::$app->session->setFlash('success', 'We have sent a verification email to the email address you provided. Please check your inbox and follow the instructions to verify your account.'); |
128 | - return $this->redirect('/',302); |
|
128 | + return $this->redirect('/', 302); |
|
129 | 129 | } |
130 | 130 | |
131 | 131 | return $this->render('signup', [ |
@@ -136,10 +136,10 @@ discard block |
||
136 | 136 | public function actionRequestPasswordReset() |
137 | 137 | { |
138 | 138 | $model = Yii::$container->get(\site\models\PasswordResetRequestForm::class); |
139 | - if($model->load(Yii::$app->request->post()) && $model->validate()) { |
|
140 | - if(!$model->sendEmail()) { |
|
139 | + if ($model->load(Yii::$app->request->post()) && $model->validate()) { |
|
140 | + if (!$model->sendEmail()) { |
|
141 | 141 | $ip = Yii::$app->getRequest()->getUserIP() ?: "UNKNOWN"; |
142 | - Yii::warning("$ip has tried to reset the password for ".$model->email); |
|
142 | + Yii::warning("$ip has tried to reset the password for " . $model->email); |
|
143 | 143 | } |
144 | 144 | |
145 | 145 | Yii::$app->session->setFlash('success', 'If there is an account with the submitted email address you will receive further instructions in your email inbox.'); |
@@ -183,14 +183,14 @@ discard block |
||
183 | 183 | throw new BadRequestHttpException("Wrong or expired email verification token. If you aren't sure why this error occurs perhaps you've already verified your account. Please try logging in."); |
184 | 184 | } |
185 | 185 | |
186 | - if($user->isTokenConfirmed($user->verify_email_token)) { |
|
186 | + if ($user->isTokenConfirmed($user->verify_email_token)) { |
|
187 | 187 | Yii::$app->session->setFlash('success', 'Your account has already been verified. Please log in.'); |
188 | - return $this->redirect('/login',302); |
|
188 | + return $this->redirect('/login', 302); |
|
189 | 189 | } else if (Yii::$app->getUser()->login($user)) { |
190 | 190 | $user->confirmVerifyEmailToken(); |
191 | 191 | $user->save(); |
192 | 192 | Yii::$app->session->setFlash('success', 'Your account has been verified. Please continue with your check-in.'); |
193 | - return $this->redirect('/welcome',302); |
|
193 | + return $this->redirect('/welcome', 302); |
|
194 | 194 | } |
195 | 195 | } |
196 | 196 |
@@ -36,7 +36,7 @@ |
||
36 | 36 | } |
37 | 37 | |
38 | 38 | if (!empty($this->json)) { |
39 | - foreach($this->json[self::POS_READY] as $json_name => $json_value) { |
|
39 | + foreach ($this->json[self::POS_READY] as $json_name => $json_value) { |
|
40 | 40 | $lines[] = Html::script($json_value, ['type' => 'application/json', 'id' => $json_name]); |
41 | 41 | } |
42 | 42 | } |
@@ -33,8 +33,8 @@ |
||
33 | 33 | { |
34 | 34 | return [ |
35 | 35 | 'error' => [ |
36 | - 'class' => 'yii\web\ErrorAction', |
|
37 | - ], |
|
36 | + 'class' => 'yii\web\ErrorAction', |
|
37 | + ], |
|
38 | 38 | 'captcha' => [ |
39 | 39 | 'class' => 'yii\captcha\CaptchaAction', |
40 | 40 | ], |
@@ -60,10 +60,10 @@ |
||
60 | 60 | */ |
61 | 61 | public function login() |
62 | 62 | { |
63 | - if($this->validate()) { |
|
63 | + if ($this->validate()) { |
|
64 | 64 | $user = $this->getUser(); |
65 | - if($user->isVerified()) { |
|
66 | - return Yii::$app->user->login($user, $this->rememberMe ? 3600 * 24 * 30 : 0); |
|
65 | + if ($user->isVerified()) { |
|
66 | + return Yii::$app->user->login($user, $this->rememberMe ? 3600*24*30 : 0); |
|
67 | 67 | } else { |
68 | 68 | Yii::$app->session->setFlash('warning', 'You must verify your account before you can proceed. Please check your email inbox for a verification email and follow the instructions.'); |
69 | 69 | } |
@@ -39,7 +39,7 @@ discard block |
||
39 | 39 | if ($form->load(Yii::$app->request->post()) && $form->validate()) { |
40 | 40 | $form->compiled_behaviors = $form->compileBehaviors(); |
41 | 41 | |
42 | - if(sizeof($form->compiled_behaviors) === 0) { |
|
42 | + if (sizeof($form->compiled_behaviors) === 0) { |
|
43 | 43 | return $this->redirect(['view']); |
44 | 44 | } |
45 | 45 | |
@@ -49,7 +49,7 @@ discard block |
||
49 | 49 | |
50 | 50 | return $this->redirect(['questions']); |
51 | 51 | } else { |
52 | - $behaviors = Yii::$container->get(BehaviorInterface::class)::$behaviors; |
|
52 | + $behaviors = Yii::$container->get(BehaviorInterface::class)::$behaviors; |
|
53 | 53 | return $this->render('index', [ |
54 | 54 | 'categories' => Yii::$container->get(CategoryInterface::class)::$categories, |
55 | 55 | 'model' => $form, |
@@ -64,7 +64,7 @@ discard block |
||
64 | 64 | $date = Yii::$container->get(TimeInterface::class)->getLocalDate(); |
65 | 65 | |
66 | 66 | $user_behaviors = $user_behavior->getUserBehaviorsWithCategory($date); |
67 | - if(count($user_behaviors) === 0) { |
|
67 | + if (count($user_behaviors) === 0) { |
|
68 | 68 | return $this->redirect(['view']); |
69 | 69 | } |
70 | 70 | |
@@ -74,9 +74,9 @@ discard block |
||
74 | 74 | $form->deleteToday(); |
75 | 75 | |
76 | 76 | $behaviors = $user_behavior->findAll($form->getUserBehaviorIds()); |
77 | - if($result = $form->saveAnswers($behaviors)) { |
|
77 | + if ($result = $form->saveAnswers($behaviors)) { |
|
78 | 78 | |
79 | - if(Yii::$app->user->identity->send_email) { |
|
79 | + if (Yii::$app->user->identity->send_email) { |
|
80 | 80 | Yii::$app->user->identity->sendEmailReport($date); |
81 | 81 | Yii::$app->session->setFlash('success', 'Your check-in is complete. A notification has been sent to your report partners.'); |
82 | 82 | } else { |
@@ -130,7 +130,7 @@ discard block |
||
130 | 130 | $raw_pie_data = $user_behavior::decorateWithCategory($user_behavior->getBehaviorsWithCounts()); |
131 | 131 | $answer_pie = $user_behavior->getBehaviorsByCategory($raw_pie_data); |
132 | 132 | |
133 | - $pie_data = [ |
|
133 | + $pie_data = [ |
|
134 | 134 | "labels" => array_column($answer_pie, "name"), |
135 | 135 | "datasets" => [[ |
136 | 136 | "data" => array_map('intval', array_column($answer_pie, "count")), |
@@ -166,14 +166,14 @@ discard block |
||
166 | 166 | $checkins = $user_behavior->getCheckInBreakdown($time->getDateTimesInPeriod($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'], |
@@ -12,13 +12,13 @@ |
||
12 | 12 | class Category extends \yii\base\BaseObject implements \common\interfaces\CategoryInterface { |
13 | 13 | |
14 | 14 | public static $categories = [ |
15 | - [ "id" => 1, "name" => "Restoration"], |
|
16 | - [ "id" => 2, "name" => "Forgetting Priorities"], |
|
17 | - [ "id" => 3, "name" => "Anxiety"], |
|
18 | - [ "id" => 4, "name" => "Speeding Up"], |
|
19 | - [ "id" => 5, "name" => "Ticked Off"], |
|
20 | - [ "id" => 6, "name" => "Exhausted"], |
|
21 | - [ "id" => 7, "name" => "Relapse/Moral Failure"], |
|
15 | + ["id" => 1, "name" => "Restoration"], |
|
16 | + ["id" => 2, "name" => "Forgetting Priorities"], |
|
17 | + ["id" => 3, "name" => "Anxiety"], |
|
18 | + ["id" => 4, "name" => "Speeding Up"], |
|
19 | + ["id" => 5, "name" => "Ticked Off"], |
|
20 | + ["id" => 6, "name" => "Exhausted"], |
|
21 | + ["id" => 7, "name" => "Relapse/Moral Failure"], |
|
22 | 22 | ]; |
23 | 23 | |
24 | 24 | public static $colors = [ |
@@ -84,7 +84,7 @@ discard block |
||
84 | 84 | ->groupBy('date, user_id') |
85 | 85 | ->having('user_id = :user_id'); |
86 | 86 | $temp_dates = $query->all(); |
87 | - foreach($temp_dates as $temp_date) { |
|
87 | + foreach ($temp_dates as $temp_date) { |
|
88 | 88 | $past_checkin_dates[] = $this->time->convertUTCToLocal($temp_date['date']); |
89 | 89 | } |
90 | 90 | |
@@ -126,13 +126,13 @@ discard block |
||
126 | 126 | } |
127 | 127 | |
128 | 128 | public function getCheckinBreakdown(\DatePeriod $datetimes) { |
129 | - $key = "scores_of_last_month_".Yii::$app->user->id."_".$this->time->getLocalDate(); |
|
129 | + $key = "scores_of_last_month_" . Yii::$app->user->id . "_" . $this->time->getLocalDate(); |
|
130 | 130 | $scores = Yii::$app->cache->get($key); |
131 | 131 | |
132 | - if($scores === false) { |
|
132 | + if ($scores === false) { |
|
133 | 133 | $scores = []; |
134 | 134 | $count = 0; |
135 | - foreach($datetimes as $datetime) { |
|
135 | + foreach ($datetimes as $datetime) { |
|
136 | 136 | $count += 1; |
137 | 137 | $behaviors = self::decorateWithCategory($this->getBehaviorsWithCounts($datetime)); |
138 | 138 | $scores[$datetime->format('Y-m-d')] = $this->getBehaviorsByCategory($behaviors); |
@@ -159,7 +159,7 @@ discard block |
||
159 | 159 | public function getBehaviorsByCategory(array $decorated_behaviors) { |
160 | 160 | $arr = array_reduce($decorated_behaviors, function($acc, $row) { |
161 | 161 | $cat_id = $row['behavior']['category']['id']; |
162 | - if(array_key_exists($cat_id, $acc)) { |
|
162 | + if (array_key_exists($cat_id, $acc)) { |
|
163 | 163 | $acc[$cat_id]['count'] += $row['count']; |
164 | 164 | } else { |
165 | 165 | $acc[$cat_id] = [ |
@@ -176,10 +176,10 @@ discard block |
||
176 | 176 | } |
177 | 177 | |
178 | 178 | public static function decorate(array $uo, $with_category = false) { |
179 | - foreach($uo as &$o) { |
|
180 | - if($behavior = \common\models\Behavior::getBehavior('id', $o['behavior_id'])) { |
|
179 | + foreach ($uo as &$o) { |
|
180 | + if ($behavior = \common\models\Behavior::getBehavior('id', $o['behavior_id'])) { |
|
181 | 181 | $o['behavior'] = $behavior; |
182 | - if($with_category) { |
|
182 | + if ($with_category) { |
|
183 | 183 | $o['behavior']['category'] = \common\models\Category::getCategory('id', $o['behavior']['category_id']); |
184 | 184 | } |
185 | 185 | } |
@@ -200,11 +200,11 @@ discard block |
||
200 | 200 | ->having('user_id = :user_id') |
201 | 201 | ->orderBy('count DESC'); |
202 | 202 | |
203 | - if($limit instanceof \DateTime) { |
|
203 | + if ($limit instanceof \DateTime) { |
|
204 | 204 | list($start, $end) = $this->time->getUTCBookends($limit->format('Y-m-d')); |
205 | 205 | $query->params += [':start_date' => $start, ':end_date' => $end]; |
206 | 206 | $query->where('user_id=:user_id AND date > :start_date AND date <= :end_date'); |
207 | - } else if(is_int($limit)) { |
|
207 | + } else if (is_int($limit)) { |
|
208 | 208 | $query->limit($limit); |
209 | 209 | } |
210 | 210 |