@@ -10,124 +10,124 @@ |
||
| 10 | 10 | |
| 11 | 11 | class CustomException extends \Exception |
| 12 | 12 | { |
| 13 | - /** |
|
| 14 | - * Model que não pertence ao usuário |
|
| 15 | - * |
|
| 16 | - * @var mixed |
|
| 17 | - */ |
|
| 18 | - protected $model; |
|
| 19 | - |
|
| 20 | - /** |
|
| 21 | - * Key para o arquivo de tradução de exceções. |
|
| 22 | - * |
|
| 23 | - * @var string |
|
| 24 | - */ |
|
| 25 | - protected $trans; |
|
| 26 | - |
|
| 27 | - /** |
|
| 28 | - * HTTP Status Code |
|
| 29 | - * |
|
| 30 | - * @var int |
|
| 31 | - */ |
|
| 32 | - protected $statusCode; |
|
| 33 | - |
|
| 34 | - /** |
|
| 35 | - * Atributo usado como key para substituir por um texto. |
|
| 36 | - * |
|
| 37 | - * @var array|string |
|
| 38 | - */ |
|
| 39 | - protected $attributes = 'model'; |
|
| 40 | - |
|
| 41 | - /** |
|
| 42 | - * Diz se o alias será no singular ou no plural. |
|
| 43 | - * |
|
| 44 | - * @var string |
|
| 45 | - */ |
|
| 46 | - protected $aliastype = 'singular'; |
|
| 47 | - |
|
| 48 | - /** |
|
| 49 | - * Valor passado para o atributo |
|
| 50 | - * |
|
| 51 | - * @var array|string|null |
|
| 52 | - */ |
|
| 53 | - protected $values = null; |
|
| 54 | - |
|
| 55 | - /** |
|
| 56 | - * Indica se a model será printada com lower case. |
|
| 57 | - * |
|
| 58 | - * @var boolean |
|
| 59 | - */ |
|
| 60 | - protected $lowercase = false; |
|
| 61 | - |
|
| 62 | - /** |
|
| 63 | - * Construtor da exceção |
|
| 64 | - * |
|
| 65 | - * @param mixed $model |
|
| 66 | - */ |
|
| 67 | - public function __construct($model = 'foo') |
|
| 68 | - { |
|
| 69 | - $this->model = $model; |
|
| 70 | - } |
|
| 71 | - |
|
| 72 | - /** |
|
| 73 | - * Render the exception as an HTTP response. |
|
| 74 | - * |
|
| 75 | - * @return \Illuminate\Http\JsonResponse |
|
| 76 | - */ |
|
| 77 | - public function render() |
|
| 78 | - { |
|
| 79 | - return response()-> |
|
| 80 | - /** @scrutinizer ignore-call */ |
|
| 81 | - json([ |
|
| 82 | - 'messages' => trans('scheduler::exceptions.'. $this->trans, $this->parseValues()) |
|
| 83 | - ], $this->statusCode); |
|
| 84 | - } |
|
| 85 | - |
|
| 86 | - /** |
|
| 87 | - * Dá parse nos valores para a string de tradução. |
|
| 88 | - * |
|
| 89 | - * @return array |
|
| 90 | - */ |
|
| 91 | - protected function parseValues() |
|
| 92 | - { |
|
| 93 | - if(is_array($this->attributes) && is_array($this->values)) |
|
| 94 | - return collect($this->attributes)->combine($this->values)->all(); |
|
| 95 | - |
|
| 96 | - return [ $this->attributes => $this->values ?? $this->isLower() ]; |
|
| 97 | - } |
|
| 98 | - |
|
| 99 | - /** |
|
| 100 | - * Verifica se é lowercase e retorna de acordo. |
|
| 101 | - * |
|
| 102 | - * @return string |
|
| 103 | - */ |
|
| 104 | - protected function isLower() |
|
| 105 | - { |
|
| 106 | - return $this->lowercase ? strtolower($this->getAlias()) : $this->getAlias(); |
|
| 107 | - } |
|
| 108 | - |
|
| 109 | - /** |
|
| 110 | - * Retorna o alias da model. |
|
| 111 | - * |
|
| 112 | - * @return string |
|
| 113 | - */ |
|
| 114 | - protected function getAlias() |
|
| 115 | - { |
|
| 116 | - if(is_object($this->model)) |
|
| 117 | - $this->model = get_class($this->model); |
|
| 118 | - |
|
| 119 | - return collect(trans('scheduler::exceptions.aliases.'. $this->aliastype))->search($this->model) ?: 'Recurso'; |
|
| 120 | - } |
|
| 121 | - |
|
| 122 | - /** |
|
| 123 | - * Seta os valores. |
|
| 124 | - * |
|
| 125 | - * @param mixed $values |
|
| 126 | - */ |
|
| 127 | - public function setValues($values) |
|
| 128 | - { |
|
| 129 | - $this->values = $values; |
|
| 130 | - |
|
| 131 | - return $this; |
|
| 132 | - } |
|
| 13 | + /** |
|
| 14 | + * Model que não pertence ao usuário |
|
| 15 | + * |
|
| 16 | + * @var mixed |
|
| 17 | + */ |
|
| 18 | + protected $model; |
|
| 19 | + |
|
| 20 | + /** |
|
| 21 | + * Key para o arquivo de tradução de exceções. |
|
| 22 | + * |
|
| 23 | + * @var string |
|
| 24 | + */ |
|
| 25 | + protected $trans; |
|
| 26 | + |
|
| 27 | + /** |
|
| 28 | + * HTTP Status Code |
|
| 29 | + * |
|
| 30 | + * @var int |
|
| 31 | + */ |
|
| 32 | + protected $statusCode; |
|
| 33 | + |
|
| 34 | + /** |
|
| 35 | + * Atributo usado como key para substituir por um texto. |
|
| 36 | + * |
|
| 37 | + * @var array|string |
|
| 38 | + */ |
|
| 39 | + protected $attributes = 'model'; |
|
| 40 | + |
|
| 41 | + /** |
|
| 42 | + * Diz se o alias será no singular ou no plural. |
|
| 43 | + * |
|
| 44 | + * @var string |
|
| 45 | + */ |
|
| 46 | + protected $aliastype = 'singular'; |
|
| 47 | + |
|
| 48 | + /** |
|
| 49 | + * Valor passado para o atributo |
|
| 50 | + * |
|
| 51 | + * @var array|string|null |
|
| 52 | + */ |
|
| 53 | + protected $values = null; |
|
| 54 | + |
|
| 55 | + /** |
|
| 56 | + * Indica se a model será printada com lower case. |
|
| 57 | + * |
|
| 58 | + * @var boolean |
|
| 59 | + */ |
|
| 60 | + protected $lowercase = false; |
|
| 61 | + |
|
| 62 | + /** |
|
| 63 | + * Construtor da exceção |
|
| 64 | + * |
|
| 65 | + * @param mixed $model |
|
| 66 | + */ |
|
| 67 | + public function __construct($model = 'foo') |
|
| 68 | + { |
|
| 69 | + $this->model = $model; |
|
| 70 | + } |
|
| 71 | + |
|
| 72 | + /** |
|
| 73 | + * Render the exception as an HTTP response. |
|
| 74 | + * |
|
| 75 | + * @return \Illuminate\Http\JsonResponse |
|
| 76 | + */ |
|
| 77 | + public function render() |
|
| 78 | + { |
|
| 79 | + return response()-> |
|
| 80 | + /** @scrutinizer ignore-call */ |
|
| 81 | + json([ |
|
| 82 | + 'messages' => trans('scheduler::exceptions.'. $this->trans, $this->parseValues()) |
|
| 83 | + ], $this->statusCode); |
|
| 84 | + } |
|
| 85 | + |
|
| 86 | + /** |
|
| 87 | + * Dá parse nos valores para a string de tradução. |
|
| 88 | + * |
|
| 89 | + * @return array |
|
| 90 | + */ |
|
| 91 | + protected function parseValues() |
|
| 92 | + { |
|
| 93 | + if(is_array($this->attributes) && is_array($this->values)) |
|
| 94 | + return collect($this->attributes)->combine($this->values)->all(); |
|
| 95 | + |
|
| 96 | + return [ $this->attributes => $this->values ?? $this->isLower() ]; |
|
| 97 | + } |
|
| 98 | + |
|
| 99 | + /** |
|
| 100 | + * Verifica se é lowercase e retorna de acordo. |
|
| 101 | + * |
|
| 102 | + * @return string |
|
| 103 | + */ |
|
| 104 | + protected function isLower() |
|
| 105 | + { |
|
| 106 | + return $this->lowercase ? strtolower($this->getAlias()) : $this->getAlias(); |
|
| 107 | + } |
|
| 108 | + |
|
| 109 | + /** |
|
| 110 | + * Retorna o alias da model. |
|
| 111 | + * |
|
| 112 | + * @return string |
|
| 113 | + */ |
|
| 114 | + protected function getAlias() |
|
| 115 | + { |
|
| 116 | + if(is_object($this->model)) |
|
| 117 | + $this->model = get_class($this->model); |
|
| 118 | + |
|
| 119 | + return collect(trans('scheduler::exceptions.aliases.'. $this->aliastype))->search($this->model) ?: 'Recurso'; |
|
| 120 | + } |
|
| 121 | + |
|
| 122 | + /** |
|
| 123 | + * Seta os valores. |
|
| 124 | + * |
|
| 125 | + * @param mixed $values |
|
| 126 | + */ |
|
| 127 | + public function setValues($values) |
|
| 128 | + { |
|
| 129 | + $this->values = $values; |
|
| 130 | + |
|
| 131 | + return $this; |
|
| 132 | + } |
|
| 133 | 133 | } |
@@ -64,7 +64,7 @@ discard block |
||
| 64 | 64 | * |
| 65 | 65 | * @param mixed $model |
| 66 | 66 | */ |
| 67 | - public function __construct($model = 'foo') |
|
| 67 | + public function __construct ($model = 'foo') |
|
| 68 | 68 | { |
| 69 | 69 | $this->model = $model; |
| 70 | 70 | } |
@@ -74,12 +74,12 @@ discard block |
||
| 74 | 74 | * |
| 75 | 75 | * @return \Illuminate\Http\JsonResponse |
| 76 | 76 | */ |
| 77 | - public function render() |
|
| 77 | + public function render () |
|
| 78 | 78 | { |
| 79 | 79 | return response()-> |
| 80 | 80 | /** @scrutinizer ignore-call */ |
| 81 | 81 | json([ |
| 82 | - 'messages' => trans('scheduler::exceptions.'. $this->trans, $this->parseValues()) |
|
| 82 | + 'messages' => trans('scheduler::exceptions.' . $this->trans, $this->parseValues()) |
|
| 83 | 83 | ], $this->statusCode); |
| 84 | 84 | } |
| 85 | 85 | |
@@ -88,9 +88,9 @@ discard block |
||
| 88 | 88 | * |
| 89 | 89 | * @return array |
| 90 | 90 | */ |
| 91 | - protected function parseValues() |
|
| 91 | + protected function parseValues () |
|
| 92 | 92 | { |
| 93 | - if(is_array($this->attributes) && is_array($this->values)) |
|
| 93 | + if (is_array($this->attributes) && is_array($this->values)) |
|
| 94 | 94 | return collect($this->attributes)->combine($this->values)->all(); |
| 95 | 95 | |
| 96 | 96 | return [ $this->attributes => $this->values ?? $this->isLower() ]; |
@@ -101,7 +101,7 @@ discard block |
||
| 101 | 101 | * |
| 102 | 102 | * @return string |
| 103 | 103 | */ |
| 104 | - protected function isLower() |
|
| 104 | + protected function isLower () |
|
| 105 | 105 | { |
| 106 | 106 | return $this->lowercase ? strtolower($this->getAlias()) : $this->getAlias(); |
| 107 | 107 | } |
@@ -111,12 +111,12 @@ discard block |
||
| 111 | 111 | * |
| 112 | 112 | * @return string |
| 113 | 113 | */ |
| 114 | - protected function getAlias() |
|
| 114 | + protected function getAlias () |
|
| 115 | 115 | { |
| 116 | - if(is_object($this->model)) |
|
| 116 | + if (is_object($this->model)) |
|
| 117 | 117 | $this->model = get_class($this->model); |
| 118 | 118 | |
| 119 | - return collect(trans('scheduler::exceptions.aliases.'. $this->aliastype))->search($this->model) ?: 'Recurso'; |
|
| 119 | + return collect(trans('scheduler::exceptions.aliases.' . $this->aliastype))->search($this->model) ?: 'Recurso'; |
|
| 120 | 120 | } |
| 121 | 121 | |
| 122 | 122 | /** |
@@ -124,7 +124,7 @@ discard block |
||
| 124 | 124 | * |
| 125 | 125 | * @param mixed $values |
| 126 | 126 | */ |
| 127 | - public function setValues($values) |
|
| 127 | + public function setValues ($values) |
|
| 128 | 128 | { |
| 129 | 129 | $this->values = $values; |
| 130 | 130 | |
@@ -14,107 +14,107 @@ |
||
| 14 | 14 | |
| 15 | 15 | class Scheduler |
| 16 | 16 | { |
| 17 | - /** |
|
| 18 | - * Laravel application |
|
| 19 | - * |
|
| 20 | - * @var \Illuminate\Foundation\Application |
|
| 21 | - */ |
|
| 22 | - public $app; |
|
| 23 | - |
|
| 24 | - /** |
|
| 25 | - * Create a new confide instance. |
|
| 26 | - * |
|
| 27 | - * @param \Illuminate\Foundation\Application $app |
|
| 28 | - * |
|
| 29 | - * @return void |
|
| 30 | - */ |
|
| 31 | - public function __construct($app) |
|
| 32 | - { |
|
| 33 | - $this->app = $app; |
|
| 34 | - } |
|
| 35 | - |
|
| 36 | - /** |
|
| 37 | - * Escopo de uma consulta que busca horarios pela data de início. |
|
| 38 | - * |
|
| 39 | - * @param string|\Carbon\Carbon $start_at |
|
| 40 | - * @param string|\Carbon\Carbon $end_at |
|
| 41 | - * @return bool |
|
| 42 | - */ |
|
| 43 | - public function hasScheduleBetween($model_type, $start_at, $end_at) |
|
| 44 | - { |
|
| 45 | - if(!Config::get('scheduler.enable_schedule_conflict')) |
|
| 46 | - return false; |
|
| 47 | - |
|
| 48 | - return !is_null( |
|
| 49 | - Schedule::latest() |
|
| 50 | - ->where('model_type', $model_type) |
|
| 51 | - ->where('start_at', '>=', $start_at) |
|
| 52 | - ->where('end_at', '<=', $end_at) |
|
| 53 | - ->first() |
|
| 54 | - ); |
|
| 55 | - } |
|
| 56 | - |
|
| 57 | - /** |
|
| 58 | - * Retorna os horários disponiveis hoje para uma determinada model. |
|
| 59 | - * . |
|
| 60 | - * @param string $model_type Tipo da model |
|
| 61 | - * @param int $duration Serve para facilitar na hora de buscar horários livres |
|
| 62 | - * que precisem ter uma certa duração. |
|
| 63 | - * @return array |
|
| 64 | - */ |
|
| 65 | - public function availableToday($model_type, $duration) |
|
| 66 | - { |
|
| 67 | - return $this->availableOn($model_type, Carbon::now(), $duration); |
|
| 68 | - } |
|
| 69 | - |
|
| 70 | - /** |
|
| 71 | - * Retorna os horários disponiveis em um determinado dia para uma certa model. |
|
| 72 | - * |
|
| 73 | - * @param string $model_type Tipo da model |
|
| 74 | - * @param string|\Carbon\Carbon $today Data para o qual ele irá fazer a busca. |
|
| 75 | - * @param int $durationMinutes Serve para facilitar na hora de buscar horários livres |
|
| 76 | - * que precisem ter uma certa duração. |
|
| 77 | - * @return array |
|
| 78 | - */ |
|
| 79 | - public function availableOn($model_type, $today, $durationMinutes) |
|
| 80 | - { |
|
| 81 | - $openingTime = Carbon::parse(Config::get('scheduler.opening_time'))->setDateFrom($today); |
|
| 82 | - $closingTime = Carbon::parse(Config::get('scheduler.closing_time'))->setDateFrom($today); |
|
| 83 | - |
|
| 84 | - $livres = []; |
|
| 85 | - $today = Carbon::parse($today->toDateString()); |
|
| 86 | - while($openingTime <= $closingTime) |
|
| 87 | - { |
|
| 88 | - $add = true; |
|
| 89 | - |
|
| 90 | - foreach (Schedule::orderBy('start_at', 'DESC')->cursor() as $schedule) { |
|
| 91 | - if($schedule->model_type != $model_type) |
|
| 92 | - continue; |
|
| 93 | - |
|
| 94 | - $start = Carbon::parse($schedule->start_at); |
|
| 95 | - $begin = Carbon::parse($start->toDateString()); |
|
| 96 | - |
|
| 97 | - if($begin->greaterThan($today)) |
|
| 98 | - break; |
|
| 99 | - |
|
| 100 | - if($begin->notEqualTo($today)) |
|
| 101 | - continue; |
|
| 102 | - |
|
| 103 | - $end = Carbon::parse($schedule->end_at); |
|
| 104 | - if($start <= Carbon::parse($openingTime->toDateTimeString()) |
|
| 105 | - && $end >= Carbon::parse($openingTime->toDateTimeString())->addMinutes($durationMinutes)) |
|
| 106 | - $add = false; |
|
| 107 | - } |
|
| 108 | - |
|
| 109 | - if($add) |
|
| 110 | - $livres[] = [ |
|
| 111 | - 'start_at' => Carbon::parse($openingTime->toDateTimeString()), |
|
| 112 | - 'end_at' => Carbon::parse($openingTime->toDateTimeString())->addMinutes($durationMinutes) |
|
| 113 | - ]; |
|
| 114 | - |
|
| 115 | - $openingTime->addMinutes($durationMinutes); |
|
| 116 | - } |
|
| 117 | - |
|
| 118 | - return $livres; |
|
| 119 | - } |
|
| 17 | + /** |
|
| 18 | + * Laravel application |
|
| 19 | + * |
|
| 20 | + * @var \Illuminate\Foundation\Application |
|
| 21 | + */ |
|
| 22 | + public $app; |
|
| 23 | + |
|
| 24 | + /** |
|
| 25 | + * Create a new confide instance. |
|
| 26 | + * |
|
| 27 | + * @param \Illuminate\Foundation\Application $app |
|
| 28 | + * |
|
| 29 | + * @return void |
|
| 30 | + */ |
|
| 31 | + public function __construct($app) |
|
| 32 | + { |
|
| 33 | + $this->app = $app; |
|
| 34 | + } |
|
| 35 | + |
|
| 36 | + /** |
|
| 37 | + * Escopo de uma consulta que busca horarios pela data de início. |
|
| 38 | + * |
|
| 39 | + * @param string|\Carbon\Carbon $start_at |
|
| 40 | + * @param string|\Carbon\Carbon $end_at |
|
| 41 | + * @return bool |
|
| 42 | + */ |
|
| 43 | + public function hasScheduleBetween($model_type, $start_at, $end_at) |
|
| 44 | + { |
|
| 45 | + if(!Config::get('scheduler.enable_schedule_conflict')) |
|
| 46 | + return false; |
|
| 47 | + |
|
| 48 | + return !is_null( |
|
| 49 | + Schedule::latest() |
|
| 50 | + ->where('model_type', $model_type) |
|
| 51 | + ->where('start_at', '>=', $start_at) |
|
| 52 | + ->where('end_at', '<=', $end_at) |
|
| 53 | + ->first() |
|
| 54 | + ); |
|
| 55 | + } |
|
| 56 | + |
|
| 57 | + /** |
|
| 58 | + * Retorna os horários disponiveis hoje para uma determinada model. |
|
| 59 | + * . |
|
| 60 | + * @param string $model_type Tipo da model |
|
| 61 | + * @param int $duration Serve para facilitar na hora de buscar horários livres |
|
| 62 | + * que precisem ter uma certa duração. |
|
| 63 | + * @return array |
|
| 64 | + */ |
|
| 65 | + public function availableToday($model_type, $duration) |
|
| 66 | + { |
|
| 67 | + return $this->availableOn($model_type, Carbon::now(), $duration); |
|
| 68 | + } |
|
| 69 | + |
|
| 70 | + /** |
|
| 71 | + * Retorna os horários disponiveis em um determinado dia para uma certa model. |
|
| 72 | + * |
|
| 73 | + * @param string $model_type Tipo da model |
|
| 74 | + * @param string|\Carbon\Carbon $today Data para o qual ele irá fazer a busca. |
|
| 75 | + * @param int $durationMinutes Serve para facilitar na hora de buscar horários livres |
|
| 76 | + * que precisem ter uma certa duração. |
|
| 77 | + * @return array |
|
| 78 | + */ |
|
| 79 | + public function availableOn($model_type, $today, $durationMinutes) |
|
| 80 | + { |
|
| 81 | + $openingTime = Carbon::parse(Config::get('scheduler.opening_time'))->setDateFrom($today); |
|
| 82 | + $closingTime = Carbon::parse(Config::get('scheduler.closing_time'))->setDateFrom($today); |
|
| 83 | + |
|
| 84 | + $livres = []; |
|
| 85 | + $today = Carbon::parse($today->toDateString()); |
|
| 86 | + while($openingTime <= $closingTime) |
|
| 87 | + { |
|
| 88 | + $add = true; |
|
| 89 | + |
|
| 90 | + foreach (Schedule::orderBy('start_at', 'DESC')->cursor() as $schedule) { |
|
| 91 | + if($schedule->model_type != $model_type) |
|
| 92 | + continue; |
|
| 93 | + |
|
| 94 | + $start = Carbon::parse($schedule->start_at); |
|
| 95 | + $begin = Carbon::parse($start->toDateString()); |
|
| 96 | + |
|
| 97 | + if($begin->greaterThan($today)) |
|
| 98 | + break; |
|
| 99 | + |
|
| 100 | + if($begin->notEqualTo($today)) |
|
| 101 | + continue; |
|
| 102 | + |
|
| 103 | + $end = Carbon::parse($schedule->end_at); |
|
| 104 | + if($start <= Carbon::parse($openingTime->toDateTimeString()) |
|
| 105 | + && $end >= Carbon::parse($openingTime->toDateTimeString())->addMinutes($durationMinutes)) |
|
| 106 | + $add = false; |
|
| 107 | + } |
|
| 108 | + |
|
| 109 | + if($add) |
|
| 110 | + $livres[] = [ |
|
| 111 | + 'start_at' => Carbon::parse($openingTime->toDateTimeString()), |
|
| 112 | + 'end_at' => Carbon::parse($openingTime->toDateTimeString())->addMinutes($durationMinutes) |
|
| 113 | + ]; |
|
| 114 | + |
|
| 115 | + $openingTime->addMinutes($durationMinutes); |
|
| 116 | + } |
|
| 117 | + |
|
| 118 | + return $livres; |
|
| 119 | + } |
|
| 120 | 120 | } |
| 121 | 121 | \ No newline at end of file |
@@ -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 | } |
@@ -40,9 +40,9 @@ discard block |
||
| 40 | 40 | * @param string|\Carbon\Carbon $end_at |
| 41 | 41 | * @return bool |
| 42 | 42 | */ |
| 43 | - public function hasScheduleBetween($model_type, $start_at, $end_at) |
|
| 43 | + public function hasScheduleBetween ($model_type, $start_at, $end_at) |
|
| 44 | 44 | { |
| 45 | - if(!Config::get('scheduler.enable_schedule_conflict')) |
|
| 45 | + if (!Config::get('scheduler.enable_schedule_conflict')) |
|
| 46 | 46 | return false; |
| 47 | 47 | |
| 48 | 48 | return !is_null( |
@@ -62,7 +62,7 @@ discard block |
||
| 62 | 62 | * que precisem ter uma certa duração. |
| 63 | 63 | * @return array |
| 64 | 64 | */ |
| 65 | - public function availableToday($model_type, $duration) |
|
| 65 | + public function availableToday ($model_type, $duration) |
|
| 66 | 66 | { |
| 67 | 67 | return $this->availableOn($model_type, Carbon::now(), $duration); |
| 68 | 68 | } |
@@ -76,38 +76,38 @@ discard block |
||
| 76 | 76 | * que precisem ter uma certa duração. |
| 77 | 77 | * @return array |
| 78 | 78 | */ |
| 79 | - public function availableOn($model_type, $today, $durationMinutes) |
|
| 79 | + public function availableOn ($model_type, $today, $durationMinutes) |
|
| 80 | 80 | { |
| 81 | 81 | $openingTime = Carbon::parse(Config::get('scheduler.opening_time'))->setDateFrom($today); |
| 82 | 82 | $closingTime = Carbon::parse(Config::get('scheduler.closing_time'))->setDateFrom($today); |
| 83 | 83 | |
| 84 | - $livres = []; |
|
| 84 | + $livres = [ ]; |
|
| 85 | 85 | $today = Carbon::parse($today->toDateString()); |
| 86 | - while($openingTime <= $closingTime) |
|
| 86 | + while ($openingTime <= $closingTime) |
|
| 87 | 87 | { |
| 88 | 88 | $add = true; |
| 89 | 89 | |
| 90 | 90 | foreach (Schedule::orderBy('start_at', 'DESC')->cursor() as $schedule) { |
| 91 | - if($schedule->model_type != $model_type) |
|
| 91 | + if ($schedule->model_type != $model_type) |
|
| 92 | 92 | continue; |
| 93 | 93 | |
| 94 | 94 | $start = Carbon::parse($schedule->start_at); |
| 95 | 95 | $begin = Carbon::parse($start->toDateString()); |
| 96 | 96 | |
| 97 | - if($begin->greaterThan($today)) |
|
| 97 | + if ($begin->greaterThan($today)) |
|
| 98 | 98 | break; |
| 99 | 99 | |
| 100 | - if($begin->notEqualTo($today)) |
|
| 100 | + if ($begin->notEqualTo($today)) |
|
| 101 | 101 | continue; |
| 102 | 102 | |
| 103 | 103 | $end = Carbon::parse($schedule->end_at); |
| 104 | - if($start <= Carbon::parse($openingTime->toDateTimeString()) |
|
| 104 | + if ($start <= Carbon::parse($openingTime->toDateTimeString()) |
|
| 105 | 105 | && $end >= Carbon::parse($openingTime->toDateTimeString())->addMinutes($durationMinutes)) |
| 106 | 106 | $add = false; |
| 107 | 107 | } |
| 108 | 108 | |
| 109 | - if($add) |
|
| 110 | - $livres[] = [ |
|
| 109 | + if ($add) |
|
| 110 | + $livres[ ] = [ |
|
| 111 | 111 | 'start_at' => Carbon::parse($openingTime->toDateTimeString()), |
| 112 | 112 | 'end_at' => Carbon::parse($openingTime->toDateTimeString())->addMinutes($durationMinutes) |
| 113 | 113 | ]; |
@@ -42,8 +42,9 @@ discard block |
||
| 42 | 42 | */ |
| 43 | 43 | public function hasScheduleBetween($model_type, $start_at, $end_at) |
| 44 | 44 | { |
| 45 | - if(!Config::get('scheduler.enable_schedule_conflict')) |
|
| 46 | - return false; |
|
| 45 | + if(!Config::get('scheduler.enable_schedule_conflict')) { |
|
| 46 | + return false; |
|
| 47 | + } |
|
| 47 | 48 | |
| 48 | 49 | return !is_null( |
| 49 | 50 | Schedule::latest() |
@@ -88,29 +89,34 @@ discard block |
||
| 88 | 89 | $add = true; |
| 89 | 90 | |
| 90 | 91 | foreach (Schedule::orderBy('start_at', 'DESC')->cursor() as $schedule) { |
| 91 | - if($schedule->model_type != $model_type) |
|
| 92 | - continue; |
|
| 92 | + if($schedule->model_type != $model_type) { |
|
| 93 | + continue; |
|
| 94 | + } |
|
| 93 | 95 | |
| 94 | 96 | $start = Carbon::parse($schedule->start_at); |
| 95 | 97 | $begin = Carbon::parse($start->toDateString()); |
| 96 | 98 | |
| 97 | - if($begin->greaterThan($today)) |
|
| 98 | - break; |
|
| 99 | + if($begin->greaterThan($today)) { |
|
| 100 | + break; |
|
| 101 | + } |
|
| 99 | 102 | |
| 100 | - if($begin->notEqualTo($today)) |
|
| 101 | - continue; |
|
| 103 | + if($begin->notEqualTo($today)) { |
|
| 104 | + continue; |
|
| 105 | + } |
|
| 102 | 106 | |
| 103 | 107 | $end = Carbon::parse($schedule->end_at); |
| 104 | 108 | if($start <= Carbon::parse($openingTime->toDateTimeString()) |
| 105 | - && $end >= Carbon::parse($openingTime->toDateTimeString())->addMinutes($durationMinutes)) |
|
| 106 | - $add = false; |
|
| 109 | + && $end >= Carbon::parse($openingTime->toDateTimeString())->addMinutes($durationMinutes)) { |
|
| 110 | + $add = false; |
|
| 111 | + } |
|
| 107 | 112 | } |
| 108 | 113 | |
| 109 | - if($add) |
|
| 110 | - $livres[] = [ |
|
| 114 | + if($add) { |
|
| 115 | + $livres[] = [ |
|
| 111 | 116 | 'start_at' => Carbon::parse($openingTime->toDateTimeString()), |
| 112 | 117 | 'end_at' => Carbon::parse($openingTime->toDateTimeString())->addMinutes($durationMinutes) |
| 113 | 118 | ]; |
| 119 | + } |
|
| 114 | 120 | |
| 115 | 121 | $openingTime->addMinutes($durationMinutes); |
| 116 | 122 | } |
@@ -27,28 +27,28 @@ |
||
| 27 | 27 | trait SchedulerModelTrait |
| 28 | 28 | { |
| 29 | 29 | /** |
| 30 | - * Define an inverse one-to-one or many relationship. |
|
| 31 | - * |
|
| 32 | - * @param string $related |
|
| 33 | - * @param string $foreignKey |
|
| 34 | - * @param string $ownerKey |
|
| 35 | - * @param string $relation |
|
| 36 | - * @return \Illuminate\Database\Eloquent\Relations\BelongsTo |
|
| 37 | - */ |
|
| 30 | + * Define an inverse one-to-one or many relationship. |
|
| 31 | + * |
|
| 32 | + * @param string $related |
|
| 33 | + * @param string $foreignKey |
|
| 34 | + * @param string $ownerKey |
|
| 35 | + * @param string $relation |
|
| 36 | + * @return \Illuminate\Database\Eloquent\Relations\BelongsTo |
|
| 37 | + */ |
|
| 38 | 38 | abstract public function belongsTo($related, $foreignKey = null, $ownerKey = null, $relation = null); |
| 39 | 39 | |
| 40 | 40 | /** |
| 41 | - * Get the value of the model's primary key. |
|
| 42 | - * |
|
| 43 | - * @return mixed |
|
| 44 | - */ |
|
| 41 | + * Get the value of the model's primary key. |
|
| 42 | + * |
|
| 43 | + * @return mixed |
|
| 44 | + */ |
|
| 45 | 45 | abstract public function getKey(); |
| 46 | 46 | |
| 47 | 47 | /** |
| 48 | - * Retorna apenas os horários que possuem o mesmo [model_type] do [parent] dessa [trait]. |
|
| 49 | - * |
|
| 50 | - * @return \Illuminate\Database\Eloquent\Relations\BelongsTo |
|
| 51 | - */ |
|
| 48 | + * Retorna apenas os horários que possuem o mesmo [model_type] do [parent] dessa [trait]. |
|
| 49 | + * |
|
| 50 | + * @return \Illuminate\Database\Eloquent\Relations\BelongsTo |
|
| 51 | + */ |
|
| 52 | 52 | public function schedules() |
| 53 | 53 | { |
| 54 | 54 | return $this->belongsTo(Config::get('scheduler.schedules_table'), 'model_id'); |
@@ -35,21 +35,21 @@ discard block |
||
| 35 | 35 | * @param string $relation |
| 36 | 36 | * @return \Illuminate\Database\Eloquent\Relations\BelongsTo |
| 37 | 37 | */ |
| 38 | - abstract public function belongsTo($related, $foreignKey = null, $ownerKey = null, $relation = null); |
|
| 38 | + abstract public function belongsTo ($related, $foreignKey = null, $ownerKey = null, $relation = null); |
|
| 39 | 39 | |
| 40 | 40 | /** |
| 41 | 41 | * Get the value of the model's primary key. |
| 42 | 42 | * |
| 43 | 43 | * @return mixed |
| 44 | 44 | */ |
| 45 | - abstract public function getKey(); |
|
| 45 | + abstract public function getKey (); |
|
| 46 | 46 | |
| 47 | 47 | /** |
| 48 | 48 | * Retorna apenas os horários que possuem o mesmo [model_type] do [parent] dessa [trait]. |
| 49 | 49 | * |
| 50 | 50 | * @return \Illuminate\Database\Eloquent\Relations\BelongsTo |
| 51 | 51 | */ |
| 52 | - public function schedules() |
|
| 52 | + public function schedules () |
|
| 53 | 53 | { |
| 54 | 54 | return $this->belongsTo(Config::get('scheduler.schedules_table'), 'model_id'); |
| 55 | 55 | } |
@@ -67,18 +67,18 @@ discard block |
||
| 67 | 67 | * @throws \H4ad\Scheduler\Exceptions\CantAddWithSameStartAt |
| 68 | 68 | * @throws \H4ad\Scheduler\Exceptions\EndCantBeforeStart |
| 69 | 69 | */ |
| 70 | - public function addSchedule($start_at, $end_at = null, $status = null) |
|
| 70 | + public function addSchedule ($start_at, $end_at = null, $status = null) |
|
| 71 | 71 | { |
| 72 | - if(!Config::get('scheduler.enable_schedule_without_end') && is_null($end_at)) |
|
| 72 | + if (!Config::get('scheduler.enable_schedule_without_end') && is_null($end_at)) |
|
| 73 | 73 | throw new CantAddWithoutEnd; |
| 74 | 74 | |
| 75 | - $start_at = $this->parseToCarbon($start_at); |
|
| 75 | + $start_at = $this->parseToCarbon($start_at); |
|
| 76 | 76 | $end_at = $this->parseToCarbon($end_at, $start_at); |
| 77 | 77 | |
| 78 | - if(Scheduler::hasScheduleBetween(self::class, $start_at, $end_at ?? $start_at)) |
|
| 78 | + if (Scheduler::hasScheduleBetween(self::class, $start_at, $end_at ?? $start_at)) |
|
| 79 | 79 | throw new CantAddWithSameStartAt; |
| 80 | 80 | |
| 81 | - if($start_at->greaterThan($end_at) && !is_null($end_at)) |
|
| 81 | + if ($start_at->greaterThan($end_at) && !is_null($end_at)) |
|
| 82 | 82 | throw new EndCantBeforeStart; |
| 83 | 83 | |
| 84 | 84 | $model_id = $this->getKey(); |
@@ -94,12 +94,12 @@ discard block |
||
| 94 | 94 | * @param \Carbon\Carbon $reference Data de referencia quando o [date] é inteiro. |
| 95 | 95 | * @return \Carbon\Carbon |
| 96 | 96 | */ |
| 97 | - public function parseToCarbon($date, $reference = null) |
|
| 97 | + public function parseToCarbon ($date, $reference = null) |
|
| 98 | 98 | { |
| 99 | - if(is_string($date)) |
|
| 99 | + if (is_string($date)) |
|
| 100 | 100 | return Carbon::parse($date); |
| 101 | 101 | |
| 102 | - if(is_int($date)) |
|
| 102 | + if (is_int($date)) |
|
| 103 | 103 | return Carbon::parse($reference->toDateTimeString())->addMinutes($date); |
| 104 | 104 | |
| 105 | 105 | return $date; |
@@ -111,12 +111,12 @@ discard block |
||
| 111 | 111 | * @param \Carbon\Carbon|string|int $value Valor que representará a data ou o id a ser buscado. |
| 112 | 112 | * @return H4ad\Scheduler\Models\Schedule|null |
| 113 | 113 | */ |
| 114 | - public function parseToSchedule($value) |
|
| 114 | + public function parseToSchedule ($value) |
|
| 115 | 115 | { |
| 116 | - if(is_int($value)) |
|
| 116 | + if (is_int($value)) |
|
| 117 | 117 | return Schedule::find($value); |
| 118 | 118 | |
| 119 | - if(is_string($value) || $value instanceof Carbon) |
|
| 119 | + if (is_string($value) || $value instanceof Carbon) |
|
| 120 | 120 | return Schedule::byStartAt($value)->first(); |
| 121 | 121 | |
| 122 | 122 | return null; |
@@ -134,17 +134,17 @@ discard block |
||
| 134 | 134 | * @throws \H4ad\Scheduler\Exceptions\CantRemoveByDate |
| 135 | 135 | * @throws \H4ad\Scheduler\Exceptions\ModelNotFound |
| 136 | 136 | */ |
| 137 | - public function removeSchedule($schedule) |
|
| 137 | + public function removeSchedule ($schedule) |
|
| 138 | 138 | { |
| 139 | - if(!Config::get('scheduler.enable_schedule_conflict') && !is_int($schedule)) |
|
| 139 | + if (!Config::get('scheduler.enable_schedule_conflict') && !is_int($schedule)) |
|
| 140 | 140 | throw new CantRemoveByDate; |
| 141 | 141 | |
| 142 | 142 | $schedule = $this->parseToSchedule($schedule); |
| 143 | 143 | |
| 144 | - if(!($schedule instanceof Model)) |
|
| 144 | + if (!($schedule instanceof Model)) |
|
| 145 | 145 | throw (new ModelNotFound)->setValues(Schedule::class); |
| 146 | 146 | |
| 147 | - if($schedule->model_type != self::class || $schedule->model_id != $this->getKey()) |
|
| 147 | + if ($schedule->model_type != self::class || $schedule->model_id != $this->getKey()) |
|
| 148 | 148 | throw new DoesNotBelong; |
| 149 | 149 | |
| 150 | 150 | return $schedule->delete(); |
@@ -69,17 +69,20 @@ discard block |
||
| 69 | 69 | */ |
| 70 | 70 | public function addSchedule($start_at, $end_at = null, $status = null) |
| 71 | 71 | { |
| 72 | - if(!Config::get('scheduler.enable_schedule_without_end') && is_null($end_at)) |
|
| 73 | - throw new CantAddWithoutEnd; |
|
| 72 | + if(!Config::get('scheduler.enable_schedule_without_end') && is_null($end_at)) { |
|
| 73 | + throw new CantAddWithoutEnd; |
|
| 74 | + } |
|
| 74 | 75 | |
| 75 | 76 | $start_at = $this->parseToCarbon($start_at); |
| 76 | 77 | $end_at = $this->parseToCarbon($end_at, $start_at); |
| 77 | 78 | |
| 78 | - if(Scheduler::hasScheduleBetween(self::class, $start_at, $end_at ?? $start_at)) |
|
| 79 | - throw new CantAddWithSameStartAt; |
|
| 79 | + if(Scheduler::hasScheduleBetween(self::class, $start_at, $end_at ?? $start_at)) { |
|
| 80 | + throw new CantAddWithSameStartAt; |
|
| 81 | + } |
|
| 80 | 82 | |
| 81 | - if($start_at->greaterThan($end_at) && !is_null($end_at)) |
|
| 82 | - throw new EndCantBeforeStart; |
|
| 83 | + if($start_at->greaterThan($end_at) && !is_null($end_at)) { |
|
| 84 | + throw new EndCantBeforeStart; |
|
| 85 | + } |
|
| 83 | 86 | |
| 84 | 87 | $model_id = $this->getKey(); |
| 85 | 88 | $model_type = self::class; |
@@ -96,11 +99,13 @@ discard block |
||
| 96 | 99 | */ |
| 97 | 100 | public function parseToCarbon($date, $reference = null) |
| 98 | 101 | { |
| 99 | - if(is_string($date)) |
|
| 100 | - return Carbon::parse($date); |
|
| 102 | + if(is_string($date)) { |
|
| 103 | + return Carbon::parse($date); |
|
| 104 | + } |
|
| 101 | 105 | |
| 102 | - if(is_int($date)) |
|
| 103 | - return Carbon::parse($reference->toDateTimeString())->addMinutes($date); |
|
| 106 | + if(is_int($date)) { |
|
| 107 | + return Carbon::parse($reference->toDateTimeString())->addMinutes($date); |
|
| 108 | + } |
|
| 104 | 109 | |
| 105 | 110 | return $date; |
| 106 | 111 | } |
@@ -113,11 +118,13 @@ discard block |
||
| 113 | 118 | */ |
| 114 | 119 | public function parseToSchedule($value) |
| 115 | 120 | { |
| 116 | - if(is_int($value)) |
|
| 117 | - return Schedule::find($value); |
|
| 121 | + if(is_int($value)) { |
|
| 122 | + return Schedule::find($value); |
|
| 123 | + } |
|
| 118 | 124 | |
| 119 | - if(is_string($value) || $value instanceof Carbon) |
|
| 120 | - return Schedule::byStartAt($value)->first(); |
|
| 125 | + if(is_string($value) || $value instanceof Carbon) { |
|
| 126 | + return Schedule::byStartAt($value)->first(); |
|
| 127 | + } |
|
| 121 | 128 | |
| 122 | 129 | return null; |
| 123 | 130 | } |
@@ -136,16 +143,19 @@ discard block |
||
| 136 | 143 | */ |
| 137 | 144 | public function removeSchedule($schedule) |
| 138 | 145 | { |
| 139 | - if(!Config::get('scheduler.enable_schedule_conflict') && !is_int($schedule)) |
|
| 140 | - throw new CantRemoveByDate; |
|
| 146 | + if(!Config::get('scheduler.enable_schedule_conflict') && !is_int($schedule)) { |
|
| 147 | + throw new CantRemoveByDate; |
|
| 148 | + } |
|
| 141 | 149 | |
| 142 | 150 | $schedule = $this->parseToSchedule($schedule); |
| 143 | 151 | |
| 144 | - if(!($schedule instanceof Model)) |
|
| 145 | - throw (new ModelNotFound)->setValues(Schedule::class); |
|
| 152 | + if(!($schedule instanceof Model)) { |
|
| 153 | + throw (new ModelNotFound)->setValues(Schedule::class); |
|
| 154 | + } |
|
| 146 | 155 | |
| 147 | - if($schedule->model_type != self::class || $schedule->model_id != $this->getKey()) |
|
| 148 | - throw new DoesNotBelong; |
|
| 156 | + if($schedule->model_type != self::class || $schedule->model_id != $this->getKey()) { |
|
| 157 | + throw new DoesNotBelong; |
|
| 158 | + } |
|
| 149 | 159 | |
| 150 | 160 | return $schedule->delete(); |
| 151 | 161 | } |