@@ -88,8 +88,9 @@ discard block |
||
88 | 88 | */ |
89 | 89 | protected function parseValues() |
90 | 90 | { |
91 | - if(is_array($this->attributes) && is_array($this->values)) |
|
92 | - return collect($this->attributes)->combine($this->values)->all(); |
|
91 | + if(is_array($this->attributes) && is_array($this->values)) { |
|
92 | + return collect($this->attributes)->combine($this->values)->all(); |
|
93 | + } |
|
93 | 94 | |
94 | 95 | return [ $this->attributes => $this->values ?? $this->isLower() ]; |
95 | 96 | } |
@@ -111,8 +112,9 @@ discard block |
||
111 | 112 | */ |
112 | 113 | protected function getAlias() |
113 | 114 | { |
114 | - if(is_object($this->model)) |
|
115 | - $this->model = get_class($this->model); |
|
115 | + if(is_object($this->model)) { |
|
116 | + $this->model = get_class($this->model); |
|
117 | + } |
|
116 | 118 | |
117 | 119 | return collect(trans('scheduler::exceptions.aliases.'. $this->aliastype))->search($this->model) ?: 'Recurso'; |
118 | 120 | } |
@@ -10,122 +10,122 @@ |
||
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()->json([ |
|
80 | - 'messages' => trans('scheduler::exceptions.'. $this->trans, $this->parseValues()) |
|
81 | - ], $this->statusCode); |
|
82 | - } |
|
83 | - |
|
84 | - /** |
|
85 | - * Dá parse nos valores para a string de tradução. |
|
86 | - * |
|
87 | - * @return array |
|
88 | - */ |
|
89 | - protected function parseValues() |
|
90 | - { |
|
91 | - if(is_array($this->attributes) && is_array($this->values)) |
|
92 | - return collect($this->attributes)->combine($this->values)->all(); |
|
93 | - |
|
94 | - return [ $this->attributes => $this->values ?? $this->isLower() ]; |
|
95 | - } |
|
96 | - |
|
97 | - /** |
|
98 | - * Verifica se é lowercase e retorna de acordo. |
|
99 | - * |
|
100 | - * @return string |
|
101 | - */ |
|
102 | - protected function isLower() |
|
103 | - { |
|
104 | - return $this->lowercase ? strtolower($this->getAlias()) : $this->getAlias(); |
|
105 | - } |
|
106 | - |
|
107 | - /** |
|
108 | - * Retorna o alias da model. |
|
109 | - * |
|
110 | - * @return string |
|
111 | - */ |
|
112 | - protected function getAlias() |
|
113 | - { |
|
114 | - if(is_object($this->model)) |
|
115 | - $this->model = get_class($this->model); |
|
116 | - |
|
117 | - return collect(trans('scheduler::exceptions.aliases.'. $this->aliastype))->search($this->model) ?: 'Recurso'; |
|
118 | - } |
|
119 | - |
|
120 | - /** |
|
121 | - * Seta os valores. |
|
122 | - * |
|
123 | - * @param mixed $values |
|
124 | - */ |
|
125 | - public function setValues($values) |
|
126 | - { |
|
127 | - $this->values = $values; |
|
128 | - |
|
129 | - return $this; |
|
130 | - } |
|
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()->json([ |
|
80 | + 'messages' => trans('scheduler::exceptions.'. $this->trans, $this->parseValues()) |
|
81 | + ], $this->statusCode); |
|
82 | + } |
|
83 | + |
|
84 | + /** |
|
85 | + * Dá parse nos valores para a string de tradução. |
|
86 | + * |
|
87 | + * @return array |
|
88 | + */ |
|
89 | + protected function parseValues() |
|
90 | + { |
|
91 | + if(is_array($this->attributes) && is_array($this->values)) |
|
92 | + return collect($this->attributes)->combine($this->values)->all(); |
|
93 | + |
|
94 | + return [ $this->attributes => $this->values ?? $this->isLower() ]; |
|
95 | + } |
|
96 | + |
|
97 | + /** |
|
98 | + * Verifica se é lowercase e retorna de acordo. |
|
99 | + * |
|
100 | + * @return string |
|
101 | + */ |
|
102 | + protected function isLower() |
|
103 | + { |
|
104 | + return $this->lowercase ? strtolower($this->getAlias()) : $this->getAlias(); |
|
105 | + } |
|
106 | + |
|
107 | + /** |
|
108 | + * Retorna o alias da model. |
|
109 | + * |
|
110 | + * @return string |
|
111 | + */ |
|
112 | + protected function getAlias() |
|
113 | + { |
|
114 | + if(is_object($this->model)) |
|
115 | + $this->model = get_class($this->model); |
|
116 | + |
|
117 | + return collect(trans('scheduler::exceptions.aliases.'. $this->aliastype))->search($this->model) ?: 'Recurso'; |
|
118 | + } |
|
119 | + |
|
120 | + /** |
|
121 | + * Seta os valores. |
|
122 | + * |
|
123 | + * @param mixed $values |
|
124 | + */ |
|
125 | + public function setValues($values) |
|
126 | + { |
|
127 | + $this->values = $values; |
|
128 | + |
|
129 | + return $this; |
|
130 | + } |
|
131 | 131 | } |
@@ -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,10 +74,10 @@ 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()->json([ |
80 | - 'messages' => trans('scheduler::exceptions.'. $this->trans, $this->parseValues()) |
|
80 | + 'messages' => trans('scheduler::exceptions.' . $this->trans, $this->parseValues()) |
|
81 | 81 | ], $this->statusCode); |
82 | 82 | } |
83 | 83 | |
@@ -86,9 +86,9 @@ discard block |
||
86 | 86 | * |
87 | 87 | * @return array |
88 | 88 | */ |
89 | - protected function parseValues() |
|
89 | + protected function parseValues () |
|
90 | 90 | { |
91 | - if(is_array($this->attributes) && is_array($this->values)) |
|
91 | + if (is_array($this->attributes) && is_array($this->values)) |
|
92 | 92 | return collect($this->attributes)->combine($this->values)->all(); |
93 | 93 | |
94 | 94 | return [ $this->attributes => $this->values ?? $this->isLower() ]; |
@@ -99,7 +99,7 @@ discard block |
||
99 | 99 | * |
100 | 100 | * @return string |
101 | 101 | */ |
102 | - protected function isLower() |
|
102 | + protected function isLower () |
|
103 | 103 | { |
104 | 104 | return $this->lowercase ? strtolower($this->getAlias()) : $this->getAlias(); |
105 | 105 | } |
@@ -109,12 +109,12 @@ discard block |
||
109 | 109 | * |
110 | 110 | * @return string |
111 | 111 | */ |
112 | - protected function getAlias() |
|
112 | + protected function getAlias () |
|
113 | 113 | { |
114 | - if(is_object($this->model)) |
|
114 | + if (is_object($this->model)) |
|
115 | 115 | $this->model = get_class($this->model); |
116 | 116 | |
117 | - return collect(trans('scheduler::exceptions.aliases.'. $this->aliastype))->search($this->model) ?: 'Recurso'; |
|
117 | + return collect(trans('scheduler::exceptions.aliases.' . $this->aliastype))->search($this->model) ?: 'Recurso'; |
|
118 | 118 | } |
119 | 119 | |
120 | 120 | /** |
@@ -122,7 +122,7 @@ discard block |
||
122 | 122 | * |
123 | 123 | * @param mixed $values |
124 | 124 | */ |
125 | - public function setValues($values) |
|
125 | + public function setValues ($values) |
|
126 | 126 | { |
127 | 127 | $this->values = $values; |
128 | 128 |
@@ -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 | } |
@@ -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')->where('model_type', self::class); |
@@ -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')->where('model_type', self::class); |
55 | 55 | } |
@@ -67,25 +67,25 @@ 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 | - if(is_string($start_at)) |
|
75 | + if (is_string($start_at)) |
|
76 | 76 | $start_at = Carbon::parse($start_at); |
77 | 77 | |
78 | - if(is_string($end_at)) |
|
78 | + if (is_string($end_at)) |
|
79 | 79 | $end_at = Carbon::parse($end_at); |
80 | 80 | |
81 | - if(is_int($end_at)) |
|
81 | + if (is_int($end_at)) |
|
82 | 82 | $end_at = Carbon::parse($start_at->toDateTimeString())->addMinutes($end_at); |
83 | 83 | |
84 | - if(Config::get('scheduler.enable_schedule_conflict')) |
|
85 | - if(Scheduler::hasScheduleBetween($start_at, $end_at ?? $start_at)) |
|
84 | + if (Config::get('scheduler.enable_schedule_conflict')) |
|
85 | + if (Scheduler::hasScheduleBetween($start_at, $end_at ?? $start_at)) |
|
86 | 86 | throw new CantAddWithSameStartAt; |
87 | 87 | |
88 | - if($start_at->greaterThan($end_at) && !is_null($end_at)) |
|
88 | + if ($start_at->greaterThan($end_at) && !is_null($end_at)) |
|
89 | 89 | throw new EndCantBeforeStart; |
90 | 90 | |
91 | 91 | $model_id = $this->getKey(); |
@@ -106,21 +106,21 @@ discard block |
||
106 | 106 | * @throws \H4ad\Scheduler\Exceptions\CantRemoveByDate |
107 | 107 | * @throws \H4ad\Scheduler\Exceptions\ModelNotFound |
108 | 108 | */ |
109 | - public function removeSchedule($schedule) |
|
109 | + public function removeSchedule ($schedule) |
|
110 | 110 | { |
111 | - if(!Config::get('scheduler.enable_schedule_conflict') && !is_int($schedule)) |
|
111 | + if (!Config::get('scheduler.enable_schedule_conflict') && !is_int($schedule)) |
|
112 | 112 | throw new CantRemoveByDate; |
113 | 113 | |
114 | - if(is_int($schedule)) |
|
114 | + if (is_int($schedule)) |
|
115 | 115 | $schedule = Schedule::find($schedule); |
116 | 116 | |
117 | - if(is_string($schedule) || $schedule instanceof Carbon) |
|
117 | + if (is_string($schedule) || $schedule instanceof Carbon) |
|
118 | 118 | $schedule = Schedule::byStartAt($schedule)->first(); |
119 | 119 | |
120 | - if(!($schedule instanceof Model)) |
|
120 | + if (!($schedule instanceof Model)) |
|
121 | 121 | throw (new ModelNotFound)->setValues(Schedule::class); |
122 | 122 | |
123 | - if($schedule->model_type != self::class) |
|
123 | + if ($schedule->model_type != self::class) |
|
124 | 124 | throw new DoesNotBelong; |
125 | 125 | |
126 | 126 | return $schedule->delete(); |
@@ -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 | } |
@@ -14,103 +14,103 @@ |
||
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($start_at, $end_at) |
|
44 | - { |
|
45 | - return !is_null( |
|
46 | - Schedule::latest() |
|
47 | - ->where('start_at', '>=', $start_at) |
|
48 | - ->where('end_at', '<=', $end_at) |
|
49 | - ->first() |
|
50 | - ); |
|
51 | - } |
|
52 | - |
|
53 | - /** |
|
54 | - * Retorna os horários disponiveis hoje para uma determinada model. |
|
55 | - * . |
|
56 | - * @param string $model_type Tipo da model |
|
57 | - * @param int $duration Serve para facilitar na hora de buscar horários livres |
|
58 | - * que precisem ter uma certa duração. |
|
59 | - * @return array |
|
60 | - */ |
|
61 | - public function availableToday($model_type, $duration = 0) |
|
62 | - { |
|
63 | - return $this->availableOn($model_type, Carbon::now(), $duration); |
|
64 | - } |
|
65 | - |
|
66 | - /** |
|
67 | - * Retorna os horários disponiveis em um determinado dia para uma certa model. |
|
68 | - * |
|
69 | - * @param string $model_type Tipo da model |
|
70 | - * @param string|\Carbon\Carbon $date Data para o qual ele irá fazer a busca. |
|
71 | - * @param int $durationMinutes Serve para facilitar na hora de buscar horários livres |
|
72 | - * que precisem ter uma certa duração. |
|
73 | - * @return array |
|
74 | - */ |
|
75 | - public function availableOn($model_type, $today, $durationMinutes) |
|
76 | - { |
|
77 | - $openingTime = Carbon::parse(Config::get('scheduler.opening_time'))->setDateFrom($today); |
|
78 | - $closingTime = Carbon::parse(Config::get('scheduler.closing_time'))->setDateFrom($today); |
|
79 | - |
|
80 | - $livres = []; |
|
81 | - $today = Carbon::parse($today->toDateString()); |
|
82 | - while($openingTime <= $closingTime) |
|
83 | - { |
|
84 | - $add = true; |
|
85 | - |
|
86 | - foreach (Schedule::orderBy('start_at', 'DESC')->cursor() as $schedule) { |
|
87 | - if($schedule->model_type != $model_type) |
|
88 | - continue; |
|
89 | - |
|
90 | - $start = Carbon::parse($schedule->start_at); |
|
91 | - $begin = Carbon::parse($start->toDateString()); |
|
92 | - |
|
93 | - if($begin->greaterThan($today)) |
|
94 | - break; |
|
95 | - |
|
96 | - if($begin->notEqualTo($today)) |
|
97 | - continue; |
|
98 | - |
|
99 | - $end = Carbon::parse($schedule->end_at); |
|
100 | - if($start <= Carbon::parse($openingTime->toDateTimeString()) |
|
101 | - && $end >= Carbon::parse($openingTime->toDateTimeString())->addMinutes($durationMinutes)) |
|
102 | - $add = false; |
|
103 | - } |
|
104 | - |
|
105 | - if($add) |
|
106 | - $livres[] = [ |
|
107 | - 'start_at' => Carbon::parse($openingTime->toDateTimeString()), |
|
108 | - 'end_at' => Carbon::parse($openingTime->toDateTimeString())->addMinutes($durationMinutes) |
|
109 | - ]; |
|
110 | - |
|
111 | - $openingTime->addMinutes($durationMinutes); |
|
112 | - } |
|
113 | - |
|
114 | - return $livres; |
|
115 | - } |
|
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($start_at, $end_at) |
|
44 | + { |
|
45 | + return !is_null( |
|
46 | + Schedule::latest() |
|
47 | + ->where('start_at', '>=', $start_at) |
|
48 | + ->where('end_at', '<=', $end_at) |
|
49 | + ->first() |
|
50 | + ); |
|
51 | + } |
|
52 | + |
|
53 | + /** |
|
54 | + * Retorna os horários disponiveis hoje para uma determinada model. |
|
55 | + * . |
|
56 | + * @param string $model_type Tipo da model |
|
57 | + * @param int $duration Serve para facilitar na hora de buscar horários livres |
|
58 | + * que precisem ter uma certa duração. |
|
59 | + * @return array |
|
60 | + */ |
|
61 | + public function availableToday($model_type, $duration = 0) |
|
62 | + { |
|
63 | + return $this->availableOn($model_type, Carbon::now(), $duration); |
|
64 | + } |
|
65 | + |
|
66 | + /** |
|
67 | + * Retorna os horários disponiveis em um determinado dia para uma certa model. |
|
68 | + * |
|
69 | + * @param string $model_type Tipo da model |
|
70 | + * @param string|\Carbon\Carbon $date Data para o qual ele irá fazer a busca. |
|
71 | + * @param int $durationMinutes Serve para facilitar na hora de buscar horários livres |
|
72 | + * que precisem ter uma certa duração. |
|
73 | + * @return array |
|
74 | + */ |
|
75 | + public function availableOn($model_type, $today, $durationMinutes) |
|
76 | + { |
|
77 | + $openingTime = Carbon::parse(Config::get('scheduler.opening_time'))->setDateFrom($today); |
|
78 | + $closingTime = Carbon::parse(Config::get('scheduler.closing_time'))->setDateFrom($today); |
|
79 | + |
|
80 | + $livres = []; |
|
81 | + $today = Carbon::parse($today->toDateString()); |
|
82 | + while($openingTime <= $closingTime) |
|
83 | + { |
|
84 | + $add = true; |
|
85 | + |
|
86 | + foreach (Schedule::orderBy('start_at', 'DESC')->cursor() as $schedule) { |
|
87 | + if($schedule->model_type != $model_type) |
|
88 | + continue; |
|
89 | + |
|
90 | + $start = Carbon::parse($schedule->start_at); |
|
91 | + $begin = Carbon::parse($start->toDateString()); |
|
92 | + |
|
93 | + if($begin->greaterThan($today)) |
|
94 | + break; |
|
95 | + |
|
96 | + if($begin->notEqualTo($today)) |
|
97 | + continue; |
|
98 | + |
|
99 | + $end = Carbon::parse($schedule->end_at); |
|
100 | + if($start <= Carbon::parse($openingTime->toDateTimeString()) |
|
101 | + && $end >= Carbon::parse($openingTime->toDateTimeString())->addMinutes($durationMinutes)) |
|
102 | + $add = false; |
|
103 | + } |
|
104 | + |
|
105 | + if($add) |
|
106 | + $livres[] = [ |
|
107 | + 'start_at' => Carbon::parse($openingTime->toDateTimeString()), |
|
108 | + 'end_at' => Carbon::parse($openingTime->toDateTimeString())->addMinutes($durationMinutes) |
|
109 | + ]; |
|
110 | + |
|
111 | + $openingTime->addMinutes($durationMinutes); |
|
112 | + } |
|
113 | + |
|
114 | + return $livres; |
|
115 | + } |
|
116 | 116 | } |
117 | 117 | \ 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,7 +40,7 @@ discard block |
||
40 | 40 | * @param string|\Carbon\Carbon $end_at |
41 | 41 | * @return bool |
42 | 42 | */ |
43 | - public function hasScheduleBetween($start_at, $end_at) |
|
43 | + public function hasScheduleBetween ($start_at, $end_at) |
|
44 | 44 | { |
45 | 45 | return !is_null( |
46 | 46 | Schedule::latest() |
@@ -58,7 +58,7 @@ discard block |
||
58 | 58 | * que precisem ter uma certa duração. |
59 | 59 | * @return array |
60 | 60 | */ |
61 | - public function availableToday($model_type, $duration = 0) |
|
61 | + public function availableToday ($model_type, $duration = 0) |
|
62 | 62 | { |
63 | 63 | return $this->availableOn($model_type, Carbon::now(), $duration); |
64 | 64 | } |
@@ -72,38 +72,38 @@ discard block |
||
72 | 72 | * que precisem ter uma certa duração. |
73 | 73 | * @return array |
74 | 74 | */ |
75 | - public function availableOn($model_type, $today, $durationMinutes) |
|
75 | + public function availableOn ($model_type, $today, $durationMinutes) |
|
76 | 76 | { |
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 | ]; |
@@ -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 | } |
@@ -14,64 +14,64 @@ |
||
14 | 14 | |
15 | 15 | class Schedule extends Model |
16 | 16 | { |
17 | - use SoftDeletes; |
|
17 | + use SoftDeletes; |
|
18 | 18 | |
19 | 19 | /** |
20 | - * Os atributos que podem ser atribuíveis em massa. |
|
21 | - * |
|
22 | - * @var array |
|
23 | - */ |
|
24 | - protected $fillable = [ |
|
25 | - 'model_type', 'model_id', 'start_at', 'end_at', 'status' |
|
26 | - ]; |
|
20 | + * Os atributos que podem ser atribuíveis em massa. |
|
21 | + * |
|
22 | + * @var array |
|
23 | + */ |
|
24 | + protected $fillable = [ |
|
25 | + 'model_type', 'model_id', 'start_at', 'end_at', 'status' |
|
26 | + ]; |
|
27 | 27 | |
28 | - /** |
|
29 | - * Os atributos que devem ser transformados para data. |
|
30 | - * |
|
31 | - * @var array |
|
32 | - */ |
|
33 | - protected $dates = [ |
|
34 | - 'start_at', 'end_at', 'deleted_at' |
|
35 | - ]; |
|
28 | + /** |
|
29 | + * Os atributos que devem ser transformados para data. |
|
30 | + * |
|
31 | + * @var array |
|
32 | + */ |
|
33 | + protected $dates = [ |
|
34 | + 'start_at', 'end_at', 'deleted_at' |
|
35 | + ]; |
|
36 | 36 | |
37 | - /** |
|
38 | - * Seta um status para o horário agendado. |
|
39 | - * |
|
40 | - * @param int|string $status Pode ser passado o ID do status ou seu nome para seta-lo no horário. |
|
41 | - */ |
|
42 | - public function setStatus($name) |
|
43 | - { |
|
44 | - $this->fill($this->parseStatusKey($name))->save(); |
|
45 | - } |
|
37 | + /** |
|
38 | + * Seta um status para o horário agendado. |
|
39 | + * |
|
40 | + * @param int|string $status Pode ser passado o ID do status ou seu nome para seta-lo no horário. |
|
41 | + */ |
|
42 | + public function setStatus($name) |
|
43 | + { |
|
44 | + $this->fill($this->parseStatusKey($name))->save(); |
|
45 | + } |
|
46 | 46 | |
47 | - /** |
|
48 | - * Retorna o ID do status caso passem o nome do status. |
|
49 | - * |
|
50 | - * @param int|string $key ID ou o nome do status. |
|
51 | - * @return array |
|
52 | - */ |
|
53 | - public function parseStatusKey($key) |
|
54 | - { |
|
55 | - if(is_int($key)) |
|
56 | - return ['status' => $key]; |
|
47 | + /** |
|
48 | + * Retorna o ID do status caso passem o nome do status. |
|
49 | + * |
|
50 | + * @param int|string $key ID ou o nome do status. |
|
51 | + * @return array |
|
52 | + */ |
|
53 | + public function parseStatusKey($key) |
|
54 | + { |
|
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]; |
|
64 | - } |
|
63 | + return ['status' => $status->id]; |
|
64 | + } |
|
65 | 65 | |
66 | - /** |
|
67 | - * Escopo de uma consulta que busca horarios pela data de início. |
|
68 | - * |
|
69 | - * @param \Illuminate\Database\Eloquent\Builder $query |
|
70 | - * @param mixed $start_at |
|
71 | - * @return \Illuminate\Database\Eloquent\Builder |
|
72 | - */ |
|
73 | - public function scopeByStartAt($query, $start_at) |
|
74 | - { |
|
75 | - return $query->where('start_at', $start_at); |
|
76 | - } |
|
66 | + /** |
|
67 | + * Escopo de uma consulta que busca horarios pela data de início. |
|
68 | + * |
|
69 | + * @param \Illuminate\Database\Eloquent\Builder $query |
|
70 | + * @param mixed $start_at |
|
71 | + * @return \Illuminate\Database\Eloquent\Builder |
|
72 | + */ |
|
73 | + public function scopeByStartAt($query, $start_at) |
|
74 | + { |
|
75 | + return $query->where('start_at', $start_at); |
|
76 | + } |
|
77 | 77 | } |
78 | 78 | \ No newline at end of file |
@@ -39,7 +39,7 @@ discard block |
||
39 | 39 | * |
40 | 40 | * @param int|string $status Pode ser passado o ID do status ou seu nome para seta-lo no horário. |
41 | 41 | */ |
42 | - public function setStatus($name) |
|
42 | + public function setStatus ($name) |
|
43 | 43 | { |
44 | 44 | $this->fill($this->parseStatusKey($name))->save(); |
45 | 45 | } |
@@ -50,17 +50,17 @@ discard block |
||
50 | 50 | * @param int|string $key ID ou o nome do status. |
51 | 51 | * @return array |
52 | 52 | */ |
53 | - public function parseStatusKey($key) |
|
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 | /** |
@@ -70,7 +70,7 @@ discard block |
||
70 | 70 | * @param mixed $start_at |
71 | 71 | * @return \Illuminate\Database\Eloquent\Builder |
72 | 72 | */ |
73 | - public function scopeByStartAt($query, $start_at) |
|
73 | + public function scopeByStartAt ($query, $start_at) |
|
74 | 74 | { |
75 | 75 | return $query->where('start_at', $start_at); |
76 | 76 | } |
@@ -15,29 +15,29 @@ |
||
15 | 15 | |
16 | 16 | class CreateScheduleStatusTable 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.schedule_status_table'), function (Blueprint $table) { |
|
26 | - $table->increments('id'); |
|
27 | - $table->string('name')->unique(); |
|
28 | - $table->text('description')->nullable(); |
|
29 | - $table->timestamps(); |
|
30 | - $table->softDeletes(); |
|
31 | - }); |
|
32 | - } |
|
18 | + /** |
|
19 | + * Run the migrations. |
|
20 | + * |
|
21 | + * @return void |
|
22 | + */ |
|
23 | + public function up() |
|
24 | + { |
|
25 | + Schema::create(Config::get('scheduler.schedule_status_table'), function (Blueprint $table) { |
|
26 | + $table->increments('id'); |
|
27 | + $table->string('name')->unique(); |
|
28 | + $table->text('description')->nullable(); |
|
29 | + $table->timestamps(); |
|
30 | + $table->softDeletes(); |
|
31 | + }); |
|
32 | + } |
|
33 | 33 | |
34 | - /** |
|
35 | - * Reverse the migrations. |
|
36 | - * |
|
37 | - * @return void |
|
38 | - */ |
|
39 | - public function down() |
|
40 | - { |
|
41 | - Schema::drop(Config::get('scheduler.schedule_status_table')); |
|
42 | - } |
|
34 | + /** |
|
35 | + * Reverse the migrations. |
|
36 | + * |
|
37 | + * @return void |
|
38 | + */ |
|
39 | + public function down() |
|
40 | + { |
|
41 | + Schema::drop(Config::get('scheduler.schedule_status_table')); |
|
42 | + } |
|
43 | 43 | } |
44 | 44 | \ No newline at end of file |
@@ -20,9 +20,9 @@ discard block |
||
20 | 20 | * |
21 | 21 | * @return void |
22 | 22 | */ |
23 | - public function up() |
|
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(); |
@@ -36,7 +36,7 @@ discard block |
||
36 | 36 | * |
37 | 37 | * @return void |
38 | 38 | */ |
39 | - public function down() |
|
39 | + public function down () |
|
40 | 40 | { |
41 | 41 | Schema::drop(Config::get('scheduler.schedule_status_table')); |
42 | 42 | } |
@@ -15,32 +15,32 @@ |
||
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->timestamps(); |
|
33 | - $table->softDeletes(); |
|
34 | - }); |
|
35 | - } |
|
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->timestamps(); |
|
33 | + $table->softDeletes(); |
|
34 | + }); |
|
35 | + } |
|
36 | 36 | |
37 | - /** |
|
38 | - * Reverse the migrations. |
|
39 | - * |
|
40 | - * @return void |
|
41 | - */ |
|
42 | - public function down() |
|
43 | - { |
|
44 | - Schema::drop(Config::get('scheduler.schedules_table')); |
|
45 | - } |
|
37 | + /** |
|
38 | + * Reverse the migrations. |
|
39 | + * |
|
40 | + * @return void |
|
41 | + */ |
|
42 | + public function down() |
|
43 | + { |
|
44 | + Schema::drop(Config::get('scheduler.schedules_table')); |
|
45 | + } |
|
46 | 46 | } |
47 | 47 | \ No newline at end of file |
@@ -20,9 +20,9 @@ discard block |
||
20 | 20 | * |
21 | 21 | * @return void |
22 | 22 | */ |
23 | - public function up() |
|
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'); |
@@ -39,7 +39,7 @@ discard block |
||
39 | 39 | * |
40 | 40 | * @return void |
41 | 41 | */ |
42 | - public function down() |
|
42 | + public function down () |
|
43 | 43 | { |
44 | 44 | Schema::drop(Config::get('scheduler.schedules_table')); |
45 | 45 | } |
@@ -12,50 +12,50 @@ |
||
12 | 12 | |
13 | 13 | class SchedulerServiceProvider extends ServiceProvider |
14 | 14 | { |
15 | - /** |
|
16 | - * Perform post-registration booting of services. |
|
17 | - * |
|
18 | - * @return void |
|
19 | - */ |
|
20 | - public function boot() |
|
21 | - { |
|
22 | - $this->publishes([ |
|
23 | - __DIR__.'/../config/config.php' => config_path('scheduler.php'), |
|
24 | - ]); |
|
25 | - |
|
26 | - $this->loadMigrationsFrom(__DIR__.'/Migrations'); |
|
27 | - $this->loadTranslationsFrom(__DIR__.'/Translations', 'scheduler'); |
|
28 | - |
|
29 | - $this->publishes([ |
|
30 | - __DIR__.'/Translations' => resource_path('lang/vendor/scheduler'), |
|
31 | - ]); |
|
32 | - } |
|
33 | - |
|
34 | - /** |
|
35 | - * Register the application services. |
|
36 | - * |
|
37 | - * @return void |
|
38 | - */ |
|
39 | - public function register() |
|
40 | - { |
|
41 | - $this->app->singleton(Scheduler::class, function ($app) { |
|
42 | - return new Scheduler($app); |
|
43 | - }); |
|
44 | - |
|
45 | - $this->app->alias(Scheduler::class, 'scheduler'); |
|
46 | - |
|
47 | - $this->mergeConfig(); |
|
48 | - } |
|
49 | - |
|
50 | - /** |
|
51 | - * Mescla configurações do usuário com as configurações do Scheduler. |
|
52 | - * |
|
53 | - * @return void |
|
54 | - */ |
|
55 | - private function mergeConfig() |
|
56 | - { |
|
57 | - $this->mergeConfigFrom( |
|
58 | - __DIR__.'/../config/config.php', 'scheduler' |
|
59 | - ); |
|
60 | - } |
|
15 | + /** |
|
16 | + * Perform post-registration booting of services. |
|
17 | + * |
|
18 | + * @return void |
|
19 | + */ |
|
20 | + public function boot() |
|
21 | + { |
|
22 | + $this->publishes([ |
|
23 | + __DIR__.'/../config/config.php' => config_path('scheduler.php'), |
|
24 | + ]); |
|
25 | + |
|
26 | + $this->loadMigrationsFrom(__DIR__.'/Migrations'); |
|
27 | + $this->loadTranslationsFrom(__DIR__.'/Translations', 'scheduler'); |
|
28 | + |
|
29 | + $this->publishes([ |
|
30 | + __DIR__.'/Translations' => resource_path('lang/vendor/scheduler'), |
|
31 | + ]); |
|
32 | + } |
|
33 | + |
|
34 | + /** |
|
35 | + * Register the application services. |
|
36 | + * |
|
37 | + * @return void |
|
38 | + */ |
|
39 | + public function register() |
|
40 | + { |
|
41 | + $this->app->singleton(Scheduler::class, function ($app) { |
|
42 | + return new Scheduler($app); |
|
43 | + }); |
|
44 | + |
|
45 | + $this->app->alias(Scheduler::class, 'scheduler'); |
|
46 | + |
|
47 | + $this->mergeConfig(); |
|
48 | + } |
|
49 | + |
|
50 | + /** |
|
51 | + * Mescla configurações do usuário com as configurações do Scheduler. |
|
52 | + * |
|
53 | + * @return void |
|
54 | + */ |
|
55 | + private function mergeConfig() |
|
56 | + { |
|
57 | + $this->mergeConfigFrom( |
|
58 | + __DIR__.'/../config/config.php', 'scheduler' |
|
59 | + ); |
|
60 | + } |
|
61 | 61 | } |
62 | 62 | \ No newline at end of file |
@@ -17,17 +17,17 @@ discard block |
||
17 | 17 | * |
18 | 18 | * @return void |
19 | 19 | */ |
20 | - public function boot() |
|
20 | + public function boot () |
|
21 | 21 | { |
22 | 22 | $this->publishes([ |
23 | - __DIR__.'/../config/config.php' => config_path('scheduler.php'), |
|
23 | + __DIR__ . '/../config/config.php' => config_path('scheduler.php'), |
|
24 | 24 | ]); |
25 | 25 | |
26 | - $this->loadMigrationsFrom(__DIR__.'/Migrations'); |
|
27 | - $this->loadTranslationsFrom(__DIR__.'/Translations', 'scheduler'); |
|
26 | + $this->loadMigrationsFrom(__DIR__ . '/Migrations'); |
|
27 | + $this->loadTranslationsFrom(__DIR__ . '/Translations', 'scheduler'); |
|
28 | 28 | |
29 | 29 | $this->publishes([ |
30 | - __DIR__.'/Translations' => resource_path('lang/vendor/scheduler'), |
|
30 | + __DIR__ . '/Translations' => resource_path('lang/vendor/scheduler'), |
|
31 | 31 | ]); |
32 | 32 | } |
33 | 33 | |
@@ -36,9 +36,9 @@ discard block |
||
36 | 36 | * |
37 | 37 | * @return void |
38 | 38 | */ |
39 | - public function register() |
|
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 | |
@@ -52,10 +52,10 @@ discard block |
||
52 | 52 | * |
53 | 53 | * @return void |
54 | 54 | */ |
55 | - private function mergeConfig() |
|
55 | + private function mergeConfig () |
|
56 | 56 | { |
57 | 57 | $this->mergeConfigFrom( |
58 | - __DIR__.'/../config/config.php', 'scheduler' |
|
58 | + __DIR__ . '/../config/config.php', 'scheduler' |
|
59 | 59 | ); |
60 | 60 | } |
61 | 61 | } |
62 | 62 | \ No newline at end of file |
@@ -11,28 +11,28 @@ |
||
11 | 11 | interface SchedulerModelInterface |
12 | 12 | { |
13 | 13 | /** |
14 | - * Define an inverse one-to-one or many relationship. |
|
15 | - * |
|
16 | - * @param string $related |
|
17 | - * @param string $foreignKey |
|
18 | - * @param string $ownerKey |
|
19 | - * @param string $relation |
|
20 | - * @return \Illuminate\Database\Eloquent\Relations\BelongsTo |
|
21 | - */ |
|
14 | + * Define an inverse one-to-one or many relationship. |
|
15 | + * |
|
16 | + * @param string $related |
|
17 | + * @param string $foreignKey |
|
18 | + * @param string $ownerKey |
|
19 | + * @param string $relation |
|
20 | + * @return \Illuminate\Database\Eloquent\Relations\BelongsTo |
|
21 | + */ |
|
22 | 22 | abstract public function belongsTo($related, $foreignKey = null, $ownerKey = null, $relation = null); |
23 | 23 | |
24 | 24 | /** |
25 | - * Get the value of the model's primary key. |
|
26 | - * |
|
27 | - * @return mixed |
|
28 | - */ |
|
25 | + * Get the value of the model's primary key. |
|
26 | + * |
|
27 | + * @return mixed |
|
28 | + */ |
|
29 | 29 | abstract public function getKey(); |
30 | 30 | |
31 | 31 | /** |
32 | - * Retorna apenas os horários que possuem o mesmo [model_type] do [parent] dessa [trait]. |
|
33 | - * |
|
34 | - * @return \Illuminate\Database\Eloquent\Relations\BelongsTo |
|
35 | - */ |
|
32 | + * Retorna apenas os horários que possuem o mesmo [model_type] do [parent] dessa [trait]. |
|
33 | + * |
|
34 | + * @return \Illuminate\Database\Eloquent\Relations\BelongsTo |
|
35 | + */ |
|
36 | 36 | public function schedules(); |
37 | 37 | |
38 | 38 | /** |
@@ -19,21 +19,21 @@ 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 | 38 | /** |
39 | 39 | * Agenda um horário para esta model. |
@@ -48,7 +48,7 @@ discard block |
||
48 | 48 | * @throws \H4ad\Scheduler\Exceptions\CantAddWithSameStartAt |
49 | 49 | * @throws \H4ad\Scheduler\Exceptions\EndCantBeforeStart |
50 | 50 | */ |
51 | - public function addSchedule($start_at, $end_at = null, $status = null); |
|
51 | + public function addSchedule ($start_at, $end_at = null, $status = null); |
|
52 | 52 | |
53 | 53 | /** |
54 | 54 | * Exibe uma lista dos horários do dia de hoje. |
@@ -57,7 +57,7 @@ discard block |
||
57 | 57 | * que precisem ter uma certa duração. |
58 | 58 | * @return array |
59 | 59 | */ |
60 | - public function availableToday($duration = 0); |
|
60 | + public function availableToday ($duration = 0); |
|
61 | 61 | |
62 | 62 | /** |
63 | 63 | * Lista os horários livres em um determinado dia. |
@@ -67,7 +67,7 @@ discard block |
||
67 | 67 | * que precisem ter uma certa duração. |
68 | 68 | * @return array |
69 | 69 | */ |
70 | - public function availableOn($date, $duration = 0); |
|
70 | + public function availableOn ($date, $duration = 0); |
|
71 | 71 | |
72 | 72 | /** |
73 | 73 | * Remove um horário agendado pelo seu ID ou pelo horário em que foi marcado. |
@@ -81,5 +81,5 @@ discard block |
||
81 | 81 | * @throws \H4ad\Scheduler\Exceptions\CantRemoveByDate |
82 | 82 | * @throws \H4ad\Scheduler\Exceptions\ModelNotFound |
83 | 83 | */ |
84 | - public function removeSchedule($schedule); |
|
84 | + public function removeSchedule ($schedule); |
|
85 | 85 | } |
86 | 86 | \ No newline at end of file |
@@ -14,33 +14,33 @@ |
||
14 | 14 | |
15 | 15 | class ScheduleStatus extends Model |
16 | 16 | { |
17 | - use SoftDeletes; |
|
17 | + use SoftDeletes; |
|
18 | 18 | |
19 | 19 | /** |
20 | - * Os atributos que podem ser atribuíveis em massa. |
|
21 | - * |
|
22 | - * @var array |
|
23 | - */ |
|
24 | - protected $fillable = [ |
|
25 | - 'name', 'description' |
|
26 | - ]; |
|
20 | + * Os atributos que podem ser atribuíveis em massa. |
|
21 | + * |
|
22 | + * @var array |
|
23 | + */ |
|
24 | + protected $fillable = [ |
|
25 | + 'name', 'description' |
|
26 | + ]; |
|
27 | 27 | |
28 | - /** |
|
29 | - * Os atributos que devem ser transformados para data. |
|
30 | - * |
|
31 | - * @var array |
|
32 | - */ |
|
33 | - protected $dates = [ |
|
34 | - 'deleted_at' |
|
35 | - ]; |
|
28 | + /** |
|
29 | + * Os atributos que devem ser transformados para data. |
|
30 | + * |
|
31 | + * @var array |
|
32 | + */ |
|
33 | + protected $dates = [ |
|
34 | + 'deleted_at' |
|
35 | + ]; |
|
36 | 36 | |
37 | - /** |
|
38 | - * Construtor para inicilizar a váriavel table. |
|
39 | - */ |
|
40 | - public function __construct(array $attributes = []) |
|
41 | - { |
|
42 | - parent::__construct($attributes); |
|
37 | + /** |
|
38 | + * Construtor para inicilizar a váriavel table. |
|
39 | + */ |
|
40 | + public function __construct(array $attributes = []) |
|
41 | + { |
|
42 | + parent::__construct($attributes); |
|
43 | 43 | |
44 | - $this->table = Config::get('scheduler.schedule_status_table'); |
|
45 | - } |
|
44 | + $this->table = Config::get('scheduler.schedule_status_table'); |
|
45 | + } |
|
46 | 46 | } |
47 | 47 | \ No newline at end of file |
@@ -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 |