@@ -158,11 +158,12 @@ discard block |
||
158 | 158 | $solver = $this->setData($solver); |
159 | 159 | $solver = $solver->solve(); |
160 | 160 | $this->solver = $solver; |
161 | - }catch(OptimiseException $e) { |
|
162 | - if(!$e->isEmpty()) |
|
163 | - \Event::fire(new ErrorEvent($this->company, $e->getMessage())); |
|
161 | + } catch(OptimiseException $e) { |
|
162 | + if(!$e->isEmpty()) { |
|
163 | + \Event::fire(new ErrorEvent($this->company, $e->getMessage())); |
|
164 | + } |
|
164 | 165 | throw $e; |
165 | - }catch (\Exception $e) { |
|
166 | + } catch (\Exception $e) { |
|
166 | 167 | //TODO use the correct exceptions to avoid to share private data |
167 | 168 | \Event::fire(new ErrorEvent($this->company, $e->getMessage())); |
168 | 169 | throw new OptimiseException('Optimising error', 0, $e); |
@@ -207,8 +208,9 @@ discard block |
||
207 | 208 | { |
208 | 209 | //since we consider busy timeslots, we need to get all users |
209 | 210 | $users = $this->company->employees->pluck('id')->toArray(); |
210 | - if(count($users) == 0) |
|
211 | - throw ((new OptimiseException("No users for this company"))->withEmpty(true)); |
|
211 | + if(count($users) == 0) { |
|
212 | + throw ((new OptimiseException("No users for this company"))->withEmpty(true)); |
|
213 | + } |
|
212 | 214 | return $solver->setUsers($users); |
213 | 215 | } |
214 | 216 | |
@@ -223,8 +225,9 @@ discard block |
||
223 | 225 | * @var $meetings \Illuminate\Support\Collection |
224 | 226 | */ |
225 | 227 | $meetings = collect($this->company->getMeetingsTimeSlots($this->startTime, $this->endTime)); |
226 | - if($meetings->count() == 0) |
|
227 | - throw ((new OptimiseException("No meetings for this week"))->withEmpty(true)); |
|
228 | + if($meetings->count() == 0) { |
|
229 | + throw ((new OptimiseException("No meetings for this week"))->withEmpty(true)); |
|
230 | + } |
|
228 | 231 | $timeslots = $meetings->groupBy('id')->map(function ($item) { //convert timeslots |
229 | 232 | return $this->durationConverter($this->timeSlotsConverter($item)); |
230 | 233 | }); |
@@ -298,8 +301,9 @@ discard block |
||
298 | 301 | { |
299 | 302 | $ret = []; |
300 | 303 | foreach ($ids as $id) { |
301 | - if(isset($timeSlots[$id])) |
|
302 | - $ret = self::fillTimeSlots($ret, $id, $timeSlots[$id], $free ? '1' : '0'); |
|
304 | + if(isset($timeSlots[$id])) { |
|
305 | + $ret = self::fillTimeSlots($ret, $id, $timeSlots[$id], $free ? '1' : '0'); |
|
306 | + } |
|
303 | 307 | $ret = self::fillRow($ret, $id, $timeslotsN, $free ? '0' : '1'); |
304 | 308 | } |
305 | 309 | |
@@ -316,8 +320,9 @@ discard block |
||
316 | 320 | static private function fillTimeSlots(array $array, $id, \Illuminate\Support\Collection $timeSlots, $fill = '0') |
317 | 321 | { |
318 | 322 | foreach ($timeSlots as $timeSlot) { |
319 | - if (!isset($array[$id])) |
|
320 | - $array[$id] = []; |
|
323 | + if (!isset($array[$id])) { |
|
324 | + $array[$id] = []; |
|
325 | + } |
|
321 | 326 | $array[$id] = self::arrayPadInterval($array[$id], $timeSlot->time_start, $timeSlot->time_end, $fill); |
322 | 327 | } |
323 | 328 | return $array; |
@@ -332,8 +337,9 @@ discard block |
||
332 | 337 | */ |
333 | 338 | static private function arrayPadInterval(array $array, $from, $to, $pad = '0') |
334 | 339 | { |
335 | - for ($i = $from; $i < $to; $i++) |
|
336 | - $array[$i] = $pad; |
|
340 | + for ($i = $from; $i < $to; $i++) { |
|
341 | + $array[$i] = $pad; |
|
342 | + } |
|
337 | 343 | return $array; |
338 | 344 | } |
339 | 345 | |
@@ -346,8 +352,9 @@ discard block |
||
346 | 352 | static private function fillRow(array $array, $id, $until, $fill = '0') |
347 | 353 | { |
348 | 354 | for ($i = 1; $i <= $until; $i++) { |
349 | - if (!isset($array[$id][$i])) |
|
350 | - $array[$id][$i] = $fill; |
|
355 | + if (!isset($array[$id][$i])) { |
|
356 | + $array[$id][$i] = $fill; |
|
357 | + } |
|
351 | 358 | } |
352 | 359 | |
353 | 360 | return $array; |
@@ -386,8 +393,9 @@ discard block |
||
386 | 393 | * @var $usersMeetings \Illuminate\Support\Collection |
387 | 394 | */ |
388 | 395 | $usersMeetings = collect($this->company->getUsersMeetings($users, $meetings))->groupBy('employee_id'); |
389 | - if($usersMeetings->count() == 0) |
|
390 | - throw ((new OptimiseException("No users for any meeting"))->withEmpty(true)); |
|
396 | + if($usersMeetings->count() == 0) { |
|
397 | + throw ((new OptimiseException("No users for any meeting"))->withEmpty(true)); |
|
398 | + } |
|
391 | 399 | |
392 | 400 | return $solver->setUsersMeetings(self::getUsersMeetingsArray($users, $meetings, $usersMeetings)); |
393 | 401 | } |
@@ -464,8 +472,10 @@ discard block |
||
464 | 472 | { |
465 | 473 | $ret = clone $this->startTime; |
466 | 474 | //TODO check, because the meetings cannot have this date available -> this to avoid errors if we don't have a date for a meeting |
467 | - if ($timeslot <= 1) //false == 0 |
|
475 | + if ($timeslot <= 1) { |
|
476 | + //false == 0 |
|
468 | 477 | return $ret; |
478 | + } |
|
469 | 479 | return $ret->add(new \DateInterval('PT' . (($timeslot - 1) * config('app.timeslots.duration')) . 'S')); |
470 | 480 | } |
471 | 481 |