@@ -10,41 +10,41 @@ |
||
| 10 | 10 | |
| 11 | 11 | return [ |
| 12 | 12 | |
| 13 | - /** |
|
| 14 | - * Horário de abertura que será usado de referencia para fazer as consultas de horários disponiveis. |
|
| 15 | - */ |
|
| 16 | - 'opening_time' => '06:00:00', |
|
| 17 | - |
|
| 18 | - /** |
|
| 19 | - * Horário de fechamento que será usado de referencia para fazer as consultas de horários disponiveis. |
|
| 20 | - */ |
|
| 21 | - 'closing_time' => '20:00:00', |
|
| 22 | - |
|
| 23 | - /** |
|
| 24 | - * Define o nome da tabela que será gerada para os horários agendados. |
|
| 25 | - */ |
|
| 26 | - 'schedules_table' => 'schedules', |
|
| 27 | - |
|
| 28 | - /** |
|
| 29 | - * Define o nome da tabela que será gerada para os status do horários agendados. |
|
| 30 | - */ |
|
| 31 | - 'schedule_status_table' => 'schedule_status', |
|
| 32 | - |
|
| 33 | - /** |
|
| 34 | - * Configuração que habilita ou desabilita mensagens de erro ao tentar agendar |
|
| 35 | - * um horário que já foi agendado. |
|
| 36 | - * |
|
| 37 | - * Ex: Duas pessoas tentam agendar no mesmo horário, a primeira consegue e a segunda |
|
| 38 | - * obtém uma mensagem de erro. |
|
| 39 | - * |
|
| 40 | - * Caso seja desabilitada, não será exibido mensagem de erro no caso acima e será |
|
| 41 | - * registrado normalmente. |
|
| 42 | - */ |
|
| 43 | - 'enable_schedule_conflict' => true, |
|
| 44 | - |
|
| 45 | - /** |
|
| 46 | - * Configuração que habilita ou desabilita mensagens de erro ao tentar agendar |
|
| 47 | - * um horário sem informar quando acaba (uma data final). |
|
| 48 | - */ |
|
| 49 | - 'enable_schedule_without_end' => false, |
|
| 13 | + /** |
|
| 14 | + * Horário de abertura que será usado de referencia para fazer as consultas de horários disponiveis. |
|
| 15 | + */ |
|
| 16 | + 'opening_time' => '06:00:00', |
|
| 17 | + |
|
| 18 | + /** |
|
| 19 | + * Horário de fechamento que será usado de referencia para fazer as consultas de horários disponiveis. |
|
| 20 | + */ |
|
| 21 | + 'closing_time' => '20:00:00', |
|
| 22 | + |
|
| 23 | + /** |
|
| 24 | + * Define o nome da tabela que será gerada para os horários agendados. |
|
| 25 | + */ |
|
| 26 | + 'schedules_table' => 'schedules', |
|
| 27 | + |
|
| 28 | + /** |
|
| 29 | + * Define o nome da tabela que será gerada para os status do horários agendados. |
|
| 30 | + */ |
|
| 31 | + 'schedule_status_table' => 'schedule_status', |
|
| 32 | + |
|
| 33 | + /** |
|
| 34 | + * Configuração que habilita ou desabilita mensagens de erro ao tentar agendar |
|
| 35 | + * um horário que já foi agendado. |
|
| 36 | + * |
|
| 37 | + * Ex: Duas pessoas tentam agendar no mesmo horário, a primeira consegue e a segunda |
|
| 38 | + * obtém uma mensagem de erro. |
|
| 39 | + * |
|
| 40 | + * Caso seja desabilitada, não será exibido mensagem de erro no caso acima e será |
|
| 41 | + * registrado normalmente. |
|
| 42 | + */ |
|
| 43 | + 'enable_schedule_conflict' => true, |
|
| 44 | + |
|
| 45 | + /** |
|
| 46 | + * Configuração que habilita ou desabilita mensagens de erro ao tentar agendar |
|
| 47 | + * um horário sem informar quando acaba (uma data final). |
|
| 48 | + */ |
|
| 49 | + 'enable_schedule_without_end' => false, |
|
| 50 | 50 | ]; |
| 51 | 51 | \ No newline at end of file |
@@ -38,7 +38,7 @@ |
||
| 38 | 38 | */ |
| 39 | 39 | public function register() |
| 40 | 40 | { |
| 41 | - $this->app->singleton(Scheduler::class, function ($app) { |
|
| 41 | + $this->app->singleton(Scheduler::class, function($app) { |
|
| 42 | 42 | return new Scheduler($app); |
| 43 | 43 | }); |
| 44 | 44 | |
@@ -1,10 +1,10 @@ |
||
| 1 | 1 | <?php |
| 2 | 2 | |
| 3 | 3 | return [ |
| 4 | - 'does_not_belong' => 'Não é possível remover registro que não possui o mesmo tipo de model.', |
|
| 5 | - 'cant_remove_by_date' => 'Não é possível remover um registro pelo horário marcado quando a configuração [enable_schedule_conflict] está desabilitada.', |
|
| 6 | - 'cant_add_without_end' => 'Não é possível adicionar um registro sem o parâmetro [end_at] quando a configuração [enable_schedule_without_end] está desabilitada.', |
|
| 7 | - 'cant_add_with_same_start_at' => 'Não é possível adicionar um registro com uma data de ínicio [start_at] que já existe enquanto a configuração [enable_schedule_conflict] estiver habilitada.', |
|
| 8 | - 'end_cant_before_start' => 'A data que indica o final [end_at] não pode ser anterior a data de início [start_at].', |
|
| 9 | - 'model_not_found' => 'Não foi encontrado resultados para [:model]' |
|
| 4 | + 'does_not_belong' => 'Não é possível remover registro que não possui o mesmo tipo de model.', |
|
| 5 | + 'cant_remove_by_date' => 'Não é possível remover um registro pelo horário marcado quando a configuração [enable_schedule_conflict] está desabilitada.', |
|
| 6 | + 'cant_add_without_end' => 'Não é possível adicionar um registro sem o parâmetro [end_at] quando a configuração [enable_schedule_without_end] está desabilitada.', |
|
| 7 | + 'cant_add_with_same_start_at' => 'Não é possível adicionar um registro com uma data de ínicio [start_at] que já existe enquanto a configuração [enable_schedule_conflict] estiver habilitada.', |
|
| 8 | + 'end_cant_before_start' => 'A data que indica o final [end_at] não pode ser anterior a data de início [start_at].', |
|
| 9 | + 'model_not_found' => 'Não foi encontrado resultados para [:model]' |
|
| 10 | 10 | ]; |
| 11 | 11 | \ No newline at end of file |
@@ -10,58 +10,58 @@ |
||
| 10 | 10 | |
| 11 | 11 | interface SchedulerModelInterface |
| 12 | 12 | { |
| 13 | - /** |
|
| 13 | + /** |
|
| 14 | 14 | * Retorna apenas os horários que possuem o mesmo [model_type] do [parent] dessa [trait]. |
| 15 | 15 | * |
| 16 | 16 | * @return \Illuminate\Database\Eloquent\Relations\BelongsTo |
| 17 | 17 | */ |
| 18 | - public function schedules(); |
|
| 18 | + public function schedules(); |
|
| 19 | 19 | |
| 20 | - /** |
|
| 21 | - * Agenda um horário para esta model. |
|
| 22 | - * |
|
| 23 | - * @param string|Carbon\Carbon $start_at Data em que será agendado, pode ser em string ou em numa classe Carbon. |
|
| 24 | - * @param string|Carbon\Carbon|int $end_at Data em que acabada esse agendamento, pode ser em string, ou numa classe Carbon |
|
| 25 | - * ou em int(sendo considerado os minutos de duração). |
|
| 26 | - * @param int $status Status desse horário ao ser agendado. |
|
| 27 | - * @return \H4ad\Scheduler\Models\Schedule |
|
| 28 | - * |
|
| 29 | - * @throws \H4ad\Scheduler\Exceptions\CantAddWithoutEnd |
|
| 30 | - * @throws \H4ad\Scheduler\Exceptions\CantAddWithSameStartAt |
|
| 31 | - * @throws \H4ad\Scheduler\Exceptions\EndCantBeforeStart |
|
| 32 | - */ |
|
| 33 | - public function addSchedule($start_at, $end_at = null, $status = null); |
|
| 20 | + /** |
|
| 21 | + * Agenda um horário para esta model. |
|
| 22 | + * |
|
| 23 | + * @param string|Carbon\Carbon $start_at Data em que será agendado, pode ser em string ou em numa classe Carbon. |
|
| 24 | + * @param string|Carbon\Carbon|int $end_at Data em que acabada esse agendamento, pode ser em string, ou numa classe Carbon |
|
| 25 | + * ou em int(sendo considerado os minutos de duração). |
|
| 26 | + * @param int $status Status desse horário ao ser agendado. |
|
| 27 | + * @return \H4ad\Scheduler\Models\Schedule |
|
| 28 | + * |
|
| 29 | + * @throws \H4ad\Scheduler\Exceptions\CantAddWithoutEnd |
|
| 30 | + * @throws \H4ad\Scheduler\Exceptions\CantAddWithSameStartAt |
|
| 31 | + * @throws \H4ad\Scheduler\Exceptions\EndCantBeforeStart |
|
| 32 | + */ |
|
| 33 | + public function addSchedule($start_at, $end_at = null, $status = null); |
|
| 34 | 34 | |
| 35 | - /** |
|
| 36 | - * Exibe uma lista dos horários do dia de hoje. |
|
| 37 | - * |
|
| 38 | - * @param int $duration Serve para facilitar na hora de buscar horários livres |
|
| 39 | - * que precisem ter uma certa duração. |
|
| 40 | - * @return array |
|
| 41 | - */ |
|
| 42 | - public function availableToday($duration = 0); |
|
| 35 | + /** |
|
| 36 | + * Exibe uma lista dos horários do dia de hoje. |
|
| 37 | + * |
|
| 38 | + * @param int $duration Serve para facilitar na hora de buscar horários livres |
|
| 39 | + * que precisem ter uma certa duração. |
|
| 40 | + * @return array |
|
| 41 | + */ |
|
| 42 | + public function availableToday($duration = 0); |
|
| 43 | 43 | |
| 44 | - /** |
|
| 45 | - * Lista os horários livres em um determinado dia. |
|
| 46 | - * |
|
| 47 | - * @param string|Carbon\Carbon $date Data para o qual ele irá fazer a busca. |
|
| 48 | - * @param int $duration Serve para facilitar na hora de buscar horários livres |
|
| 49 | - * que precisem ter uma certa duração. |
|
| 50 | - * @return array |
|
| 51 | - */ |
|
| 52 | - public function availableOn($date, $duration = 0); |
|
| 44 | + /** |
|
| 45 | + * Lista os horários livres em um determinado dia. |
|
| 46 | + * |
|
| 47 | + * @param string|Carbon\Carbon $date Data para o qual ele irá fazer a busca. |
|
| 48 | + * @param int $duration Serve para facilitar na hora de buscar horários livres |
|
| 49 | + * que precisem ter uma certa duração. |
|
| 50 | + * @return array |
|
| 51 | + */ |
|
| 52 | + public function availableOn($date, $duration = 0); |
|
| 53 | 53 | |
| 54 | - /** |
|
| 55 | - * Remove um horário agendado pelo seu ID ou pelo horário em que foi marcado. |
|
| 56 | - * Caso a configuração "enable_schedule_conflict" estiver desabilitada, será lançado uma exceção |
|
| 57 | - * se for tentado remover um horário agendado pela data de quando foi marcado. |
|
| 58 | - * |
|
| 59 | - * @param int|string|Carbon\Carbon $schedule Horário agendado. |
|
| 60 | - * @return bool|null |
|
| 61 | - * |
|
| 62 | - * @throws \H4ad\Scheduler\Exceptions\DoesNotBelong |
|
| 63 | - * @throws \H4ad\Scheduler\Exceptions\CantRemoveByDate |
|
| 64 | - * @throws \H4ad\Scheduler\Exceptions\ModelNotFound |
|
| 65 | - */ |
|
| 66 | - public function removeSchedule($schedule); |
|
| 54 | + /** |
|
| 55 | + * Remove um horário agendado pelo seu ID ou pelo horário em que foi marcado. |
|
| 56 | + * Caso a configuração "enable_schedule_conflict" estiver desabilitada, será lançado uma exceção |
|
| 57 | + * se for tentado remover um horário agendado pela data de quando foi marcado. |
|
| 58 | + * |
|
| 59 | + * @param int|string|Carbon\Carbon $schedule Horário agendado. |
|
| 60 | + * @return bool|null |
|
| 61 | + * |
|
| 62 | + * @throws \H4ad\Scheduler\Exceptions\DoesNotBelong |
|
| 63 | + * @throws \H4ad\Scheduler\Exceptions\CantRemoveByDate |
|
| 64 | + * @throws \H4ad\Scheduler\Exceptions\ModelNotFound |
|
| 65 | + */ |
|
| 66 | + public function removeSchedule($schedule); |
|
| 67 | 67 | } |
| 68 | 68 | \ No newline at end of file |
@@ -77,9 +77,9 @@ discard block |
||
| 77 | 77 | $openingTime = Carbon::parse(Config::get('scheduler.opening_time'))->setDateFrom($today); |
| 78 | 78 | $closingTime = Carbon::parse(Config::get('scheduler.closing_time'))->setDateFrom($today); |
| 79 | 79 | |
| 80 | - $livres = []; |
|
| 80 | + $livres = [ ]; |
|
| 81 | 81 | $today = Carbon::parse($today->toDateString()); |
| 82 | - while($openingTime <= $closingTime) |
|
| 82 | + while ($openingTime <= $closingTime) |
|
| 83 | 83 | { |
| 84 | 84 | $add = true; |
| 85 | 85 | |
@@ -87,20 +87,20 @@ discard block |
||
| 87 | 87 | $start = Carbon::parse($schedule->start_at); |
| 88 | 88 | $begin = Carbon::parse($start->toDateString()); |
| 89 | 89 | |
| 90 | - if($begin->greaterThan($today)) |
|
| 90 | + if ($begin->greaterThan($today)) |
|
| 91 | 91 | break; |
| 92 | 92 | |
| 93 | - if($begin->notEqualTo($today)) |
|
| 93 | + if ($begin->notEqualTo($today)) |
|
| 94 | 94 | continue; |
| 95 | 95 | |
| 96 | 96 | $end = Carbon::parse($schedule->end_at); |
| 97 | - if($start <= Carbon::parse($openingTime->toDateTimeString()) |
|
| 97 | + if ($start <= Carbon::parse($openingTime->toDateTimeString()) |
|
| 98 | 98 | && $end >= Carbon::parse($openingTime->toDateTimeString())->addMinutes($durationMinutes)) |
| 99 | 99 | $add = false; |
| 100 | 100 | } |
| 101 | 101 | |
| 102 | - if($add) |
|
| 103 | - $livres[] = [ |
|
| 102 | + if ($add) |
|
| 103 | + $livres[ ] = [ |
|
| 104 | 104 | 'start_at' => Carbon::parse($openingTime->toDateTimeString()), |
| 105 | 105 | 'end_at' => Carbon::parse($openingTime->toDateTimeString())->addMinutes($durationMinutes) |
| 106 | 106 | ]; |
@@ -87,23 +87,27 @@ |
||
| 87 | 87 | $start = Carbon::parse($schedule->start_at); |
| 88 | 88 | $begin = Carbon::parse($start->toDateString()); |
| 89 | 89 | |
| 90 | - if($begin->greaterThan($today)) |
|
| 91 | - break; |
|
| 90 | + if($begin->greaterThan($today)) { |
|
| 91 | + break; |
|
| 92 | + } |
|
| 92 | 93 | |
| 93 | - if($begin->notEqualTo($today)) |
|
| 94 | - continue; |
|
| 94 | + if($begin->notEqualTo($today)) { |
|
| 95 | + continue; |
|
| 96 | + } |
|
| 95 | 97 | |
| 96 | 98 | $end = Carbon::parse($schedule->end_at); |
| 97 | 99 | if($start <= Carbon::parse($openingTime->toDateTimeString()) |
| 98 | - && $end >= Carbon::parse($openingTime->toDateTimeString())->addMinutes($durationMinutes)) |
|
| 99 | - $add = false; |
|
| 100 | + && $end >= Carbon::parse($openingTime->toDateTimeString())->addMinutes($durationMinutes)) { |
|
| 101 | + $add = false; |
|
| 102 | + } |
|
| 100 | 103 | } |
| 101 | 104 | |
| 102 | - if($add) |
|
| 103 | - $livres[] = [ |
|
| 105 | + if($add) { |
|
| 106 | + $livres[] = [ |
|
| 104 | 107 | 'start_at' => Carbon::parse($openingTime->toDateTimeString()), |
| 105 | 108 | 'end_at' => Carbon::parse($openingTime->toDateTimeString())->addMinutes($durationMinutes) |
| 106 | 109 | ]; |
| 110 | + } |
|
| 107 | 111 | |
| 108 | 112 | $openingTime->addMinutes($durationMinutes); |
| 109 | 113 | } |
@@ -22,7 +22,7 @@ |
||
| 22 | 22 | */ |
| 23 | 23 | public function up() |
| 24 | 24 | { |
| 25 | - Schema::create(Config::get('scheduler.schedule_status_table'), function (Blueprint $table) { |
|
| 25 | + Schema::create(Config::get('scheduler.schedule_status_table'), function(Blueprint $table) { |
|
| 26 | 26 | $table->increments('id'); |
| 27 | 27 | $table->string('name')->unique(); |
| 28 | 28 | $table->text('description')->nullable(); |
@@ -22,7 +22,7 @@ |
||
| 22 | 22 | */ |
| 23 | 23 | public function up() |
| 24 | 24 | { |
| 25 | - Schema::create(Config::get('scheduler.schedules_table'), function (Blueprint $table) { |
|
| 25 | + Schema::create(Config::get('scheduler.schedules_table'), function(Blueprint $table) { |
|
| 26 | 26 | $table->increments('id'); |
| 27 | 27 | $table->string('model_type'); |
| 28 | 28 | $table->integer('model_id'); |
@@ -13,13 +13,13 @@ |
||
| 13 | 13 | class ModelNotFound extends CustomException |
| 14 | 14 | { |
| 15 | 15 | |
| 16 | - /** |
|
| 17 | - * {@inheritDoc} |
|
| 18 | - */ |
|
| 19 | - protected $trans = 'model_not_found'; |
|
| 16 | + /** |
|
| 17 | + * {@inheritDoc} |
|
| 18 | + */ |
|
| 19 | + protected $trans = 'model_not_found'; |
|
| 20 | 20 | |
| 21 | - /** |
|
| 22 | - * {@inheritDoc} |
|
| 23 | - */ |
|
| 24 | - protected $statusCode = Response::HTTP_NOT_FOUND; |
|
| 21 | + /** |
|
| 22 | + * {@inheritDoc} |
|
| 23 | + */ |
|
| 24 | + protected $statusCode = Response::HTTP_NOT_FOUND; |
|
| 25 | 25 | } |
| 26 | 26 | \ No newline at end of file |
@@ -13,13 +13,13 @@ |
||
| 13 | 13 | class EndCantBeforeStart extends CustomException |
| 14 | 14 | { |
| 15 | 15 | |
| 16 | - /** |
|
| 17 | - * {@inheritDoc} |
|
| 18 | - */ |
|
| 19 | - protected $trans = 'end_cant_before_start'; |
|
| 16 | + /** |
|
| 17 | + * {@inheritDoc} |
|
| 18 | + */ |
|
| 19 | + protected $trans = 'end_cant_before_start'; |
|
| 20 | 20 | |
| 21 | - /** |
|
| 22 | - * {@inheritDoc} |
|
| 23 | - */ |
|
| 24 | - protected $statusCode = Response::HTTP_BAD_REQUEST; |
|
| 21 | + /** |
|
| 22 | + * {@inheritDoc} |
|
| 23 | + */ |
|
| 24 | + protected $statusCode = Response::HTTP_BAD_REQUEST; |
|
| 25 | 25 | } |
| 26 | 26 | \ No newline at end of file |