@@ -38,11 +38,11 @@ |
||
| 38 | 38 | { |
| 39 | 39 | $validator = parent::getValidatorInstance(); |
| 40 | 40 | |
| 41 | - $validator->sometimes('site', 'integer|digits_between:1,10|exists:sites,id', function ($input) { |
|
| 41 | + $validator->sometimes('site', 'integer|digits_between:1,10|exists:sites,id', function($input) { |
|
| 42 | 42 | return !$input->new_site_name; |
| 43 | 43 | }); |
| 44 | 44 | |
| 45 | - $validator->sometimes('new_site_name', 'bail|min:2|max:75|name|unique:sites,name', function ($input) { |
|
| 45 | + $validator->sometimes('new_site_name', 'bail|min:2|max:75|name|unique:sites,name', function($input) { |
|
| 46 | 46 | return !$input->site; |
| 47 | 47 | }); |
| 48 | 48 | |
@@ -46,19 +46,19 @@ |
||
| 46 | 46 | { |
| 47 | 47 | $validator = parent::getValidatorInstance(); |
| 48 | 48 | |
| 49 | - $validator->sometimes('site_id', 'bail|integer|digits_between:1,10|exists:sites,id', function ($input) { |
|
| 49 | + $validator->sometimes('site_id', 'bail|integer|digits_between:1,10|exists:sites,id', function($input) { |
|
| 50 | 50 | return !$input->new_site_name && $input->site_id; |
| 51 | 51 | }); |
| 52 | 52 | |
| 53 | - $validator->sometimes('location_id', 'bail|integer|digits_between:1,10|exists:locations,id', function ($input) { |
|
| 53 | + $validator->sometimes('location_id', 'bail|integer|digits_between:1,10|exists:locations,id', function($input) { |
|
| 54 | 54 | return !$input->new_location_name && $input->location_id; |
| 55 | 55 | }); |
| 56 | 56 | |
| 57 | - $validator->sometimes('new_site_name', 'bail|min:2|max:75|name|unique:sites,name', function ($input) { |
|
| 57 | + $validator->sometimes('new_site_name', 'bail|min:2|max:75|name|unique:sites,name', function($input) { |
|
| 58 | 58 | return !$input->site_id && $input->name; |
| 59 | 59 | }); |
| 60 | 60 | |
| 61 | - $validator->sometimes('new_location_name', 'bail|min:2|max:75|name|unique:locations,name', function ($input) { |
|
| 61 | + $validator->sometimes('new_location_name', 'bail|min:2|max:75|name|unique:locations,name', function($input) { |
|
| 62 | 62 | return !$input->location_id && $input->name; |
| 63 | 63 | }); |
| 64 | 64 | |
@@ -49,7 +49,7 @@ discard block |
||
| 49 | 49 | 'name' => 'required|min:2|max:75|name|unique:sites,name', |
| 50 | 50 | ]); |
| 51 | 51 | |
| 52 | - $site = Site::create(['name' => $request->name]); |
|
| 52 | + $site = Site::create([ 'name' => $request->name ]); |
|
| 53 | 53 | |
| 54 | 54 | return redirect()->route('site.show', $site->id) |
| 55 | 55 | ->with('success', 'Site created successfully'); |
@@ -67,7 +67,7 @@ discard block |
||
| 67 | 67 | $locations = $site->locations()->orderBy('name', 'ASC')->paginate(15); |
| 68 | 68 | |
| 69 | 69 | if (\Request::ajax()) |
| 70 | - return response()->json(['site' => $site, 'locations' => $locations]); |
|
| 70 | + return response()->json([ 'site' => $site, 'locations' => $locations ]); |
|
| 71 | 71 | else |
| 72 | 72 | return view('site.show', [ 'site' => $site, 'locations' => $locations ]); |
| 73 | 73 | } |
@@ -98,7 +98,7 @@ discard block |
||
| 98 | 98 | 'name' => 'required|min:2|max:75|name|unique:sites,name,'.$site->id, |
| 99 | 99 | ]); |
| 100 | 100 | |
| 101 | - $site->update(['name' => $request->name]); |
|
| 101 | + $site->update([ 'name' => $request->name ]); |
|
| 102 | 102 | |
| 103 | 103 | return redirect()->route('site.show', $site->id) |
| 104 | 104 | ->with('success', 'Site updated successfully'); |
@@ -114,6 +114,6 @@ discard block |
||
| 114 | 114 | { |
| 115 | 115 | Site::findOrFail($id)->delete(); |
| 116 | 116 | return redirect()->route('site.index') |
| 117 | - ->with('success','Site deleted successfully'); |
|
| 117 | + ->with('success', 'Site deleted successfully'); |
|
| 118 | 118 | } |
| 119 | 119 | } |
@@ -55,10 +55,10 @@ discard block |
||
| 55 | 55 | { |
| 56 | 56 | $device = Device::findOrFail($id); |
| 57 | 57 | |
| 58 | - $charts = []; |
|
| 58 | + $charts = [ ]; |
|
| 59 | 59 | foreach ($device->sensors as $sensor) { |
| 60 | 60 | $data = $sensor->last_month_daily_avg_data; |
| 61 | - $charts[$sensor->id] = Charts::create('line', 'highcharts') |
|
| 61 | + $charts[ $sensor->id ] = Charts::create('line', 'highcharts') |
|
| 62 | 62 | ->title($sensor->name) |
| 63 | 63 | ->elementLabel($sensor->type) |
| 64 | 64 | ->labels($data->pluck('date')) |
@@ -90,7 +90,7 @@ discard block |
||
| 90 | 90 | $sites = Site::select('id', 'name')->orderByRaw("id = ? DESC", $site_id) |
| 91 | 91 | ->orderBy('name', 'ASC')->get(); |
| 92 | 92 | //Get all locations for the selected site with the selected location first |
| 93 | - $locations = Location::select('id', 'name')->where('site_id', '=', $sites[0]->id ?? 0) |
|
| 93 | + $locations = Location::select('id', 'name')->where('site_id', '=', $sites[ 0 ]->id ?? 0) |
|
| 94 | 94 | ->orderByRaw("id = ? DESC", $location_id)->orderBy('name', 'ASC')->get(); |
| 95 | 95 | |
| 96 | 96 | return view('device.edit', [ 'device' => $device, 'locations' => $locations, 'sites' => $sites ]); |
@@ -116,7 +116,7 @@ discard block |
||
| 116 | 116 | if (!empty($request->input('new_site_name'))) |
| 117 | 117 | { |
| 118 | 118 | //Create a new site |
| 119 | - $site = Site::create(['name' => $request->input('new_site_name')]); |
|
| 119 | + $site = Site::create([ 'name' => $request->input('new_site_name') ]); |
|
| 120 | 120 | $site_id = $site->id; |
| 121 | 121 | } else |
| 122 | 122 | $site_id = $request->input('site_id'); |
@@ -125,7 +125,7 @@ discard block |
||
| 125 | 125 | if (!empty($request->input('new_location_name'))) |
| 126 | 126 | { |
| 127 | 127 | //Create a new location |
| 128 | - $location = Location::create(['name' => $request->input('new_location_name'), 'site_id' => $site_id]); |
|
| 128 | + $location = Location::create([ 'name' => $request->input('new_location_name'), 'site_id' => $site_id ]); |
|
| 129 | 129 | $location_id = $location->id; |
| 130 | 130 | } else |
| 131 | 131 | $location_id = $request->input('location_id'); |
@@ -159,9 +159,9 @@ discard block |
||
| 159 | 159 | if ($request->command === 'unlock') |
| 160 | 160 | { |
| 161 | 161 | if ($device->isDuringScheduleOpen()) |
| 162 | - $command = 'open'; |
|
| 162 | + $command = 'open'; |
|
| 163 | 163 | else |
| 164 | - $command = 'close'; |
|
| 164 | + $command = 'close'; |
|
| 165 | 165 | } |
| 166 | 166 | $device->cover_command = $command; |
| 167 | 167 | } |
@@ -169,7 +169,7 @@ discard block |
||
| 169 | 169 | $device->save(); |
| 170 | 170 | |
| 171 | 171 | if (\Request::ajax()) |
| 172 | - return response()->json(['success' => 'Device updated successfully']); |
|
| 172 | + return response()->json([ 'success' => 'Device updated successfully' ]); |
|
| 173 | 173 | else |
| 174 | 174 | return redirect()->route('device.show', $id) |
| 175 | 175 | ->with('success', 'Device updated successfully'); |
@@ -201,7 +201,7 @@ discard block |
||
| 201 | 201 | } |
| 202 | 202 | |
| 203 | 203 | return redirect()->route('device.index') |
| 204 | - ->with('success','Device deleted successfully'); |
|
| 204 | + ->with('success', 'Device deleted successfully'); |
|
| 205 | 205 | } |
| 206 | 206 | |
| 207 | 207 | /** |
@@ -217,6 +217,6 @@ discard block |
||
| 217 | 217 | $device->restore(); |
| 218 | 218 | |
| 219 | 219 | return redirect()->route('device.show', $device->id) |
| 220 | - ->with('success','Device restored successfully'); |
|
| 220 | + ->with('success', 'Device restored successfully'); |
|
| 221 | 221 | } |
| 222 | 222 | } |
@@ -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; |
@@ -29,7 +29,7 @@ discard block |
||
| 29 | 29 | * |
| 30 | 30 | * @var array |
| 31 | 31 | */ |
| 32 | - protected $hidden = ['token']; |
|
| 32 | + protected $hidden = [ 'token' ]; |
|
| 33 | 33 | |
| 34 | 34 | /** |
| 35 | 35 | * The attributes that are mass assignable. |
@@ -48,7 +48,7 @@ discard block |
||
| 48 | 48 | * |
| 49 | 49 | * @var array |
| 50 | 50 | */ |
| 51 | - protected static $ignoreChangedAttributes = ['updated_at']; |
|
| 51 | + protected static $ignoreChangedAttributes = [ 'updated_at' ]; |
|
| 52 | 52 | |
| 53 | 53 | /** |
| 54 | 54 | * The attributes to log in the Activity Log |
@@ -89,7 +89,7 @@ discard block |
||
| 89 | 89 | */ |
| 90 | 90 | public function getSiteAttribute() |
| 91 | 91 | { |
| 92 | - return $this->location->site ?? (object)[]; |
|
| 92 | + return $this->location->site ?? (object) [ ]; |
|
| 93 | 93 | } |
| 94 | 94 | |
| 95 | 95 | /** |
@@ -149,7 +149,7 @@ discard block |
||
| 149 | 149 | else |
| 150 | 150 | $time = new Carbon($value, 'UTC'); |
| 151 | 151 | |
| 152 | - $this->attributes['open_time'] = $time->format('H:i:s'); |
|
| 152 | + $this->attributes[ 'open_time' ] = $time->format('H:i:s'); |
|
| 153 | 153 | } |
| 154 | 154 | |
| 155 | 155 | /** |
@@ -171,7 +171,7 @@ discard block |
||
| 171 | 171 | else |
| 172 | 172 | $time = new Carbon($value, 'UTC'); |
| 173 | 173 | |
| 174 | - $this->attributes['close_time'] = $time->format('H:i:s'); |
|
| 174 | + $this->attributes[ 'close_time' ] = $time->format('H:i:s'); |
|
| 175 | 175 | } |
| 176 | 176 | |
| 177 | 177 | /** |
@@ -311,7 +311,7 @@ discard block |
||
| 311 | 311 | $isClosed = $this->cover_status === 'closed'; |
| 312 | 312 | $isLocked = $this->cover_status === 'locked'; |
| 313 | 313 | |
| 314 | - switch ($this['cover_command']) |
|
| 314 | + switch ($this[ 'cover_command' ]) |
|
| 315 | 315 | { |
| 316 | 316 | case 'open': |
| 317 | 317 | if ($isOpen) |
@@ -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 | } |