1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Timegridio\Concierge\Calendar; |
4
|
|
|
|
5
|
|
|
use Carbon\Carbon; |
6
|
|
|
use Illuminate\Database\Eloquent\Relations\HasMany; |
7
|
|
|
use Illuminate\Support\Collection; |
8
|
|
|
|
9
|
|
|
/** |
10
|
|
|
* @property Illuminate\Database\Eloquent\Relations\HasMany $vacancies |
11
|
|
|
* @property Timegridio\Concierge\Models\Service $service |
12
|
|
|
* @property int $duration |
13
|
|
|
* @property string $date |
14
|
|
|
* @property string $time |
15
|
|
|
* @property string $timezone |
16
|
|
|
*/ |
17
|
|
|
abstract class BaseCalendar |
18
|
|
|
{ |
19
|
|
|
protected $vacancies; |
20
|
|
|
|
21
|
|
|
protected $service = null; |
22
|
|
|
|
23
|
|
|
protected $duration = null; |
24
|
|
|
|
25
|
|
|
protected $date = null; |
26
|
|
|
|
27
|
|
|
protected $time = null; |
28
|
|
|
|
29
|
|
|
protected $timezone = 'UTC'; |
30
|
|
|
|
31
|
|
|
/** |
32
|
|
|
* @param Illuminate\Database\Eloquent\Relations\HasMany $vacancies |
33
|
|
|
* @param string $timezone |
34
|
|
|
*/ |
35
|
17 |
|
public function __construct(HasMany $vacancies, $timezone = 'UTC') |
36
|
|
|
{ |
37
|
17 |
|
$this->vacancies = $vacancies; |
38
|
|
|
|
39
|
17 |
|
$this->timezone($timezone); |
40
|
17 |
|
} |
41
|
|
|
|
42
|
17 |
|
public function timezone($timezone = null) |
43
|
|
|
{ |
44
|
17 |
|
$this->timezone = $timezone; |
45
|
|
|
|
46
|
17 |
|
return $this; |
47
|
|
|
} |
48
|
|
|
|
49
|
14 |
|
public function forService($service = null) |
50
|
|
|
{ |
51
|
14 |
|
$this->service = $service; |
52
|
|
|
|
53
|
14 |
|
return $this; |
54
|
|
|
} |
55
|
|
|
|
56
|
10 |
|
public function forDate($date) |
57
|
|
|
{ |
58
|
10 |
|
$this->date = $date; |
59
|
|
|
|
60
|
10 |
|
return $this; |
61
|
|
|
} |
62
|
|
|
|
63
|
9 |
|
public function atTime($time, $timezone = null) |
64
|
|
|
{ |
65
|
9 |
|
$this->time = $time; |
66
|
|
|
|
67
|
9 |
|
if ($timezone !== null) { |
68
|
8 |
|
$this->timezone = $timezone; |
69
|
8 |
|
} |
70
|
|
|
|
71
|
9 |
|
return $this; |
72
|
|
|
} |
73
|
|
|
|
74
|
8 |
|
public function withDuration($duration) |
75
|
|
|
{ |
76
|
8 |
|
$this->duration = $duration; |
77
|
|
|
|
78
|
8 |
|
return $this; |
79
|
|
|
} |
80
|
|
|
|
81
|
7 |
|
public function getUTCDateTime() |
82
|
|
|
{ |
83
|
7 |
|
return Carbon::parse("{$this->date} {$this->time} {$this->timezone}")->timezone('UTC'); |
84
|
|
|
} |
85
|
|
|
|
86
|
4 |
|
final protected function date() |
87
|
|
|
{ |
88
|
4 |
|
return Carbon::parse($this->date); |
89
|
|
|
} |
90
|
|
|
|
91
|
|
|
abstract public function find(); |
92
|
|
|
|
93
|
|
|
abstract protected function prepare(); |
94
|
|
|
} |
95
|
|
|
|