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 Doctrine\Common\Collections\ArrayCollection; |
12
|
|
|
use Doctrine\Common\Collections\Collection; |
13
|
|
|
use Doctrine\ORM\Mapping as ORM; |
14
|
|
|
use GraphQL\Doctrine\Annotation as API; |
15
|
|
|
|
16
|
|
|
/** |
17
|
|
|
* An item that can be booked by a user |
18
|
|
|
* |
19
|
|
|
* @ORM\Entity(repositoryClass="Application\Repository\BookableRepository") |
20
|
|
|
*/ |
21
|
|
|
class Bookable extends AbstractModel |
22
|
|
|
{ |
23
|
|
|
use HasName; |
24
|
|
|
use HasDescription; |
25
|
|
|
use HasCode; |
26
|
|
|
|
27
|
|
|
/** |
28
|
|
|
* @var string |
29
|
|
|
* |
30
|
|
|
* @ORM\Column(type="decimal", length=10, options={"default" = "0"}) |
31
|
|
|
*/ |
32
|
|
|
private $initialPrice = '0.00'; |
33
|
|
|
|
34
|
|
|
/** |
35
|
|
|
* @var string |
36
|
|
|
* |
37
|
|
|
* @ORM\Column(type="decimal", length=10, options={"default" = "0"}) |
38
|
|
|
*/ |
39
|
|
|
private $periodicPrice = '0.00'; |
40
|
|
|
|
41
|
|
|
/** |
42
|
|
|
* @var int |
43
|
|
|
* |
44
|
|
|
* @ORM\Column(type="smallint", options={"unsigned" = true, "default" = "1"}) |
45
|
|
|
*/ |
46
|
|
|
private $simultaneousBookingMaximum = 1; |
47
|
|
|
|
48
|
|
|
/** |
49
|
|
|
* @var string |
50
|
|
|
* |
51
|
|
|
* @ORM\Column(type="BookingType", length=10, options={"default" = BookingTypeType::SELF_APPROVED}) |
52
|
|
|
*/ |
53
|
|
|
private $bookingType = BookingTypeType::SELF_APPROVED; |
54
|
|
|
|
55
|
|
|
/** |
56
|
|
|
* @var BookableType |
57
|
|
|
* @ORM\ManyToOne(targetEntity="BookableType") |
58
|
|
|
*/ |
59
|
|
|
private $type; |
60
|
|
|
|
61
|
|
|
/** |
62
|
|
|
* @var Collection |
63
|
|
|
* @ORM\ManyToMany(targetEntity="Booking", mappedBy="bookables") |
64
|
|
|
*/ |
65
|
|
|
private $bookings; |
66
|
|
|
|
67
|
|
|
/** |
68
|
|
|
* @var Collection |
69
|
|
|
* @ORM\ManyToMany(targetEntity="License", mappedBy="bookables") |
70
|
|
|
*/ |
71
|
|
|
private $licenses; |
72
|
|
|
|
73
|
|
|
/** |
74
|
|
|
* Constructor |
75
|
|
|
*/ |
76
|
2 |
|
public function __construct() |
77
|
|
|
{ |
78
|
2 |
|
$this->bookings = new ArrayCollection(); |
79
|
2 |
|
$this->licenses = new ArrayCollection(); |
80
|
2 |
|
} |
81
|
|
|
|
82
|
|
|
/** |
83
|
|
|
* @return Collection |
84
|
|
|
*/ |
85
|
1 |
|
public function getBookings(): Collection |
86
|
|
|
{ |
87
|
1 |
|
return $this->bookings; |
88
|
|
|
} |
89
|
|
|
|
90
|
|
|
/** |
91
|
|
|
* Notify the bookable that it has a new booking. |
92
|
|
|
* This should only be called by Booking::addBookable() |
93
|
|
|
* |
94
|
|
|
* @param Booking $booking |
95
|
|
|
*/ |
96
|
1 |
|
public function bookingAdded(Booking $booking): void |
97
|
|
|
{ |
98
|
1 |
|
$this->bookings->add($booking); |
99
|
1 |
|
} |
100
|
|
|
|
101
|
|
|
/** |
102
|
|
|
* Notify the bookable that it a booking was removed. |
103
|
|
|
* This should only be called by Booking::removeBookable() |
104
|
|
|
* |
105
|
|
|
* @param Booking $booking |
106
|
|
|
*/ |
107
|
1 |
|
public function bookingRemoved(Booking $booking): void |
108
|
|
|
{ |
109
|
1 |
|
$this->bookings->removeElement($booking); |
110
|
1 |
|
} |
111
|
|
|
|
112
|
|
|
/** |
113
|
|
|
* @return Collection |
114
|
|
|
*/ |
115
|
1 |
|
public function getLicenses(): Collection |
116
|
|
|
{ |
117
|
1 |
|
return $this->licenses; |
118
|
|
|
} |
119
|
|
|
|
120
|
|
|
/** |
121
|
|
|
* Notify the bookable that it has a new license. |
122
|
|
|
* This should only be called by License::addBookable() |
123
|
|
|
* |
124
|
|
|
* @param License $license |
125
|
|
|
*/ |
126
|
1 |
|
public function licenseAdded(License $license): void |
127
|
|
|
{ |
128
|
1 |
|
$this->licenses->add($license); |
129
|
1 |
|
} |
130
|
|
|
|
131
|
|
|
/** |
132
|
|
|
* Notify the bookable that it a license was removed. |
133
|
|
|
* This should only be called by License::removeBookable() |
134
|
|
|
* |
135
|
|
|
* @param License $license |
136
|
|
|
*/ |
137
|
1 |
|
public function licenseRemoved(License $license): void |
138
|
|
|
{ |
139
|
1 |
|
$this->licenses->removeElement($license); |
140
|
1 |
|
} |
141
|
|
|
|
142
|
|
|
/** |
143
|
|
|
* @return BookableType |
144
|
|
|
*/ |
145
|
|
|
public function getType(): BookableType |
146
|
|
|
{ |
147
|
|
|
return $this->type; |
148
|
|
|
} |
149
|
|
|
|
150
|
|
|
/** |
151
|
|
|
* @param BookableType $type |
152
|
|
|
*/ |
153
|
|
|
public function setType(BookableType $type): void |
154
|
|
|
{ |
155
|
|
|
$this->type = $type; |
156
|
|
|
} |
157
|
|
|
|
158
|
|
|
/** |
159
|
|
|
* @return string |
160
|
|
|
*/ |
161
|
|
|
public function getInitialPrice(): string |
162
|
|
|
{ |
163
|
|
|
return $this->initialPrice; |
164
|
|
|
} |
165
|
|
|
|
166
|
|
|
/** |
167
|
|
|
* @param string $initialPrice |
168
|
|
|
*/ |
169
|
|
|
public function setInitialPrice(string $initialPrice): void |
170
|
|
|
{ |
171
|
|
|
$this->initialPrice = $initialPrice; |
172
|
|
|
} |
173
|
|
|
|
174
|
|
|
/** |
175
|
|
|
* @return string |
176
|
|
|
*/ |
177
|
|
|
public function getPeriodicPrice(): string |
178
|
|
|
{ |
179
|
|
|
return $this->periodicPrice; |
180
|
|
|
} |
181
|
|
|
|
182
|
|
|
/** |
183
|
|
|
* @param string $periodicPrice |
184
|
|
|
*/ |
185
|
|
|
public function setPeriodicPrice(string $periodicPrice): void |
186
|
|
|
{ |
187
|
|
|
$this->periodicPrice = $periodicPrice; |
188
|
|
|
} |
189
|
|
|
|
190
|
|
|
/** |
191
|
|
|
* @return int |
192
|
|
|
*/ |
193
|
|
|
public function getSimultaneousBookingMaximum(): int |
194
|
|
|
{ |
195
|
|
|
return $this->simultaneousBookingMaximum; |
196
|
|
|
} |
197
|
|
|
|
198
|
|
|
/** |
199
|
|
|
* @param int $simultaneousBookingMaximum |
200
|
|
|
*/ |
201
|
|
|
public function setSimultaneousBookingMaximum(int $simultaneousBookingMaximum): void |
202
|
|
|
{ |
203
|
|
|
$this->simultaneousBookingMaximum = $simultaneousBookingMaximum; |
204
|
|
|
} |
205
|
|
|
|
206
|
|
|
/** |
207
|
|
|
* @API\Field(type="BookingType") |
208
|
|
|
* |
209
|
|
|
* @return string |
210
|
|
|
*/ |
211
|
|
|
public function getBookingType(): string |
212
|
|
|
{ |
213
|
|
|
return $this->bookingType; |
214
|
|
|
} |
215
|
|
|
|
216
|
|
|
/** |
217
|
|
|
* @API\Input(type="BookingType") |
218
|
|
|
* |
219
|
|
|
* @param string $bookingType |
220
|
|
|
*/ |
221
|
|
|
public function setBookingType(string $bookingType): void |
222
|
|
|
{ |
223
|
|
|
$this->bookingType = $bookingType; |
224
|
|
|
} |
225
|
|
|
} |
226
|
|
|
|