@@ -35,7 +35,7 @@ discard block |
||
35 | 35 | //Get the first device that doesn't have a null location_id |
36 | 36 | $device = Device::publicDashData()->where('location_id', '!=', 'null')->orderBy('id', 'ASC')->first(); |
37 | 37 | } |
38 | - catch(ModelNotFoundException $e) |
|
38 | + catch (ModelNotFoundException $e) |
|
39 | 39 | { |
40 | 40 | //If no device is found then redirect the user to the home page and display a message about registering a device |
41 | 41 | return redirect('home')->with('no_devices', 'To access the dashboard page there must be at least one registered device assigned to a location.'); |
@@ -48,7 +48,7 @@ discard block |
||
48 | 48 | |
49 | 49 | $data = $this->dashData($site, $location, $device); |
50 | 50 | |
51 | - return view('dashboard.index', [ 'active_device' => $data[0], 'devices' => $data[1], 'locations' => $data[2], 'sites' => $data[3] ]); |
|
51 | + return view('dashboard.index', [ 'active_device' => $data[ 0 ], 'devices' => $data[ 1 ], 'locations' => $data[ 2 ], 'sites' => $data[ 3 ] ]); |
|
52 | 52 | } |
53 | 53 | |
54 | 54 | /** |
@@ -92,7 +92,7 @@ discard block |
||
92 | 92 | //Get the first site and if no sites exist throw an error |
93 | 93 | $site = Site::select('id', 'name')->firstOrFail(); |
94 | 94 | } |
95 | - catch(ModelNotFoundException $e) |
|
95 | + catch (ModelNotFoundException $e) |
|
96 | 96 | { |
97 | 97 | //If no device is found then redirect the user to the home page and display a message about registering a device |
98 | 98 | return redirect('home')->with('no_devices', 'To access the dashboard page there must be at least one registered device assigned to a location.'); |
@@ -118,7 +118,7 @@ discard block |
||
118 | 118 | |
119 | 119 | $data = $this->dashData($site, $location, $device); |
120 | 120 | |
121 | - return response()->json([ 'active_device' => $data[0], 'devices' => $data[1], 'locations' => $data[2], 'sites' => $data[3] ]); |
|
121 | + return response()->json([ 'active_device' => $data[ 0 ], 'devices' => $data[ 1 ], 'locations' => $data[ 2 ], 'sites' => $data[ 3 ] ]); |
|
122 | 122 | } |
123 | 123 | |
124 | 124 | /** |
@@ -138,7 +138,7 @@ discard block |
||
138 | 138 | |
139 | 139 | $data = $this->dashData($site, $location, $device); |
140 | 140 | |
141 | - return response()->json([ 'active_device' => $data[0], 'devices' => $data[1], 'locations' => $data[2], 'sites' => $data[3] ]); |
|
141 | + return response()->json([ 'active_device' => $data[ 0 ], 'devices' => $data[ 1 ], 'locations' => $data[ 2 ], 'sites' => $data[ 3 ] ]); |
|
142 | 142 | } |
143 | 143 | |
144 | 144 | /** |
@@ -158,7 +158,7 @@ discard block |
||
158 | 158 | |
159 | 159 | $data = $this->dashData($site, $location, $device); |
160 | 160 | |
161 | - return response()->json([ 'active_device' => $data[0], 'devices' => $data[1], 'locations' => $data[2], 'sites' => $data[3] ]); |
|
161 | + return response()->json([ 'active_device' => $data[ 0 ], 'devices' => $data[ 1 ], 'locations' => $data[ 2 ], 'sites' => $data[ 3 ] ]); |
|
162 | 162 | } |
163 | 163 | |
164 | 164 | /** |
@@ -180,9 +180,9 @@ discard block |
||
180 | 180 | //Get all the devices that belong to the given location ordered by name |
181 | 181 | $devices = $location->devices()->publicDashData()->orderBy('name', 'ASC')->get(); |
182 | 182 | |
183 | - $active_device = collect([$device, $location, $site]); |
|
183 | + $active_device = collect([ $device, $location, $site ]); |
|
184 | 184 | |
185 | - return collect([$active_device, $devices, $locations, $sites]); |
|
185 | + return collect([ $active_device, $devices, $locations, $sites ]); |
|
186 | 186 | } |
187 | 187 | |
188 | 188 | /** |
@@ -203,7 +203,7 @@ discard block |
||
203 | 203 | return response()->json("Device is currently in use.", 403); |
204 | 204 | |
205 | 205 | //1 = open, 2 = close, 3 = lock |
206 | - switch($request->command) |
|
206 | + switch ($request->command) |
|
207 | 207 | { |
208 | 208 | case 1: |
209 | 209 | $device->cover_command = 'open'; |
@@ -239,12 +239,12 @@ discard block |
||
239 | 239 | |
240 | 240 | //Check if the current time is during the open schedule or not |
241 | 241 | if (($time_now > $open_time) && ($time_now < $close_time)) |
242 | - $command = 'open'; |
|
242 | + $command = 'open'; |
|
243 | 243 | else |
244 | - $command = 'close'; |
|
244 | + $command = 'close'; |
|
245 | 245 | } |
246 | 246 | else |
247 | - $command = 'lock'; |
|
247 | + $command = 'lock'; |
|
248 | 248 | |
249 | 249 | return $command; |
250 | 250 | } |
@@ -34,8 +34,7 @@ discard block |
||
34 | 34 | //Todo use the users preferred device |
35 | 35 | //Get the first device that doesn't have a null location_id |
36 | 36 | $device = Device::publicDashData()->where('location_id', '!=', 'null')->orderBy('id', 'ASC')->first(); |
37 | - } |
|
38 | - catch(ModelNotFoundException $e) |
|
37 | + } catch(ModelNotFoundException $e) |
|
39 | 38 | { |
40 | 39 | //If no device is found then redirect the user to the home page and display a message about registering a device |
41 | 40 | return redirect('home')->with('no_devices', 'To access the dashboard page there must be at least one registered device assigned to a location.'); |
@@ -85,14 +84,15 @@ discard block |
||
85 | 84 | //Get the given device if it is still at the same location |
86 | 85 | $device = Device::publicDashData()->where('location_id', '=', $request->location_id)->find($request->device_id); |
87 | 86 | |
88 | - if (empty($site)) //Check if the site still exists |
|
87 | + if (empty($site)) { |
|
88 | + //Check if the site still exists |
|
89 | 89 | { |
90 | 90 | try |
91 | 91 | { |
92 | 92 | //Get the first site and if no sites exist throw an error |
93 | 93 | $site = Site::select('id', 'name')->firstOrFail(); |
94 | - } |
|
95 | - catch(ModelNotFoundException $e) |
|
94 | + } |
|
95 | + } catch(ModelNotFoundException $e) |
|
96 | 96 | { |
97 | 97 | //If no device is found then redirect the user to the home page and display a message about registering a device |
98 | 98 | return redirect('home')->with('no_devices', 'To access the dashboard page there must be at least one registered device assigned to a location.'); |
@@ -102,19 +102,21 @@ discard block |
||
102 | 102 | $location = $site->locations()->select('id', 'name', 'site_id')->firstOrFail(); |
103 | 103 | //Get the first device from the location |
104 | 104 | $device = $location->devices()->publicDashData()->firstOrFail(); |
105 | - } |
|
106 | - else if (empty($location)) //Check if the location still exists |
|
105 | + } else if (empty($location)) { |
|
106 | + //Check if the location still exists |
|
107 | 107 | { |
108 | 108 | //Get the first location from the given site |
109 | 109 | $location = $site->locations()->select('id', 'name', 'site_id')->firstOrFail(); |
110 | + } |
|
110 | 111 | //Get the first device from the location |
111 | 112 | $device = $location->devices()->publicDashData()->firstOrFail(); |
112 | - } |
|
113 | - else if (empty($device)) //Check if the device still exists at the given location |
|
113 | + } else if (empty($device)) { |
|
114 | + //Check if the device still exists at the given location |
|
114 | 115 | { |
115 | 116 | //Get the first device from the location |
116 | 117 | $device = $location->devices()->publicDashData()->firstOrFail(); |
117 | 118 | } |
119 | + } |
|
118 | 120 | |
119 | 121 | $data = $this->dashData($site, $location, $device); |
120 | 122 | |
@@ -199,8 +201,9 @@ discard block |
||
199 | 201 | ])->validate(); |
200 | 202 | |
201 | 203 | //Check that device isn't currently in use or has an error |
202 | - if ($device->cover_status === 'opening' || $device->cover_status === 'closing' || $device->cover_status === 'error') |
|
203 | - return response()->json("Device is currently in use.", 403); |
|
204 | + if ($device->cover_status === 'opening' || $device->cover_status === 'closing' || $device->cover_status === 'error') { |
|
205 | + return response()->json("Device is currently in use.", 403); |
|
206 | + } |
|
204 | 207 | |
205 | 208 | //1 = open, 2 = close, 3 = lock |
206 | 209 | switch($request->command) |
@@ -238,13 +241,14 @@ discard block |
||
238 | 241 | $time_now = Carbon::now(Auth::user()->timezone); |
239 | 242 | |
240 | 243 | //Check if the current time is during the open schedule or not |
241 | - if (($time_now > $open_time) && ($time_now < $close_time)) |
|
242 | - $command = 'open'; |
|
243 | - else |
|
244 | - $command = 'close'; |
|
244 | + if (($time_now > $open_time) && ($time_now < $close_time)) { |
|
245 | + $command = 'open'; |
|
246 | + } else { |
|
247 | + $command = 'close'; |
|
248 | + } |
|
249 | + } else { |
|
250 | + $command = 'lock'; |
|
245 | 251 | } |
246 | - else |
|
247 | - $command = 'lock'; |
|
248 | 252 | |
249 | 253 | return $command; |
250 | 254 | } |