@@ -41,7 +41,7 @@ discard block |
||
41 | 41 | ]; |
42 | 42 | |
43 | 43 | $tmp_pie = []; |
44 | -foreach($answer_pie as $key => $category) { |
|
44 | +foreach ($answer_pie as $key => $category) { |
|
45 | 45 | $json = [ |
46 | 46 | "value" => (int)$category['count'], |
47 | 47 | "color" => $pie_colors[$key]["color"], |
@@ -80,13 +80,13 @@ discard block |
||
80 | 80 | <th>Behavior</th> |
81 | 81 | <th>Count</th> |
82 | 82 | </tr> |
83 | -<?php foreach($top_behaviors as $key => $row) { |
|
83 | +<?php foreach ($top_behaviors as $key => $row) { |
|
84 | 84 | $num = $key + 1; |
85 | -print "<tr>". |
|
86 | - "<td>".$num."</td>". |
|
87 | - "<td>{$row['behavior']['category']['name']}</td>". |
|
88 | - "<td>{$row['behavior']['name']}</td>". |
|
89 | - "<td>{$row['count']}</td>". |
|
85 | +print "<tr>" . |
|
86 | + "<td>" . $num . "</td>" . |
|
87 | + "<td>{$row['behavior']['category']['name']}</td>" . |
|
88 | + "<td>{$row['behavior']['name']}</td>" . |
|
89 | + "<td>{$row['count']}</td>" . |
|
90 | 90 | "</tr>"; |
91 | 91 | |
92 | 92 | } |
@@ -92,7 +92,7 @@ |
||
92 | 92 | print $form |
93 | 93 | ->field($model, "behaviors{$category['id']}") |
94 | 94 | ->checkboxList($behaviors, |
95 | - ['item' => "checkboxItemTemplate"]); |
|
95 | + ['item' => "checkboxItemTemplate"]); |
|
96 | 96 | } |
97 | 97 | ActiveForm::end(); |
98 | 98 |
@@ -41,10 +41,10 @@ |
||
41 | 41 | |
42 | 42 | <?php |
43 | 43 | switch(true) { |
44 | - case ($score < 30): |
|
45 | - $alert_level = "success"; |
|
46 | - $alert_msg = "You're doing well! Keep on doing whatever it is you're doing!"; |
|
47 | - break; |
|
44 | + case ($score < 30): |
|
45 | + $alert_level = "success"; |
|
46 | + $alert_msg = "You're doing well! Keep on doing whatever it is you're doing!"; |
|
47 | + break; |
|
48 | 48 | |
49 | 49 | case ($score < 40): |
50 | 50 | $alert_level = "info"; |
@@ -40,7 +40,7 @@ discard block |
||
40 | 40 | </div> |
41 | 41 | |
42 | 42 | <?php |
43 | - switch(true) { |
|
43 | + switch (true) { |
|
44 | 44 | case ($score < 30): |
45 | 45 | $alert_level = "success"; |
46 | 46 | $alert_msg = "You're doing well! Keep on doing whatever it is you're doing!"; |
@@ -67,15 +67,15 @@ discard block |
||
67 | 67 | <div class='alert alert-<?=$alert_level?>'><?=$alert_msg?></div> |
68 | 68 | </div> |
69 | 69 | |
70 | - <?php if($questions) { |
|
71 | - foreach($questions as $behavior_id => $behavior_questions) { |
|
70 | + <?php if ($questions) { |
|
71 | + foreach ($questions as $behavior_id => $behavior_questions) { |
|
72 | 72 | print "<div class='well well-sm'>"; |
73 | 73 | print "<button type='button' class='btn btn-primary' disabled='disabled'>{$behavior_questions['question']['title']}</button>"; |
74 | 74 | print "<div class='row'>"; |
75 | - foreach($behavior_questions['answers'] as $question) { |
|
75 | + foreach ($behavior_questions['answers'] as $question) { |
|
76 | 76 | print "<div class='col-md-4'>"; |
77 | 77 | print "<p><strong>{$question['title']}</strong></p>"; |
78 | - print "<p>".Html::encode($question['answer'])."</p>"; |
|
78 | + print "<p>" . Html::encode($question['answer']) . "</p>"; |
|
79 | 79 | print "</div>"; |
80 | 80 | } |
81 | 81 | print "</div></div>"; |
@@ -87,7 +87,7 @@ discard block |
||
87 | 87 | 'options' => ['class' => 'form-horizontal'], |
88 | 88 | ]); |
89 | 89 | |
90 | - foreach($categories as $category) { |
|
90 | + foreach ($categories as $category) { |
|
91 | 91 | $behaviors = AH::map($behaviorsList[$category['id']], 'id', 'name'); |
92 | 92 | print $form |
93 | 93 | ->field($model, "behaviors{$category['id']}") |
@@ -12,9 +12,9 @@ |
||
12 | 12 | $name, |
13 | 13 | $checked, |
14 | 14 | ['value' => $value, |
15 | - 'label' => $label, |
|
16 | - 'container' => false, |
|
17 | - 'labelOptions' => [ 'class' => $checked |
|
15 | + 'label' => $label, |
|
16 | + 'container' => false, |
|
17 | + 'labelOptions' => [ 'class' => $checked |
|
18 | 18 | ? 'btn btn-info active' |
19 | 19 | : 'btn btn-info'], |
20 | 20 | ]); |
@@ -14,7 +14,7 @@ discard block |
||
14 | 14 | ['value' => $value, |
15 | 15 | 'label' => $label, |
16 | 16 | 'container' => false, |
17 | - 'labelOptions' => [ 'class' => $checked |
|
17 | + 'labelOptions' => ['class' => $checked |
|
18 | 18 | ? 'btn btn-info active' |
19 | 19 | : 'btn btn-info'], |
20 | 20 | ]); |
@@ -32,7 +32,7 @@ discard block |
||
32 | 32 | 'id' => 'checkin-form', |
33 | 33 | ]); |
34 | 34 | |
35 | -foreach($categories as $category_id => $category_name) { |
|
35 | +foreach ($categories as $category_id => $category_name) { |
|
36 | 36 | print $form->field($model, "user_behavior_id{$category_id}")->radioList($behaviors[$category_id], ['class' => "btn-group", 'data-toggle' => 'buttons', 'item'=>"radioItemTemplate"]); |
37 | 37 | print $form->field($model, "answer_{$category_id}a")->textarea()->label("How does it affect me? How do I act and feel?"); |
38 | 38 | print $form->field($model, "answer_{$category_id}b")->textarea()->label("How does it affect the important people in my life?"); |
@@ -66,7 +66,7 @@ discard block |
||
66 | 66 | public function setBehaviors($behaviors) { |
67 | 67 | foreach($behaviors as $category_id => $category_data) { |
68 | 68 | $attribute = "behaviors$category_id"; |
69 | - $this->$attribute = []; |
|
69 | + $this->$attribute = []; |
|
70 | 70 | foreach($category_data['behaviors'] as $behavior) { |
71 | 71 | $this->{$attribute}[] = $behavior['id']; |
72 | 72 | } |
@@ -85,12 +85,12 @@ discard block |
||
85 | 85 | |
86 | 86 | public function compileBehaviors() { |
87 | 87 | $behaviors = array_merge((array)$this->behaviors1, |
88 | - (array)$this->behaviors2, |
|
89 | - (array)$this->behaviors3, |
|
90 | - (array)$this->behaviors4, |
|
91 | - (array)$this->behaviors5, |
|
92 | - (array)$this->behaviors6, |
|
93 | - (array)$this->behaviors7); |
|
88 | + (array)$this->behaviors2, |
|
89 | + (array)$this->behaviors3, |
|
90 | + (array)$this->behaviors4, |
|
91 | + (array)$this->behaviors5, |
|
92 | + (array)$this->behaviors6, |
|
93 | + (array)$this->behaviors7); |
|
94 | 94 | |
95 | 95 | return array_filter($behaviors); // strip out false values |
96 | 96 | } |
@@ -64,10 +64,10 @@ discard block |
||
64 | 64 | } |
65 | 65 | |
66 | 66 | public function setBehaviors($behaviors) { |
67 | - foreach($behaviors as $category_id => $category_data) { |
|
67 | + foreach ($behaviors as $category_id => $category_data) { |
|
68 | 68 | $attribute = "behaviors$category_id"; |
69 | 69 | $this->$attribute = []; |
70 | - foreach($category_data['behaviors'] as $behavior) { |
|
70 | + foreach ($category_data['behaviors'] as $behavior) { |
|
71 | 71 | $this->{$attribute}[] = $behavior['id']; |
72 | 72 | } |
73 | 73 | } |
@@ -75,8 +75,8 @@ discard block |
||
75 | 75 | |
76 | 76 | public function validateBehaviors($attribute, $params) { |
77 | 77 | if (!$this->hasErrors()) { |
78 | - foreach($this->$attribute as $behavior) { |
|
79 | - if(!is_numeric($behavior)) { |
|
78 | + foreach ($this->$attribute as $behavior) { |
|
79 | + if (!is_numeric($behavior)) { |
|
80 | 80 | $this->addError($attribute, 'One of your behaviors is not an integer!'); |
81 | 81 | } |
82 | 82 | } |
@@ -110,12 +110,12 @@ discard block |
||
110 | 110 | } |
111 | 111 | |
112 | 112 | public function save() { |
113 | - if(empty($this->compiled_behaviors)) { |
|
113 | + if (empty($this->compiled_behaviors)) { |
|
114 | 114 | $this->commpiled_behaviors = $this->compileBehaviors(); |
115 | 115 | } |
116 | 116 | |
117 | 117 | $rows = []; |
118 | - foreach($this->compiled_behaviors as $behavior_id) { |
|
118 | + foreach ($this->compiled_behaviors as $behavior_id) { |
|
119 | 119 | $temp = [ |
120 | 120 | Yii::$app->user->id, |
121 | 121 | (int)$behavior_id, |
@@ -56,7 +56,7 @@ |
||
56 | 56 | return Yii::$app->mailer->compose() |
57 | 57 | ->setTo($email) |
58 | 58 | ->setFrom([$this->email => $this->name]) |
59 | - ->setSubject("[FSA Contact] ".$this->subject) |
|
59 | + ->setSubject("[FSA Contact] " . $this->subject) |
|
60 | 60 | ->setTextBody($this->body) |
61 | 61 | ->send(); |
62 | 62 | } |
@@ -95,7 +95,7 @@ discard block |
||
95 | 95 | */ |
96 | 96 | public function signup() { |
97 | 97 | $user = $this->user->findByEmail($this->email); |
98 | - if(!$user) { |
|
98 | + if (!$user) { |
|
99 | 99 | // this is a brand new user |
100 | 100 | $this->user = $this->setFields($this->user); |
101 | 101 | $this->user->save(); |
@@ -109,7 +109,7 @@ discard block |
||
109 | 109 | * this is a user that for whatever reason is trying to sign up again |
110 | 110 | * with the same email address. |
111 | 111 | */ |
112 | - if(!$user->isTokenConfirmed()) { |
|
112 | + if (!$user->isTokenConfirmed()) { |
|
113 | 113 | /* |
114 | 114 | * they've never verified their account. We don't care if their |
115 | 115 | * verification token is current or expired. We're resetting their |
@@ -136,7 +136,7 @@ discard block |
||
136 | 136 | $user->generateAuthKey(); |
137 | 137 | $user->generateVerifyEmailToken(); |
138 | 138 | |
139 | - if($this->send_email) { |
|
139 | + if ($this->send_email) { |
|
140 | 140 | $user->email_threshold = $this->email_threshold; |
141 | 141 | $user->partner_email1 = $this->partner_email1; |
142 | 142 | $user->partner_email2 = $this->partner_email2; |
@@ -42,7 +42,7 @@ discard block |
||
42 | 42 | ['email', 'filter', 'filter' => 'trim'], |
43 | 43 | ['email', 'filter', 'filter' => 'strtolower'], |
44 | 44 | ['email', 'email'], |
45 | - ['email', 'unique', 'targetClass' => '\common\models\User', 'message' => 'This email address has already been taken.', 'filter' => "id <> ".Yii::$app->user->id], |
|
45 | + ['email', 'unique', 'targetClass' => '\common\models\User', 'message' => 'This email address has already been taken.', 'filter' => "id <> " . Yii::$app->user->id], |
|
46 | 46 | |
47 | 47 | |
48 | 48 | ['timezone', 'string', 'min' => 2, 'max' => 255], |
@@ -88,11 +88,11 @@ discard block |
||
88 | 88 | $graph = Yii::$container |
89 | 89 | ->get('common\components\Graph', [$this->user]); |
90 | 90 | |
91 | - if($this->email) |
|
91 | + if ($this->email) |
|
92 | 92 | $user->email = $this->email; |
93 | - if($this->timezone) |
|
93 | + if ($this->timezone) |
|
94 | 94 | $user->timezone = $this->timezone; |
95 | - if($this->expose_graph) { |
|
95 | + if ($this->expose_graph) { |
|
96 | 96 | $user->expose_graph = true; |
97 | 97 | |
98 | 98 | // generate scores graph image |
@@ -100,7 +100,7 @@ discard block |
||
100 | 100 | // if they haven't done a check-in in the last month this |
101 | 101 | // will explode because $scores_last_month is an empty |
102 | 102 | // array |
103 | - if($scores_last_month) { |
|
103 | + if ($scores_last_month) { |
|
104 | 104 | $graph->create($scores_last_month, true); |
105 | 105 | } |
106 | 106 | } else { |
@@ -108,7 +108,7 @@ discard block |
||
108 | 108 | // remove scores graph image |
109 | 109 | $graph->destroy(); |
110 | 110 | } |
111 | - if($this->send_email) { |
|
111 | + if ($this->send_email) { |
|
112 | 112 | $user->email_threshold = $this->email_threshold; |
113 | 113 | $user->partner_email1 = $this->partner_email1; |
114 | 114 | $user->partner_email2 = $this->partner_email2; |
@@ -88,10 +88,12 @@ |
||
88 | 88 | $graph = Yii::$container |
89 | 89 | ->get('common\components\Graph', [$this->user]); |
90 | 90 | |
91 | - if($this->email) |
|
92 | - $user->email = $this->email; |
|
93 | - if($this->timezone) |
|
94 | - $user->timezone = $this->timezone; |
|
91 | + if($this->email) { |
|
92 | + $user->email = $this->email; |
|
93 | + } |
|
94 | + if($this->timezone) { |
|
95 | + $user->timezone = $this->timezone; |
|
96 | + } |
|
95 | 97 | if($this->expose_graph) { |
96 | 98 | $user->expose_graph = true; |
97 | 99 |
@@ -157,11 +157,11 @@ |
||
157 | 157 | foreach($this->behaviorToAnswers($behavior_id) as $answer_letter => $answer) { |
158 | 158 | $question_id = \common\models\Question::$TYPES[$answer_letter]; |
159 | 159 | array_push($answers, [ |
160 | - 'behavior_id' => $user_bhvr->behavior_id, |
|
161 | - 'user_bhvr_id' => $user_bhvr->id, |
|
162 | - 'question_id' => $question_id, |
|
163 | - 'answer' => $answer, |
|
164 | - ]); |
|
160 | + 'behavior_id' => $user_bhvr->behavior_id, |
|
161 | + 'user_bhvr_id' => $user_bhvr->id, |
|
162 | + 'question_id' => $question_id, |
|
163 | + 'answer' => $answer, |
|
164 | + ]); |
|
165 | 165 | } |
166 | 166 | } |
167 | 167 | return $answers; |
@@ -83,7 +83,7 @@ discard block |
||
83 | 83 | 'whenClient' => "function(attribute, value) { return false; }", // lame, but acceptable |
84 | 84 | "message" => "You must select a behavior your responses apply to."], |
85 | 85 | |
86 | - [['answer_1a','answer_1b','answer_1c','answer_2a','answer_2b','answer_2c','answer_3a','answer_3b','answer_3c','answer_4a','answer_4b','answer_4c','answer_5a', 'answer_5b','answer_5c','answer_6a', 'answer_6b','answer_6c','answer_7a','answer_7b','answer_7c'], 'safe'] |
|
86 | + [['answer_1a', 'answer_1b', 'answer_1c', 'answer_2a', 'answer_2b', 'answer_2c', 'answer_3a', 'answer_3b', 'answer_3c', 'answer_4a', 'answer_4b', 'answer_4c', 'answer_5a', 'answer_5b', 'answer_5c', 'answer_6a', 'answer_6b', 'answer_6c', 'answer_7a', 'answer_7b', 'answer_7c'], 'safe'] |
|
87 | 87 | ]; |
88 | 88 | } |
89 | 89 | |
@@ -101,10 +101,10 @@ discard block |
||
101 | 101 | |
102 | 102 | public function getBhvrValidator() { |
103 | 103 | return function($model, $attr) { |
104 | - $attrNum = $attr[strlen($attr)-1]; |
|
105 | - foreach(['a', 'b', 'c'] as $l) { |
|
104 | + $attrNum = $attr[strlen($attr) - 1]; |
|
105 | + foreach (['a', 'b', 'c'] as $l) { |
|
106 | 106 | $attr = "answer_{$attrNum}{$l}"; |
107 | - if($model->$attr) return true; |
|
107 | + if ($model->$attr) return true; |
|
108 | 108 | } |
109 | 109 | return false; |
110 | 110 | }; |
@@ -134,7 +134,7 @@ discard block |
||
134 | 134 | |
135 | 135 | public function getPrefixProps($prefix) { |
136 | 136 | return array_filter(get_object_vars($this), function($v, $k) use($prefix) { |
137 | - if(strpos($k, $prefix) === 0 && strlen($v)) { |
|
137 | + if (strpos($k, $prefix) === 0 && strlen($v)) { |
|
138 | 138 | return true; |
139 | 139 | } |
140 | 140 | }, ARRAY_FILTER_USE_BOTH); |
@@ -152,9 +152,9 @@ discard block |
||
152 | 152 | public function getAnswers($bhvrs) { |
153 | 153 | $answers = []; |
154 | 154 | $user_bhvrs = array_combine($this->getUserBehaviorProps(), $bhvrs); |
155 | - foreach($user_bhvrs as $property => $user_bhvr) { |
|
155 | + foreach ($user_bhvrs as $property => $user_bhvr) { |
|
156 | 156 | $behavior_id = intval(substr($property, -1, 1)); |
157 | - foreach($this->behaviorToAnswers($behavior_id) as $answer_letter => $answer) { |
|
157 | + foreach ($this->behaviorToAnswers($behavior_id) as $answer_letter => $answer) { |
|
158 | 158 | $question_id = \common\models\Question::$TYPES[$answer_letter]; |
159 | 159 | array_push($answers, [ |
160 | 160 | 'behavior_id' => $user_bhvr->behavior_id, |
@@ -169,7 +169,7 @@ discard block |
||
169 | 169 | |
170 | 170 | public function saveAnswers($bhvrs) { |
171 | 171 | $result = true; |
172 | - foreach($this->getAnswers($bhvrs) as $answer) { |
|
172 | + foreach ($this->getAnswers($bhvrs) as $answer) { |
|
173 | 173 | $model = new \common\models\Question; |
174 | 174 | $model->user_id = Yii::$app->user->id; |
175 | 175 | $model->behavior_id = $answer['behavior_id']; |
@@ -177,7 +177,7 @@ discard block |
||
177 | 177 | $model->date = new Expression("now()::timestamp"); |
178 | 178 | $model->question = $answer['question_id']; |
179 | 179 | $model->answer = $answer['answer']; |
180 | - if(!$model->save()) { |
|
180 | + if (!$model->save()) { |
|
181 | 181 | $result = false; |
182 | 182 | } |
183 | 183 | } |
@@ -104,7 +104,9 @@ |
||
104 | 104 | $attrNum = $attr[strlen($attr)-1]; |
105 | 105 | foreach(['a', 'b', 'c'] as $l) { |
106 | 106 | $attr = "answer_{$attrNum}{$l}"; |
107 | - if($model->$attr) return true; |
|
107 | + if($model->$attr) { |
|
108 | + return true; |
|
109 | + } |
|
108 | 110 | } |
109 | 111 | return false; |
110 | 112 | }; |
@@ -67,7 +67,7 @@ discard block |
||
67 | 67 | |
68 | 68 | if ($editProfileForm->load(Yii::$app->request->post())) { |
69 | 69 | $saved_user = $editProfileForm->saveProfile(); |
70 | - if($saved_user) { |
|
70 | + if ($saved_user) { |
|
71 | 71 | Yii::$app->getSession()->setFlash('success', 'New profile data saved!'); |
72 | 72 | } |
73 | 73 | } |
@@ -85,7 +85,7 @@ discard block |
||
85 | 85 | $model = Yii::$container->get('\site\models\DeleteAccountForm', [Yii::$app->user->identity]); |
86 | 86 | |
87 | 87 | if ($model->load(Yii::$app->request->post()) && $model->validate()) { |
88 | - if($model->deleteAccount()) { |
|
88 | + if ($model->deleteAccount()) { |
|
89 | 89 | $this->redirect(['site/index']); |
90 | 90 | } else { |
91 | 91 | Yii::$app->getSession()->setFlash('error', 'Wrong password!'); |
@@ -100,7 +100,7 @@ discard block |
||
100 | 100 | $model = Yii::$container->get('\site\models\ChangePasswordForm', [Yii::$app->user->identity]); |
101 | 101 | |
102 | 102 | if ($model->load(Yii::$app->request->post())) { |
103 | - if($model->validate() && $model->changePassword()) { |
|
103 | + if ($model->validate() && $model->changePassword()) { |
|
104 | 104 | Yii::$app->getSession()->setFlash('success', 'Password successfully changed'); |
105 | 105 | } else { |
106 | 106 | Yii::$app->getSession()->setFlash('error', 'Wrong password!'); |
@@ -113,7 +113,7 @@ discard block |
||
113 | 113 | public function actionExport() |
114 | 114 | { |
115 | 115 | header("Content-Type: text/csv"); |
116 | - header("Content-Disposition: attachment; filename=fsa-data-export-".Yii::$app->user->identity->email."-".date('Ymd').".csv"); |
|
116 | + header("Content-Disposition: attachment; filename=fsa-data-export-" . Yii::$app->user->identity->email . "-" . date('Ymd') . ".csv"); |
|
117 | 117 | |
118 | 118 | $reader = Yii::$app->user->identity->getExportData(); |
119 | 119 | $fp = fopen('php://output', 'w'); |
@@ -129,7 +129,7 @@ discard block |
||
129 | 129 | |
130 | 130 | fputcsv($fp, $header); |
131 | 131 | $user_behavior = Yii::$container->get('common\interfaces\UserBehaviorInterface'); |
132 | - while($row = $reader->read()) { |
|
132 | + while ($row = $reader->read()) { |
|
133 | 133 | $row = $user_behavior::decorateWithCategory([$row]); |
134 | 134 | $row = Yii::$app->user->identity->cleanExportData($row); |
135 | 135 | fputcsv($fp, $row[0]); |