1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
declare(strict_types=1); |
4
|
|
|
|
5
|
|
|
namespace Application\Model; |
6
|
|
|
|
7
|
|
|
use Application\DBAL\Types\BookingStatusType; |
8
|
|
|
use Cake\Chronos\Chronos; |
9
|
|
|
use Doctrine\Common\Collections\ArrayCollection; |
10
|
|
|
use Doctrine\Common\Collections\Collection; |
11
|
|
|
use Doctrine\ORM\Mapping as ORM; |
12
|
|
|
use GraphQL\Doctrine\Annotation as API; |
13
|
|
|
|
14
|
|
|
/** |
15
|
|
|
* A booking linking a user and several bookables |
16
|
|
|
* |
17
|
|
|
* @ORM\Entity(repositoryClass="Application\Repository\BookingRepository") |
18
|
|
|
* @ORM\AssociationOverrides({ |
19
|
|
|
* @ORM\AssociationOverride(name="owner", inversedBy="bookings") |
20
|
|
|
* }) |
21
|
|
|
*/ |
22
|
|
|
class Booking extends AbstractModel |
23
|
|
|
{ |
24
|
|
|
/** |
25
|
|
|
* @var string |
26
|
|
|
* |
27
|
|
|
* @ORM\Column(type="BookingStatus", length=10, options={"default" = BookingStatusType::APPLICATION}) |
28
|
|
|
*/ |
29
|
|
|
private $status = BookingStatusType::APPLICATION; |
30
|
|
|
|
31
|
|
|
/** |
32
|
|
|
* @var int |
33
|
|
|
* @ORM\Column(type="integer", options={"unsigned" = true, "default" = 1}) |
34
|
|
|
*/ |
35
|
|
|
private $participantCount = 1; |
36
|
|
|
|
37
|
|
|
/** |
38
|
|
|
* @var string |
39
|
|
|
* |
40
|
|
|
* @ORM\Column(type="string", length=50, options={"default" = ""}) |
41
|
|
|
*/ |
42
|
|
|
private $destination = ''; |
43
|
|
|
|
44
|
|
|
/** |
45
|
|
|
* @var string |
46
|
|
|
* |
47
|
|
|
* @ORM\Column(type="text", length=65535, options={"default" = ""}) |
48
|
|
|
*/ |
49
|
|
|
private $startComment = ''; |
50
|
|
|
|
51
|
|
|
/** |
52
|
|
|
* @var string |
53
|
|
|
* |
54
|
|
|
* @ORM\Column(type="text", length=65535, options={"default" = ""}) |
55
|
|
|
*/ |
56
|
|
|
private $endComment = ''; |
57
|
|
|
|
58
|
|
|
/** |
59
|
|
|
* @var Chronos |
60
|
|
|
* |
61
|
|
|
* @ORM\Column(type="datetime") |
62
|
|
|
*/ |
63
|
|
|
private $startDate; |
64
|
|
|
|
65
|
|
|
/** |
66
|
|
|
* @var Chronos |
67
|
|
|
* |
68
|
|
|
* @ORM\Column(type="datetime", nullable=true) |
69
|
|
|
*/ |
70
|
|
|
private $endDate; |
71
|
|
|
|
72
|
|
|
/** |
73
|
|
|
* @var string |
74
|
|
|
* |
75
|
|
|
* @ORM\Column(type="string", length=50, options={"default" = ""}) |
76
|
|
|
*/ |
77
|
|
|
private $estimatedEndDate = ''; |
78
|
|
|
|
79
|
|
|
/** |
80
|
|
|
* @var Collection |
81
|
|
|
* |
82
|
|
|
* @ORM\ManyToMany(targetEntity="Bookable", inversedBy="bookings") |
83
|
|
|
*/ |
84
|
|
|
private $bookables; |
85
|
|
|
|
86
|
|
|
/** |
87
|
|
|
* Constructor |
88
|
|
|
*/ |
89
|
9 |
|
public function __construct() |
90
|
|
|
{ |
91
|
9 |
|
$this->bookables = new ArrayCollection(); |
92
|
9 |
|
} |
93
|
|
|
|
94
|
8 |
|
public function setOwner(User $owner = null): void |
95
|
|
|
{ |
96
|
8 |
|
if ($this->getOwner()) { |
97
|
3 |
|
$this->getOwner()->bookingRemoved($this); |
98
|
|
|
} |
99
|
|
|
|
100
|
8 |
|
parent::setOwner($owner); |
101
|
|
|
|
102
|
8 |
|
if ($this->getOwner()) { |
103
|
7 |
|
$this->getOwner()->bookingAdded($this); |
104
|
|
|
} |
105
|
8 |
|
} |
106
|
|
|
|
107
|
|
|
/** |
108
|
|
|
* Total count of participant, at least 1. |
109
|
|
|
* |
110
|
|
|
* @return int |
111
|
|
|
*/ |
112
|
|
|
public function getParticipantCount(): int |
113
|
|
|
{ |
114
|
|
|
return $this->participantCount; |
115
|
|
|
} |
116
|
|
|
|
117
|
|
|
/** |
118
|
|
|
* @param int $participantCount |
119
|
|
|
*/ |
120
|
|
|
public function setParticipantCount(int $participantCount): void |
121
|
|
|
{ |
122
|
|
|
$this->participantCount = $participantCount; |
123
|
|
|
} |
124
|
|
|
|
125
|
|
|
/** |
126
|
|
|
* @return string |
127
|
|
|
*/ |
128
|
|
|
public function getDestination(): string |
129
|
|
|
{ |
130
|
|
|
return $this->destination; |
131
|
|
|
} |
132
|
|
|
|
133
|
|
|
/** |
134
|
|
|
* @param string $destination |
135
|
|
|
*/ |
136
|
|
|
public function setDestination(string $destination): void |
137
|
|
|
{ |
138
|
|
|
$this->destination = $destination; |
139
|
|
|
} |
140
|
|
|
|
141
|
|
|
/** |
142
|
|
|
* @return string |
143
|
|
|
*/ |
144
|
|
|
public function getStartComment(): string |
145
|
|
|
{ |
146
|
|
|
return $this->startComment; |
147
|
|
|
} |
148
|
|
|
|
149
|
|
|
/** |
150
|
|
|
* @param string $startComment |
151
|
|
|
*/ |
152
|
|
|
public function setStartComment(string $startComment): void |
153
|
|
|
{ |
154
|
|
|
$this->startComment = $startComment; |
155
|
|
|
} |
156
|
|
|
|
157
|
|
|
/** |
158
|
|
|
* @return string |
159
|
|
|
*/ |
160
|
|
|
public function getEndComment(): string |
161
|
|
|
{ |
162
|
|
|
return $this->endComment; |
163
|
|
|
} |
164
|
|
|
|
165
|
|
|
/** |
166
|
|
|
* @param string $endComment |
167
|
|
|
*/ |
168
|
|
|
public function setEndComment(string $endComment): void |
169
|
|
|
{ |
170
|
|
|
$this->endComment = $endComment; |
171
|
|
|
} |
172
|
|
|
|
173
|
|
|
/** |
174
|
|
|
* @return Chronos |
175
|
|
|
*/ |
176
|
|
|
public function getStartDate(): Chronos |
177
|
|
|
{ |
178
|
|
|
return $this->startDate; |
179
|
|
|
} |
180
|
|
|
|
181
|
|
|
/** |
182
|
|
|
* @param Chronos $startDate |
183
|
|
|
*/ |
184
|
|
|
public function setStartDate(Chronos $startDate): void |
185
|
|
|
{ |
186
|
|
|
$this->startDate = $startDate; |
187
|
|
|
} |
188
|
|
|
|
189
|
|
|
/** |
190
|
|
|
* @return null|Chronos |
191
|
|
|
*/ |
192
|
|
|
public function getEndDate(): ?Chronos |
193
|
|
|
{ |
194
|
|
|
return $this->endDate; |
195
|
|
|
} |
196
|
|
|
|
197
|
|
|
/** |
198
|
|
|
* @param null|Chronos $endDate |
199
|
|
|
*/ |
200
|
|
|
public function setEndDate(?Chronos $endDate): void |
201
|
|
|
{ |
202
|
|
|
$this->endDate = $endDate; |
203
|
|
|
} |
204
|
|
|
|
205
|
|
|
/** |
206
|
|
|
* @return string |
207
|
|
|
*/ |
208
|
|
|
public function getEstimatedEndDate(): string |
209
|
|
|
{ |
210
|
|
|
return $this->estimatedEndDate; |
211
|
|
|
} |
212
|
|
|
|
213
|
|
|
/** |
214
|
|
|
* @param string $estimatedEndDate |
215
|
|
|
*/ |
216
|
|
|
public function setEstimatedEndDate(string $estimatedEndDate): void |
217
|
|
|
{ |
218
|
|
|
$this->estimatedEndDate = $estimatedEndDate; |
219
|
|
|
} |
220
|
|
|
|
221
|
|
|
/** |
222
|
|
|
* @return Collection |
223
|
|
|
*/ |
224
|
1 |
|
public function getBookables(): Collection |
225
|
|
|
{ |
226
|
1 |
|
return $this->bookables; |
227
|
|
|
} |
228
|
|
|
|
229
|
|
|
/** |
230
|
|
|
* Add bookable |
231
|
|
|
* |
232
|
|
|
* @param Bookable $bookable |
233
|
|
|
*/ |
234
|
1 |
|
public function addBookable(Bookable $bookable): void |
235
|
|
|
{ |
236
|
1 |
|
if (!$this->bookables->contains($bookable)) { |
237
|
1 |
|
$this->bookables->add($bookable); |
238
|
1 |
|
$bookable->bookingAdded($this); |
239
|
|
|
} |
240
|
1 |
|
} |
241
|
|
|
|
242
|
|
|
/** |
243
|
|
|
* Remove bookable |
244
|
|
|
* |
245
|
|
|
* @param Bookable $bookable |
246
|
|
|
*/ |
247
|
1 |
|
public function removeBookable(Bookable $bookable): void |
248
|
|
|
{ |
249
|
1 |
|
$this->bookables->removeElement($bookable); |
250
|
1 |
|
$bookable->bookingRemoved($this); |
251
|
1 |
|
} |
252
|
|
|
|
253
|
|
|
/** |
254
|
|
|
* @API\Field(type="BookingStatus") |
255
|
|
|
* |
256
|
|
|
* @return string |
257
|
|
|
*/ |
258
|
|
|
public function getStatus(): string |
259
|
|
|
{ |
260
|
|
|
return $this->status; |
261
|
|
|
} |
262
|
|
|
|
263
|
|
|
/** |
264
|
|
|
* @API\Input(type="BookingStatus") |
265
|
|
|
* |
266
|
|
|
* @param string $status |
267
|
|
|
*/ |
268
|
|
|
public function setStatus(string $status): void |
269
|
|
|
{ |
270
|
|
|
$this->status = $status; |
271
|
|
|
} |
272
|
|
|
} |
273
|
|
|
|