Completed
Pull Request — master (#163)
by Corey
03:20
created
common/models/UserBehavior.php 1 patch
Spacing   +10 added lines, -10 removed lines patch added patch discarded remove patch
@@ -84,7 +84,7 @@  discard block
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 
Please login to merge, or discard this patch.
site/models/CheckinForm.php 1 patch
Spacing   +9 added lines, -9 removed lines patch added patch discarded remove patch
@@ -64,10 +64,10 @@  discard block
 block discarded – undo
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
 block discarded – undo
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,17 +110,17 @@  discard block
 block discarded – undo
110 110
 
111 111
     // delete cached scores
112 112
     $time = Yii::$container->get(\common\interfaces\TimeInterface::class);
113
-    $key = "scores_of_last_month_".Yii::$app->user->id."_{$period}_".$this->time->getLocalDate();
113
+    $key = "scores_of_last_month_" . Yii::$app->user->id . "_{$period}_" . $this->time->getLocalDate();
114 114
     Yii::$app->cache->delete($key);
115 115
   }
116 116
 
117 117
   public function save() {
118
-    if(empty($this->compiled_behaviors)) {
118
+    if (empty($this->compiled_behaviors)) {
119 119
       $this->commpiled_behaviors = $this->compileBehaviors();
120 120
     }
121 121
 
122 122
     $rows = [];
123
-    foreach($this->compiled_behaviors as $behavior_id) {
123
+    foreach ($this->compiled_behaviors as $behavior_id) {
124 124
       $temp = [
125 125
         Yii::$app->user->id,
126 126
         (int)$behavior_id,
@@ -139,10 +139,10 @@  discard block
 block discarded – undo
139 139
       )->execute();
140 140
 
141 141
     // if the user has publicised their score graph, create the image
142
-    if(Yii::$app->user->identity->expose_graph) {
142
+    if (Yii::$app->user->identity->expose_graph) {
143 143
       $checkins_last_month = $this->user_behavior->getCheckInBreakdown();
144 144
 
145
-      if($checkins_last_month) {
145
+      if ($checkins_last_month) {
146 146
         Yii::$container
147 147
           ->get(\common\components\Graph::class, [Yii::$app->user->identity])
148 148
           ->create($checkins_last_month, true);
Please login to merge, or discard this patch.