Completed
Pull Request — master (#63)
by Brandon
02:14
created
app/Http/Controllers/DashboardController.php 1 patch
Braces   +19 added lines, -13 removed lines patch added patch discarded remove patch
@@ -80,27 +80,31 @@  discard block
 block discarded – undo
80 80
         //Get the given device if it is still at the same location
81 81
         $device = Device::publicDashData()->where('location_id', '=', $request->location_id)->find($request->device_id);
82 82
         
83
-        if (empty($site))                 //Check if the site still exists
83
+        if (empty($site)) {
84
+            //Check if the site still exists
84 85
         {
85 86
             //Get the first site and if no sites exist throw an error
86 87
             $site = Site::select('id', 'name')->firstOrFail();
88
+        }
87 89
             //Get the first location from the site
88 90
             $location = $site->locations()->select('id', 'name', 'site_id')->firstOrFail();
89 91
             //Get the first device from the location
90 92
             $device = $location->devices()->publicDashData()->firstOrFail();
91
-        }
92
-        else if (empty($location))        //Check if the location still exists
93
+        } else if (empty($location)) {
94
+            //Check if the location still exists
93 95
         {
94 96
             //Get the first location from the given site
95 97
             $location = $site->locations()->select('id', 'name', 'site_id')->firstOrFail();
98
+        }
96 99
             //Get the first device from the location
97 100
             $device = $location->devices()->publicDashData()->firstOrFail();
98
-        }
99
-        else if (empty($device))        //Check if the device still exists at the given location
101
+        } else if (empty($device)) {
102
+            //Check if the device still exists at the given location
100 103
         {
101 104
             //Get the first device from the location
102 105
             $device = $location->devices()->publicDashData()->firstOrFail();
103 106
         }
107
+        }
104 108
         
105 109
         $data = $this->dashData($site, $location, $device);
106 110
         
@@ -185,8 +189,9 @@  discard block
 block discarded – undo
185 189
         ])->validate();
186 190
         
187 191
         //Check that device isn't currently in use or has an error
188
-        if ($device->cover_status === 'opening' || $device->cover_status === 'closing' || $device->cover_status === 'error')
189
-            return response()->json("Device is currently in use.", 403);
192
+        if ($device->cover_status === 'opening' || $device->cover_status === 'closing' || $device->cover_status === 'error') {
193
+                    return response()->json("Device is currently in use.", 403);
194
+        }
190 195
         
191 196
         //1 = open, 2 = close, 3 = lock
192 197
         switch($request->command)
@@ -224,13 +229,14 @@  discard block
 block discarded – undo
224 229
             $time_now = Carbon::now(Auth::user()->timezone);
225 230
             
226 231
             //Check if the current time is during the open schedule or not
227
-            if (($time_now > $open_time) && ($time_now < $close_time))
228
-                $command =  'open';
229
-            else
230
-                $command =  'close';
232
+            if (($time_now > $open_time) && ($time_now < $close_time)) {
233
+                            $command =  'open';
234
+            } else {
235
+                            $command =  'close';
236
+            }
237
+        } else {
238
+                    $command =  'lock';
231 239
         }
232
-        else
233
-            $command =  'lock';
234 240
         
235 241
         return $command;
236 242
     }
Please login to merge, or discard this patch.
app/Http/Controllers/DeviceController.php 1 patch
Braces   +14 added lines, -16 removed lines patch added patch discarded remove patch
@@ -84,8 +84,7 @@  discard block
 block discarded – undo
84 84
             $sites->prepend($location->site);
85 85
             //Add the current location to the front of the collection of locations
86 86
             $locations->prepend($location);
87
-        }
88
-        else
87
+        } else
89 88
         {
90 89
             //Set locations to null since there is no site or location attached to the selected device
91 90
             $locations = null;
@@ -93,10 +92,11 @@  discard block
 block discarded – undo
93 92
             $sites = Site::all();
94 93
         }
95 94
         
96
-        if (\Request::ajax())
97
-            return response()->json([ 'device' => $device, 'locations' => $locations, 'sites' => $sites ]);
98
-        else
99
-            return view('device.edit', [ 'device' => $device, 'locations' => $locations, 'sites' => $sites ]);
95
+        if (\Request::ajax()) {
96
+                    return response()->json([ 'device' => $device, 'locations' => $locations, 'sites' => $sites ]);
97
+        } else {
98
+                    return view('device.edit', [ 'device' => $device, 'locations' => $locations, 'sites' => $sites ]);
99
+        }
100 100
     }
101 101
     
102 102
     /**
@@ -146,8 +146,7 @@  discard block
 block discarded – undo
146 146
             //Create a new site
147 147
             $siteName = $request->input('new_site_name');
148 148
             $site_id = Site::createSite($siteName)->id;
149
-        }
150
-        else
149
+        } else
151 150
         {
152 151
             $site_id = $request->input('site');
153 152
         }
@@ -158,8 +157,7 @@  discard block
 block discarded – undo
158 157
             //Create a new location
159 158
             $locationName = $request->input('new_location_name');
160 159
             $location_id = Location::createLocation($locationName, $site_id)->id;
161
-        }
162
-        else
160
+        } else
163 161
         {
164 162
             $location_id = $request->input('location');
165 163
         }
@@ -177,10 +175,11 @@  discard block
 block discarded – undo
177 175
         //Remove any unused sites or locations
178 176
         $this->RemoveUnusedSiteLoc();
179 177
     
180
-        if (\Request::ajax())
181
-            return response()->json("Success");
182
-        else
183
-            return redirect('device');
178
+        if (\Request::ajax()) {
179
+                    return response()->json("Success");
180
+        } else {
181
+                    return redirect('device');
182
+        }
184 183
     }
185 184
 
186 185
     /**
@@ -197,8 +196,7 @@  discard block
 block discarded – undo
197 196
         {
198 197
             //If the device was already deleted then permanently delete it
199 198
             Device::destroy($id);
200
-        }
201
-        else
199
+        } else
202 200
         {
203 201
             //Remove the location from the device
204 202
             $device->location_id = null;
Please login to merge, or discard this patch.