@@ -1,21 +1,21 @@ |
||
| 1 | 1 | <?php |
| 2 | 2 | /** |
| 3 | - * Created by PhpStorm. |
|
| 4 | - * User: Claudio Cardinale <[email protected]> |
|
| 5 | - * Date: 07/12/15 |
|
| 6 | - * Time: 21.18 |
|
| 7 | - * This program is free software; you can redistribute it and/or |
|
| 8 | - * modify it under the terms of the GNU General Public License |
|
| 9 | - * as published by the Free Software Foundation; either version 2 |
|
| 10 | - * of the License, or (at your option) any later version. |
|
| 11 | - * This program is distributed in the hope that it will be useful, |
|
| 12 | - * but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
| 13 | - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
| 14 | - * GNU General Public License for more details. |
|
| 15 | - * You should have received a copy of the GNU General Public License |
|
| 16 | - * along with this program; if not, write to the Free Software |
|
| 17 | - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. |
|
| 18 | - */ |
|
| 3 | + * Created by PhpStorm. |
|
| 4 | + * User: Claudio Cardinale <[email protected]> |
|
| 5 | + * Date: 07/12/15 |
|
| 6 | + * Time: 21.18 |
|
| 7 | + * This program is free software; you can redistribute it and/or |
|
| 8 | + * modify it under the terms of the GNU General Public License |
|
| 9 | + * as published by the Free Software Foundation; either version 2 |
|
| 10 | + * of the License, or (at your option) any later version. |
|
| 11 | + * This program is distributed in the hope that it will be useful, |
|
| 12 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
| 13 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
| 14 | + * GNU General Public License for more details. |
|
| 15 | + * You should have received a copy of the GNU General Public License |
|
| 16 | + * along with this program; if not, write to the Free Software |
|
| 17 | + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. |
|
| 18 | + */ |
|
| 19 | 19 | |
| 20 | 20 | namespace plunner\Console\Commands\Optimise; |
| 21 | 21 | |
@@ -244,7 +244,7 @@ discard block |
||
| 244 | 244 | $timeSlots = array_keys($meetingsAvailabilityS); |
| 245 | 245 | if (count($timeSlots) != $this->timeSlots) |
| 246 | 246 | throw new OptimiseException('timeSlots different from timeSlots set'); |
| 247 | - $meetingsAvailability[$key] = self::arrayPad($meetingsAvailabilityS, $this->timeSlots + $this->maxTimeSlots, 0); |
|
| 247 | + $meetingsAvailability[ $key ] = self::arrayPad($meetingsAvailabilityS, $this->timeSlots + $this->maxTimeSlots, 0); |
|
| 248 | 248 | } |
| 249 | 249 | |
| 250 | 250 | $this->meetingsAvailability = $meetingsAvailability; |
@@ -261,7 +261,7 @@ discard block |
||
| 261 | 261 | { |
| 262 | 262 | $len = $len - count($array); |
| 263 | 263 | for ($i = 0; $i < $len; $i++) |
| 264 | - $array[] = $pad; |
|
| 264 | + $array[ ] = $pad; |
|
| 265 | 265 | return $array; |
| 266 | 266 | } |
| 267 | 267 | |
@@ -286,7 +286,7 @@ discard block |
||
| 286 | 286 | throw new OptimiseException('meetings different from meetings set'); |
| 287 | 287 | } |
| 288 | 288 | foreach ($meetingsDuration as $duration) { |
| 289 | - $duration = (int)$duration; //TODO fix this (fix for optimise) |
|
| 289 | + $duration = (int) $duration; //TODO fix this (fix for optimise) |
|
| 290 | 290 | if (!is_int($duration) || $duration <= 0) |
| 291 | 291 | throw new OptimiseException('duration is not integer or it is not >0'); |
| 292 | 292 | } |
@@ -318,7 +318,7 @@ discard block |
||
| 318 | 318 | if (count($timeSlots) != $this->timeSlots) |
| 319 | 319 | throw new OptimiseException('timeSlots different from timeSlots set'); |
| 320 | 320 | |
| 321 | - $usersAvailability[$key] = self::arrayPad($usersAvailabilityS, $this->timeSlots + $this->maxTimeSlots, 0); |
|
| 321 | + $usersAvailability[ $key ] = self::arrayPad($usersAvailabilityS, $this->timeSlots + $this->maxTimeSlots, 0); |
|
| 322 | 322 | } |
| 323 | 323 | |
| 324 | 324 | $this->usersAvailability = $usersAvailability; |
@@ -361,7 +361,7 @@ discard block |
||
| 361 | 361 | { |
| 362 | 362 | $this->writeData(); |
| 363 | 363 | $this->writeModelFile(); |
| 364 | - $event = $this->schedule->exec('glpsol --math ' . $this->path->getModelPath())->sendOutputTo($this->path->getOutputPath())->after(function () { |
|
| 364 | + $event = $this->schedule->exec('glpsol --math '.$this->path->getModelPath())->sendOutputTo($this->path->getOutputPath())->after(function() { |
|
| 365 | 365 | }); //this just to execute in foreground |
| 366 | 366 | if ($event->isDue($this->laravel)) |
| 367 | 367 | $event->run($this->laravel); |
@@ -388,8 +388,8 @@ discard block |
||
| 388 | 388 | */ |
| 389 | 389 | private function checkData() |
| 390 | 390 | { |
| 391 | - $this->checkArrayProprieties(['users', 'meetings', 'meetingsAvailability', 'meetingsDuration', 'usersAvailability', 'usersMeetings']); |
|
| 392 | - $this->checkIntProprieties(['timeSlots', 'maxTimeSlots']); |
|
| 391 | + $this->checkArrayProprieties([ 'users', 'meetings', 'meetingsAvailability', 'meetingsDuration', 'usersAvailability', 'usersMeetings' ]); |
|
| 392 | + $this->checkIntProprieties([ 'timeSlots', 'maxTimeSlots' ]); |
|
| 393 | 393 | } |
| 394 | 394 | |
| 395 | 395 | /** |
@@ -400,7 +400,7 @@ discard block |
||
| 400 | 400 | { |
| 401 | 401 | foreach ($proprieties as $propriety) |
| 402 | 402 | if (count($this->$propriety) == 0) |
| 403 | - throw new OptimiseException($propriety . ' property is not set correctly'); |
|
| 403 | + throw new OptimiseException($propriety.' property is not set correctly'); |
|
| 404 | 404 | } |
| 405 | 405 | |
| 406 | 406 | /** |
@@ -411,7 +411,7 @@ discard block |
||
| 411 | 411 | { |
| 412 | 412 | foreach ($proprieties as $propriety) |
| 413 | 413 | if (!is_int($this->$propriety) || $this->$propriety <= 0) |
| 414 | - throw new OptimiseException($propriety . ' property is not set correctly'); |
|
| 414 | + throw new OptimiseException($propriety.' property is not set correctly'); |
|
| 415 | 415 | } |
| 416 | 416 | |
| 417 | 417 | /** |
@@ -429,13 +429,13 @@ discard block |
||
| 429 | 429 | */ |
| 430 | 430 | static private function writeCSVArrayNoKey($file, $data) |
| 431 | 431 | { |
| 432 | - $f = function ($fp, $data) { |
|
| 432 | + $f = function($fp, $data) { |
|
| 433 | 433 | foreach ($data as $field) { |
| 434 | - fputcsv($fp, [$field]); |
|
| 434 | + fputcsv($fp, [ $field ]); |
|
| 435 | 435 | } |
| 436 | 436 | }; |
| 437 | 437 | |
| 438 | - self::writeCSV($file, $data, ['i'], $f); |
|
| 438 | + self::writeCSV($file, $data, [ 'i' ], $f); |
|
| 439 | 439 | } |
| 440 | 440 | |
| 441 | 441 | /** |
@@ -484,13 +484,13 @@ discard block |
||
| 484 | 484 | */ |
| 485 | 485 | static private function writeCSVArray($file, $data, $name) |
| 486 | 486 | { |
| 487 | - $f = function ($fp, $data) { |
|
| 487 | + $f = function($fp, $data) { |
|
| 488 | 488 | foreach ($data as $key => $field) { |
| 489 | - fputcsv($fp, [$key, $field]); |
|
| 489 | + fputcsv($fp, [ $key, $field ]); |
|
| 490 | 490 | } |
| 491 | 491 | }; |
| 492 | 492 | |
| 493 | - self::writeCSV($file, $data, ['i', $name], $f); |
|
| 493 | + self::writeCSV($file, $data, [ 'i', $name ], $f); |
|
| 494 | 494 | } |
| 495 | 495 | |
| 496 | 496 | /** |
@@ -509,14 +509,14 @@ discard block |
||
| 509 | 509 | */ |
| 510 | 510 | static private function writeCSVMatrix($file, $data, $name) |
| 511 | 511 | { |
| 512 | - $f = function ($fp, $data) { |
|
| 512 | + $f = function($fp, $data) { |
|
| 513 | 513 | foreach ($data as $key => $field) { |
| 514 | 514 | foreach ($field as $key2 => $field2) |
| 515 | - fputcsv($fp, [$key, $key2, $field2]); |
|
| 515 | + fputcsv($fp, [ $key, $key2, $field2 ]); |
|
| 516 | 516 | } |
| 517 | 517 | }; |
| 518 | 518 | |
| 519 | - self::writeCSV($file, $data, ['i', 'j', $name], $f); |
|
| 519 | + self::writeCSV($file, $data, [ 'i', 'j', $name ], $f); |
|
| 520 | 520 | } |
| 521 | 521 | |
| 522 | 522 | /** |
@@ -545,7 +545,7 @@ discard block |
||
| 545 | 545 | $f = @fopen($this->path->getModelPath(), "w"); |
| 546 | 546 | if (!$f) |
| 547 | 547 | throw new OptimiseException('problem during creation of a file'); |
| 548 | - fwrite($f, str_replace($strReplaceS, $strReplaceR, file_get_contents(__DIR__ . "/model.stub"))); |
|
| 548 | + fwrite($f, str_replace($strReplaceS, $strReplaceR, file_get_contents(__DIR__."/model.stub"))); |
|
| 549 | 549 | fclose($f); |
| 550 | 550 | } |
| 551 | 551 | |
@@ -572,7 +572,7 @@ discard block |
||
| 572 | 572 | if (!$handle) |
| 573 | 573 | throw new OptimiseException('problems during reading the file'); |
| 574 | 574 | |
| 575 | - $ret = []; |
|
| 575 | + $ret = [ ]; |
|
| 576 | 576 | fgetcsv($handle); //skip head |
| 577 | 577 | while (($data = fgetcsv($handle)) !== FALSE) { |
| 578 | 578 | if (count($data) != 3) { |
@@ -580,7 +580,7 @@ discard block |
||
| 580 | 580 | throw new OptimiseException('problems during parsing the file'); |
| 581 | 581 | } |
| 582 | 582 | |
| 583 | - $ret[$data[0]][$data[1]] = $data[2]; |
|
| 583 | + $ret[ $data[ 0 ] ][ $data[ 1 ] ] = $data[ 2 ]; |
|
| 584 | 584 | } |
| 585 | 585 | |
| 586 | 586 | fclose($handle); |
@@ -85,8 +85,8 @@ 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) * |
|
| 89 | - config('app.timeslots.duration')) . 'S')); |
|
| 88 | + $this->endTime->add(new \DateInterval('PT'.(($this->max_time_slots + $this->time_slots) * |
|
| 89 | + config('app.timeslots.duration')).'S')); |
|
| 90 | 90 | } |
| 91 | 91 | |
| 92 | 92 | /** |
@@ -158,9 +158,9 @@ discard block |
||
| 158 | 158 | $solver = $this->setData($solver); |
| 159 | 159 | $solver = $solver->solve(); |
| 160 | 160 | $this->solver = $solver; |
| 161 | - }catch(OptimiseException $e) { |
|
| 161 | + } catch (OptimiseException $e) { |
|
| 162 | 162 | throw $e; |
| 163 | - }catch (\Exception $e) { |
|
| 163 | + } catch (\Exception $e) { |
|
| 164 | 164 | \Event::fire(new ErrorEvent($this->company, $e->getMessage())); |
| 165 | 165 | throw new OptimiseException('Optimising error', 0, $e); |
| 166 | 166 | //TODO catch specif exception |
@@ -204,7 +204,7 @@ discard block |
||
| 204 | 204 | { |
| 205 | 205 | //since we consider busy timeslots, we need to get all users |
| 206 | 206 | $users = $this->company->employees->pluck('id')->toArray(); |
| 207 | - if(count($users) == 0) |
|
| 207 | + if (count($users) == 0) |
|
| 208 | 208 | throw ((new OptimiseException("No users for this company"))->withEmpty(true)); |
| 209 | 209 | return $solver->setUsers($users); |
| 210 | 210 | } |
@@ -220,9 +220,9 @@ discard block |
||
| 220 | 220 | * @var $meetings \Illuminate\Support\Collection |
| 221 | 221 | */ |
| 222 | 222 | $meetings = collect($this->company->getMeetingsTimeSlots($this->startTime, $this->endTime)); |
| 223 | - if($meetings->count() == 0) |
|
| 223 | + if ($meetings->count() == 0) |
|
| 224 | 224 | throw ((new OptimiseException("No meetings for this week"))->withEmpty(true)); |
| 225 | - $timeslots = $meetings->groupBy('id')->map(function ($item) { //convert timeslots |
|
| 225 | + $timeslots = $meetings->groupBy('id')->map(function($item) { //convert timeslots |
|
| 226 | 226 | return $this->durationConverter($this->timeSlotsConverter($item)); |
| 227 | 227 | }); |
| 228 | 228 | return $solver->setMeetings($timeslots->keys()->toArray()) |
@@ -236,8 +236,8 @@ discard block |
||
| 236 | 236 | */ |
| 237 | 237 | private function durationConverter($item) |
| 238 | 238 | { |
| 239 | - return $item->each(function ($item2) { |
|
| 240 | - $item2->duration = $this->convertDuration((int)$item2->duration); |
|
| 239 | + return $item->each(function($item2) { |
|
| 240 | + $item2->duration = $this->convertDuration((int) $item2->duration); |
|
| 241 | 241 | return $item2; |
| 242 | 242 | //TODO try catch |
| 243 | 243 | }); |
@@ -249,7 +249,7 @@ discard block |
||
| 249 | 249 | */ |
| 250 | 250 | static private function convertDuration($duration) |
| 251 | 251 | { |
| 252 | - return (int)ceil($duration / config('app.timeslots.duration')); |
|
| 252 | + return (int) ceil($duration / config('app.timeslots.duration')); |
|
| 253 | 253 | } |
| 254 | 254 | |
| 255 | 255 | /** |
@@ -258,7 +258,7 @@ discard block |
||
| 258 | 258 | */ |
| 259 | 259 | private function timeSlotsConverter($item) |
| 260 | 260 | { |
| 261 | - return $item->each(function ($item2) { |
|
| 261 | + return $item->each(function($item2) { |
|
| 262 | 262 | $item2->time_start = $this->toTimeSlot($item2->time_start); |
| 263 | 263 | $item2->time_end = $this->toTimeSlot($item2->time_end); |
| 264 | 264 | return $item2; |
@@ -276,13 +276,13 @@ discard block |
||
| 276 | 276 | $dateTime = new \DateTime($time); |
| 277 | 277 | $diff = $dateTime->diff($this->startTime); |
| 278 | 278 | $diff = explode(':', $diff->format('%R:%d:%h:%i:%s')); |
| 279 | - $diff = $diff[1] * 86400 + $diff[2] * 3600 + $diff[3] * 60 + $diff[4]; |
|
| 279 | + $diff = $diff[ 1 ] * 86400 + $diff[ 2 ] * 3600 + $diff[ 3 ] * 60 + $diff[ 4 ]; |
|
| 280 | 280 | //if($diff[0] != '-' && $diff != 0) |
| 281 | 281 | // throw new OptimiseException('timeslot time <= startTime'); |
| 282 | 282 | //TODO fix check |
| 283 | 283 | //TODO check if diff makes sense |
| 284 | 284 | //TODO check upper limit |
| 285 | - return (int)(round($diff / config('app.timeslots.duration')) + 1); //TODO can round cause overlaps? |
|
| 285 | + return (int) (round($diff / config('app.timeslots.duration')) + 1); //TODO can round cause overlaps? |
|
| 286 | 286 | } |
| 287 | 287 | |
| 288 | 288 | /** |
@@ -292,7 +292,7 @@ discard block |
||
| 292 | 292 | */ |
| 293 | 293 | static private function getAvailabilityArray(\Illuminate\Support\Collection $timeSlots, $timeslotsN, $free = true) |
| 294 | 294 | { |
| 295 | - $ret = []; |
|
| 295 | + $ret = [ ]; |
|
| 296 | 296 | foreach ($timeSlots as $id => $timeSlots2) { |
| 297 | 297 | $ret = self::fillTimeSlots($ret, $id, $timeSlots2, $free ? '1' : '0'); |
| 298 | 298 | $ret = self::fillRow($ret, $id, $timeslotsN, $free ? '0' : '1'); |
@@ -311,9 +311,9 @@ discard block |
||
| 311 | 311 | static private function fillTimeSlots(array $array, $id, \Illuminate\Support\Collection $timeSlots, $fill = '0') |
| 312 | 312 | { |
| 313 | 313 | foreach ($timeSlots as $timeSlot) { |
| 314 | - if (!isset($array[$id])) |
|
| 315 | - $array[$id] = []; |
|
| 316 | - $array[$id] = self::arrayPadInterval($array[$id], $timeSlot->time_start, $timeSlot->time_end, $fill); |
|
| 314 | + if (!isset($array[ $id ])) |
|
| 315 | + $array[ $id ] = [ ]; |
|
| 316 | + $array[ $id ] = self::arrayPadInterval($array[ $id ], $timeSlot->time_start, $timeSlot->time_end, $fill); |
|
| 317 | 317 | } |
| 318 | 318 | return $array; |
| 319 | 319 | } |
@@ -328,7 +328,7 @@ discard block |
||
| 328 | 328 | static private function arrayPadInterval(array $array, $from, $to, $pad = '0') |
| 329 | 329 | { |
| 330 | 330 | for ($i = $from; $i < $to; $i++) |
| 331 | - $array[$i] = $pad; |
|
| 331 | + $array[ $i ] = $pad; |
|
| 332 | 332 | return $array; |
| 333 | 333 | } |
| 334 | 334 | |
@@ -341,8 +341,8 @@ discard block |
||
| 341 | 341 | static private function fillRow(array $array, $id, $until, $fill = '0') |
| 342 | 342 | { |
| 343 | 343 | for ($i = 1; $i <= $until; $i++) { |
| 344 | - if (!isset($array[$id][$i])) |
|
| 345 | - $array[$id][$i] = $fill; |
|
| 344 | + if (!isset($array[ $id ][ $i ])) |
|
| 345 | + $array[ $id ][ $i ] = $fill; |
|
| 346 | 346 | } |
| 347 | 347 | |
| 348 | 348 | return $array; |
@@ -359,9 +359,9 @@ discard block |
||
| 359 | 359 | * @var $users \Illuminate\Support\Collection |
| 360 | 360 | */ |
| 361 | 361 | $users = collect($this->company->getEmployeesTimeSlots($this->startTime, $this->endTime)); |
| 362 | - if($users->count() == 0) |
|
| 362 | + if ($users->count() == 0) |
|
| 363 | 363 | throw ((new OptimiseException("No users for this company"))->withEmpty(true)); |
| 364 | - $timeslots = $users->groupBy('id')->map(function ($item) { //convert timeslots |
|
| 364 | + $timeslots = $users->groupBy('id')->map(function($item) { //convert timeslots |
|
| 365 | 365 | return $this->timeSlotsConverter($item); |
| 366 | 366 | }); |
| 367 | 367 | return $solver->setUsersAvailability(self::getAvailabilityArray($timeslots, $this->time_slots, false)); |
@@ -380,7 +380,7 @@ discard block |
||
| 380 | 380 | * @var $usersMeetings \Illuminate\Support\Collection |
| 381 | 381 | */ |
| 382 | 382 | $usersMeetings = collect($this->company->getUsersMeetings($users, $meetings))->groupBy('employee_id'); |
| 383 | - if($usersMeetings->count() == 0) |
|
| 383 | + if ($usersMeetings->count() == 0) |
|
| 384 | 384 | throw ((new OptimiseException("No users for any meeting"))->withEmpty(true)); |
| 385 | 385 | |
| 386 | 386 | return $solver->setUsersMeetings(self::getUsersMeetingsArray($users, $meetings, $usersMeetings)); |
@@ -394,14 +394,14 @@ discard block |
||
| 394 | 394 | */ |
| 395 | 395 | static private function getUsersMeetingsArray($users, $meetings, \Illuminate\Support\Collection $usersMeetings) |
| 396 | 396 | { |
| 397 | - $ret = []; |
|
| 397 | + $ret = [ ]; |
|
| 398 | 398 | foreach ($users as $user) { |
| 399 | 399 | $usersMeetingsTmp = $usersMeetings->get($user); |
| 400 | 400 | foreach ($meetings as $meeting) { |
| 401 | 401 | if ($usersMeetingsTmp->contains('meeting_id', $meeting)) { |
| 402 | - $ret[$user][$meeting] = 1; |
|
| 402 | + $ret[ $user ][ $meeting ] = 1; |
|
| 403 | 403 | } else { |
| 404 | - $ret[$user][$meeting] = 0; |
|
| 404 | + $ret[ $user ][ $meeting ] = 0; |
|
| 405 | 405 | } |
| 406 | 406 | } |
| 407 | 407 | } |
@@ -442,7 +442,7 @@ discard block |
||
| 442 | 442 | { |
| 443 | 443 | $meetings = $solver->getYResults(); |
| 444 | 444 | foreach ($meetings as $id => $meeting) { |
| 445 | - $meetingO = \plunner\Meeting::findOrFail($id);//TODO catch error |
|
| 445 | + $meetingO = \plunner\Meeting::findOrFail($id); //TODO catch error |
|
| 446 | 446 | $meetingO->start_time = $this->toDateTime(array_search('1', $meeting)); |
| 447 | 447 | $meetingO->save(); |
| 448 | 448 | } |
@@ -455,7 +455,7 @@ discard block |
||
| 455 | 455 | private function toDateTime($timeslot) |
| 456 | 456 | { |
| 457 | 457 | $ret = clone $this->startTime; |
| 458 | - return $ret->add(new \DateInterval('PT' . (($timeslot - 1) * config('app.timeslots.duration')) . 'S')); |
|
| 458 | + return $ret->add(new \DateInterval('PT'.(($timeslot - 1) * config('app.timeslots.duration')).'S')); |
|
| 459 | 459 | } |
| 460 | 460 | |
| 461 | 461 | /** |
@@ -467,7 +467,7 @@ discard block |
||
| 467 | 467 | foreach ($employeesMeetings as $eId => $employeeMeetings) { |
| 468 | 468 | $employee = \plunner\Employee::findOrFail($eId); |
| 469 | 469 | $employeeMeetings = collect($employeeMeetings); |
| 470 | - $employeeMeetings = $employeeMeetings->filter(function ($item) { |
|
| 470 | + $employeeMeetings = $employeeMeetings->filter(function($item) { |
|
| 471 | 471 | return $item == 1; |
| 472 | 472 | }); |
| 473 | 473 | $employee->meetings()->attach($employeeMeetings->keys()->toArray()); |
@@ -158,9 +158,9 @@ discard block |
||
| 158 | 158 | $solver = $this->setData($solver); |
| 159 | 159 | $solver = $solver->solve(); |
| 160 | 160 | $this->solver = $solver; |
| 161 | - }catch(OptimiseException $e) { |
|
| 161 | + } catch(OptimiseException $e) { |
|
| 162 | 162 | throw $e; |
| 163 | - }catch (\Exception $e) { |
|
| 163 | + } catch (\Exception $e) { |
|
| 164 | 164 | \Event::fire(new ErrorEvent($this->company, $e->getMessage())); |
| 165 | 165 | throw new OptimiseException('Optimising error', 0, $e); |
| 166 | 166 | //TODO catch specif exception |
@@ -204,8 +204,9 @@ discard block |
||
| 204 | 204 | { |
| 205 | 205 | //since we consider busy timeslots, we need to get all users |
| 206 | 206 | $users = $this->company->employees->pluck('id')->toArray(); |
| 207 | - if(count($users) == 0) |
|
| 208 | - throw ((new OptimiseException("No users for this company"))->withEmpty(true)); |
|
| 207 | + if(count($users) == 0) { |
|
| 208 | + throw ((new OptimiseException("No users for this company"))->withEmpty(true)); |
|
| 209 | + } |
|
| 209 | 210 | return $solver->setUsers($users); |
| 210 | 211 | } |
| 211 | 212 | |
@@ -220,8 +221,9 @@ discard block |
||
| 220 | 221 | * @var $meetings \Illuminate\Support\Collection |
| 221 | 222 | */ |
| 222 | 223 | $meetings = collect($this->company->getMeetingsTimeSlots($this->startTime, $this->endTime)); |
| 223 | - if($meetings->count() == 0) |
|
| 224 | - throw ((new OptimiseException("No meetings for this week"))->withEmpty(true)); |
|
| 224 | + if($meetings->count() == 0) { |
|
| 225 | + throw ((new OptimiseException("No meetings for this week"))->withEmpty(true)); |
|
| 226 | + } |
|
| 225 | 227 | $timeslots = $meetings->groupBy('id')->map(function ($item) { //convert timeslots |
| 226 | 228 | return $this->durationConverter($this->timeSlotsConverter($item)); |
| 227 | 229 | }); |
@@ -311,8 +313,9 @@ discard block |
||
| 311 | 313 | static private function fillTimeSlots(array $array, $id, \Illuminate\Support\Collection $timeSlots, $fill = '0') |
| 312 | 314 | { |
| 313 | 315 | foreach ($timeSlots as $timeSlot) { |
| 314 | - if (!isset($array[$id])) |
|
| 315 | - $array[$id] = []; |
|
| 316 | + if (!isset($array[$id])) { |
|
| 317 | + $array[$id] = []; |
|
| 318 | + } |
|
| 316 | 319 | $array[$id] = self::arrayPadInterval($array[$id], $timeSlot->time_start, $timeSlot->time_end, $fill); |
| 317 | 320 | } |
| 318 | 321 | return $array; |
@@ -327,8 +330,9 @@ discard block |
||
| 327 | 330 | */ |
| 328 | 331 | static private function arrayPadInterval(array $array, $from, $to, $pad = '0') |
| 329 | 332 | { |
| 330 | - for ($i = $from; $i < $to; $i++) |
|
| 331 | - $array[$i] = $pad; |
|
| 333 | + for ($i = $from; $i < $to; $i++) { |
|
| 334 | + $array[$i] = $pad; |
|
| 335 | + } |
|
| 332 | 336 | return $array; |
| 333 | 337 | } |
| 334 | 338 | |
@@ -341,8 +345,9 @@ discard block |
||
| 341 | 345 | static private function fillRow(array $array, $id, $until, $fill = '0') |
| 342 | 346 | { |
| 343 | 347 | for ($i = 1; $i <= $until; $i++) { |
| 344 | - if (!isset($array[$id][$i])) |
|
| 345 | - $array[$id][$i] = $fill; |
|
| 348 | + if (!isset($array[$id][$i])) { |
|
| 349 | + $array[$id][$i] = $fill; |
|
| 350 | + } |
|
| 346 | 351 | } |
| 347 | 352 | |
| 348 | 353 | return $array; |
@@ -359,8 +364,9 @@ discard block |
||
| 359 | 364 | * @var $users \Illuminate\Support\Collection |
| 360 | 365 | */ |
| 361 | 366 | $users = collect($this->company->getEmployeesTimeSlots($this->startTime, $this->endTime)); |
| 362 | - if($users->count() == 0) |
|
| 363 | - throw ((new OptimiseException("No users for this company"))->withEmpty(true)); |
|
| 367 | + if($users->count() == 0) { |
|
| 368 | + throw ((new OptimiseException("No users for this company"))->withEmpty(true)); |
|
| 369 | + } |
|
| 364 | 370 | $timeslots = $users->groupBy('id')->map(function ($item) { //convert timeslots |
| 365 | 371 | return $this->timeSlotsConverter($item); |
| 366 | 372 | }); |
@@ -380,8 +386,9 @@ discard block |
||
| 380 | 386 | * @var $usersMeetings \Illuminate\Support\Collection |
| 381 | 387 | */ |
| 382 | 388 | $usersMeetings = collect($this->company->getUsersMeetings($users, $meetings))->groupBy('employee_id'); |
| 383 | - if($usersMeetings->count() == 0) |
|
| 384 | - throw ((new OptimiseException("No users for any meeting"))->withEmpty(true)); |
|
| 389 | + if($usersMeetings->count() == 0) { |
|
| 390 | + throw ((new OptimiseException("No users for any meeting"))->withEmpty(true)); |
|
| 391 | + } |
|
| 385 | 392 | |
| 386 | 393 | return $solver->setUsersMeetings(self::getUsersMeetingsArray($users, $meetings, $usersMeetings)); |
| 387 | 394 | } |
@@ -70,17 +70,17 @@ discard block |
||
| 70 | 70 | */ |
| 71 | 71 | private function makeForeground(Company $company) |
| 72 | 72 | { |
| 73 | - $this->info('Optimisation company ' . $company->id . ' started'); |
|
| 73 | + $this->info('Optimisation company '.$company->id.' started'); |
|
| 74 | 74 | try { |
| 75 | 75 | (new Optimise($company, $this->schedule, $this->laravel))->optimise()->save(); |
| 76 | - $this->info('Optimisation ' . $company->id . ' completed'); |
|
| 77 | - }catch(OptimiseException $e){ |
|
| 78 | - if($e->isEmpty()) |
|
| 79 | - $this->warn('Company ' . $company->id . ' has no sufficient data'); |
|
| 76 | + $this->info('Optimisation '.$company->id.' completed'); |
|
| 77 | + } catch (OptimiseException $e) { |
|
| 78 | + if ($e->isEmpty()) |
|
| 79 | + $this->warn('Company '.$company->id.' has no sufficient data'); |
|
| 80 | 80 | else |
| 81 | - $this->error('Error during optimisation of company ' . $company->id .': '. $e->getMessage()); |
|
| 82 | - }catch(\Exception $e) { |
|
| 83 | - $this->error('Error during optimisation of company ' . $company->id .': '. $e->getMessage()); |
|
| 81 | + $this->error('Error during optimisation of company '.$company->id.': '.$e->getMessage()); |
|
| 82 | + } catch (\Exception $e) { |
|
| 83 | + $this->error('Error during optimisation of company '.$company->id.': '.$e->getMessage()); |
|
| 84 | 84 | } |
| 85 | 85 | } |
| 86 | 86 | |
@@ -105,7 +105,7 @@ discard block |
||
| 105 | 105 | */ |
| 106 | 106 | private function makeBackground(Company $company) |
| 107 | 107 | { |
| 108 | - $event = $this->schedule->command('optimise:meetings ' . $company->id)->withoutOverlapping(); |
|
| 108 | + $event = $this->schedule->command('optimise:meetings '.$company->id)->withoutOverlapping(); |
|
| 109 | 109 | if ($event->isDue($this->laravel)) |
| 110 | 110 | $event->run($this->laravel); |
| 111 | 111 | } |
@@ -58,10 +58,11 @@ discard block |
||
| 58 | 58 | //TODO insert a timeout |
| 59 | 59 | //TODO try...catch with destruct |
| 60 | 60 | $companyId = $this->argument('companyId'); |
| 61 | - if (is_numeric($companyId)) |
|
| 62 | - $this->makeForeground(Company::findOrFail($companyId)); |
|
| 63 | - else |
|
| 64 | - $this->syncAll(); |
|
| 61 | + if (is_numeric($companyId)) { |
|
| 62 | + $this->makeForeground(Company::findOrFail($companyId)); |
|
| 63 | + } else { |
|
| 64 | + $this->syncAll(); |
|
| 65 | + } |
|
| 65 | 66 | } |
| 66 | 67 | |
| 67 | 68 | /** |
@@ -74,12 +75,13 @@ discard block |
||
| 74 | 75 | try { |
| 75 | 76 | (new Optimise($company, $this->schedule, $this->laravel))->optimise()->save(); |
| 76 | 77 | $this->info('Optimisation ' . $company->id . ' completed'); |
| 77 | - }catch(OptimiseException $e){ |
|
| 78 | - if($e->isEmpty()) |
|
| 79 | - $this->warn('Company ' . $company->id . ' has no sufficient data'); |
|
| 80 | - else |
|
| 81 | - $this->error('Error during optimisation of company ' . $company->id .': '. $e->getMessage()); |
|
| 82 | - }catch(\Exception $e) { |
|
| 78 | + } catch(OptimiseException $e){ |
|
| 79 | + if($e->isEmpty()) { |
|
| 80 | + $this->warn('Company ' . $company->id . ' has no sufficient data'); |
|
| 81 | + } else { |
|
| 82 | + $this->error('Error during optimisation of company ' . $company->id .': '. $e->getMessage()); |
|
| 83 | + } |
|
| 84 | + } catch(\Exception $e) { |
|
| 83 | 85 | $this->error('Error during optimisation of company ' . $company->id .': '. $e->getMessage()); |
| 84 | 86 | } |
| 85 | 87 | } |
@@ -90,13 +92,15 @@ discard block |
||
| 90 | 92 | if ($this->option('background')) { |
| 91 | 93 | \Log::debug(self::BACKGROUND_MOD_MEX); |
| 92 | 94 | $this->info(self::BACKGROUND_MOD_MEX); |
| 93 | - foreach ($companies as $company) |
|
| 94 | - $this->makeBackground($company); |
|
| 95 | + foreach ($companies as $company) { |
|
| 96 | + $this->makeBackground($company); |
|
| 97 | + } |
|
| 95 | 98 | \Log::debug(self::BACKGROUND_COMPLETED_MEX); |
| 96 | 99 | $this->info(self::BACKGROUND_COMPLETED_MEX); |
| 97 | - } else |
|
| 98 | - foreach ($companies as $company) |
|
| 100 | + } else { |
|
| 101 | + foreach ($companies as $company) |
|
| 99 | 102 | $this->makeForeground($company); |
| 103 | + } |
|
| 100 | 104 | } |
| 101 | 105 | |
| 102 | 106 | /** |
@@ -106,7 +110,8 @@ discard block |
||
| 106 | 110 | private function makeBackground(Company $company) |
| 107 | 111 | { |
| 108 | 112 | $event = $this->schedule->command('optimise:meetings ' . $company->id)->withoutOverlapping(); |
| 109 | - if ($event->isDue($this->laravel)) |
|
| 110 | - $event->run($this->laravel); |
|
| 113 | + if ($event->isDue($this->laravel)) { |
|
| 114 | + $event->run($this->laravel); |
|
| 115 | + } |
|
| 111 | 116 | } |
| 112 | 117 | } |
@@ -36,7 +36,7 @@ |
||
| 36 | 36 | * @param Exception $previous |
| 37 | 37 | * @param bool $empty |
| 38 | 38 | */ |
| 39 | - public function __construct($message = "", $code = 0, Exception $previous = null, $empty = false) |
|
| 39 | + public function __construct($message = "", $code = 0, Exception $previous = null, $empty = false) |
|
| 40 | 40 | { |
| 41 | 41 | parent::__construct($message, $code, $previous); |
| 42 | 42 | $this->empty = $empty; |