@@ -80,27 +80,31 @@ discard block |
||
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 |
||
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 |
||
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 | } |
@@ -84,8 +84,7 @@ discard block |
||
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 |
||
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 |
||
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 |
||
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 |
||
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 |
||
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; |
@@ -75,8 +75,9 @@ discard block |
||
75 | 75 | $time = new Carbon($value, 'UTC'); |
76 | 76 | |
77 | 77 | //If the user is logged in then use there preferred timezone |
78 | - if (Auth::check()) |
|
79 | - $time = $time->setTimezone(Auth::user()->timezone); |
|
78 | + if (Auth::check()) { |
|
79 | + $time = $time->setTimezone(Auth::user()->timezone); |
|
80 | + } |
|
80 | 81 | |
81 | 82 | return $time->format('H:i'); |
82 | 83 | } |
@@ -94,8 +95,9 @@ discard block |
||
94 | 95 | $time = new Carbon($value, 'UTC'); |
95 | 96 | |
96 | 97 | //If the user is logged in then use there preferred timezone |
97 | - if (Auth::check()) |
|
98 | - $time = $time->setTimezone(Auth::user()->timezone); |
|
98 | + if (Auth::check()) { |
|
99 | + $time = $time->setTimezone(Auth::user()->timezone); |
|
100 | + } |
|
99 | 101 | |
100 | 102 | return $time->format('H:i'); |
101 | 103 | } |
@@ -115,9 +117,9 @@ discard block |
||
115 | 117 | { |
116 | 118 | $time = new Carbon($value, Auth::user()->timezone); |
117 | 119 | $time = $time->setTimezone('UTC'); |
120 | + } else { |
|
121 | + $time = new Carbon($value, 'UTC'); |
|
118 | 122 | } |
119 | - else |
|
120 | - $time = new Carbon($value, 'UTC'); |
|
121 | 123 | |
122 | 124 | $this->attributes['open_time'] = $time; |
123 | 125 | } |
@@ -137,9 +139,9 @@ discard block |
||
137 | 139 | { |
138 | 140 | $time = new Carbon($value, Auth::user()->timezone); |
139 | 141 | $time = $time->setTimezone('UTC'); |
142 | + } else { |
|
143 | + $time = new Carbon($value, 'UTC'); |
|
140 | 144 | } |
141 | - else |
|
142 | - $time = new Carbon($value, 'UTC'); |
|
143 | 145 | |
144 | 146 | $this->attributes['close_time'] = $time; |
145 | 147 | } |