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