1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
declare(strict_types=1); |
4
|
|
|
|
5
|
|
|
namespace Application\Model; |
6
|
|
|
|
7
|
|
|
use Application\DBAL\Types\BookableStateType; |
8
|
|
|
use Application\DBAL\Types\BookingTypeType; |
9
|
|
|
use Application\Traits\HasCode; |
10
|
|
|
use Application\Traits\HasDescription; |
11
|
|
|
use Application\Traits\HasName; |
12
|
|
|
use Application\Traits\HasRemarks; |
13
|
|
|
use Cake\Chronos\Date; |
14
|
|
|
use Doctrine\Common\Collections\ArrayCollection; |
15
|
|
|
use Doctrine\Common\Collections\Collection; |
16
|
|
|
use Doctrine\ORM\Mapping as ORM; |
17
|
|
|
use GraphQL\Doctrine\Annotation as API; |
18
|
|
|
|
19
|
|
|
/** |
20
|
|
|
* An item that can be booked by a user |
21
|
|
|
* |
22
|
|
|
* @ORM\Entity(repositoryClass="Application\Repository\BookableRepository") |
23
|
|
|
*/ |
24
|
|
|
class Bookable extends AbstractModel |
25
|
|
|
{ |
26
|
|
|
use HasName; |
27
|
|
|
use HasDescription; |
28
|
|
|
use HasCode; |
29
|
|
|
use HasRemarks; |
30
|
|
|
|
31
|
|
|
/** |
32
|
|
|
* @var string |
33
|
|
|
* |
34
|
|
|
* @ORM\Column(type="decimal", precision=7, scale=2, options={"default" = "0.00"}) |
35
|
|
|
*/ |
36
|
|
|
private $initialPrice = '0'; |
37
|
|
|
|
38
|
|
|
/** |
39
|
|
|
* @var string |
40
|
|
|
* |
41
|
|
|
* @ORM\Column(type="decimal", precision=7, scale=2, options={"default" = "0.00"}) |
42
|
|
|
*/ |
43
|
|
|
private $periodicPrice = '0'; |
44
|
|
|
|
45
|
|
|
/** |
46
|
|
|
* @var string |
47
|
|
|
* |
48
|
|
|
* @ORM\Column(type="decimal", precision=7, scale=2, options={"default" = "0.00"}) |
49
|
|
|
*/ |
50
|
|
|
private $purchasePrice = '0'; |
51
|
|
|
|
52
|
|
|
/** |
53
|
|
|
* @var int |
54
|
|
|
* |
55
|
|
|
* @ORM\Column(type="smallint", options={"default" = "-1"}) |
56
|
|
|
*/ |
57
|
|
|
private $simultaneousBookingMaximum = 1; |
58
|
|
|
|
59
|
|
|
/** |
60
|
|
|
* @var string |
61
|
|
|
* |
62
|
|
|
* @ORM\Column(type="BookingType", length=10, options={"default" = BookingTypeType::SELF_APPROVED}) |
63
|
|
|
*/ |
64
|
|
|
private $bookingType = BookingTypeType::SELF_APPROVED; |
65
|
|
|
|
66
|
|
|
/** |
67
|
|
|
* @var bool |
68
|
|
|
* |
69
|
|
|
* @ORM\Column(type="boolean", options={"default" = 1}) |
70
|
|
|
*/ |
71
|
|
|
private $isActive = true; |
72
|
|
|
|
73
|
|
|
/** |
74
|
|
|
* @var string |
75
|
|
|
* |
76
|
|
|
* @ORM\Column(type="BookableState", length=10, options={"default" = BookableStateType::GOOD}) |
77
|
|
|
*/ |
78
|
|
|
private $state = BookableStateType::GOOD; |
79
|
|
|
|
80
|
|
|
/** |
81
|
|
|
* @var null|Date |
82
|
|
|
* @ORM\Column(type="date", nullable=true) |
83
|
|
|
*/ |
84
|
|
|
private $verificationDate; |
85
|
|
|
|
86
|
|
|
/** |
87
|
|
|
* @var BookableTag |
88
|
|
|
* |
89
|
|
|
* @ORM\ManyToMany(targetEntity="BookableTag", mappedBy="bookables") |
90
|
|
|
*/ |
91
|
|
|
private $bookableTags; |
92
|
|
|
|
93
|
|
|
/** |
94
|
|
|
* @var Collection |
95
|
|
|
* @ORM\ManyToMany(targetEntity="Booking", mappedBy="bookables") |
96
|
|
|
*/ |
97
|
|
|
private $bookings; |
98
|
|
|
|
99
|
|
|
/** |
100
|
|
|
* @var Collection |
101
|
|
|
* @ORM\ManyToMany(targetEntity="License", mappedBy="bookables") |
102
|
|
|
*/ |
103
|
|
|
private $licenses; |
104
|
|
|
|
105
|
|
|
/** |
106
|
|
|
* @var null|Image |
107
|
|
|
* @ORM\OneToOne(targetEntity="Image", orphanRemoval=true) |
108
|
|
|
* @ORM\JoinColumn(name="image_id", referencedColumnName="id") |
109
|
|
|
*/ |
110
|
|
|
private $image; |
111
|
|
|
|
112
|
|
|
/** |
113
|
|
|
* Constructor |
114
|
|
|
*/ |
115
|
5 |
|
public function __construct() |
116
|
|
|
{ |
117
|
5 |
|
$this->bookings = new ArrayCollection(); |
118
|
5 |
|
$this->licenses = new ArrayCollection(); |
119
|
5 |
|
$this->bookableTags = new ArrayCollection(); |
|
|
|
|
120
|
5 |
|
} |
121
|
|
|
|
122
|
|
|
/** |
123
|
|
|
* @return Collection |
124
|
|
|
*/ |
125
|
1 |
|
public function getBookings(): Collection |
126
|
|
|
{ |
127
|
1 |
|
return $this->bookings; |
128
|
|
|
} |
129
|
|
|
|
130
|
|
|
/** |
131
|
|
|
* Notify the bookable that it has a new booking. |
132
|
|
|
* This should only be called by Booking::addBookable() |
133
|
|
|
* |
134
|
|
|
* @param Booking $booking |
135
|
|
|
*/ |
136
|
2 |
|
public function bookingAdded(Booking $booking): void |
137
|
|
|
{ |
138
|
2 |
|
$this->bookings->add($booking); |
139
|
2 |
|
} |
140
|
|
|
|
141
|
|
|
/** |
142
|
|
|
* Notify the bookable that it a booking was removed. |
143
|
|
|
* This should only be called by Booking::removeBookable() |
144
|
|
|
* |
145
|
|
|
* @param Booking $booking |
146
|
|
|
*/ |
147
|
1 |
|
public function bookingRemoved(Booking $booking): void |
148
|
|
|
{ |
149
|
1 |
|
$this->bookings->removeElement($booking); |
150
|
1 |
|
} |
151
|
|
|
|
152
|
|
|
/** |
153
|
|
|
* @return Collection |
154
|
|
|
*/ |
155
|
1 |
|
public function getLicenses(): Collection |
156
|
|
|
{ |
157
|
1 |
|
return $this->licenses; |
158
|
|
|
} |
159
|
|
|
|
160
|
|
|
/** |
161
|
|
|
* Notify the bookable that it has a new license. |
162
|
|
|
* This should only be called by License::addBookable() |
163
|
|
|
* |
164
|
|
|
* @param License $license |
165
|
|
|
*/ |
166
|
1 |
|
public function licenseAdded(License $license): void |
167
|
|
|
{ |
168
|
1 |
|
$this->licenses->add($license); |
169
|
1 |
|
} |
170
|
|
|
|
171
|
|
|
/** |
172
|
|
|
* Notify the bookable that it a license was removed. |
173
|
|
|
* This should only be called by License::removeBookable() |
174
|
|
|
* |
175
|
|
|
* @param License $license |
176
|
|
|
*/ |
177
|
1 |
|
public function licenseRemoved(License $license): void |
178
|
|
|
{ |
179
|
1 |
|
$this->licenses->removeElement($license); |
180
|
1 |
|
} |
181
|
|
|
|
182
|
|
|
/** |
183
|
|
|
* @return string |
184
|
|
|
*/ |
185
|
|
|
public function getInitialPrice(): string |
186
|
|
|
{ |
187
|
|
|
return $this->initialPrice; |
188
|
|
|
} |
189
|
|
|
|
190
|
|
|
/** |
191
|
|
|
* @param string $initialPrice |
192
|
|
|
*/ |
193
|
|
|
public function setInitialPrice(string $initialPrice): void |
194
|
|
|
{ |
195
|
|
|
$this->initialPrice = $initialPrice; |
196
|
|
|
} |
197
|
|
|
|
198
|
|
|
/** |
199
|
|
|
* @return string |
200
|
|
|
*/ |
201
|
|
|
public function getPeriodicPrice(): string |
202
|
|
|
{ |
203
|
|
|
return $this->periodicPrice; |
204
|
|
|
} |
205
|
|
|
|
206
|
|
|
/** |
207
|
|
|
* @param string $periodicPrice |
208
|
|
|
*/ |
209
|
|
|
public function setPeriodicPrice(string $periodicPrice): void |
210
|
|
|
{ |
211
|
|
|
$this->periodicPrice = $periodicPrice; |
212
|
|
|
} |
213
|
|
|
|
214
|
|
|
/** |
215
|
|
|
* @return string |
216
|
|
|
*/ |
217
|
|
|
public function getPurchasePrice(): string |
218
|
|
|
{ |
219
|
|
|
return $this->purchasePrice; |
220
|
|
|
} |
221
|
|
|
|
222
|
|
|
/** |
223
|
|
|
* @param string $purchasePrice |
224
|
|
|
*/ |
225
|
|
|
public function setPurchasePrice(string $purchasePrice): void |
226
|
|
|
{ |
227
|
|
|
$this->purchasePrice = $purchasePrice; |
228
|
|
|
} |
229
|
|
|
|
230
|
|
|
/** |
231
|
|
|
* @return int |
232
|
|
|
*/ |
233
|
|
|
public function getSimultaneousBookingMaximum(): int |
234
|
|
|
{ |
235
|
|
|
return $this->simultaneousBookingMaximum; |
236
|
|
|
} |
237
|
|
|
|
238
|
|
|
/** |
239
|
|
|
* @param int $simultaneousBookingMaximum |
240
|
|
|
*/ |
241
|
|
|
public function setSimultaneousBookingMaximum(int $simultaneousBookingMaximum): void |
242
|
|
|
{ |
243
|
|
|
$this->simultaneousBookingMaximum = $simultaneousBookingMaximum; |
244
|
|
|
} |
245
|
|
|
|
246
|
|
|
/** |
247
|
|
|
* @API\Field(type="BookingType") |
248
|
|
|
* |
249
|
|
|
* @return string |
250
|
|
|
*/ |
251
|
|
|
public function getBookingType(): string |
252
|
|
|
{ |
253
|
|
|
return $this->bookingType; |
254
|
|
|
} |
255
|
|
|
|
256
|
|
|
/** |
257
|
|
|
* Whether this bookable can be booked |
258
|
|
|
* |
259
|
|
|
* @return bool |
260
|
|
|
*/ |
261
|
|
|
public function isActive(): bool |
262
|
|
|
{ |
263
|
|
|
return $this->isActive; |
264
|
|
|
} |
265
|
|
|
|
266
|
|
|
/** |
267
|
|
|
* Whether this bookable can be booked |
268
|
|
|
* |
269
|
|
|
* @param bool $isActive |
270
|
|
|
*/ |
271
|
|
|
public function setIsActive(bool $isActive): void |
272
|
|
|
{ |
273
|
|
|
$this->isActive = $isActive; |
274
|
|
|
} |
275
|
|
|
|
276
|
|
|
/** |
277
|
|
|
* @API\Input(type="BookingType") |
278
|
|
|
* |
279
|
|
|
* @param string $state |
280
|
|
|
*/ |
281
|
|
|
public function setBookingType(string $state): void |
282
|
|
|
{ |
283
|
|
|
$this->bookingType = $state; |
284
|
|
|
} |
285
|
|
|
|
286
|
|
|
/** |
287
|
|
|
* State of the bookable |
288
|
|
|
* |
289
|
|
|
* @API\Field(type="BookableState") |
290
|
|
|
* |
291
|
|
|
* @return string |
292
|
|
|
*/ |
293
|
|
|
public function getState(): string |
294
|
|
|
{ |
295
|
|
|
return $this->state; |
296
|
|
|
} |
297
|
|
|
|
298
|
|
|
/** |
299
|
|
|
* State of the bookable |
300
|
|
|
* |
301
|
|
|
* @API\Input(type="BookableState") |
302
|
|
|
* |
303
|
|
|
* @param string $state |
304
|
|
|
*/ |
305
|
|
|
public function setState(string $state): void |
306
|
|
|
{ |
307
|
|
|
$this->state = $state; |
308
|
|
|
} |
309
|
|
|
|
310
|
|
|
/** |
311
|
|
|
* The date then the bookable was last checked |
312
|
|
|
* |
313
|
|
|
* @return null|Date |
314
|
|
|
*/ |
315
|
|
|
public function getVerificationDate(): ?Date |
316
|
|
|
{ |
317
|
|
|
return $this->verificationDate; |
318
|
|
|
} |
319
|
|
|
|
320
|
|
|
/** |
321
|
|
|
* The date then the bookable was last checked |
322
|
|
|
* |
323
|
|
|
* @param null|Date $verificationDate |
324
|
|
|
*/ |
325
|
|
|
public function setVerificationDate(?Date $verificationDate): void |
326
|
|
|
{ |
327
|
|
|
$this->verificationDate = $verificationDate; |
328
|
|
|
} |
329
|
|
|
|
330
|
|
|
/** |
331
|
|
|
* @return Collection |
332
|
|
|
*/ |
333
|
|
|
public function getBookableTags(): Collection |
334
|
|
|
{ |
335
|
|
|
return $this->bookableTags; |
|
|
|
|
336
|
|
|
} |
337
|
|
|
|
338
|
|
|
/** |
339
|
|
|
* Notify the user that it has a new bookableTag. |
340
|
|
|
* This should only be called by BookableTag::addUser() |
341
|
|
|
* |
342
|
|
|
* @param BookableTag $bookableTag |
343
|
|
|
*/ |
344
|
|
|
public function bookableTagAdded(BookableTag $bookableTag): void |
345
|
|
|
{ |
346
|
|
|
$this->bookableTags->add($bookableTag); |
|
|
|
|
347
|
|
|
} |
348
|
|
|
|
349
|
|
|
/** |
350
|
|
|
* Notify the user that it a bookableTag was removed. |
351
|
|
|
* This should only be called by BookableTag::removeUser() |
352
|
|
|
* |
353
|
|
|
* @param BookableTag $bookableTag |
354
|
|
|
*/ |
355
|
|
|
public function bookableTagRemoved(BookableTag $bookableTag): void |
356
|
|
|
{ |
357
|
|
|
$this->bookableTags->removeElement($bookableTag); |
|
|
|
|
358
|
|
|
} |
359
|
|
|
|
360
|
|
|
/** |
361
|
|
|
* @return null|Image |
362
|
|
|
*/ |
363
|
1 |
|
public function getImage(): ?Image |
364
|
|
|
{ |
365
|
1 |
|
return $this->image; |
366
|
|
|
} |
367
|
|
|
|
368
|
|
|
/** |
369
|
|
|
* @param null|Image $image |
370
|
|
|
*/ |
371
|
1 |
|
public function setImage(?Image $image): void |
372
|
|
|
{ |
373
|
|
|
// We must trigger lazy loading, otherwise Doctrine will seriously |
374
|
|
|
// mess up lifecycle callbacks and delete unrelated image on disk |
375
|
1 |
|
if ($this->image) { |
376
|
1 |
|
$this->image->getFilename(); |
377
|
|
|
} |
378
|
|
|
|
379
|
1 |
|
$this->image = $image; |
380
|
1 |
|
} |
381
|
|
|
} |
382
|
|
|
|
Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.
Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..