@@ -118,8 +118,9 @@ discard block |
||
118 | 118 | //Create a new site |
119 | 119 | $site = Site::create(['name' => $request->input('new_site_name')]); |
120 | 120 | $site_id = $site->id; |
121 | - } else |
|
122 | - $site_id = $request->input('site_id'); |
|
121 | + } else { |
|
122 | + $site_id = $request->input('site_id'); |
|
123 | + } |
|
123 | 124 | |
124 | 125 | //Get the location id of the old or newly created location |
125 | 126 | if (!empty($request->input('new_location_name'))) |
@@ -127,52 +128,63 @@ discard block |
||
127 | 128 | //Create a new location |
128 | 129 | $location = Location::create(['name' => $request->input('new_location_name'), 'site_id' => $site_id]); |
129 | 130 | $location_id = $location->id; |
130 | - } else |
|
131 | - $location_id = $request->input('location_id'); |
|
131 | + } else { |
|
132 | + $location_id = $request->input('location_id'); |
|
133 | + } |
|
132 | 134 | } |
133 | 135 | |
134 | 136 | //Update the device |
135 | - if ($location_id != null) |
|
136 | - $device->location_id = $location_id; |
|
137 | - if ($request->input('name') != null) |
|
138 | - $device->name = $request->input('name'); |
|
139 | - if ($request->input('open_time') != null) |
|
140 | - $device->open_time = $request->input('open_time'); |
|
141 | - if ($request->input('close_time') != null) |
|
142 | - $device->close_time = $request->input('close_time'); |
|
143 | - if ($request->input('update_rate') != null) |
|
144 | - $device->update_rate = $request->input('update_rate'); |
|
145 | - if ($request->input('image_rate') != null) |
|
146 | - $device->image_rate = $request->input('image_rate'); |
|
147 | - if ($request->input('sensor_rate') != null) |
|
148 | - $device->sensor_rate = $request->input('sensor_rate'); |
|
137 | + if ($location_id != null) { |
|
138 | + $device->location_id = $location_id; |
|
139 | + } |
|
140 | + if ($request->input('name') != null) { |
|
141 | + $device->name = $request->input('name'); |
|
142 | + } |
|
143 | + if ($request->input('open_time') != null) { |
|
144 | + $device->open_time = $request->input('open_time'); |
|
145 | + } |
|
146 | + if ($request->input('close_time') != null) { |
|
147 | + $device->close_time = $request->input('close_time'); |
|
148 | + } |
|
149 | + if ($request->input('update_rate') != null) { |
|
150 | + $device->update_rate = $request->input('update_rate'); |
|
151 | + } |
|
152 | + if ($request->input('image_rate') != null) { |
|
153 | + $device->image_rate = $request->input('image_rate'); |
|
154 | + } |
|
155 | + if ($request->input('sensor_rate') != null) { |
|
156 | + $device->sensor_rate = $request->input('sensor_rate'); |
|
157 | + } |
|
149 | 158 | //Check if the cover_command needs to be updated |
150 | 159 | if ($request->input('command') != null) |
151 | 160 | { |
152 | 161 | //If device is currently opening, closing or in an error state don't update command |
153 | - if (!$device->isReadyForCommand()) |
|
154 | - return response()->json("Device is currently in use.", 403); |
|
162 | + if (!$device->isReadyForCommand()) { |
|
163 | + return response()->json("Device is currently in use.", 403); |
|
164 | + } |
|
155 | 165 | |
156 | 166 | $command = $request->input('command'); |
157 | 167 | |
158 | 168 | //If command is to unlock the device then check if the device should be open or closed based on the schedule |
159 | 169 | if ($request->command === 'unlock') |
160 | 170 | { |
161 | - if ($device->isDuringScheduleOpen()) |
|
162 | - $command = 'open'; |
|
163 | - else |
|
164 | - $command = 'close'; |
|
171 | + if ($device->isDuringScheduleOpen()) { |
|
172 | + $command = 'open'; |
|
173 | + } else { |
|
174 | + $command = 'close'; |
|
175 | + } |
|
165 | 176 | } |
166 | 177 | $device->cover_command = $command; |
167 | 178 | } |
168 | 179 | |
169 | 180 | $device->save(); |
170 | 181 | |
171 | - if (\Request::ajax()) |
|
172 | - return response()->json(['success' => 'Device updated successfully']); |
|
173 | - else |
|
174 | - return redirect()->route('device.show', $id) |
|
182 | + if (\Request::ajax()) { |
|
183 | + return response()->json(['success' => 'Device updated successfully']); |
|
184 | + } else { |
|
185 | + return redirect()->route('device.show', $id) |
|
175 | 186 | ->with('success', 'Device updated successfully'); |
187 | + } |
|
176 | 188 | } |
177 | 189 | |
178 | 190 | /** |
@@ -189,8 +201,7 @@ discard block |
||
189 | 201 | { |
190 | 202 | //If the device was already deleted then permanently delete it |
191 | 203 | $device->forceDelete($device->id); |
192 | - } |
|
193 | - else |
|
204 | + } else |
|
194 | 205 | { |
195 | 206 | //Remove the location from the device |
196 | 207 | $device->location_id = null; |
@@ -105,8 +105,9 @@ discard block |
||
105 | 105 | $time = new Carbon($value, 'UTC'); |
106 | 106 | |
107 | 107 | //If the user is logged in then use there preferred timezone |
108 | - if (Auth::check()) |
|
109 | - $time = $time->setTimezone(Auth::user()->timezone); |
|
108 | + if (Auth::check()) { |
|
109 | + $time = $time->setTimezone(Auth::user()->timezone); |
|
110 | + } |
|
110 | 111 | |
111 | 112 | return $time->format('H:i'); |
112 | 113 | } |
@@ -124,8 +125,9 @@ discard block |
||
124 | 125 | $time = new Carbon($value, 'UTC'); |
125 | 126 | |
126 | 127 | //If the user is logged in then use there preferred timezone |
127 | - if (Auth::check()) |
|
128 | - $time = $time->setTimezone(Auth::user()->timezone); |
|
128 | + if (Auth::check()) { |
|
129 | + $time = $time->setTimezone(Auth::user()->timezone); |
|
130 | + } |
|
129 | 131 | |
130 | 132 | return $time->format('H:i'); |
131 | 133 | } |
@@ -145,9 +147,9 @@ discard block |
||
145 | 147 | { |
146 | 148 | $time = new Carbon($value, Auth::user()->timezone); |
147 | 149 | $time = $time->setTimezone('UTC'); |
150 | + } else { |
|
151 | + $time = new Carbon($value, 'UTC'); |
|
148 | 152 | } |
149 | - else |
|
150 | - $time = new Carbon($value, 'UTC'); |
|
151 | 153 | |
152 | 154 | $this->attributes['open_time'] = $time->format('H:i:s'); |
153 | 155 | } |
@@ -167,9 +169,9 @@ discard block |
||
167 | 169 | { |
168 | 170 | $time = new Carbon($value, Auth::user()->timezone); |
169 | 171 | $time = $time->setTimezone('UTC'); |
172 | + } else { |
|
173 | + $time = new Carbon($value, 'UTC'); |
|
170 | 174 | } |
171 | - else |
|
172 | - $time = new Carbon($value, 'UTC'); |
|
173 | 175 | |
174 | 176 | $this->attributes['close_time'] = $time->format('H:i:s'); |
175 | 177 | } |
@@ -293,10 +295,11 @@ discard block |
||
293 | 295 | $time_now = Carbon::now($timezone); |
294 | 296 | |
295 | 297 | //Check if the current time is during the open schedule or not |
296 | - if ($time_now->gt($open_time) && $time_now->lt($close_time)) |
|
297 | - return true; |
|
298 | - else |
|
299 | - return false; |
|
298 | + if ($time_now->gt($open_time) && $time_now->lt($close_time)) { |
|
299 | + return true; |
|
300 | + } else { |
|
301 | + return false; |
|
302 | + } |
|
300 | 303 | } |
301 | 304 | |
302 | 305 | /** |
@@ -314,20 +317,22 @@ discard block |
||
314 | 317 | switch ($this['cover_command']) |
315 | 318 | { |
316 | 319 | case 'open': |
317 | - if ($isOpen) |
|
318 | - $status = 'open'; |
|
319 | - else if ($isLocked) |
|
320 | - $status = 'unlocking'; |
|
321 | - else |
|
322 | - $status = 'opening'; |
|
320 | + if ($isOpen) { |
|
321 | + $status = 'open'; |
|
322 | + } else if ($isLocked) { |
|
323 | + $status = 'unlocking'; |
|
324 | + } else { |
|
325 | + $status = 'opening'; |
|
326 | + } |
|
323 | 327 | break; |
324 | 328 | case 'close': |
325 | - if ($isClosed) |
|
326 | - $status = 'closed'; |
|
327 | - else if ($isLocked) |
|
328 | - $status = 'unlocking'; |
|
329 | - else |
|
330 | - $status = 'closing'; |
|
329 | + if ($isClosed) { |
|
330 | + $status = 'closed'; |
|
331 | + } else if ($isLocked) { |
|
332 | + $status = 'unlocking'; |
|
333 | + } else { |
|
334 | + $status = 'closing'; |
|
335 | + } |
|
331 | 336 | break; |
332 | 337 | case 'lock': |
333 | 338 | $status = 'locked'; |
@@ -336,8 +341,9 @@ discard block |
||
336 | 341 | $status = 'error'; |
337 | 342 | } |
338 | 343 | |
339 | - if ($this->cover_status === 'error') |
|
340 | - $status = 'error'; |
|
344 | + if ($this->cover_status === 'error') { |
|
345 | + $status = 'error'; |
|
346 | + } |
|
341 | 347 | |
342 | 348 | return $status; |
343 | 349 | } |