@@ -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 | |
@@ -127,12 +127,12 @@ discard block |
||
127 | 127 | |
128 | 128 | public function getCheckinBreakdown(int $period = 30) { |
129 | 129 | $datetimes = $this->time->getDateTimesInPeriod($period); |
130 | - $key = "scores_of_last_month_".Yii::$app->user->id."_{$period}_".$this->time->getLocalDate(); |
|
130 | + $key = "scores_of_last_month_" . Yii::$app->user->id . "_{$period}_" . $this->time->getLocalDate(); |
|
131 | 131 | $scores = Yii::$app->cache->get($key); |
132 | 132 | |
133 | - if($scores === false) { |
|
133 | + if ($scores === false) { |
|
134 | 134 | $scores = []; |
135 | - foreach($datetimes as $datetime) { |
|
135 | + foreach ($datetimes as $datetime) { |
|
136 | 136 | $behaviors = self::decorateWithCategory($this->getBehaviorsWithCounts($datetime)); |
137 | 137 | $scores[$datetime->format('Y-m-d')] = $this->getBehaviorsByCategory($behaviors); |
138 | 138 | } |
@@ -158,7 +158,7 @@ discard block |
||
158 | 158 | public function getBehaviorsByCategory(array $decorated_behaviors) { |
159 | 159 | $arr = array_reduce($decorated_behaviors, function($acc, $row) { |
160 | 160 | $cat_id = $row['behavior']['category']['id']; |
161 | - if(array_key_exists($cat_id, $acc)) { |
|
161 | + if (array_key_exists($cat_id, $acc)) { |
|
162 | 162 | $acc[$cat_id]['count'] += $row['count']; |
163 | 163 | } else { |
164 | 164 | $acc[$cat_id] = [ |
@@ -175,10 +175,10 @@ discard block |
||
175 | 175 | } |
176 | 176 | |
177 | 177 | public static function decorate(array $uo, $with_category = false) { |
178 | - foreach($uo as &$o) { |
|
179 | - if($behavior = \common\models\Behavior::getBehavior('id', $o['behavior_id'])) { |
|
178 | + foreach ($uo as &$o) { |
|
179 | + if ($behavior = \common\models\Behavior::getBehavior('id', $o['behavior_id'])) { |
|
180 | 180 | $o['behavior'] = $behavior; |
181 | - if($with_category) { |
|
181 | + if ($with_category) { |
|
182 | 182 | $o['behavior']['category'] = \common\models\Category::getCategory('id', $o['behavior']['category_id']); |
183 | 183 | } |
184 | 184 | } |
@@ -204,11 +204,11 @@ discard block |
||
204 | 204 | ->having('user_id = :user_id') |
205 | 205 | ->orderBy('count DESC'); |
206 | 206 | |
207 | - if($limit instanceof \DateTime) { |
|
207 | + if ($limit instanceof \DateTime) { |
|
208 | 208 | list($start, $end) = $this->time->getUTCBookends($limit->format('Y-m-d')); |
209 | 209 | $query->params += [':start_date' => $start, ':end_date' => $end]; |
210 | 210 | $query->where('user_id=:user_id AND date > :start_date AND date <= :end_date'); |
211 | - } else if(is_int($limit)) { |
|
211 | + } else if (is_int($limit)) { |
|
212 | 212 | $query->limit($limit); |
213 | 213 | } |
214 | 214 |
@@ -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 | } |
@@ -111,18 +111,18 @@ discard block |
||
111 | 111 | // delete cached scores |
112 | 112 | $time = Yii::$container->get(\common\interfaces\TimeInterface::class); |
113 | 113 | array_map(function($period) { |
114 | - $key = "scores_of_last_month_".Yii::$app->user->id."_{$period}_".$this->time->getLocalDate(); |
|
114 | + $key = "scores_of_last_month_" . Yii::$app->user->id . "_{$period}_" . $this->time->getLocalDate(); |
|
115 | 115 | Yii::$app->cache->delete($key); |
116 | 116 | }, [30, 90, 180]); |
117 | 117 | } |
118 | 118 | |
119 | 119 | public function save() { |
120 | - if(empty($this->compiled_behaviors)) { |
|
120 | + if (empty($this->compiled_behaviors)) { |
|
121 | 121 | $this->commpiled_behaviors = $this->compileBehaviors(); |
122 | 122 | } |
123 | 123 | |
124 | 124 | $rows = []; |
125 | - foreach($this->compiled_behaviors as $behavior_id) { |
|
125 | + foreach ($this->compiled_behaviors as $behavior_id) { |
|
126 | 126 | $temp = [ |
127 | 127 | Yii::$app->user->id, |
128 | 128 | (int)$behavior_id, |
@@ -141,10 +141,10 @@ discard block |
||
141 | 141 | )->execute(); |
142 | 142 | |
143 | 143 | // if the user has publicised their score graph, create the image |
144 | - if(Yii::$app->user->identity->expose_graph) { |
|
144 | + if (Yii::$app->user->identity->expose_graph) { |
|
145 | 145 | $checkins_last_month = $this->user_behavior->getCheckInBreakdown(); |
146 | 146 | |
147 | - if($checkins_last_month) { |
|
147 | + if ($checkins_last_month) { |
|
148 | 148 | Yii::$container |
149 | 149 | ->get(\common\components\Graph::class, [Yii::$app->user->identity]) |
150 | 150 | ->create($checkins_last_month, true); |