@@ -24,7 +24,7 @@ discard block |
||
24 | 24 | //TODo max timeslots can be an environment var |
25 | 25 | const TIME_SLOT_DURATION = 900; //seconds -> 15 minutes |
26 | 26 | const DEFAULT_MAX_TIME_SLOTS = 20; //max duration of a meeting in term of timeslots //20 |
27 | - const DEFAULT_TIME_SLOTS = 672; //total amount of timeslots that must be optimised -> one week 4*24*7 = 672 |
|
27 | + const DEFAULT_TIME_SLOTS = 672; //total amount of timeslots that must be optimised -> one week 4*24*7 = 672 |
|
28 | 28 | |
29 | 29 | private $max_time_slots = self::DEFAULT_MAX_TIME_SLOTS; |
30 | 30 | private $time_slots = self::DEFAULT_TIME_SLOTS; |
@@ -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()); |
@@ -272,7 +272,7 @@ discard block |
||
272 | 272 | return $this->timeSlotsConverter($item); |
273 | 273 | }); |
274 | 274 | return $solver->setMeetings($timeslots->keys()->toArray()) |
275 | - ->setMeetingsDuration($meetings->pluck('duration','id')->toArray()) |
|
275 | + ->setMeetingsDuration($meetings->pluck('duration', 'id')->toArray()) |
|
276 | 276 | ->setMeetingsAvailability(self::getAvailabilityArray($timeslots, $this->time_slots)); |
277 | 277 | } |
278 | 278 | |
@@ -318,15 +318,15 @@ discard block |
||
318 | 318 | */ |
319 | 319 | static private function getUsersMeetingsArray($users, $meetings, \Illuminate\Support\Collection $usersMeetings) |
320 | 320 | { |
321 | - $ret = []; |
|
322 | - foreach($users as $user) |
|
321 | + $ret = [ ]; |
|
322 | + foreach ($users as $user) |
|
323 | 323 | { |
324 | 324 | $usersMeetingsTmp = $usersMeetings->get($user); |
325 | - foreach($meetings as $meeting){ |
|
326 | - if($usersMeetingsTmp->contains('meeting_id', $meeting)){ |
|
327 | - $ret[$user][$meeting] = 1; |
|
328 | - }else{ |
|
329 | - $ret[$user][$meeting] = 0; |
|
325 | + foreach ($meetings as $meeting) { |
|
326 | + if ($usersMeetingsTmp->contains('meeting_id', $meeting)) { |
|
327 | + $ret[ $user ][ $meeting ] = 1; |
|
328 | + } else { |
|
329 | + $ret[ $user ][ $meeting ] = 0; |
|
330 | 330 | } |
331 | 331 | } |
332 | 332 | } |
@@ -336,7 +336,7 @@ discard block |
||
336 | 336 | |
337 | 337 | private function timeSlotsConverter($item) |
338 | 338 | { |
339 | - return $item->each(function($item2){ |
|
339 | + return $item->each(function($item2) { |
|
340 | 340 | $item2->time_start = $this->toTimeSlot($item2->time_start); |
341 | 341 | $item2->time_end = $this->toTimeSlot($item2->time_end); |
342 | 342 | return $item2; |
@@ -349,13 +349,13 @@ discard block |
||
349 | 349 | * @param bool|true $free if true the array is filled with 1 for timeslots values else with 0 for timeslots values |
350 | 350 | * @return array |
351 | 351 | */ |
352 | - static private function getAvailabilityArray(\Illuminate\Support\Collection $timeSlots, $timeslotsN, $free=true) |
|
352 | + static private function getAvailabilityArray(\Illuminate\Support\Collection $timeSlots, $timeslotsN, $free = true) |
|
353 | 353 | { |
354 | - $ret = []; |
|
355 | - foreach($timeSlots as $id=>$timeSlots2) |
|
354 | + $ret = [ ]; |
|
355 | + foreach ($timeSlots as $id=>$timeSlots2) |
|
356 | 356 | { |
357 | - $ret = self::fillTimeSlots($ret, $id, $timeSlots2, $free?'1':'0'); |
|
358 | - $ret = self::fillRow($ret, $id, $timeslotsN, $free?'0':'1'); |
|
357 | + $ret = self::fillTimeSlots($ret, $id, $timeSlots2, $free ? '1' : '0'); |
|
358 | + $ret = self::fillRow($ret, $id, $timeslotsN, $free ? '0' : '1'); |
|
359 | 359 | } |
360 | 360 | |
361 | 361 | return $ret; |
@@ -370,10 +370,10 @@ discard block |
||
370 | 370 | */ |
371 | 371 | static private function fillTimeSlots(array $array, $id, \Illuminate\Support\Collection $timeSlots, $fill = '0') |
372 | 372 | { |
373 | - foreach($timeSlots as $timeSlot) { |
|
374 | - if(!isset($array[$id])) |
|
375 | - $array[$id] = []; |
|
376 | - $array[$id] = self::arrayPadInterval($array[$id], $timeSlot->time_start, $timeSlot->time_end, $fill); |
|
373 | + foreach ($timeSlots as $timeSlot) { |
|
374 | + if (!isset($array[ $id ])) |
|
375 | + $array[ $id ] = [ ]; |
|
376 | + $array[ $id ] = self::arrayPadInterval($array[ $id ], $timeSlot->time_start, $timeSlot->time_end, $fill); |
|
377 | 377 | } |
378 | 378 | return $array; |
379 | 379 | } |
@@ -386,9 +386,9 @@ discard block |
||
386 | 386 | */ |
387 | 387 | static private function fillRow(array $array, $id, $until, $fill = '0') |
388 | 388 | { |
389 | - for($i = 1; $i <= $until; $i++){ |
|
390 | - if(!isset($array[$id][$i])) |
|
391 | - $array[$id][$i] = $fill; |
|
389 | + for ($i = 1; $i <= $until; $i++) { |
|
390 | + if (!isset($array[ $id ][ $i ])) |
|
391 | + $array[ $id ][ $i ] = $fill; |
|
392 | 392 | } |
393 | 393 | |
394 | 394 | return $array; |
@@ -403,8 +403,8 @@ discard block |
||
403 | 403 | */ |
404 | 404 | static private function arrayPadInterval(array $array, $from, $to, $pad = '0') |
405 | 405 | { |
406 | - for($i = $from; $i<$to; $i++) |
|
407 | - $array[$i] = $pad; |
|
406 | + for ($i = $from; $i < $to; $i++) |
|
407 | + $array[ $i ] = $pad; |
|
408 | 408 | return $array; |
409 | 409 | } |
410 | 410 | |
@@ -418,14 +418,14 @@ discard block |
||
418 | 418 | { |
419 | 419 | $dateTime = new \DateTime($time); |
420 | 420 | $diff = $dateTime->diff($this->startTime); |
421 | - $diff = explode(':',$diff->format('%R:%d:%h:%i:%s')); |
|
422 | - $diff = $diff[1]*86400 + $diff[2]*3600 + $diff[3]*60 + $diff[4]; |
|
421 | + $diff = explode(':', $diff->format('%R:%d:%h:%i:%s')); |
|
422 | + $diff = $diff[ 1 ] * 86400 + $diff[ 2 ] * 3600 + $diff[ 3 ] * 60 + $diff[ 4 ]; |
|
423 | 423 | //if($diff[0] != '-' && $diff != 0) |
424 | 424 | // throw new OptimiseException('timeslot time <= startTime'); |
425 | 425 | //TODO fix check |
426 | 426 | //TODO check if diff makes sense |
427 | 427 | //TODO check upper limit |
428 | - return (int)(round($diff/self::TIME_SLOT_DURATION)+1); //TODO can round cause overlaps? |
|
428 | + return (int) (round($diff / self::TIME_SLOT_DURATION) + 1); //TODO can round cause overlaps? |
|
429 | 429 | } |
430 | 430 | |
431 | 431 | /** |
@@ -435,6 +435,6 @@ discard block |
||
435 | 435 | private function toDateTime($timeslot) |
436 | 436 | { |
437 | 437 | $ret = clone $this->startTime; |
438 | - return $ret->add(new \DateInterval('PT'.(($timeslot-1)*self::TIME_SLOT_DURATION).'S')); |
|
438 | + return $ret->add(new \DateInterval('PT'.(($timeslot - 1) * self::TIME_SLOT_DURATION).'S')); |
|
439 | 439 | } |
440 | 440 | } |
441 | 441 | \ No newline at end of file |