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