Completed
Pull Request — master (#163)
by Corey
02:38
created
site/views/profile/index.php 1 patch
Spacing   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -70,11 +70,11 @@
 block discarded – undo
70 70
 ]); ?>
71 71
             <?= $form->field($profile, 'timezone')->dropDownList(array_combine($timezones, $timezones)); ?>
72 72
             <?= $form->field($profile, 'expose_graph')->checkbox() ?>
73
-            <?php if($profile->expose_graph): ?>
73
+            <?php if ($profile->expose_graph): ?>
74 74
             <div class='alert alert-success score-graph-info'>Your score graph can be found at:<br /> <a id="score-graph-link" target="_blank" href="<?=$graph_url?>"><?=$graph_url?></a></div>
75 75
             <?php endif; ?>
76 76
             <?= $form->field($profile, 'send_email')->checkbox() ?>
77
-            <div id='send_email_fields' <?php if(!$profile->send_email) { ?>style="display: none;"<?php } ?>>
77
+            <div id='send_email_fields' <?php if (!$profile->send_email) { ?>style="display: none;"<?php } ?>>
78 78
               <?= $form->field($profile, 'partner_email1')->input('email'); ?>
79 79
               <?= $form->field($profile, 'partner_email2')->input('email'); ?>
80 80
               <?= $form->field($profile, 'partner_email3')->input('email'); ?>
Please login to merge, or discard this patch.
site/controllers/CheckinController.php 1 patch
Spacing   +9 added lines, -9 removed lines patch added patch discarded remove patch
@@ -39,7 +39,7 @@  discard block
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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")),
@@ -165,14 +165,14 @@  discard block
 block discarded – undo
165 165
     $checkins = $user_behavior->getCheckInBreakdown($period);
166 166
 
167 167
     $accum = [];
168
-    foreach($checkins as $date => $cats) {
169
-      for($i = 1; $i <= 7; $i ++) {
168
+    foreach ($checkins as $date => $cats) {
169
+      for ($i = 1; $i <= 7; $i++) {
170 170
         $accum[$i][] = array_key_exists($i, $cats) ? $cats[$i]['count'] : [];
171 171
       }
172 172
     }
173 173
 
174 174
     $bar_datasets = [];
175
-    foreach($accum as $idx => $data) {
175
+    foreach ($accum as $idx => $data) {
176 176
       $bar_datasets[] = [
177 177
         'label' => ($category::getCategories())[$idx],
178 178
         'backgroundColor' => $category::$colors[$idx]['color'],
Please login to merge, or discard this patch.
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."_".$this->time->getLocalDate();
130
+    $key = "scores_of_last_month_" . Yii::$app->user->id . "_" . $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
       }
@@ -199,11 +199,11 @@  discard block
 block discarded – undo
199 199
       ->having('user_id = :user_id')
200 200
       ->orderBy('count DESC');
201 201
 
202
-    if($limit instanceof \DateTime) {
202
+    if ($limit instanceof \DateTime) {
203 203
       list($start, $end) = $this->time->getUTCBookends($limit->format('Y-m-d'));
204 204
       $query->params += [':start_date' => $start, ':end_date' => $end];
205 205
       $query->where('user_id=:user_id AND date > :start_date AND date <= :end_date');
206
-    } else if(is_int($limit)) {
206
+    } else if (is_int($limit)) {
207 207
       $query->limit($limit);
208 208
     }
209 209
 
Please login to merge, or discard this patch.
common/components/Graph.php 1 patch
Spacing   +10 added lines, -10 removed lines patch added patch discarded remove patch
@@ -28,7 +28,7 @@  discard block
 block discarded – undo
28 28
   public function getFilepath() {
29 29
     $path = Yii::getAlias('@graphImgPath');
30 30
     $filename = $this->user->getIdHash() . ".png";
31
-    return $path. '/' . $filename;
31
+    return $path . '/' . $filename;
32 32
   }
33 33
 
34 34
   /**
@@ -61,7 +61,7 @@  discard block
 block discarded – undo
61 61
    * @return string the encoded image
62 62
    */
63 63
   public function create(array $checkins, bool $toDisk = false) {
64
-    if($toDisk) {
64
+    if ($toDisk) {
65 65
       // wipe out the current image, if it exists
66 66
       $this->destroy();
67 67
     }
@@ -80,10 +80,10 @@  discard block
 block discarded – undo
80 80
 
81 81
     // Setup dates as labels on the X-axis
82 82
     $graph->xaxis->SetTickLabels(array_keys($checkins));
83
-    $graph->xaxis->HideTicks(false,false);
83
+    $graph->xaxis->HideTicks(false, false);
84 84
     $graph->yaxis->scale->SetAutoMin(0);
85 85
     $graph->yaxis->HideLine(false);
86
-    $graph->yaxis->HideTicks(false,false);
86
+    $graph->yaxis->HideTicks(false, false);
87 87
     $graph->xaxis->SetLabelAngle(45);
88 88
     $graph->xaxis->SetFont(FF_ARIAL, FS_NORMAL, 10);
89 89
     $graph->yaxis->SetFont(FF_ARIAL, FS_NORMAL, 15);
@@ -92,15 +92,15 @@  discard block
 block discarded – undo
92 92
 
93 93
     // format the data into something nicer
94 94
     $accum = [];
95
-    foreach($checkins as $checkin_sum) {
96
-      for($i = 1; $i <= 7; $i ++) {
95
+    foreach ($checkins as $checkin_sum) {
96
+      for ($i = 1; $i <= 7; $i++) {
97 97
         $accum[$i][] = array_key_exists($i, $checkin_sum) ? $checkin_sum[$i]['count'] : 0;
98 98
       }
99 99
     }
100 100
 
101 101
     // Create the bar plots
102 102
     $plots = [];
103
-    foreach($accum as $category_key => $category_data) {
103
+    foreach ($accum as $category_key => $category_data) {
104 104
       $bplot = new BarPlot($category_data);
105 105
       $color = $category::$colors[$category_key]['color'];
106 106
 
@@ -116,7 +116,7 @@  discard block
 block discarded – undo
116 116
 
117 117
     // $graph->legend->SetFrameWeight(1);
118 118
     $graph->legend->SetColumns(3);
119
-    $graph->legend->SetColor('#4E4E4E','#00A78A');
119
+    $graph->legend->SetColor('#4E4E4E', '#00A78A');
120 120
 
121 121
     //$graph->title->SetFont(FF_ARIAL, FS_BOLD, 20);
122 122
     //$graph->title->Set("Behaviors by category over time");
@@ -146,9 +146,9 @@  discard block
 block discarded – undo
146 146
     imagepng($img);
147 147
     $img_data = ob_get_clean();
148 148
 
149
-    if($toDisk) {
149
+    if ($toDisk) {
150 150
       $filepath = $this->getFilepath(); 
151
-      if(!is_dir(dirname($filepath))) {
151
+      if (!is_dir(dirname($filepath))) {
152 152
         mkdir(dirname($filepath), 0766, true);
153 153
       }
154 154
 
Please login to merge, or discard this patch.
common/tests/unit/data/behaviorsWithCounts.php 1 patch
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -337,7 +337,7 @@
 block discarded – undo
337 337
   ], [
338 338
   ], [
339 339
   ], [
340
-  ], [ [
340
+  ], [[
341 341
       'user_id' => 1,
342 342
       'behavior_id' => 117,
343 343
       'count' => 1,
Please login to merge, or discard this patch.
common/tests/unit/models/UserBehaviorTest.php 2 patches
Indentation   +14 added lines, -14 removed lines patch added patch discarded remove patch
@@ -105,19 +105,19 @@  discard block
 block discarded – undo
105 105
     expect('decorate should add Behavior data and Category data to an array of UserBehaviors',
106 106
       $this->assertEquals(
107 107
         $this->user_behavior->decorateWithCategory($this->singleSimpleBehaviorNoBehavior),
108
-         [['id' => 396,
109
-           'user_id' => 2,
110
-           'behavior_id' => 107,
111
-           'date' => '2016-06-17 04:12:43',
112
-           'behavior' => [
113
-             'id' => 107,
114
-             'name' => 'numb',
115
-             'category_id' => 6,
116
-             'category' => [
117
-               'id' => 6,
118
-               'name' => 'Exhausted',
119
-             ]
120
-           ]]]));
108
+          [['id' => 396,
109
+            'user_id' => 2,
110
+            'behavior_id' => 107,
111
+            'date' => '2016-06-17 04:12:43',
112
+            'behavior' => [
113
+              'id' => 107,
114
+              'name' => 'numb',
115
+              'category_id' => 6,
116
+              'category' => [
117
+                'id' => 6,
118
+                'name' => 'Exhausted',
119
+              ]
120
+            ]]]));
121 121
   }
122 122
 
123 123
   public function testGetBehaviorsByCategory() {
@@ -198,6 +198,6 @@  discard block
 block discarded – undo
198 198
     $bhvrs = require(__DIR__.'/../data/behaviorsWithCounts.php');
199 199
     $expected = require(__DIR__.'/../data/expected_getCheckinBreakdown.php');
200 200
     $this->user_behavior->method('getBehaviorsWithCounts')->willReturn(...$bhvrs);
201
-		expect('asdf', $this->assertEquals($expected, $this->user_behavior->getCheckinBreakdown()));
201
+    expect('asdf', $this->assertEquals($expected, $this->user_behavior->getCheckinBreakdown()));
202 202
   }
203 203
 }
Please login to merge, or discard this patch.
Spacing   +4 added lines, -4 removed lines patch added patch discarded remove patch
@@ -33,7 +33,7 @@  discard block
 block discarded – undo
33 33
   ]; 
34 34
   public function setUp() {
35 35
     // pull in test data
36
-    $data = require(__DIR__.'/../data/checkinData.php');
36
+    $data = require(__DIR__ . '/../data/checkinData.php');
37 37
     $this->singleBhvr = $data['singleBhvr'];
38 38
     $this->manyBhvrs = $data['manyBhvrs'];
39 39
     $this->allBhvrs = $data['allBhvrs'];
@@ -43,7 +43,7 @@  discard block
 block discarded – undo
43 43
     $this->container->set('common\interfaces\UserInterface', '\site\tests\_support\MockUser');
44 44
     $this->container->set('common\interfaces\QuestionInterface', '\site\tests\_support\MockQuestion');
45 45
     $this->container->set('common\interfaces\BehaviorInterface', 'common\models\Behavior');
46
-    $this->container->set('common\interfaces\TimeInterface', function () {
46
+    $this->container->set('common\interfaces\TimeInterface', function() {
47 47
         return new \common\components\Time('America/Los_Angeles');
48 48
       });
49 49
 
@@ -195,8 +195,8 @@  discard block
 block discarded – undo
195 195
                             ->setMethods(['getIsNewRecord', 'save', 'getBehaviorsByDate', 'getBehaviorsWithCounts'])
196 196
                             ->getMock();
197 197
 
198
-    $bhvrs = require(__DIR__.'/../data/behaviorsWithCounts.php');
199
-    $expected = require(__DIR__.'/../data/expected_getCheckinBreakdown.php');
198
+    $bhvrs = require(__DIR__ . '/../data/behaviorsWithCounts.php');
199
+    $expected = require(__DIR__ . '/../data/expected_getCheckinBreakdown.php');
200 200
     $this->user_behavior->method('getBehaviorsWithCounts')->willReturn(...$bhvrs);
201 201
 		expect('asdf', $this->assertEquals($expected, $this->user_behavior->getCheckinBreakdown()));
202 202
   }
Please login to merge, or discard this patch.