|
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", "unsigned" = true}) |
|
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\OneToMany(targetEntity="Booking", mappedBy="bookable") |
|
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
|
|
|
* @var null|Account |
|
114
|
|
|
* |
|
115
|
|
|
* @ORM\ManyToOne(targetEntity="Account") |
|
116
|
|
|
* @ORM\JoinColumns({ |
|
117
|
|
|
* @ORM\JoinColumn(nullable=true, onDelete="CASCADE") |
|
118
|
|
|
* }) |
|
119
|
|
|
*/ |
|
120
|
|
|
private $creditAccount; |
|
121
|
|
|
|
|
122
|
|
|
/** |
|
123
|
|
|
* Constructor |
|
124
|
|
|
*/ |
|
125
|
13 |
|
public function __construct() |
|
126
|
|
|
{ |
|
127
|
13 |
|
$this->bookings = new ArrayCollection(); |
|
128
|
13 |
|
$this->licenses = new ArrayCollection(); |
|
129
|
13 |
|
$this->bookableTags = new ArrayCollection(); |
|
|
|
|
|
|
130
|
13 |
|
} |
|
131
|
|
|
|
|
132
|
|
|
/** |
|
133
|
|
|
* @return Collection |
|
134
|
|
|
*/ |
|
135
|
1 |
|
public function getBookings(): Collection |
|
136
|
|
|
{ |
|
137
|
1 |
|
return $this->bookings; |
|
138
|
|
|
} |
|
139
|
|
|
|
|
140
|
|
|
/** |
|
141
|
|
|
* Notify the bookable that it has a new booking. |
|
142
|
|
|
* This should only be called by Booking::addBookable() |
|
143
|
|
|
* |
|
144
|
|
|
* @param Booking $booking |
|
145
|
|
|
*/ |
|
146
|
8 |
|
public function bookingAdded(Booking $booking): void |
|
147
|
|
|
{ |
|
148
|
8 |
|
$this->bookings->add($booking); |
|
149
|
8 |
|
} |
|
150
|
|
|
|
|
151
|
|
|
/** |
|
152
|
|
|
* Notify the bookable that it a booking was removed. |
|
153
|
|
|
* This should only be called by Booking::removeBookable() |
|
154
|
|
|
* |
|
155
|
|
|
* @param Booking $booking |
|
156
|
|
|
*/ |
|
157
|
1 |
|
public function bookingRemoved(Booking $booking): void |
|
158
|
|
|
{ |
|
159
|
1 |
|
$this->bookings->removeElement($booking); |
|
160
|
1 |
|
} |
|
161
|
|
|
|
|
162
|
|
|
/** |
|
163
|
|
|
* @return Collection |
|
164
|
|
|
*/ |
|
165
|
1 |
|
public function getLicenses(): Collection |
|
166
|
|
|
{ |
|
167
|
1 |
|
return $this->licenses; |
|
168
|
|
|
} |
|
169
|
|
|
|
|
170
|
|
|
/** |
|
171
|
|
|
* Notify the bookable that it has a new license. |
|
172
|
|
|
* This should only be called by License::addBookable() |
|
173
|
|
|
* |
|
174
|
|
|
* @param License $license |
|
175
|
|
|
*/ |
|
176
|
1 |
|
public function licenseAdded(License $license): void |
|
177
|
|
|
{ |
|
178
|
1 |
|
$this->licenses->add($license); |
|
179
|
1 |
|
} |
|
180
|
|
|
|
|
181
|
|
|
/** |
|
182
|
|
|
* Notify the bookable that it a license was removed. |
|
183
|
|
|
* This should only be called by License::removeBookable() |
|
184
|
|
|
* |
|
185
|
|
|
* @param License $license |
|
186
|
|
|
*/ |
|
187
|
1 |
|
public function licenseRemoved(License $license): void |
|
188
|
|
|
{ |
|
189
|
1 |
|
$this->licenses->removeElement($license); |
|
190
|
1 |
|
} |
|
191
|
|
|
|
|
192
|
|
|
/** |
|
193
|
|
|
* @return string |
|
194
|
|
|
*/ |
|
195
|
6 |
|
public function getInitialPrice(): string |
|
196
|
|
|
{ |
|
197
|
6 |
|
return $this->initialPrice; |
|
198
|
|
|
} |
|
199
|
|
|
|
|
200
|
|
|
/** |
|
201
|
|
|
* @param string $initialPrice |
|
202
|
|
|
*/ |
|
203
|
6 |
|
public function setInitialPrice(string $initialPrice): void |
|
204
|
|
|
{ |
|
205
|
6 |
|
$this->initialPrice = $initialPrice; |
|
206
|
6 |
|
} |
|
207
|
|
|
|
|
208
|
|
|
/** |
|
209
|
|
|
* @return string |
|
210
|
|
|
*/ |
|
211
|
10 |
|
public function getPeriodicPrice(): string |
|
212
|
|
|
{ |
|
213
|
10 |
|
return $this->periodicPrice; |
|
214
|
|
|
} |
|
215
|
|
|
|
|
216
|
|
|
/** |
|
217
|
|
|
* @param string $periodicPrice |
|
218
|
|
|
*/ |
|
219
|
8 |
|
public function setPeriodicPrice(string $periodicPrice): void |
|
220
|
|
|
{ |
|
221
|
8 |
|
$this->periodicPrice = $periodicPrice; |
|
222
|
8 |
|
} |
|
223
|
|
|
|
|
224
|
|
|
/** |
|
225
|
|
|
* @return string |
|
226
|
|
|
*/ |
|
227
|
|
|
public function getPurchasePrice(): string |
|
228
|
|
|
{ |
|
229
|
|
|
return $this->purchasePrice; |
|
230
|
|
|
} |
|
231
|
|
|
|
|
232
|
|
|
/** |
|
233
|
|
|
* @param string $purchasePrice |
|
234
|
|
|
*/ |
|
235
|
|
|
public function setPurchasePrice(string $purchasePrice): void |
|
236
|
|
|
{ |
|
237
|
|
|
$this->purchasePrice = $purchasePrice; |
|
238
|
|
|
} |
|
239
|
|
|
|
|
240
|
|
|
/** |
|
241
|
|
|
* @return int |
|
242
|
|
|
*/ |
|
243
|
|
|
public function getSimultaneousBookingMaximum(): int |
|
244
|
|
|
{ |
|
245
|
|
|
return $this->simultaneousBookingMaximum; |
|
246
|
|
|
} |
|
247
|
|
|
|
|
248
|
|
|
/** |
|
249
|
|
|
* @param int $simultaneousBookingMaximum |
|
250
|
|
|
*/ |
|
251
|
|
|
public function setSimultaneousBookingMaximum(int $simultaneousBookingMaximum): void |
|
252
|
|
|
{ |
|
253
|
|
|
$this->simultaneousBookingMaximum = $simultaneousBookingMaximum; |
|
254
|
|
|
} |
|
255
|
|
|
|
|
256
|
|
|
/** |
|
257
|
|
|
* @API\Field(type="BookingType") |
|
258
|
|
|
* |
|
259
|
|
|
* @return string |
|
260
|
|
|
*/ |
|
261
|
6 |
|
public function getBookingType(): string |
|
262
|
|
|
{ |
|
263
|
6 |
|
return $this->bookingType; |
|
264
|
|
|
} |
|
265
|
|
|
|
|
266
|
|
|
/** |
|
267
|
|
|
* Whether this bookable can be booked |
|
268
|
|
|
* |
|
269
|
|
|
* @return bool |
|
270
|
|
|
*/ |
|
271
|
|
|
public function isActive(): bool |
|
272
|
|
|
{ |
|
273
|
|
|
return $this->isActive; |
|
274
|
|
|
} |
|
275
|
|
|
|
|
276
|
|
|
/** |
|
277
|
|
|
* Whether this bookable can be booked |
|
278
|
|
|
* |
|
279
|
|
|
* @param bool $isActive |
|
280
|
|
|
*/ |
|
281
|
|
|
public function setIsActive(bool $isActive): void |
|
282
|
|
|
{ |
|
283
|
|
|
$this->isActive = $isActive; |
|
284
|
|
|
} |
|
285
|
|
|
|
|
286
|
|
|
/** |
|
287
|
|
|
* @API\Input(type="BookingType") |
|
288
|
|
|
* |
|
289
|
|
|
* @param string $state |
|
290
|
|
|
*/ |
|
291
|
|
|
public function setBookingType(string $state): void |
|
292
|
|
|
{ |
|
293
|
|
|
$this->bookingType = $state; |
|
294
|
|
|
} |
|
295
|
|
|
|
|
296
|
|
|
/** |
|
297
|
|
|
* State of the bookable |
|
298
|
|
|
* |
|
299
|
|
|
* @API\Field(type="BookableState") |
|
300
|
|
|
* |
|
301
|
|
|
* @return string |
|
302
|
|
|
*/ |
|
303
|
|
|
public function getState(): string |
|
304
|
|
|
{ |
|
305
|
|
|
return $this->state; |
|
306
|
|
|
} |
|
307
|
|
|
|
|
308
|
|
|
/** |
|
309
|
|
|
* State of the bookable |
|
310
|
|
|
* |
|
311
|
|
|
* @API\Input(type="BookableState") |
|
312
|
|
|
* |
|
313
|
|
|
* @param string $state |
|
314
|
|
|
*/ |
|
315
|
|
|
public function setState(string $state): void |
|
316
|
|
|
{ |
|
317
|
|
|
$this->state = $state; |
|
318
|
|
|
} |
|
319
|
|
|
|
|
320
|
|
|
/** |
|
321
|
|
|
* The date then the bookable was last checked |
|
322
|
|
|
* |
|
323
|
|
|
* @return null|Date |
|
324
|
|
|
*/ |
|
325
|
|
|
public function getVerificationDate(): ?Date |
|
326
|
|
|
{ |
|
327
|
|
|
return $this->verificationDate; |
|
328
|
|
|
} |
|
329
|
|
|
|
|
330
|
|
|
/** |
|
331
|
|
|
* The date then the bookable was last checked |
|
332
|
|
|
* |
|
333
|
|
|
* @param null|Date $verificationDate |
|
334
|
|
|
*/ |
|
335
|
|
|
public function setVerificationDate(?Date $verificationDate): void |
|
336
|
|
|
{ |
|
337
|
|
|
$this->verificationDate = $verificationDate; |
|
338
|
|
|
} |
|
339
|
|
|
|
|
340
|
|
|
/** |
|
341
|
|
|
* @return Collection |
|
342
|
|
|
*/ |
|
343
|
6 |
|
public function getBookableTags(): Collection |
|
344
|
|
|
{ |
|
345
|
6 |
|
return $this->bookableTags; |
|
|
|
|
|
|
346
|
|
|
} |
|
347
|
|
|
|
|
348
|
|
|
/** |
|
349
|
|
|
* Notify the user that it has a new bookableTag. |
|
350
|
|
|
* This should only be called by BookableTag::addUser() |
|
351
|
|
|
* |
|
352
|
|
|
* @param BookableTag $bookableTag |
|
353
|
|
|
*/ |
|
354
|
|
|
public function bookableTagAdded(BookableTag $bookableTag): void |
|
355
|
|
|
{ |
|
356
|
|
|
$this->bookableTags->add($bookableTag); |
|
|
|
|
|
|
357
|
|
|
} |
|
358
|
|
|
|
|
359
|
|
|
/** |
|
360
|
|
|
* Notify the user that it a bookableTag was removed. |
|
361
|
|
|
* This should only be called by BookableTag::removeUser() |
|
362
|
|
|
* |
|
363
|
|
|
* @param BookableTag $bookableTag |
|
364
|
|
|
*/ |
|
365
|
|
|
public function bookableTagRemoved(BookableTag $bookableTag): void |
|
366
|
|
|
{ |
|
367
|
|
|
$this->bookableTags->removeElement($bookableTag); |
|
|
|
|
|
|
368
|
|
|
} |
|
369
|
|
|
|
|
370
|
|
|
/** |
|
371
|
|
|
* @return null|Image |
|
372
|
|
|
*/ |
|
373
|
1 |
|
public function getImage(): ?Image |
|
374
|
|
|
{ |
|
375
|
1 |
|
return $this->image; |
|
376
|
|
|
} |
|
377
|
|
|
|
|
378
|
|
|
/** |
|
379
|
|
|
* @param null|Image $image |
|
380
|
|
|
*/ |
|
381
|
1 |
|
public function setImage(?Image $image): void |
|
382
|
|
|
{ |
|
383
|
|
|
// We must trigger lazy loading, otherwise Doctrine will seriously |
|
384
|
|
|
// mess up lifecycle callbacks and delete unrelated image on disk |
|
385
|
1 |
|
if ($this->image) { |
|
386
|
1 |
|
$this->image->getFilename(); |
|
387
|
|
|
} |
|
388
|
|
|
|
|
389
|
1 |
|
$this->image = $image; |
|
390
|
1 |
|
} |
|
391
|
|
|
|
|
392
|
|
|
/** |
|
393
|
|
|
* The account to credit when booking this bookable |
|
394
|
|
|
* |
|
395
|
|
|
* @return null|Account |
|
396
|
|
|
*/ |
|
397
|
6 |
|
public function getCreditAccount(): ?Account |
|
398
|
|
|
{ |
|
399
|
6 |
|
return $this->creditAccount; |
|
400
|
|
|
} |
|
401
|
|
|
|
|
402
|
|
|
/** |
|
403
|
|
|
* The account to credit when booking this bookable |
|
404
|
|
|
* |
|
405
|
|
|
* @param null|Account $creditAccount |
|
406
|
|
|
*/ |
|
407
|
5 |
|
public function setCreditAccount(?Account $creditAccount): void |
|
408
|
|
|
{ |
|
409
|
5 |
|
$this->creditAccount = $creditAccount; |
|
410
|
5 |
|
} |
|
411
|
|
|
} |
|
412
|
|
|
|
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..