@@ -85,7 +85,7 @@ discard block |
||
85 | 85 | { |
86 | 86 | $this->startTime = clone $startTime; |
87 | 87 | $this->endTime = clone $this->startTime; |
88 | - $this->endTime->add(new \DateInterval('PT'.(($this->max_time_slots+$this->time_slots)*self::TIME_SLOT_DURATION).'S')); |
|
88 | + $this->endTime->add(new \DateInterval('PT'.(($this->max_time_slots + $this->time_slots) * self::TIME_SLOT_DURATION).'S')); |
|
89 | 89 | } |
90 | 90 | |
91 | 91 | /** |
@@ -156,7 +156,7 @@ discard block |
||
156 | 156 | $solver = $this->setData($solver); |
157 | 157 | $solver = $solver->solve(); |
158 | 158 | $this->solver = $solver; |
159 | - }catch(\Exception $e) |
|
159 | + } catch (\Exception $e) |
|
160 | 160 | { |
161 | 161 | \Event::fire(new ErrorEvent($this->company, $e->getMessage())); |
162 | 162 | throw new OptimiseException('Optimising error', 0, $e); |
@@ -170,7 +170,7 @@ discard block |
||
170 | 170 | */ |
171 | 171 | public function save() |
172 | 172 | { |
173 | - if(!($this->solver instanceof Solver)) { |
|
173 | + if (!($this->solver instanceof Solver)) { |
|
174 | 174 | \Event::fire(new ErrorEvent($this->company, 'solver is not an instace of Solver')); |
175 | 175 | throw new OptimiseException('solver is not an instance of Solver'); |
176 | 176 | return; |
@@ -180,7 +180,7 @@ discard block |
||
180 | 180 | try { |
181 | 181 | $this->saveMeetings($this->solver); |
182 | 182 | $this->saveEmployeesMeetings($this->solver); |
183 | - }catch(\Exception $e) |
|
183 | + } catch (\Exception $e) |
|
184 | 184 | { |
185 | 185 | \Event::fire(new ErrorEvent($this->company, $e->getMessage())); |
186 | 186 | throw new OptimiseException('Optimising error', 0, $e); |
@@ -197,8 +197,8 @@ discard block |
||
197 | 197 | private function saveMeetings(Solver $solver) |
198 | 198 | { |
199 | 199 | $meetings = $solver->getYResults(); |
200 | - foreach($meetings as $id=>$meeting){ |
|
201 | - $meetingO = \plunner\Meeting::findOrFail($id);//TODO catch error |
|
200 | + foreach ($meetings as $id=>$meeting) { |
|
201 | + $meetingO = \plunner\Meeting::findOrFail($id); //TODO catch error |
|
202 | 202 | $meetingO->start_time = $this->toDateTime(array_search('1', $meeting)); |
203 | 203 | $meetingO->save(); |
204 | 204 | } |
@@ -210,11 +210,11 @@ discard block |
||
210 | 210 | private function saveEmployeesMeetings(Solver $solver) |
211 | 211 | { |
212 | 212 | $employeesMeetings = $solver->getXResults(); |
213 | - foreach($employeesMeetings as $eId =>$employeeMeetings) |
|
213 | + foreach ($employeesMeetings as $eId =>$employeeMeetings) |
|
214 | 214 | { |
215 | 215 | $employee = \plunner\Employee::findOrFail($eId); |
216 | 216 | $employeeMeetings = collect($employeeMeetings); |
217 | - $employeeMeetings = $employeeMeetings->filter(function ($item) { |
|
217 | + $employeeMeetings = $employeeMeetings->filter(function($item) { |
|
218 | 218 | return $item == 1; |
219 | 219 | }); |
220 | 220 | $employee->meetings()->attach($employeeMeetings->keys()->toArray()); |
@@ -274,7 +274,7 @@ discard block |
||
274 | 274 | return $this->timeSlotsConverter($item); |
275 | 275 | }); |
276 | 276 | return $solver->setMeetings($timeslots->keys()->toArray()) |
277 | - ->setMeetingsDuration($meetings->pluck('duration','id')->toArray()) |
|
277 | + ->setMeetingsDuration($meetings->pluck('duration', 'id')->toArray()) |
|
278 | 278 | ->setMeetingsAvailability(self::getAvailabilityArray($timeslots, $this->time_slots)); |
279 | 279 | } |
280 | 280 | |
@@ -320,15 +320,15 @@ discard block |
||
320 | 320 | */ |
321 | 321 | static private function getUsersMeetingsArray($users, $meetings, \Illuminate\Support\Collection $usersMeetings) |
322 | 322 | { |
323 | - $ret = []; |
|
324 | - foreach($users as $user) |
|
323 | + $ret = [ ]; |
|
324 | + foreach ($users as $user) |
|
325 | 325 | { |
326 | 326 | $usersMeetingsTmp = $usersMeetings->get($user); |
327 | - foreach($meetings as $meeting){ |
|
328 | - if($usersMeetingsTmp->contains('meeting_id', $meeting)){ |
|
329 | - $ret[$user][$meeting] = 1; |
|
330 | - }else{ |
|
331 | - $ret[$user][$meeting] = 0; |
|
327 | + foreach ($meetings as $meeting) { |
|
328 | + if ($usersMeetingsTmp->contains('meeting_id', $meeting)) { |
|
329 | + $ret[ $user ][ $meeting ] = 1; |
|
330 | + } else { |
|
331 | + $ret[ $user ][ $meeting ] = 0; |
|
332 | 332 | } |
333 | 333 | } |
334 | 334 | } |
@@ -338,7 +338,7 @@ discard block |
||
338 | 338 | |
339 | 339 | private function timeSlotsConverter($item) |
340 | 340 | { |
341 | - return $item->each(function($item2){ |
|
341 | + return $item->each(function($item2) { |
|
342 | 342 | $item2->time_start = $this->toTimeSlot($item2->time_start); |
343 | 343 | $item2->time_end = $this->toTimeSlot($item2->time_end); |
344 | 344 | return $item2; |
@@ -351,13 +351,13 @@ discard block |
||
351 | 351 | * @param bool|true $free if true the array is filled with 1 for timeslots values else with 0 for timeslots values |
352 | 352 | * @return array |
353 | 353 | */ |
354 | - static private function getAvailabilityArray(\Illuminate\Support\Collection $timeSlots, $timeslotsN, $free=true) |
|
354 | + static private function getAvailabilityArray(\Illuminate\Support\Collection $timeSlots, $timeslotsN, $free = true) |
|
355 | 355 | { |
356 | - $ret = []; |
|
357 | - foreach($timeSlots as $id=>$timeSlots2) |
|
356 | + $ret = [ ]; |
|
357 | + foreach ($timeSlots as $id=>$timeSlots2) |
|
358 | 358 | { |
359 | - $ret = self::fillTimeSlots($ret, $id, $timeSlots2, $free?'1':'0'); |
|
360 | - $ret = self::fillRow($ret, $id, $timeslotsN, $free?'0':'1'); |
|
359 | + $ret = self::fillTimeSlots($ret, $id, $timeSlots2, $free ? '1' : '0'); |
|
360 | + $ret = self::fillRow($ret, $id, $timeslotsN, $free ? '0' : '1'); |
|
361 | 361 | } |
362 | 362 | |
363 | 363 | return $ret; |
@@ -372,10 +372,10 @@ discard block |
||
372 | 372 | */ |
373 | 373 | static private function fillTimeSlots(array $array, $id, \Illuminate\Support\Collection $timeSlots, $fill = '0') |
374 | 374 | { |
375 | - foreach($timeSlots as $timeSlot) { |
|
376 | - if(!isset($array[$id])) |
|
377 | - $array[$id] = []; |
|
378 | - $array[$id] = self::arrayPadInterval($array[$id], $timeSlot->time_start, $timeSlot->time_end, $fill); |
|
375 | + foreach ($timeSlots as $timeSlot) { |
|
376 | + if (!isset($array[ $id ])) |
|
377 | + $array[ $id ] = [ ]; |
|
378 | + $array[ $id ] = self::arrayPadInterval($array[ $id ], $timeSlot->time_start, $timeSlot->time_end, $fill); |
|
379 | 379 | } |
380 | 380 | return $array; |
381 | 381 | } |
@@ -388,9 +388,9 @@ discard block |
||
388 | 388 | */ |
389 | 389 | static private function fillRow(array $array, $id, $until, $fill = '0') |
390 | 390 | { |
391 | - for($i = 1; $i <= $until; $i++){ |
|
392 | - if(!isset($array[$id][$i])) |
|
393 | - $array[$id][$i] = $fill; |
|
391 | + for ($i = 1; $i <= $until; $i++) { |
|
392 | + if (!isset($array[ $id ][ $i ])) |
|
393 | + $array[ $id ][ $i ] = $fill; |
|
394 | 394 | } |
395 | 395 | |
396 | 396 | return $array; |
@@ -405,8 +405,8 @@ discard block |
||
405 | 405 | */ |
406 | 406 | static private function arrayPadInterval(array $array, $from, $to, $pad = '0') |
407 | 407 | { |
408 | - for($i = $from; $i<$to; $i++) |
|
409 | - $array[$i] = $pad; |
|
408 | + for ($i = $from; $i < $to; $i++) |
|
409 | + $array[ $i ] = $pad; |
|
410 | 410 | return $array; |
411 | 411 | } |
412 | 412 | |
@@ -420,14 +420,14 @@ discard block |
||
420 | 420 | { |
421 | 421 | $dateTime = new \DateTime($time); |
422 | 422 | $diff = $dateTime->diff($this->startTime); |
423 | - $diff = explode(':',$diff->format('%R:%d:%h:%i:%s')); |
|
424 | - $diff = $diff[1]*86400 + $diff[2]*3600 + $diff[3]*60 + $diff[4]; |
|
423 | + $diff = explode(':', $diff->format('%R:%d:%h:%i:%s')); |
|
424 | + $diff = $diff[ 1 ] * 86400 + $diff[ 2 ] * 3600 + $diff[ 3 ] * 60 + $diff[ 4 ]; |
|
425 | 425 | //if($diff[0] != '-' && $diff != 0) |
426 | 426 | // throw new OptimiseException('timeslot time <= startTime'); |
427 | 427 | //TODO fix check |
428 | 428 | //TODO check if diff makes sense |
429 | 429 | //TODO check upper limit |
430 | - return (int)(round($diff/self::TIME_SLOT_DURATION)+1); //TODO can round cause overlaps? |
|
430 | + return (int) (round($diff / self::TIME_SLOT_DURATION) + 1); //TODO can round cause overlaps? |
|
431 | 431 | } |
432 | 432 | |
433 | 433 | /** |
@@ -437,6 +437,6 @@ discard block |
||
437 | 437 | private function toDateTime($timeslot) |
438 | 438 | { |
439 | 439 | $ret = clone $this->startTime; |
440 | - return $ret->add(new \DateInterval('PT'.(($timeslot-1)*self::TIME_SLOT_DURATION).'S')); |
|
440 | + return $ret->add(new \DateInterval('PT'.(($timeslot - 1) * self::TIME_SLOT_DURATION).'S')); |
|
441 | 441 | } |
442 | 442 | } |
443 | 443 | \ No newline at end of file |