1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
declare(strict_types=1); |
4
|
|
|
|
5
|
|
|
namespace Application\Model; |
6
|
|
|
|
7
|
|
|
use Application\DBAL\Types\BookingTypeType; |
8
|
|
|
use Application\Traits\HasCode; |
9
|
|
|
use Application\Traits\HasDescription; |
10
|
|
|
use Application\Traits\HasName; |
11
|
|
|
use Application\Traits\HasRemarks; |
12
|
|
|
use Doctrine\Common\Collections\ArrayCollection; |
13
|
|
|
use Doctrine\Common\Collections\Collection; |
14
|
|
|
use Doctrine\ORM\Mapping as ORM; |
15
|
|
|
use GraphQL\Doctrine\Annotation as API; |
16
|
|
|
|
17
|
|
|
/** |
18
|
|
|
* An item that can be booked by a user |
19
|
|
|
* |
20
|
|
|
* @ORM\Entity(repositoryClass="Application\Repository\BookableRepository") |
21
|
|
|
*/ |
22
|
|
|
class Bookable extends AbstractModel |
23
|
|
|
{ |
24
|
|
|
use HasName; |
25
|
|
|
use HasDescription; |
26
|
|
|
use HasCode; |
27
|
|
|
use HasRemarks; |
28
|
|
|
|
29
|
|
|
/** |
30
|
|
|
* @var string |
31
|
|
|
* |
32
|
|
|
* @ORM\Column(type="decimal", length=10, options={"default" = "0"}) |
33
|
|
|
*/ |
34
|
|
|
private $initialPrice = '0.00'; |
35
|
|
|
|
36
|
|
|
/** |
37
|
|
|
* @var string |
38
|
|
|
* |
39
|
|
|
* @ORM\Column(type="decimal", length=10, options={"default" = "0"}) |
40
|
|
|
*/ |
41
|
|
|
private $periodicPrice = '0.00'; |
42
|
|
|
|
43
|
|
|
/** |
44
|
|
|
* @var int |
45
|
|
|
* |
46
|
|
|
* @ORM\Column(type="smallint", options={"unsigned" = true, "default" = "1"}) |
47
|
|
|
*/ |
48
|
|
|
private $simultaneousBookingMaximum = 1; |
49
|
|
|
|
50
|
|
|
/** |
51
|
|
|
* @var string |
52
|
|
|
* |
53
|
|
|
* @ORM\Column(type="BookingType", length=10, options={"default" = BookingTypeType::SELF_APPROVED}) |
54
|
|
|
*/ |
55
|
|
|
private $bookingType = BookingTypeType::SELF_APPROVED; |
56
|
|
|
|
57
|
|
|
/** |
58
|
|
|
* @var BookableTag |
59
|
|
|
* |
60
|
|
|
* @ORM\ManyToMany(targetEntity="BookableTag", mappedBy="bookables") |
61
|
|
|
*/ |
62
|
|
|
private $bookableTags; |
63
|
|
|
|
64
|
|
|
/** |
65
|
|
|
* @var Collection |
66
|
|
|
* @ORM\ManyToMany(targetEntity="Booking", mappedBy="bookables") |
67
|
|
|
*/ |
68
|
|
|
private $bookings; |
69
|
|
|
|
70
|
|
|
/** |
71
|
|
|
* @var Collection |
72
|
|
|
* @ORM\OneToMany(targetEntity="Transaction", mappedBy="bookable") |
73
|
|
|
*/ |
74
|
|
|
private $transactions; |
75
|
|
|
|
76
|
|
|
/** |
77
|
|
|
* @var Collection |
78
|
|
|
* @ORM\ManyToMany(targetEntity="License", mappedBy="bookables") |
79
|
|
|
*/ |
80
|
|
|
private $licenses; |
81
|
|
|
|
82
|
|
|
/** |
83
|
|
|
* Constructor |
84
|
|
|
*/ |
85
|
3 |
|
public function __construct() |
86
|
|
|
{ |
87
|
3 |
|
$this->bookings = new ArrayCollection(); |
88
|
3 |
|
$this->licenses = new ArrayCollection(); |
89
|
3 |
|
$this->bookableTags = new ArrayCollection(); |
|
|
|
|
90
|
3 |
|
$this->transactions = new ArrayCollection(); |
91
|
3 |
|
} |
92
|
|
|
|
93
|
|
|
/** |
94
|
|
|
* @return Collection |
95
|
|
|
*/ |
96
|
1 |
|
public function getBookings(): Collection |
97
|
|
|
{ |
98
|
1 |
|
return $this->bookings; |
99
|
|
|
} |
100
|
|
|
|
101
|
|
|
/** |
102
|
|
|
* Notify the bookable that it has a new booking. |
103
|
|
|
* This should only be called by Booking::addBookable() |
104
|
|
|
* |
105
|
|
|
* @param Booking $booking |
106
|
|
|
*/ |
107
|
1 |
|
public function bookingAdded(Booking $booking): void |
108
|
|
|
{ |
109
|
1 |
|
$this->bookings->add($booking); |
110
|
1 |
|
} |
111
|
|
|
|
112
|
|
|
/** |
113
|
|
|
* Notify the bookable that it a booking was removed. |
114
|
|
|
* This should only be called by Booking::removeBookable() |
115
|
|
|
* |
116
|
|
|
* @param Booking $booking |
117
|
|
|
*/ |
118
|
1 |
|
public function bookingRemoved(Booking $booking): void |
119
|
|
|
{ |
120
|
1 |
|
$this->bookings->removeElement($booking); |
121
|
1 |
|
} |
122
|
|
|
|
123
|
|
|
/** |
124
|
|
|
* @return Collection |
125
|
|
|
*/ |
126
|
1 |
|
public function getLicenses(): Collection |
127
|
|
|
{ |
128
|
1 |
|
return $this->licenses; |
129
|
|
|
} |
130
|
|
|
|
131
|
|
|
/** |
132
|
|
|
* Notify the bookable that it has a new license. |
133
|
|
|
* This should only be called by License::addBookable() |
134
|
|
|
* |
135
|
|
|
* @param License $license |
136
|
|
|
*/ |
137
|
1 |
|
public function licenseAdded(License $license): void |
138
|
|
|
{ |
139
|
1 |
|
$this->licenses->add($license); |
140
|
1 |
|
} |
141
|
|
|
|
142
|
|
|
/** |
143
|
|
|
* Notify the bookable that it a license was removed. |
144
|
|
|
* This should only be called by License::removeBookable() |
145
|
|
|
* |
146
|
|
|
* @param License $license |
147
|
|
|
*/ |
148
|
1 |
|
public function licenseRemoved(License $license): void |
149
|
|
|
{ |
150
|
1 |
|
$this->licenses->removeElement($license); |
151
|
1 |
|
} |
152
|
|
|
|
153
|
|
|
/** |
154
|
|
|
* @return string |
155
|
|
|
*/ |
156
|
|
|
public function getInitialPrice(): string |
157
|
|
|
{ |
158
|
|
|
return $this->initialPrice; |
159
|
|
|
} |
160
|
|
|
|
161
|
|
|
/** |
162
|
|
|
* @param string $initialPrice |
163
|
|
|
*/ |
164
|
|
|
public function setInitialPrice(string $initialPrice): void |
165
|
|
|
{ |
166
|
|
|
$this->initialPrice = $initialPrice; |
167
|
|
|
} |
168
|
|
|
|
169
|
|
|
/** |
170
|
|
|
* @return string |
171
|
|
|
*/ |
172
|
|
|
public function getPeriodicPrice(): string |
173
|
|
|
{ |
174
|
|
|
return $this->periodicPrice; |
175
|
|
|
} |
176
|
|
|
|
177
|
|
|
/** |
178
|
|
|
* @param string $periodicPrice |
179
|
|
|
*/ |
180
|
|
|
public function setPeriodicPrice(string $periodicPrice): void |
181
|
|
|
{ |
182
|
|
|
$this->periodicPrice = $periodicPrice; |
183
|
|
|
} |
184
|
|
|
|
185
|
|
|
/** |
186
|
|
|
* @return int |
187
|
|
|
*/ |
188
|
|
|
public function getSimultaneousBookingMaximum(): int |
189
|
|
|
{ |
190
|
|
|
return $this->simultaneousBookingMaximum; |
191
|
|
|
} |
192
|
|
|
|
193
|
|
|
/** |
194
|
|
|
* @param int $simultaneousBookingMaximum |
195
|
|
|
*/ |
196
|
|
|
public function setSimultaneousBookingMaximum(int $simultaneousBookingMaximum): void |
197
|
|
|
{ |
198
|
|
|
$this->simultaneousBookingMaximum = $simultaneousBookingMaximum; |
199
|
|
|
} |
200
|
|
|
|
201
|
|
|
/** |
202
|
|
|
* @API\Field(type="BookingType") |
203
|
|
|
* |
204
|
|
|
* @return string |
205
|
|
|
*/ |
206
|
|
|
public function getBookingType(): string |
207
|
|
|
{ |
208
|
|
|
return $this->bookingType; |
209
|
|
|
} |
210
|
|
|
|
211
|
|
|
/** |
212
|
|
|
* @API\Input(type="BookingType") |
213
|
|
|
* |
214
|
|
|
* @param string $bookingType |
215
|
|
|
*/ |
216
|
|
|
public function setBookingType(string $bookingType): void |
217
|
|
|
{ |
218
|
|
|
$this->bookingType = $bookingType; |
219
|
|
|
} |
220
|
|
|
|
221
|
|
|
/** |
222
|
|
|
* @return Collection |
223
|
|
|
*/ |
224
|
|
|
public function getBookableTags(): Collection |
225
|
|
|
{ |
226
|
|
|
return $this->bookableTags; |
|
|
|
|
227
|
|
|
} |
228
|
|
|
|
229
|
|
|
/** |
230
|
|
|
* Notify the user that it has a new bookableTag. |
231
|
|
|
* This should only be called by BookableTag::addUser() |
232
|
|
|
* |
233
|
|
|
* @param BookableTag $bookableTag |
234
|
|
|
*/ |
235
|
|
|
public function bookableTagAdded(BookableTag $bookableTag): void |
236
|
|
|
{ |
237
|
|
|
$this->bookableTags->add($bookableTag); |
|
|
|
|
238
|
|
|
} |
239
|
|
|
|
240
|
|
|
/** |
241
|
|
|
* Notify the user that it a bookableTag was removed. |
242
|
|
|
* This should only be called by BookableTag::removeUser() |
243
|
|
|
* |
244
|
|
|
* @param BookableTag $bookableTag |
245
|
|
|
*/ |
246
|
|
|
public function bookableTagRemoved(BookableTag $bookableTag): void |
247
|
|
|
{ |
248
|
|
|
$this->bookableTags->removeElement($bookableTag); |
|
|
|
|
249
|
|
|
} |
250
|
|
|
|
251
|
|
|
/** |
252
|
|
|
* @return Collection |
253
|
|
|
*/ |
254
|
1 |
|
public function getTransactions(): Collection |
255
|
|
|
{ |
256
|
1 |
|
return $this->transactions; |
257
|
|
|
} |
258
|
|
|
|
259
|
|
|
/** |
260
|
|
|
* Notify the bookable that it has a new transaction. |
261
|
|
|
* This should only be called by Transaction::setBookable() |
262
|
|
|
* |
263
|
|
|
* @param Transaction $transaction |
264
|
|
|
*/ |
265
|
1 |
|
public function transactionAdded(Transaction $transaction): void |
266
|
|
|
{ |
267
|
1 |
|
$this->transactions->add($transaction); |
268
|
1 |
|
} |
269
|
|
|
|
270
|
|
|
/** |
271
|
|
|
* Notify the bookable that one of its transactions was removed |
272
|
|
|
* This should only be called by Transaction::setBookable() |
273
|
|
|
* |
274
|
|
|
* @param Transaction $transaction |
275
|
|
|
*/ |
276
|
1 |
|
public function transactionRemoved(Transaction $transaction): void |
277
|
|
|
{ |
278
|
1 |
|
$this->transactions->removeElement($transaction); |
279
|
1 |
|
} |
280
|
|
|
} |
281
|
|
|
|
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..