@@ -13,13 +13,13 @@ |
||
13 | 13 | class DoesNotBelong extends CustomException |
14 | 14 | { |
15 | 15 | |
16 | - /** |
|
17 | - * {@inheritDoc} |
|
18 | - */ |
|
19 | - protected $trans = 'does_not_belong'; |
|
16 | + /** |
|
17 | + * {@inheritDoc} |
|
18 | + */ |
|
19 | + protected $trans = 'does_not_belong'; |
|
20 | 20 | |
21 | - /** |
|
22 | - * {@inheritDoc} |
|
23 | - */ |
|
24 | - protected $statusCode = Response::HTTP_FORBIDDEN; |
|
21 | + /** |
|
22 | + * {@inheritDoc} |
|
23 | + */ |
|
24 | + protected $statusCode = Response::HTTP_FORBIDDEN; |
|
25 | 25 | } |
26 | 26 | \ No newline at end of file |
@@ -13,13 +13,13 @@ |
||
13 | 13 | class CantAddWithoutEnd extends CustomException |
14 | 14 | { |
15 | 15 | |
16 | - /** |
|
17 | - * {@inheritDoc} |
|
18 | - */ |
|
19 | - protected $trans = 'cant_add_without_end'; |
|
16 | + /** |
|
17 | + * {@inheritDoc} |
|
18 | + */ |
|
19 | + protected $trans = 'cant_add_without_end'; |
|
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 |
@@ -16,13 +16,13 @@ discard block |
||
16 | 16 | { |
17 | 17 | use SoftDeletes; |
18 | 18 | |
19 | - /** |
|
19 | + /** |
|
20 | 20 | * Os atributos que podem ser atribuíveis em massa. |
21 | 21 | * |
22 | 22 | * @var array |
23 | 23 | */ |
24 | 24 | protected $fillable = [ |
25 | - 'name', 'description' |
|
25 | + 'name', 'description' |
|
26 | 26 | ]; |
27 | 27 | |
28 | 28 | /** |
@@ -31,7 +31,7 @@ discard block |
||
31 | 31 | * @var array |
32 | 32 | */ |
33 | 33 | protected $dates = [ |
34 | - 'deleted_at' |
|
34 | + 'deleted_at' |
|
35 | 35 | ]; |
36 | 36 | |
37 | 37 | /** |
@@ -37,7 +37,7 @@ |
||
37 | 37 | /** |
38 | 38 | * Construtor para inicilizar a váriavel table. |
39 | 39 | */ |
40 | - public function __construct(array $attributes = []) |
|
40 | + public function __construct(array $attributes = [ ]) |
|
41 | 41 | { |
42 | 42 | parent::__construct($attributes); |
43 | 43 |
@@ -51,23 +51,23 @@ discard block |
||
51 | 51 | */ |
52 | 52 | public function addSchedule($start_at, $end_at = null, $status = null) |
53 | 53 | { |
54 | - if(!Config::get('scheduler.enable_schedule_without_end') && is_null($end_at)) |
|
54 | + if (!Config::get('scheduler.enable_schedule_without_end') && is_null($end_at)) |
|
55 | 55 | throw new CantAddWithoutEnd; |
56 | 56 | |
57 | - if(is_string($start_at)) |
|
57 | + if (is_string($start_at)) |
|
58 | 58 | $start_at = Carbon::parse($start_at); |
59 | 59 | |
60 | - if(is_string($end_at)) |
|
60 | + if (is_string($end_at)) |
|
61 | 61 | $end_at = Carbon::parse($end_at); |
62 | 62 | |
63 | - if(is_int($end_at)) |
|
63 | + if (is_int($end_at)) |
|
64 | 64 | $end_at = Carbon::parse($start_at->toDateTimeString())->addMinutes($end_at); |
65 | 65 | |
66 | - if(Config::get('scheduler.enable_schedule_conflict')) |
|
67 | - if(Scheduler::hasScheduleBetween($start_at, $end_at ?? $start_at)) |
|
66 | + if (Config::get('scheduler.enable_schedule_conflict')) |
|
67 | + if (Scheduler::hasScheduleBetween($start_at, $end_at ?? $start_at)) |
|
68 | 68 | throw new CantAddWithSameStartAt; |
69 | 69 | |
70 | - if($start_at->greaterThan($end_at) && !is_null($end_at)) |
|
70 | + if ($start_at->greaterThan($end_at) && !is_null($end_at)) |
|
71 | 71 | throw new EndCantBeforeStart; |
72 | 72 | |
73 | 73 | $model_id = $this->getKey(); |
@@ -90,19 +90,19 @@ discard block |
||
90 | 90 | */ |
91 | 91 | public function removeSchedule($schedule) |
92 | 92 | { |
93 | - if(!Config::get('scheduler.enable_schedule_conflict') && !is_int($schedule)) |
|
93 | + if (!Config::get('scheduler.enable_schedule_conflict') && !is_int($schedule)) |
|
94 | 94 | throw new CantRemoveByDate; |
95 | 95 | |
96 | - if(is_int($schedule)) |
|
96 | + if (is_int($schedule)) |
|
97 | 97 | $schedule = Schedule::find($schedule); |
98 | 98 | |
99 | - if(is_string($schedule) || $schedule instanceof Carbon) |
|
99 | + if (is_string($schedule) || $schedule instanceof Carbon) |
|
100 | 100 | $schedule = Schedule::byStartAt($schedule)->first(); |
101 | 101 | |
102 | - if(!($schedule instanceof Model)) |
|
102 | + if (!($schedule instanceof Model)) |
|
103 | 103 | throw (new ModelNotFound)->setValues(Schedule::class); |
104 | 104 | |
105 | - if($schedule->model_type != self::class) |
|
105 | + if ($schedule->model_type != self::class) |
|
106 | 106 | throw new DoesNotBelong; |
107 | 107 | |
108 | 108 | return $schedule->delete(); |
@@ -51,24 +51,30 @@ discard block |
||
51 | 51 | */ |
52 | 52 | public function addSchedule($start_at, $end_at = null, $status = null) |
53 | 53 | { |
54 | - if(!Config::get('scheduler.enable_schedule_without_end') && is_null($end_at)) |
|
55 | - throw new CantAddWithoutEnd; |
|
54 | + if(!Config::get('scheduler.enable_schedule_without_end') && is_null($end_at)) { |
|
55 | + throw new CantAddWithoutEnd; |
|
56 | + } |
|
56 | 57 | |
57 | - if(is_string($start_at)) |
|
58 | - $start_at = Carbon::parse($start_at); |
|
58 | + if(is_string($start_at)) { |
|
59 | + $start_at = Carbon::parse($start_at); |
|
60 | + } |
|
59 | 61 | |
60 | - if(is_string($end_at)) |
|
61 | - $end_at = Carbon::parse($end_at); |
|
62 | + if(is_string($end_at)) { |
|
63 | + $end_at = Carbon::parse($end_at); |
|
64 | + } |
|
62 | 65 | |
63 | - if(is_int($end_at)) |
|
64 | - $end_at = Carbon::parse($start_at->toDateTimeString())->addMinutes($end_at); |
|
66 | + if(is_int($end_at)) { |
|
67 | + $end_at = Carbon::parse($start_at->toDateTimeString())->addMinutes($end_at); |
|
68 | + } |
|
65 | 69 | |
66 | - if(Config::get('scheduler.enable_schedule_conflict')) |
|
67 | - if(Scheduler::hasScheduleBetween($start_at, $end_at ?? $start_at)) |
|
70 | + if(Config::get('scheduler.enable_schedule_conflict')) { |
|
71 | + if(Scheduler::hasScheduleBetween($start_at, $end_at ?? $start_at)) |
|
68 | 72 | throw new CantAddWithSameStartAt; |
73 | + } |
|
69 | 74 | |
70 | - if($start_at->greaterThan($end_at) && !is_null($end_at)) |
|
71 | - throw new EndCantBeforeStart; |
|
75 | + if($start_at->greaterThan($end_at) && !is_null($end_at)) { |
|
76 | + throw new EndCantBeforeStart; |
|
77 | + } |
|
72 | 78 | |
73 | 79 | $model_id = $this->getKey(); |
74 | 80 | $model_type = self::class; |
@@ -90,20 +96,25 @@ discard block |
||
90 | 96 | */ |
91 | 97 | public function removeSchedule($schedule) |
92 | 98 | { |
93 | - if(!Config::get('scheduler.enable_schedule_conflict') && !is_int($schedule)) |
|
94 | - throw new CantRemoveByDate; |
|
99 | + if(!Config::get('scheduler.enable_schedule_conflict') && !is_int($schedule)) { |
|
100 | + throw new CantRemoveByDate; |
|
101 | + } |
|
95 | 102 | |
96 | - if(is_int($schedule)) |
|
97 | - $schedule = Schedule::find($schedule); |
|
103 | + if(is_int($schedule)) { |
|
104 | + $schedule = Schedule::find($schedule); |
|
105 | + } |
|
98 | 106 | |
99 | - if(is_string($schedule) || $schedule instanceof Carbon) |
|
100 | - $schedule = Schedule::byStartAt($schedule)->first(); |
|
107 | + if(is_string($schedule) || $schedule instanceof Carbon) { |
|
108 | + $schedule = Schedule::byStartAt($schedule)->first(); |
|
109 | + } |
|
101 | 110 | |
102 | - if(!($schedule instanceof Model)) |
|
103 | - throw (new ModelNotFound)->setValues(Schedule::class); |
|
111 | + if(!($schedule instanceof Model)) { |
|
112 | + throw (new ModelNotFound)->setValues(Schedule::class); |
|
113 | + } |
|
104 | 114 | |
105 | - if($schedule->model_type != self::class) |
|
106 | - throw new DoesNotBelong; |
|
115 | + if($schedule->model_type != self::class) { |
|
116 | + throw new DoesNotBelong; |
|
117 | + } |
|
107 | 118 | |
108 | 119 | return $schedule->delete(); |
109 | 120 | } |
@@ -26,7 +26,7 @@ discard block |
||
26 | 26 | */ |
27 | 27 | trait SchedulerModelTrait |
28 | 28 | { |
29 | - /** |
|
29 | + /** |
|
30 | 30 | * Define an inverse one-to-one or many relationship. |
31 | 31 | * |
32 | 32 | * @param string $related |
@@ -35,94 +35,94 @@ 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() |
|
53 | - { |
|
54 | - return $this->belongsTo(Config::get('scheduler.schedules_table'), 'model_id')->where('model_type', self::class); |
|
55 | - } |
|
56 | - |
|
57 | - /** |
|
58 | - * Agenda um horário para esta model. |
|
59 | - * |
|
60 | - * @param string|\Carbon\Carbon $start_at Data em que será agendado, pode ser em string ou em numa classe Carbon. |
|
61 | - * @param string|\Carbon\Carbon|int $end_at Data em que acabada esse agendamento, pode ser em string, ou numa classe Carbon |
|
62 | - * ou em int(sendo considerado os minutos de duração). |
|
63 | - * @param int $status Status desse horário ao ser agendado. |
|
64 | - * @return \H4ad\Scheduler\Models\Schedule |
|
65 | - * |
|
66 | - * @throws \H4ad\Scheduler\Exceptions\CantAddWithoutEnd |
|
67 | - * @throws \H4ad\Scheduler\Exceptions\CantAddWithSameStartAt |
|
68 | - * @throws \H4ad\Scheduler\Exceptions\EndCantBeforeStart |
|
69 | - */ |
|
70 | - public function addSchedule($start_at, $end_at = null, $status = null) |
|
71 | - { |
|
72 | - if(!Config::get('scheduler.enable_schedule_without_end') && is_null($end_at)) |
|
73 | - throw new CantAddWithoutEnd; |
|
74 | - |
|
75 | - if(is_string($start_at)) |
|
76 | - $start_at = Carbon::parse($start_at); |
|
77 | - |
|
78 | - if(is_string($end_at)) |
|
79 | - $end_at = Carbon::parse($end_at); |
|
80 | - |
|
81 | - if(is_int($end_at)) |
|
82 | - $end_at = Carbon::parse($start_at->toDateTimeString())->addMinutes($end_at); |
|
83 | - |
|
84 | - if(Config::get('scheduler.enable_schedule_conflict')) |
|
85 | - if(Scheduler::hasScheduleBetween($start_at, $end_at ?? $start_at)) |
|
86 | - throw new CantAddWithSameStartAt; |
|
87 | - |
|
88 | - if($start_at->greaterThan($end_at) && !is_null($end_at)) |
|
89 | - throw new EndCantBeforeStart; |
|
90 | - |
|
91 | - $model_id = $this->getKey(); |
|
92 | - $model_type = self::class; |
|
93 | - |
|
94 | - return Schedule::create(compact('start_at', 'end_at', 'status', 'model_id', 'model_type')); |
|
95 | - } |
|
96 | - |
|
97 | - /** |
|
98 | - * Remove um horário agendado pelo seu ID ou pelo horário em que foi marcado. |
|
99 | - * Caso a configuração "enable_schedule_conflict" estiver desabilitada, será lançado uma exceção |
|
100 | - * se for tentado remover um horário agendado pela data de quando foi marcado. |
|
101 | - * |
|
102 | - * @param int|string|\Carbon\Carbon $schedule Horário agendado. |
|
103 | - * @return bool|null |
|
104 | - * |
|
105 | - * @throws \H4ad\Scheduler\Exceptions\DoesNotBelong |
|
106 | - * @throws \H4ad\Scheduler\Exceptions\CantRemoveByDate |
|
107 | - * @throws \H4ad\Scheduler\Exceptions\ModelNotFound |
|
108 | - */ |
|
109 | - public function removeSchedule($schedule) |
|
110 | - { |
|
111 | - if(!Config::get('scheduler.enable_schedule_conflict') && !is_int($schedule)) |
|
112 | - throw new CantRemoveByDate; |
|
113 | - |
|
114 | - if(is_int($schedule)) |
|
115 | - $schedule = Schedule::find($schedule); |
|
116 | - |
|
117 | - if(is_string($schedule) || $schedule instanceof Carbon) |
|
118 | - $schedule = Schedule::byStartAt($schedule)->first(); |
|
119 | - |
|
120 | - if(!($schedule instanceof Model)) |
|
121 | - throw (new ModelNotFound)->setValues(Schedule::class); |
|
122 | - |
|
123 | - if($schedule->model_type != self::class) |
|
124 | - throw new DoesNotBelong; |
|
125 | - |
|
126 | - return $schedule->delete(); |
|
127 | - } |
|
52 | + public function schedules() |
|
53 | + { |
|
54 | + return $this->belongsTo(Config::get('scheduler.schedules_table'), 'model_id')->where('model_type', self::class); |
|
55 | + } |
|
56 | + |
|
57 | + /** |
|
58 | + * Agenda um horário para esta model. |
|
59 | + * |
|
60 | + * @param string|\Carbon\Carbon $start_at Data em que será agendado, pode ser em string ou em numa classe Carbon. |
|
61 | + * @param string|\Carbon\Carbon|int $end_at Data em que acabada esse agendamento, pode ser em string, ou numa classe Carbon |
|
62 | + * ou em int(sendo considerado os minutos de duração). |
|
63 | + * @param int $status Status desse horário ao ser agendado. |
|
64 | + * @return \H4ad\Scheduler\Models\Schedule |
|
65 | + * |
|
66 | + * @throws \H4ad\Scheduler\Exceptions\CantAddWithoutEnd |
|
67 | + * @throws \H4ad\Scheduler\Exceptions\CantAddWithSameStartAt |
|
68 | + * @throws \H4ad\Scheduler\Exceptions\EndCantBeforeStart |
|
69 | + */ |
|
70 | + public function addSchedule($start_at, $end_at = null, $status = null) |
|
71 | + { |
|
72 | + if(!Config::get('scheduler.enable_schedule_without_end') && is_null($end_at)) |
|
73 | + throw new CantAddWithoutEnd; |
|
74 | + |
|
75 | + if(is_string($start_at)) |
|
76 | + $start_at = Carbon::parse($start_at); |
|
77 | + |
|
78 | + if(is_string($end_at)) |
|
79 | + $end_at = Carbon::parse($end_at); |
|
80 | + |
|
81 | + if(is_int($end_at)) |
|
82 | + $end_at = Carbon::parse($start_at->toDateTimeString())->addMinutes($end_at); |
|
83 | + |
|
84 | + if(Config::get('scheduler.enable_schedule_conflict')) |
|
85 | + if(Scheduler::hasScheduleBetween($start_at, $end_at ?? $start_at)) |
|
86 | + throw new CantAddWithSameStartAt; |
|
87 | + |
|
88 | + if($start_at->greaterThan($end_at) && !is_null($end_at)) |
|
89 | + throw new EndCantBeforeStart; |
|
90 | + |
|
91 | + $model_id = $this->getKey(); |
|
92 | + $model_type = self::class; |
|
93 | + |
|
94 | + return Schedule::create(compact('start_at', 'end_at', 'status', 'model_id', 'model_type')); |
|
95 | + } |
|
96 | + |
|
97 | + /** |
|
98 | + * Remove um horário agendado pelo seu ID ou pelo horário em que foi marcado. |
|
99 | + * Caso a configuração "enable_schedule_conflict" estiver desabilitada, será lançado uma exceção |
|
100 | + * se for tentado remover um horário agendado pela data de quando foi marcado. |
|
101 | + * |
|
102 | + * @param int|string|\Carbon\Carbon $schedule Horário agendado. |
|
103 | + * @return bool|null |
|
104 | + * |
|
105 | + * @throws \H4ad\Scheduler\Exceptions\DoesNotBelong |
|
106 | + * @throws \H4ad\Scheduler\Exceptions\CantRemoveByDate |
|
107 | + * @throws \H4ad\Scheduler\Exceptions\ModelNotFound |
|
108 | + */ |
|
109 | + public function removeSchedule($schedule) |
|
110 | + { |
|
111 | + if(!Config::get('scheduler.enable_schedule_conflict') && !is_int($schedule)) |
|
112 | + throw new CantRemoveByDate; |
|
113 | + |
|
114 | + if(is_int($schedule)) |
|
115 | + $schedule = Schedule::find($schedule); |
|
116 | + |
|
117 | + if(is_string($schedule) || $schedule instanceof Carbon) |
|
118 | + $schedule = Schedule::byStartAt($schedule)->first(); |
|
119 | + |
|
120 | + if(!($schedule instanceof Model)) |
|
121 | + throw (new ModelNotFound)->setValues(Schedule::class); |
|
122 | + |
|
123 | + if($schedule->model_type != self::class) |
|
124 | + throw new DoesNotBelong; |
|
125 | + |
|
126 | + return $schedule->delete(); |
|
127 | + } |
|
128 | 128 | } |
129 | 129 | \ No newline at end of file |
@@ -84,8 +84,8 @@ |
||
84 | 84 | $add = true; |
85 | 85 | |
86 | 86 | foreach (Schedule::orderBy('start_at', 'DESC')->cursor() as $schedule) { |
87 | - if($schedule->model_type != $model_type) |
|
88 | - continue; |
|
87 | + if($schedule->model_type != $model_type) |
|
88 | + continue; |
|
89 | 89 | |
90 | 90 | $start = Carbon::parse($schedule->start_at); |
91 | 91 | $begin = Carbon::parse($start->toDateString()); |
@@ -77,33 +77,33 @@ |
||
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 | |
86 | 86 | foreach (Schedule::orderBy('start_at', 'DESC')->cursor() as $schedule) { |
87 | - if($schedule->model_type != $model_type) |
|
87 | + if ($schedule->model_type != $model_type) |
|
88 | 88 | continue; |
89 | 89 | |
90 | 90 | $start = Carbon::parse($schedule->start_at); |
91 | 91 | $begin = Carbon::parse($start->toDateString()); |
92 | 92 | |
93 | - if($begin->greaterThan($today)) |
|
93 | + if ($begin->greaterThan($today)) |
|
94 | 94 | break; |
95 | 95 | |
96 | - if($begin->notEqualTo($today)) |
|
96 | + if ($begin->notEqualTo($today)) |
|
97 | 97 | continue; |
98 | 98 | |
99 | 99 | $end = Carbon::parse($schedule->end_at); |
100 | - if($start <= Carbon::parse($openingTime->toDateTimeString()) |
|
100 | + if ($start <= Carbon::parse($openingTime->toDateTimeString()) |
|
101 | 101 | && $end >= Carbon::parse($openingTime->toDateTimeString())->addMinutes($durationMinutes)) |
102 | 102 | $add = false; |
103 | 103 | } |
104 | 104 | |
105 | - if($add) |
|
106 | - $livres[] = [ |
|
105 | + if ($add) |
|
106 | + $livres[ ] = [ |
|
107 | 107 | 'start_at' => Carbon::parse($openingTime->toDateTimeString()), |
108 | 108 | 'end_at' => Carbon::parse($openingTime->toDateTimeString())->addMinutes($durationMinutes) |
109 | 109 | ]; |
@@ -84,29 +84,34 @@ |
||
84 | 84 | $add = true; |
85 | 85 | |
86 | 86 | foreach (Schedule::orderBy('start_at', 'DESC')->cursor() as $schedule) { |
87 | - if($schedule->model_type != $model_type) |
|
88 | - continue; |
|
87 | + if($schedule->model_type != $model_type) { |
|
88 | + continue; |
|
89 | + } |
|
89 | 90 | |
90 | 91 | $start = Carbon::parse($schedule->start_at); |
91 | 92 | $begin = Carbon::parse($start->toDateString()); |
92 | 93 | |
93 | - if($begin->greaterThan($today)) |
|
94 | - break; |
|
94 | + if($begin->greaterThan($today)) { |
|
95 | + break; |
|
96 | + } |
|
95 | 97 | |
96 | - if($begin->notEqualTo($today)) |
|
97 | - continue; |
|
98 | + if($begin->notEqualTo($today)) { |
|
99 | + continue; |
|
100 | + } |
|
98 | 101 | |
99 | 102 | $end = Carbon::parse($schedule->end_at); |
100 | 103 | if($start <= Carbon::parse($openingTime->toDateTimeString()) |
101 | - && $end >= Carbon::parse($openingTime->toDateTimeString())->addMinutes($durationMinutes)) |
|
102 | - $add = false; |
|
104 | + && $end >= Carbon::parse($openingTime->toDateTimeString())->addMinutes($durationMinutes)) { |
|
105 | + $add = false; |
|
106 | + } |
|
103 | 107 | } |
104 | 108 | |
105 | - if($add) |
|
106 | - $livres[] = [ |
|
109 | + if($add) { |
|
110 | + $livres[] = [ |
|
107 | 111 | 'start_at' => Carbon::parse($openingTime->toDateTimeString()), |
108 | 112 | 'end_at' => Carbon::parse($openingTime->toDateTimeString())->addMinutes($durationMinutes) |
109 | 113 | ]; |
114 | + } |
|
110 | 115 | |
111 | 116 | $openingTime->addMinutes($durationMinutes); |
112 | 117 | } |
@@ -16,13 +16,13 @@ discard block |
||
16 | 16 | { |
17 | 17 | use SoftDeletes; |
18 | 18 | |
19 | - /** |
|
19 | + /** |
|
20 | 20 | * Os atributos que podem ser atribuíveis em massa. |
21 | 21 | * |
22 | 22 | * @var array |
23 | 23 | */ |
24 | 24 | protected $fillable = [ |
25 | - 'model_type', 'model_id', 'start_at', 'end_at', 'status' |
|
25 | + 'model_type', 'model_id', 'start_at', 'end_at', 'status' |
|
26 | 26 | ]; |
27 | 27 | |
28 | 28 | /** |
@@ -31,7 +31,7 @@ discard block |
||
31 | 31 | * @var array |
32 | 32 | */ |
33 | 33 | protected $dates = [ |
34 | - 'start_at', 'end_at', 'deleted_at' |
|
34 | + 'start_at', 'end_at', 'deleted_at' |
|
35 | 35 | ]; |
36 | 36 | |
37 | 37 | /** |
@@ -41,7 +41,7 @@ discard block |
||
41 | 41 | */ |
42 | 42 | public function setStatus($name) |
43 | 43 | { |
44 | - $this->fill($this->parseStatusKey($name))->save(); |
|
44 | + $this->fill($this->parseStatusKey($name))->save(); |
|
45 | 45 | } |
46 | 46 | |
47 | 47 | /** |
@@ -52,15 +52,15 @@ discard block |
||
52 | 52 | */ |
53 | 53 | public function parseStatusKey($key) |
54 | 54 | { |
55 | - if(is_int($key)) |
|
56 | - return ['status' => $key]; |
|
55 | + if(is_int($key)) |
|
56 | + return ['status' => $key]; |
|
57 | 57 | |
58 | - $status = ScheduleStatus::where('name', $key)->first(); |
|
58 | + $status = ScheduleStatus::where('name', $key)->first(); |
|
59 | 59 | |
60 | - if(is_null($status)) |
|
61 | - throw (new ModelNotFound)->setValues(ScheduleStatus::class); |
|
60 | + if(is_null($status)) |
|
61 | + throw (new ModelNotFound)->setValues(ScheduleStatus::class); |
|
62 | 62 | |
63 | - return ['status' => $status->id]; |
|
63 | + return ['status' => $status->id]; |
|
64 | 64 | } |
65 | 65 | |
66 | 66 | /** |
@@ -52,15 +52,15 @@ |
||
52 | 52 | */ |
53 | 53 | public function parseStatusKey($key) |
54 | 54 | { |
55 | - if(is_int($key)) |
|
56 | - return ['status' => $key]; |
|
55 | + if (is_int($key)) |
|
56 | + return [ 'status' => $key ]; |
|
57 | 57 | |
58 | 58 | $status = ScheduleStatus::where('name', $key)->first(); |
59 | 59 | |
60 | - if(is_null($status)) |
|
60 | + if (is_null($status)) |
|
61 | 61 | throw (new ModelNotFound)->setValues(ScheduleStatus::class); |
62 | 62 | |
63 | - return ['status' => $status->id]; |
|
63 | + return [ 'status' => $status->id ]; |
|
64 | 64 | } |
65 | 65 | |
66 | 66 | /** |
@@ -52,13 +52,15 @@ |
||
52 | 52 | */ |
53 | 53 | public function parseStatusKey($key) |
54 | 54 | { |
55 | - if(is_int($key)) |
|
56 | - return ['status' => $key]; |
|
55 | + if(is_int($key)) { |
|
56 | + return ['status' => $key]; |
|
57 | + } |
|
57 | 58 | |
58 | 59 | $status = ScheduleStatus::where('name', $key)->first(); |
59 | 60 | |
60 | - if(is_null($status)) |
|
61 | - throw (new ModelNotFound)->setValues(ScheduleStatus::class); |
|
61 | + if(is_null($status)) { |
|
62 | + throw (new ModelNotFound)->setValues(ScheduleStatus::class); |
|
63 | + } |
|
62 | 64 | |
63 | 65 | return ['status' => $status->id]; |
64 | 66 | } |
@@ -10,7 +10,7 @@ discard block |
||
10 | 10 | |
11 | 11 | interface SchedulerModelInterface |
12 | 12 | { |
13 | - /** |
|
13 | + /** |
|
14 | 14 | * Define an inverse one-to-one or many relationship. |
15 | 15 | * |
16 | 16 | * @param string $related |
@@ -19,67 +19,67 @@ discard block |
||
19 | 19 | * @param string $relation |
20 | 20 | * @return \Illuminate\Database\Eloquent\Relations\BelongsTo |
21 | 21 | */ |
22 | - abstract public function belongsTo($related, $foreignKey = null, $ownerKey = null, $relation = null); |
|
22 | + abstract public function belongsTo($related, $foreignKey = null, $ownerKey = null, $relation = null); |
|
23 | 23 | |
24 | - /** |
|
24 | + /** |
|
25 | 25 | * Get the value of the model's primary key. |
26 | 26 | * |
27 | 27 | * @return mixed |
28 | 28 | */ |
29 | - abstract public function getKey(); |
|
29 | + abstract public function getKey(); |
|
30 | 30 | |
31 | - /** |
|
31 | + /** |
|
32 | 32 | * Retorna apenas os horários que possuem o mesmo [model_type] do [parent] dessa [trait]. |
33 | 33 | * |
34 | 34 | * @return \Illuminate\Database\Eloquent\Relations\BelongsTo |
35 | 35 | */ |
36 | - public function schedules(); |
|
36 | + public function schedules(); |
|
37 | 37 | |
38 | - /** |
|
39 | - * Agenda um horário para esta model. |
|
40 | - * |
|
41 | - * @param string|\Carbon\Carbon $start_at Data em que será agendado, pode ser em string ou em numa classe Carbon. |
|
42 | - * @param string|\Carbon\Carbon|int $end_at Data em que acabada esse agendamento, pode ser em string, ou numa classe Carbon |
|
43 | - * ou em int(sendo considerado os minutos de duração). |
|
44 | - * @param int $status Status desse horário ao ser agendado. |
|
45 | - * @return \H4ad\Scheduler\Models\Schedule |
|
46 | - * |
|
47 | - * @throws \H4ad\Scheduler\Exceptions\CantAddWithoutEnd |
|
48 | - * @throws \H4ad\Scheduler\Exceptions\CantAddWithSameStartAt |
|
49 | - * @throws \H4ad\Scheduler\Exceptions\EndCantBeforeStart |
|
50 | - */ |
|
51 | - public function addSchedule($start_at, $end_at = null, $status = null); |
|
38 | + /** |
|
39 | + * Agenda um horário para esta model. |
|
40 | + * |
|
41 | + * @param string|\Carbon\Carbon $start_at Data em que será agendado, pode ser em string ou em numa classe Carbon. |
|
42 | + * @param string|\Carbon\Carbon|int $end_at Data em que acabada esse agendamento, pode ser em string, ou numa classe Carbon |
|
43 | + * ou em int(sendo considerado os minutos de duração). |
|
44 | + * @param int $status Status desse horário ao ser agendado. |
|
45 | + * @return \H4ad\Scheduler\Models\Schedule |
|
46 | + * |
|
47 | + * @throws \H4ad\Scheduler\Exceptions\CantAddWithoutEnd |
|
48 | + * @throws \H4ad\Scheduler\Exceptions\CantAddWithSameStartAt |
|
49 | + * @throws \H4ad\Scheduler\Exceptions\EndCantBeforeStart |
|
50 | + */ |
|
51 | + public function addSchedule($start_at, $end_at = null, $status = null); |
|
52 | 52 | |
53 | - /** |
|
54 | - * Exibe uma lista dos horários do dia de hoje. |
|
55 | - * |
|
56 | - * @param int $duration Serve para facilitar na hora de buscar horários livres |
|
57 | - * que precisem ter uma certa duração. |
|
58 | - * @return array |
|
59 | - */ |
|
60 | - public function availableToday($duration = 0); |
|
53 | + /** |
|
54 | + * Exibe uma lista dos horários do dia de hoje. |
|
55 | + * |
|
56 | + * @param int $duration Serve para facilitar na hora de buscar horários livres |
|
57 | + * que precisem ter uma certa duração. |
|
58 | + * @return array |
|
59 | + */ |
|
60 | + public function availableToday($duration = 0); |
|
61 | 61 | |
62 | - /** |
|
63 | - * Lista os horários livres em um determinado dia. |
|
64 | - * |
|
65 | - * @param string|\Carbon\Carbon $date Data para o qual ele irá fazer a busca. |
|
66 | - * @param int $duration Serve para facilitar na hora de buscar horários livres |
|
67 | - * que precisem ter uma certa duração. |
|
68 | - * @return array |
|
69 | - */ |
|
70 | - public function availableOn($date, $duration = 0); |
|
62 | + /** |
|
63 | + * Lista os horários livres em um determinado dia. |
|
64 | + * |
|
65 | + * @param string|\Carbon\Carbon $date Data para o qual ele irá fazer a busca. |
|
66 | + * @param int $duration Serve para facilitar na hora de buscar horários livres |
|
67 | + * que precisem ter uma certa duração. |
|
68 | + * @return array |
|
69 | + */ |
|
70 | + public function availableOn($date, $duration = 0); |
|
71 | 71 | |
72 | - /** |
|
73 | - * Remove um horário agendado pelo seu ID ou pelo horário em que foi marcado. |
|
74 | - * Caso a configuração "enable_schedule_conflict" estiver desabilitada, será lançado uma exceção |
|
75 | - * se for tentado remover um horário agendado pela data de quando foi marcado. |
|
76 | - * |
|
77 | - * @param int|string|\Carbon\Carbon $schedule Horário agendado. |
|
78 | - * @return bool|null |
|
79 | - * |
|
80 | - * @throws \H4ad\Scheduler\Exceptions\DoesNotBelong |
|
81 | - * @throws \H4ad\Scheduler\Exceptions\CantRemoveByDate |
|
82 | - * @throws \H4ad\Scheduler\Exceptions\ModelNotFound |
|
83 | - */ |
|
84 | - public function removeSchedule($schedule); |
|
72 | + /** |
|
73 | + * Remove um horário agendado pelo seu ID ou pelo horário em que foi marcado. |
|
74 | + * Caso a configuração "enable_schedule_conflict" estiver desabilitada, será lançado uma exceção |
|
75 | + * se for tentado remover um horário agendado pela data de quando foi marcado. |
|
76 | + * |
|
77 | + * @param int|string|\Carbon\Carbon $schedule Horário agendado. |
|
78 | + * @return bool|null |
|
79 | + * |
|
80 | + * @throws \H4ad\Scheduler\Exceptions\DoesNotBelong |
|
81 | + * @throws \H4ad\Scheduler\Exceptions\CantRemoveByDate |
|
82 | + * @throws \H4ad\Scheduler\Exceptions\ModelNotFound |
|
83 | + */ |
|
84 | + public function removeSchedule($schedule); |
|
85 | 85 | } |
86 | 86 | \ No newline at end of file |