@@ -28,7 +28,7 @@ discard block |
||
| 28 | 28 | * |
| 29 | 29 | * @return void |
| 30 | 30 | */ |
| 31 | - public function __construct($app) |
|
| 31 | + public function __construct ($app) |
|
| 32 | 32 | { |
| 33 | 33 | $this->app = $app; |
| 34 | 34 | } |
@@ -41,9 +41,9 @@ discard block |
||
| 41 | 41 | * @param string|\Carbon\Carbon $end_at |
| 42 | 42 | * @return bool |
| 43 | 43 | */ |
| 44 | - public function hasScheduleBetween($model_type, $start_at, $end_at) |
|
| 44 | + public function hasScheduleBetween ($model_type, $start_at, $end_at) |
|
| 45 | 45 | { |
| 46 | - if(!Config::get('scheduler.enable_schedule_conflict')) |
|
| 46 | + if (!Config::get('scheduler.enable_schedule_conflict')) |
|
| 47 | 47 | return false; |
| 48 | 48 | |
| 49 | 49 | return !is_null( |
@@ -65,7 +65,7 @@ discard block |
||
| 65 | 65 | * Se for nulo, ele busca a referencia da config. |
| 66 | 66 | * @return array |
| 67 | 67 | */ |
| 68 | - public function availableToday($model_type, $duration, $openingTime = null) |
|
| 68 | + public function availableToday ($model_type, $duration, $openingTime = null) |
|
| 69 | 69 | { |
| 70 | 70 | return $this->availableOn($model_type, Carbon::now(), $duration, $openingTime); |
| 71 | 71 | } |
@@ -81,14 +81,14 @@ discard block |
||
| 81 | 81 | * Se for nulo, ele busca a referencia da config. |
| 82 | 82 | * @return array |
| 83 | 83 | */ |
| 84 | - public function availableOn($model_type, $today, $durationMinutes, $openingTime = null) |
|
| 84 | + public function availableOn ($model_type, $today, $durationMinutes, $openingTime = null) |
|
| 85 | 85 | { |
| 86 | 86 | $openingTime = $openingTime ?? Carbon::parse(Config::get('scheduler.opening_time'))->setDateFrom($today); |
| 87 | 87 | $closingTime = Carbon::parse(Config::get('scheduler.closing_time'))->setDateFrom($today); |
| 88 | 88 | |
| 89 | - $livres = []; |
|
| 89 | + $livres = [ ]; |
|
| 90 | 90 | $today = Carbon::parse($today->toDateString()); |
| 91 | - while($openingTime <= $closingTime) |
|
| 91 | + while ($openingTime <= $closingTime) |
|
| 92 | 92 | { |
| 93 | 93 | $add = true; |
| 94 | 94 | |
@@ -96,26 +96,26 @@ discard block |
||
| 96 | 96 | $closing = Carbon::parse($openingTime->toDateTimeString())->addMinutes($durationMinutes); |
| 97 | 97 | |
| 98 | 98 | foreach (Schedule::orderBy('start_at', 'DESC')->cursor() as $schedule) { |
| 99 | - if($schedule->model_type != $model_type) |
|
| 99 | + if ($schedule->model_type != $model_type) |
|
| 100 | 100 | continue; |
| 101 | 101 | |
| 102 | 102 | $start = Carbon::parse($schedule->start_at); |
| 103 | 103 | $begin = Carbon::parse($start->toDateString()); |
| 104 | 104 | |
| 105 | - if($begin->greaterThan($today)) |
|
| 105 | + if ($begin->greaterThan($today)) |
|
| 106 | 106 | break; |
| 107 | 107 | |
| 108 | - if($begin->notEqualTo($today)) |
|
| 108 | + if ($begin->notEqualTo($today)) |
|
| 109 | 109 | continue; |
| 110 | 110 | |
| 111 | 111 | $end = Carbon::parse($schedule->end_at); |
| 112 | 112 | |
| 113 | - if($this->isShouldntAdd($opening, $closing, $start, $end)) |
|
| 113 | + if ($this->isShouldntAdd($opening, $closing, $start, $end)) |
|
| 114 | 114 | $add = false; |
| 115 | 115 | } |
| 116 | 116 | |
| 117 | - if($add && $closing->lessThanOrEqualTo($closingTime)) |
|
| 118 | - $livres[] = [ |
|
| 117 | + if ($add && $closing->lessThanOrEqualTo($closingTime)) |
|
| 118 | + $livres[ ] = [ |
|
| 119 | 119 | 'start_at' => $opening, |
| 120 | 120 | 'end_at' => $closing |
| 121 | 121 | ]; |
@@ -135,7 +135,7 @@ discard block |
||
| 135 | 135 | * @param \Carbon\Carbon $end |
| 136 | 136 | * @return boolean |
| 137 | 137 | */ |
| 138 | - private function isShouldntAdd($opening, $closing, $start, $end) |
|
| 138 | + private function isShouldntAdd ($opening, $closing, $start, $end) |
|
| 139 | 139 | { |
| 140 | 140 | return $start <= $opening && $end >= $closing; |
| 141 | 141 | } |
@@ -43,8 +43,9 @@ discard block |
||
| 43 | 43 | */ |
| 44 | 44 | public function hasScheduleBetween($model_type, $start_at, $end_at) |
| 45 | 45 | { |
| 46 | - if(!Config::get('scheduler.enable_schedule_conflict')) |
|
| 47 | - return false; |
|
| 46 | + if(!Config::get('scheduler.enable_schedule_conflict')) { |
|
| 47 | + return false; |
|
| 48 | + } |
|
| 48 | 49 | |
| 49 | 50 | return !is_null( |
| 50 | 51 | Schedule::latest() |
@@ -96,29 +97,34 @@ discard block |
||
| 96 | 97 | $closing = Carbon::parse($openingTime->toDateTimeString())->addMinutes($durationMinutes); |
| 97 | 98 | |
| 98 | 99 | foreach (Schedule::orderBy('start_at', 'DESC')->cursor() as $schedule) { |
| 99 | - if($schedule->model_type != $model_type) |
|
| 100 | - continue; |
|
| 100 | + if($schedule->model_type != $model_type) { |
|
| 101 | + continue; |
|
| 102 | + } |
|
| 101 | 103 | |
| 102 | 104 | $start = Carbon::parse($schedule->start_at); |
| 103 | 105 | $begin = Carbon::parse($start->toDateString()); |
| 104 | 106 | |
| 105 | - if($begin->greaterThan($today)) |
|
| 106 | - break; |
|
| 107 | + if($begin->greaterThan($today)) { |
|
| 108 | + break; |
|
| 109 | + } |
|
| 107 | 110 | |
| 108 | - if($begin->notEqualTo($today)) |
|
| 109 | - continue; |
|
| 111 | + if($begin->notEqualTo($today)) { |
|
| 112 | + continue; |
|
| 113 | + } |
|
| 110 | 114 | |
| 111 | 115 | $end = Carbon::parse($schedule->end_at); |
| 112 | 116 | |
| 113 | - if($this->isShouldntAdd($opening, $closing, $start, $end)) |
|
| 114 | - $add = false; |
|
| 117 | + if($this->isShouldntAdd($opening, $closing, $start, $end)) { |
|
| 118 | + $add = false; |
|
| 119 | + } |
|
| 115 | 120 | } |
| 116 | 121 | |
| 117 | - if($add && $closing->lessThanOrEqualTo($closingTime)) |
|
| 118 | - $livres[] = [ |
|
| 122 | + if($add && $closing->lessThanOrEqualTo($closingTime)) { |
|
| 123 | + $livres[] = [ |
|
| 119 | 124 | 'start_at' => $opening, |
| 120 | 125 | 'end_at' => $closing |
| 121 | 126 | ]; |
| 127 | + } |
|
| 122 | 128 | |
| 123 | 129 | $openingTime->addMinutes($durationMinutes); |
| 124 | 130 | } |