@@ -15,33 +15,33 @@ |
||
| 15 | 15 | |
| 16 | 16 | class CreateSchedulesTable extends Migration |
| 17 | 17 | { |
| 18 | - /** |
|
| 19 | - * Run the migrations. |
|
| 20 | - * |
|
| 21 | - * @return void |
|
| 22 | - */ |
|
| 23 | - public function up() |
|
| 24 | - { |
|
| 25 | - Schema::create(Config::get('scheduler.schedules_table'), function (Blueprint $table) { |
|
| 26 | - $table->increments('id'); |
|
| 27 | - $table->string('model_type'); |
|
| 28 | - $table->integer('model_id'); |
|
| 29 | - $table->timestamp('start_at'); |
|
| 30 | - $table->timestamp('end_at')->nullable(); |
|
| 31 | - $table->integer('status')->nullable(); |
|
| 32 | - $table->json('data')->nullable(); |
|
| 33 | - $table->timestamps(); |
|
| 34 | - $table->softDeletes(); |
|
| 35 | - }); |
|
| 36 | - } |
|
| 18 | + /** |
|
| 19 | + * Run the migrations. |
|
| 20 | + * |
|
| 21 | + * @return void |
|
| 22 | + */ |
|
| 23 | + public function up() |
|
| 24 | + { |
|
| 25 | + Schema::create(Config::get('scheduler.schedules_table'), function (Blueprint $table) { |
|
| 26 | + $table->increments('id'); |
|
| 27 | + $table->string('model_type'); |
|
| 28 | + $table->integer('model_id'); |
|
| 29 | + $table->timestamp('start_at'); |
|
| 30 | + $table->timestamp('end_at')->nullable(); |
|
| 31 | + $table->integer('status')->nullable(); |
|
| 32 | + $table->json('data')->nullable(); |
|
| 33 | + $table->timestamps(); |
|
| 34 | + $table->softDeletes(); |
|
| 35 | + }); |
|
| 36 | + } |
|
| 37 | 37 | |
| 38 | - /** |
|
| 39 | - * Reverse the migrations. |
|
| 40 | - * |
|
| 41 | - * @return void |
|
| 42 | - */ |
|
| 43 | - public function down() |
|
| 44 | - { |
|
| 45 | - Schema::drop(Config::get('scheduler.schedules_table')); |
|
| 46 | - } |
|
| 38 | + /** |
|
| 39 | + * Reverse the migrations. |
|
| 40 | + * |
|
| 41 | + * @return void |
|
| 42 | + */ |
|
| 43 | + public function down() |
|
| 44 | + { |
|
| 45 | + Schema::drop(Config::get('scheduler.schedules_table')); |
|
| 46 | + } |
|
| 47 | 47 | } |
| 48 | 48 | \ No newline at end of file |
@@ -18,21 +18,21 @@ discard block |
||
| 18 | 18 | * @param string $localKey |
| 19 | 19 | * @return \Illuminate\Database\Eloquent\Relations\HasOne |
| 20 | 20 | */ |
| 21 | - abstract public function hasOne($related, $foreignKey = null, $localKey = null); |
|
| 21 | + abstract public function hasOne ($related, $foreignKey = null, $localKey = null); |
|
| 22 | 22 | |
| 23 | 23 | /** |
| 24 | 24 | * Get the value of the model's primary key. |
| 25 | 25 | * |
| 26 | 26 | * @return mixed |
| 27 | 27 | */ |
| 28 | - abstract public function getKey(); |
|
| 28 | + abstract public function getKey (); |
|
| 29 | 29 | |
| 30 | 30 | /** |
| 31 | 31 | * Retorna apenas os horários que possuem o mesmo [model_type] do [parent] dessa [trait]. |
| 32 | 32 | * |
| 33 | 33 | * @return \Illuminate\Database\Eloquent\Relations\HasMany |
| 34 | 34 | */ |
| 35 | - public function schedules(); |
|
| 35 | + public function schedules (); |
|
| 36 | 36 | |
| 37 | 37 | /** |
| 38 | 38 | * Agenda um horário para esta model. |
@@ -44,7 +44,7 @@ discard block |
||
| 44 | 44 | * @param array|null $data Informações opcionais que podem ser anexadas ao horário cadastrado. |
| 45 | 45 | * @return \H4ad\Scheduler\Models\Schedule |
| 46 | 46 | */ |
| 47 | - public function addSchedule($start_at, $end_at = null, $status = null, $data = null); |
|
| 47 | + public function addSchedule ($start_at, $end_at = null, $status = null, $data = null); |
|
| 48 | 48 | |
| 49 | 49 | /** |
| 50 | 50 | * Exibe uma lista dos horários do dia de hoje. |
@@ -55,7 +55,7 @@ discard block |
||
| 55 | 55 | * Se for nulo, ele busca a referencia da config. |
| 56 | 56 | * @return array |
| 57 | 57 | */ |
| 58 | - public function availableToday($duration = 0, $openingTime = null); |
|
| 58 | + public function availableToday ($duration = 0, $openingTime = null); |
|
| 59 | 59 | |
| 60 | 60 | /** |
| 61 | 61 | * Lista os horários livres em um determinado dia. |
@@ -67,7 +67,7 @@ discard block |
||
| 67 | 67 | * Se for nulo, ele busca a referencia da config. |
| 68 | 68 | * @return array |
| 69 | 69 | */ |
| 70 | - public function availableOn($date, $duration = 0, $openingTime = null); |
|
| 70 | + public function availableOn ($date, $duration = 0, $openingTime = null); |
|
| 71 | 71 | |
| 72 | 72 | /** |
| 73 | 73 | * Faz um parse e retorna um Schedule. |
@@ -75,7 +75,7 @@ discard block |
||
| 75 | 75 | * @param \Carbon\Carbon|string|int $value Valor que representará a data ou o id a ser buscado. |
| 76 | 76 | * @return \H4ad\Scheduler\Models\Schedule|null |
| 77 | 77 | */ |
| 78 | - public function parseToSchedule($value); |
|
| 78 | + public function parseToSchedule ($value); |
|
| 79 | 79 | |
| 80 | 80 | /** |
| 81 | 81 | * Remove um horário agendado pelo seu ID ou pelo horário em que foi marcado. |
@@ -89,5 +89,5 @@ discard block |
||
| 89 | 89 | * @throws \H4ad\Scheduler\Exceptions\CantRemoveByDate |
| 90 | 90 | * @throws \H4ad\Scheduler\Exceptions\ModelNotFound |
| 91 | 91 | */ |
| 92 | - public function removeSchedule($schedule); |
|
| 92 | + public function removeSchedule ($schedule); |
|
| 93 | 93 | } |
| 94 | 94 | \ No newline at end of file |
@@ -31,21 +31,21 @@ discard block |
||
| 31 | 31 | * @param string $localKey |
| 32 | 32 | * @return \Illuminate\Database\Eloquent\Relations\HasOne |
| 33 | 33 | */ |
| 34 | - abstract public function hasOne($related, $foreignKey = null, $localKey = null); |
|
| 34 | + abstract public function hasOne ($related, $foreignKey = null, $localKey = null); |
|
| 35 | 35 | |
| 36 | 36 | /** |
| 37 | 37 | * Get the value of the model's primary key. |
| 38 | 38 | * |
| 39 | 39 | * @return mixed |
| 40 | 40 | */ |
| 41 | - abstract public function getKey(); |
|
| 41 | + abstract public function getKey (); |
|
| 42 | 42 | |
| 43 | 43 | /** |
| 44 | 44 | * Retorna apenas o horário que possui o mesmo [model_id] do [parent] dessa [trait]. |
| 45 | 45 | * |
| 46 | 46 | * @return \Illuminate\Database\Eloquent\Relations\HasOne |
| 47 | 47 | */ |
| 48 | - public function schedules() |
|
| 48 | + public function schedules () |
|
| 49 | 49 | { |
| 50 | 50 | return $this->hasOne(Config::get('scheduler.schedules_table'), 'model_id'); |
| 51 | 51 | } |
@@ -60,12 +60,12 @@ discard block |
||
| 60 | 60 | * @param array|null $data Informações opcionais que podem ser anexadas ao horário cadastrado. |
| 61 | 61 | * @return \H4ad\Scheduler\Models\Schedule |
| 62 | 62 | */ |
| 63 | - public function addSchedule($start_at, $end_at = null, $status = null, $data = null) |
|
| 63 | + public function addSchedule ($start_at, $end_at = null, $status = null, $data = null) |
|
| 64 | 64 | { |
| 65 | 65 | $schedule = Scheduler::validateSchedule(self::class, $start_at, $end_at, $status); |
| 66 | 66 | |
| 67 | - $schedule['model_id'] = $this->getKey(); |
|
| 68 | - $schedule['data'] = $data; |
|
| 67 | + $schedule[ 'model_id' ] = $this->getKey(); |
|
| 68 | + $schedule[ 'data' ] = $data; |
|
| 69 | 69 | |
| 70 | 70 | return Schedule::create($schedule); |
| 71 | 71 | } |
@@ -79,7 +79,7 @@ discard block |
||
| 79 | 79 | * Se for nulo, ele busca a referencia da config. |
| 80 | 80 | * @return array |
| 81 | 81 | */ |
| 82 | - public function availableToday($duration = 0, $openingTime = null) |
|
| 82 | + public function availableToday ($duration = 0, $openingTime = null) |
|
| 83 | 83 | { |
| 84 | 84 | return Scheduler::availableToday(self::class, $duration, $openingTime); |
| 85 | 85 | } |
@@ -94,7 +94,7 @@ discard block |
||
| 94 | 94 | * Se for nulo, ele busca a referencia da config. |
| 95 | 95 | * @return array |
| 96 | 96 | */ |
| 97 | - public function availableOn($date, $duration = 0, $openingTime = null) |
|
| 97 | + public function availableOn ($date, $duration = 0, $openingTime = null) |
|
| 98 | 98 | { |
| 99 | 99 | return Scheduler::availableOn(self::class, $date, $duration, $openingTime); |
| 100 | 100 | } |
@@ -111,17 +111,17 @@ discard block |
||
| 111 | 111 | * @throws \H4ad\Scheduler\Exceptions\CantRemoveByDate |
| 112 | 112 | * @throws \H4ad\Scheduler\Exceptions\ModelNotFound |
| 113 | 113 | */ |
| 114 | - public function removeSchedule($schedule) |
|
| 114 | + public function removeSchedule ($schedule) |
|
| 115 | 115 | { |
| 116 | - if(!Config::get('scheduler.enable_schedule_conflict') && !is_int($schedule)) |
|
| 116 | + if (!Config::get('scheduler.enable_schedule_conflict') && !is_int($schedule)) |
|
| 117 | 117 | throw new CantRemoveByDate; |
| 118 | 118 | |
| 119 | 119 | $schedule = Scheduler::parseToSchedule($schedule); |
| 120 | 120 | |
| 121 | - if(!($schedule instanceof Model)) |
|
| 121 | + if (!($schedule instanceof Model)) |
|
| 122 | 122 | throw (new ModelNotFound)->setValues(Schedule::class); |
| 123 | 123 | |
| 124 | - if($schedule->model_type != self::class || $schedule->model_id != $this->getKey()) |
|
| 124 | + if ($schedule->model_type != self::class || $schedule->model_id != $this->getKey()) |
|
| 125 | 125 | throw new DoesNotBelong; |
| 126 | 126 | |
| 127 | 127 | return $schedule->delete(); |
@@ -19,76 +19,76 @@ |
||
| 19 | 19 | */ |
| 20 | 20 | class Schedule extends Model |
| 21 | 21 | { |
| 22 | - use SoftDeletes; |
|
| 22 | + use SoftDeletes; |
|
| 23 | 23 | |
| 24 | - /** |
|
| 25 | - * Os atributos que devem ser mutados para os tipos nátivos. |
|
| 26 | - * |
|
| 27 | - * @var array |
|
| 28 | - */ |
|
| 29 | - protected $casts = [ |
|
| 30 | - 'data' => 'array', |
|
| 31 | - ]; |
|
| 24 | + /** |
|
| 25 | + * Os atributos que devem ser mutados para os tipos nátivos. |
|
| 26 | + * |
|
| 27 | + * @var array |
|
| 28 | + */ |
|
| 29 | + protected $casts = [ |
|
| 30 | + 'data' => 'array', |
|
| 31 | + ]; |
|
| 32 | 32 | |
| 33 | 33 | /** |
| 34 | - * Os atributos que podem ser atribuíveis em massa. |
|
| 35 | - * |
|
| 36 | - * @var array |
|
| 37 | - */ |
|
| 38 | - protected $fillable = [ |
|
| 39 | - 'model_type', 'model_id', 'start_at', 'end_at', 'status', 'data' |
|
| 40 | - ]; |
|
| 34 | + * Os atributos que podem ser atribuíveis em massa. |
|
| 35 | + * |
|
| 36 | + * @var array |
|
| 37 | + */ |
|
| 38 | + protected $fillable = [ |
|
| 39 | + 'model_type', 'model_id', 'start_at', 'end_at', 'status', 'data' |
|
| 40 | + ]; |
|
| 41 | 41 | |
| 42 | - /** |
|
| 43 | - * Os atributos que devem ser transformados para data. |
|
| 44 | - * |
|
| 45 | - * @var array |
|
| 46 | - */ |
|
| 47 | - protected $dates = [ |
|
| 48 | - 'start_at', 'end_at', 'deleted_at' |
|
| 49 | - ]; |
|
| 42 | + /** |
|
| 43 | + * Os atributos que devem ser transformados para data. |
|
| 44 | + * |
|
| 45 | + * @var array |
|
| 46 | + */ |
|
| 47 | + protected $dates = [ |
|
| 48 | + 'start_at', 'end_at', 'deleted_at' |
|
| 49 | + ]; |
|
| 50 | 50 | |
| 51 | - /** |
|
| 52 | - * Seta um status para o horário agendado. |
|
| 53 | - * |
|
| 54 | - * @param int|string $status Pode ser passado o ID do status ou seu nome para seta-lo no horário. |
|
| 55 | - */ |
|
| 56 | - public function setStatus($name) |
|
| 57 | - { |
|
| 58 | - $this->fill($this->parseStatusKey($name))->save(); |
|
| 59 | - } |
|
| 51 | + /** |
|
| 52 | + * Seta um status para o horário agendado. |
|
| 53 | + * |
|
| 54 | + * @param int|string $status Pode ser passado o ID do status ou seu nome para seta-lo no horário. |
|
| 55 | + */ |
|
| 56 | + public function setStatus($name) |
|
| 57 | + { |
|
| 58 | + $this->fill($this->parseStatusKey($name))->save(); |
|
| 59 | + } |
|
| 60 | 60 | |
| 61 | - /** |
|
| 62 | - * Retorna o ID do status caso passem o nome do status. |
|
| 63 | - * |
|
| 64 | - * @param int|string $status ID ou o nome do status. |
|
| 65 | - * @return array |
|
| 66 | - * |
|
| 67 | - * @throws \H4ad\Scheduler\Exceptions\ModelNotFound |
|
| 68 | - */ |
|
| 69 | - public function parseStatusKey($status) |
|
| 70 | - { |
|
| 71 | - if(is_int($status)) |
|
| 72 | - $status = ScheduleStatus::find($status); |
|
| 61 | + /** |
|
| 62 | + * Retorna o ID do status caso passem o nome do status. |
|
| 63 | + * |
|
| 64 | + * @param int|string $status ID ou o nome do status. |
|
| 65 | + * @return array |
|
| 66 | + * |
|
| 67 | + * @throws \H4ad\Scheduler\Exceptions\ModelNotFound |
|
| 68 | + */ |
|
| 69 | + public function parseStatusKey($status) |
|
| 70 | + { |
|
| 71 | + if(is_int($status)) |
|
| 72 | + $status = ScheduleStatus::find($status); |
|
| 73 | 73 | |
| 74 | - if(is_string($status)) |
|
| 75 | - $status = ScheduleStatus::where('name', $status)->first(); |
|
| 74 | + if(is_string($status)) |
|
| 75 | + $status = ScheduleStatus::where('name', $status)->first(); |
|
| 76 | 76 | |
| 77 | - if(is_null($status)) |
|
| 78 | - throw (new ModelNotFound)->setValues(ScheduleStatus::class); |
|
| 77 | + if(is_null($status)) |
|
| 78 | + throw (new ModelNotFound)->setValues(ScheduleStatus::class); |
|
| 79 | 79 | |
| 80 | - return ['status' => $status->id]; |
|
| 81 | - } |
|
| 80 | + return ['status' => $status->id]; |
|
| 81 | + } |
|
| 82 | 82 | |
| 83 | - /** |
|
| 84 | - * Escopo de uma consulta que busca horarios pela data de início. |
|
| 85 | - * |
|
| 86 | - * @param \Illuminate\Database\Eloquent\Builder $query |
|
| 87 | - * @param \Carbon\Carbon|string $start_at |
|
| 88 | - * @return \Illuminate\Database\Eloquent\Builder |
|
| 89 | - */ |
|
| 90 | - public function scopeByStartAt($query, $start_at) |
|
| 91 | - { |
|
| 92 | - return $query->where('start_at', $start_at); |
|
| 93 | - } |
|
| 83 | + /** |
|
| 84 | + * Escopo de uma consulta que busca horarios pela data de início. |
|
| 85 | + * |
|
| 86 | + * @param \Illuminate\Database\Eloquent\Builder $query |
|
| 87 | + * @param \Carbon\Carbon|string $start_at |
|
| 88 | + * @return \Illuminate\Database\Eloquent\Builder |
|
| 89 | + */ |
|
| 90 | + public function scopeByStartAt($query, $start_at) |
|
| 91 | + { |
|
| 92 | + return $query->where('start_at', $start_at); |
|
| 93 | + } |
|
| 94 | 94 | } |
| 95 | 95 | \ No newline at end of file |