@@ -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 | } |
@@ -14,107 +14,107 @@ |
||
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($model_type, $start_at, $end_at) |
|
44 | - { |
|
45 | - if(!Config::get('scheduler.enable_schedule_conflict')) |
|
46 | - return false; |
|
47 | - |
|
48 | - return !is_null( |
|
49 | - Schedule::latest() |
|
50 | - ->where('model_type', $model_type) |
|
51 | - ->where('start_at', '>=', $start_at) |
|
52 | - ->where('end_at', '<=', $end_at) |
|
53 | - ->first() |
|
54 | - ); |
|
55 | - } |
|
56 | - |
|
57 | - /** |
|
58 | - * Retorna os horários disponiveis hoje para uma determinada model. |
|
59 | - * . |
|
60 | - * @param string $model_type Tipo da model |
|
61 | - * @param int $duration Serve para facilitar na hora de buscar horários livres |
|
62 | - * que precisem ter uma certa duração. |
|
63 | - * @return array |
|
64 | - */ |
|
65 | - public function availableToday($model_type, $duration) |
|
66 | - { |
|
67 | - return $this->availableOn($model_type, Carbon::now(), $duration); |
|
68 | - } |
|
69 | - |
|
70 | - /** |
|
71 | - * Retorna os horários disponiveis em um determinado dia para uma certa model. |
|
72 | - * |
|
73 | - * @param string $model_type Tipo da model |
|
74 | - * @param string|\Carbon\Carbon $today Data para o qual ele irá fazer a busca. |
|
75 | - * @param int $durationMinutes Serve para facilitar na hora de buscar horários livres |
|
76 | - * que precisem ter uma certa duração. |
|
77 | - * @return array |
|
78 | - */ |
|
79 | - public function availableOn($model_type, $today, $durationMinutes) |
|
80 | - { |
|
81 | - $openingTime = Carbon::parse(Config::get('scheduler.opening_time'))->setDateFrom($today); |
|
82 | - $closingTime = Carbon::parse(Config::get('scheduler.closing_time'))->setDateFrom($today); |
|
83 | - |
|
84 | - $livres = []; |
|
85 | - $today = Carbon::parse($today->toDateString()); |
|
86 | - while($openingTime <= $closingTime) |
|
87 | - { |
|
88 | - $add = true; |
|
89 | - |
|
90 | - foreach (Schedule::orderBy('start_at', 'DESC')->cursor() as $schedule) { |
|
91 | - if($schedule->model_type != $model_type) |
|
92 | - continue; |
|
93 | - |
|
94 | - $start = Carbon::parse($schedule->start_at); |
|
95 | - $begin = Carbon::parse($start->toDateString()); |
|
96 | - |
|
97 | - if($begin->greaterThan($today)) |
|
98 | - break; |
|
99 | - |
|
100 | - if($begin->notEqualTo($today)) |
|
101 | - continue; |
|
102 | - |
|
103 | - $end = Carbon::parse($schedule->end_at); |
|
104 | - if($start <= Carbon::parse($openingTime->toDateTimeString()) |
|
105 | - && $end >= Carbon::parse($openingTime->toDateTimeString())->addMinutes($durationMinutes)) |
|
106 | - $add = false; |
|
107 | - } |
|
108 | - |
|
109 | - if($add) |
|
110 | - $livres[] = [ |
|
111 | - 'start_at' => Carbon::parse($openingTime->toDateTimeString()), |
|
112 | - 'end_at' => Carbon::parse($openingTime->toDateTimeString())->addMinutes($durationMinutes) |
|
113 | - ]; |
|
114 | - |
|
115 | - $openingTime->addMinutes($durationMinutes); |
|
116 | - } |
|
117 | - |
|
118 | - return $livres; |
|
119 | - } |
|
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($model_type, $start_at, $end_at) |
|
44 | + { |
|
45 | + if(!Config::get('scheduler.enable_schedule_conflict')) |
|
46 | + return false; |
|
47 | + |
|
48 | + return !is_null( |
|
49 | + Schedule::latest() |
|
50 | + ->where('model_type', $model_type) |
|
51 | + ->where('start_at', '>=', $start_at) |
|
52 | + ->where('end_at', '<=', $end_at) |
|
53 | + ->first() |
|
54 | + ); |
|
55 | + } |
|
56 | + |
|
57 | + /** |
|
58 | + * Retorna os horários disponiveis hoje para uma determinada model. |
|
59 | + * . |
|
60 | + * @param string $model_type Tipo da model |
|
61 | + * @param int $duration Serve para facilitar na hora de buscar horários livres |
|
62 | + * que precisem ter uma certa duração. |
|
63 | + * @return array |
|
64 | + */ |
|
65 | + public function availableToday($model_type, $duration) |
|
66 | + { |
|
67 | + return $this->availableOn($model_type, Carbon::now(), $duration); |
|
68 | + } |
|
69 | + |
|
70 | + /** |
|
71 | + * Retorna os horários disponiveis em um determinado dia para uma certa model. |
|
72 | + * |
|
73 | + * @param string $model_type Tipo da model |
|
74 | + * @param string|\Carbon\Carbon $today Data para o qual ele irá fazer a busca. |
|
75 | + * @param int $durationMinutes Serve para facilitar na hora de buscar horários livres |
|
76 | + * que precisem ter uma certa duração. |
|
77 | + * @return array |
|
78 | + */ |
|
79 | + public function availableOn($model_type, $today, $durationMinutes) |
|
80 | + { |
|
81 | + $openingTime = Carbon::parse(Config::get('scheduler.opening_time'))->setDateFrom($today); |
|
82 | + $closingTime = Carbon::parse(Config::get('scheduler.closing_time'))->setDateFrom($today); |
|
83 | + |
|
84 | + $livres = []; |
|
85 | + $today = Carbon::parse($today->toDateString()); |
|
86 | + while($openingTime <= $closingTime) |
|
87 | + { |
|
88 | + $add = true; |
|
89 | + |
|
90 | + foreach (Schedule::orderBy('start_at', 'DESC')->cursor() as $schedule) { |
|
91 | + if($schedule->model_type != $model_type) |
|
92 | + continue; |
|
93 | + |
|
94 | + $start = Carbon::parse($schedule->start_at); |
|
95 | + $begin = Carbon::parse($start->toDateString()); |
|
96 | + |
|
97 | + if($begin->greaterThan($today)) |
|
98 | + break; |
|
99 | + |
|
100 | + if($begin->notEqualTo($today)) |
|
101 | + continue; |
|
102 | + |
|
103 | + $end = Carbon::parse($schedule->end_at); |
|
104 | + if($start <= Carbon::parse($openingTime->toDateTimeString()) |
|
105 | + && $end >= Carbon::parse($openingTime->toDateTimeString())->addMinutes($durationMinutes)) |
|
106 | + $add = false; |
|
107 | + } |
|
108 | + |
|
109 | + if($add) |
|
110 | + $livres[] = [ |
|
111 | + 'start_at' => Carbon::parse($openingTime->toDateTimeString()), |
|
112 | + 'end_at' => Carbon::parse($openingTime->toDateTimeString())->addMinutes($durationMinutes) |
|
113 | + ]; |
|
114 | + |
|
115 | + $openingTime->addMinutes($durationMinutes); |
|
116 | + } |
|
117 | + |
|
118 | + return $livres; |
|
119 | + } |
|
120 | 120 | } |
121 | 121 | \ No newline at end of file |
@@ -42,8 +42,9 @@ discard block |
||
42 | 42 | */ |
43 | 43 | public function hasScheduleBetween($model_type, $start_at, $end_at) |
44 | 44 | { |
45 | - if(!Config::get('scheduler.enable_schedule_conflict')) |
|
46 | - return false; |
|
45 | + if(!Config::get('scheduler.enable_schedule_conflict')) { |
|
46 | + return false; |
|
47 | + } |
|
47 | 48 | |
48 | 49 | return !is_null( |
49 | 50 | Schedule::latest() |
@@ -88,29 +89,34 @@ discard block |
||
88 | 89 | $add = true; |
89 | 90 | |
90 | 91 | foreach (Schedule::orderBy('start_at', 'DESC')->cursor() as $schedule) { |
91 | - if($schedule->model_type != $model_type) |
|
92 | - continue; |
|
92 | + if($schedule->model_type != $model_type) { |
|
93 | + continue; |
|
94 | + } |
|
93 | 95 | |
94 | 96 | $start = Carbon::parse($schedule->start_at); |
95 | 97 | $begin = Carbon::parse($start->toDateString()); |
96 | 98 | |
97 | - if($begin->greaterThan($today)) |
|
98 | - break; |
|
99 | + if($begin->greaterThan($today)) { |
|
100 | + break; |
|
101 | + } |
|
99 | 102 | |
100 | - if($begin->notEqualTo($today)) |
|
101 | - continue; |
|
103 | + if($begin->notEqualTo($today)) { |
|
104 | + continue; |
|
105 | + } |
|
102 | 106 | |
103 | 107 | $end = Carbon::parse($schedule->end_at); |
104 | 108 | if($start <= Carbon::parse($openingTime->toDateTimeString()) |
105 | - && $end >= Carbon::parse($openingTime->toDateTimeString())->addMinutes($durationMinutes)) |
|
106 | - $add = false; |
|
109 | + && $end >= Carbon::parse($openingTime->toDateTimeString())->addMinutes($durationMinutes)) { |
|
110 | + $add = false; |
|
111 | + } |
|
107 | 112 | } |
108 | 113 | |
109 | - if($add) |
|
110 | - $livres[] = [ |
|
114 | + if($add) { |
|
115 | + $livres[] = [ |
|
111 | 116 | 'start_at' => Carbon::parse($openingTime->toDateTimeString()), |
112 | 117 | 'end_at' => Carbon::parse($openingTime->toDateTimeString())->addMinutes($durationMinutes) |
113 | 118 | ]; |
119 | + } |
|
114 | 120 | |
115 | 121 | $openingTime->addMinutes($durationMinutes); |
116 | 122 | } |
@@ -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'); |
@@ -69,17 +69,20 @@ discard block |
||
69 | 69 | */ |
70 | 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)) |
|
73 | - throw new CantAddWithoutEnd; |
|
72 | + if(!Config::get('scheduler.enable_schedule_without_end') && is_null($end_at)) { |
|
73 | + throw new CantAddWithoutEnd; |
|
74 | + } |
|
74 | 75 | |
75 | 76 | $start_at = $this->parseToCarbon($start_at); |
76 | 77 | $end_at = $this->parseToCarbon($end_at, $start_at); |
77 | 78 | |
78 | - if(Scheduler::hasScheduleBetween(self::class, $start_at, $end_at ?? $start_at)) |
|
79 | - throw new CantAddWithSameStartAt; |
|
79 | + if(Scheduler::hasScheduleBetween(self::class, $start_at, $end_at ?? $start_at)) { |
|
80 | + throw new CantAddWithSameStartAt; |
|
81 | + } |
|
80 | 82 | |
81 | - if($start_at->greaterThan($end_at) && !is_null($end_at)) |
|
82 | - throw new EndCantBeforeStart; |
|
83 | + if($start_at->greaterThan($end_at) && !is_null($end_at)) { |
|
84 | + throw new EndCantBeforeStart; |
|
85 | + } |
|
83 | 86 | |
84 | 87 | $model_id = $this->getKey(); |
85 | 88 | $model_type = self::class; |
@@ -96,11 +99,13 @@ discard block |
||
96 | 99 | */ |
97 | 100 | public function parseToCarbon($date, $reference = null) |
98 | 101 | { |
99 | - if(is_string($date)) |
|
100 | - return Carbon::parse($date); |
|
102 | + if(is_string($date)) { |
|
103 | + return Carbon::parse($date); |
|
104 | + } |
|
101 | 105 | |
102 | - if(is_int($date)) |
|
103 | - return Carbon::parse($reference->toDateTimeString())->addMinutes($date); |
|
106 | + if(is_int($date)) { |
|
107 | + return Carbon::parse($reference->toDateTimeString())->addMinutes($date); |
|
108 | + } |
|
104 | 109 | |
105 | 110 | return $date; |
106 | 111 | } |
@@ -113,11 +118,13 @@ discard block |
||
113 | 118 | */ |
114 | 119 | public function parseToSchedule($value) |
115 | 120 | { |
116 | - if(is_int($value)) |
|
117 | - return Schedule::find($value); |
|
121 | + if(is_int($value)) { |
|
122 | + return Schedule::find($value); |
|
123 | + } |
|
118 | 124 | |
119 | - if(is_string($value) || $value instanceof Carbon) |
|
120 | - return Schedule::byStartAt($value)->first(); |
|
125 | + if(is_string($value) || $value instanceof Carbon) { |
|
126 | + return Schedule::byStartAt($value)->first(); |
|
127 | + } |
|
121 | 128 | |
122 | 129 | return null; |
123 | 130 | } |
@@ -136,16 +143,19 @@ discard block |
||
136 | 143 | */ |
137 | 144 | public function removeSchedule($schedule) |
138 | 145 | { |
139 | - if(!Config::get('scheduler.enable_schedule_conflict') && !is_int($schedule)) |
|
140 | - throw new CantRemoveByDate; |
|
146 | + if(!Config::get('scheduler.enable_schedule_conflict') && !is_int($schedule)) { |
|
147 | + throw new CantRemoveByDate; |
|
148 | + } |
|
141 | 149 | |
142 | 150 | $schedule = $this->parseToSchedule($schedule); |
143 | 151 | |
144 | - if(!($schedule instanceof Model)) |
|
145 | - throw (new ModelNotFound)->setValues(Schedule::class); |
|
152 | + if(!($schedule instanceof Model)) { |
|
153 | + throw (new ModelNotFound)->setValues(Schedule::class); |
|
154 | + } |
|
146 | 155 | |
147 | - if($schedule->model_type != self::class || $schedule->model_id != $this->getKey()) |
|
148 | - throw new DoesNotBelong; |
|
156 | + if($schedule->model_type != self::class || $schedule->model_id != $this->getKey()) { |
|
157 | + throw new DoesNotBelong; |
|
158 | + } |
|
149 | 159 | |
150 | 160 | return $schedule->delete(); |
151 | 161 | } |