1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace SDIS62\Core\Ops\Entity; |
4
|
|
|
|
5
|
|
|
use Datetime; |
6
|
|
|
use Doctrine\Common\Collections\ArrayCollection; |
7
|
|
|
use libphonenumber\PhoneNumberFormat; |
8
|
|
|
use libphonenumber\PhoneNumberUtil; |
9
|
|
|
use SDIS62\Core\Ops\Entity\Engagement\PompierEngagement; |
10
|
|
|
use SDIS62\Core\Ops\Exception\InvalidPhoneNumberException; |
11
|
|
|
|
12
|
|
|
class Pompier |
13
|
|
|
{ |
14
|
|
|
/** |
15
|
|
|
* Type. |
16
|
|
|
* |
17
|
|
|
* @var string |
18
|
|
|
*/ |
19
|
|
|
protected $type = 'pompier'; |
20
|
|
|
|
21
|
|
|
/** |
22
|
|
|
* Inscription dans les plannings du pompier. |
23
|
|
|
* |
24
|
|
|
* @var SDIS62\Core\Ops\Entity\PlageHoraire[] |
25
|
|
|
*/ |
26
|
|
|
protected $plages_horaires; |
27
|
|
|
|
28
|
|
|
/** |
29
|
|
|
* Centre dans lequel le pompier est affecté. |
30
|
|
|
* |
31
|
|
|
* @var SDIS62\Core\Ops\Entity\Centre |
32
|
|
|
*/ |
33
|
|
|
protected $centre; |
34
|
|
|
|
35
|
|
|
/** |
36
|
|
|
* Matricule du pompier. |
37
|
|
|
* |
38
|
|
|
* @var string |
39
|
|
|
*/ |
40
|
|
|
protected $matricule; |
41
|
|
|
|
42
|
|
|
/** |
43
|
|
|
* Engagement du pompier. |
44
|
|
|
* |
45
|
|
|
* @var SDIS62\Core\Ops\Entity\Engagement\PompierEngagement[] |
46
|
|
|
*/ |
47
|
|
|
protected $engagements; |
48
|
|
|
|
49
|
|
|
/** |
50
|
|
|
* Grade. |
51
|
|
|
* |
52
|
|
|
* @var string |
53
|
|
|
*/ |
54
|
|
|
protected $grade; |
55
|
|
|
|
56
|
|
|
/** |
57
|
|
|
* Nom du pompier. |
58
|
|
|
* |
59
|
|
|
* @var string |
60
|
|
|
*/ |
61
|
|
|
protected $name; |
62
|
|
|
|
63
|
|
|
/** |
64
|
|
|
* Numéro de téléphone. |
65
|
|
|
* |
66
|
|
|
* @var string |
67
|
|
|
*/ |
68
|
|
|
protected $phone_number; |
69
|
|
|
|
70
|
|
|
/** |
71
|
|
|
* Etat du pompier. |
72
|
|
|
* |
73
|
|
|
* @var SDIS62\Core\Ops\Entity\Statut |
74
|
|
|
*/ |
75
|
|
|
protected $statut; |
76
|
|
|
|
77
|
|
|
/** |
78
|
|
|
* Profesionnel ? |
79
|
|
|
* |
80
|
|
|
* @var bool |
81
|
|
|
*/ |
82
|
|
|
protected $is_pro; |
83
|
|
|
|
84
|
|
|
/** |
85
|
|
|
* Coordonnées du pompier. |
86
|
|
|
* |
87
|
|
|
* @var SDIS62\Core\Ops\Entity\Coordinates |
88
|
|
|
*/ |
89
|
|
|
protected $coordinates; |
90
|
|
|
|
91
|
|
|
/** |
92
|
|
|
* Ajout d'un pompier. |
93
|
|
|
* |
94
|
|
|
* @param string $name |
95
|
|
|
* @param string $matricule |
96
|
|
|
* @param SDIS62\Core\Ops\Entity\Centre $centre |
97
|
|
|
*/ |
98
|
|
|
public function __construct($name, $matricule, Centre $centre) |
99
|
|
|
{ |
100
|
|
|
$this->matricule = $matricule; |
101
|
|
|
$this->setName($name); |
102
|
|
|
$this->setCentre($centre); |
103
|
|
|
$this->engagements = new ArrayCollection(); |
|
|
|
|
104
|
|
|
$this->plages_horaires = new ArrayCollection(); |
|
|
|
|
105
|
|
|
$this->statut = Statut::DISPONIBLE(); |
106
|
|
|
$this->is_pro = true; |
107
|
|
|
} |
108
|
|
|
|
109
|
|
|
/** |
110
|
|
|
* Get the value of Plannings du pompier. |
111
|
|
|
* |
112
|
|
|
* @return SDIS62\Core\Ops\Entity\Planning[] |
113
|
|
|
*/ |
114
|
|
|
public function getPlannings() |
115
|
|
|
{ |
116
|
|
|
$plannings = []; |
117
|
|
|
|
118
|
|
|
foreach ($this->plages_horaires as $plage_horaire) { |
119
|
|
|
if (!in_array($plage_horaire->getPlanning(), $plannings)) { |
120
|
|
|
$plannings[] = $plage_horaire->getPlanning(); |
121
|
|
|
} |
122
|
|
|
} |
123
|
|
|
|
124
|
|
|
return $plannings; |
125
|
|
|
} |
126
|
|
|
|
127
|
|
|
/** |
128
|
|
|
* Get the value of Plages horaires. |
129
|
|
|
* |
130
|
|
|
* @return SDIS62\Core\Ops\Entity\PlageHoraire[] |
131
|
|
|
*/ |
132
|
|
|
public function getPlagesHoraires() |
133
|
|
|
{ |
134
|
|
|
return $this->plages_horaires; |
135
|
|
|
} |
136
|
|
|
|
137
|
|
|
/** |
138
|
|
|
* Get the value of Gardes. |
139
|
|
|
* |
140
|
|
|
* @return SDIS62\Core\Ops\Entity\PlageHoraire\Garde[] |
141
|
|
|
*/ |
142
|
|
|
public function getGardes() |
143
|
|
|
{ |
144
|
|
|
$gardes = []; |
145
|
|
|
|
146
|
|
|
foreach ($this->plages_horaires as $plage_horaire) { |
147
|
|
|
if ($plage_horaire instanceof PlageHoraire\GardePlageHoraire) { |
148
|
|
|
$gardes[] = $plage_horaire; |
149
|
|
|
} |
150
|
|
|
} |
151
|
|
|
|
152
|
|
|
return $gardes; |
153
|
|
|
} |
154
|
|
|
|
155
|
|
|
/** |
156
|
|
|
* Get the value of Dispos. |
157
|
|
|
* |
158
|
|
|
* @return SDIS62\Core\Ops\Entity\PlageHoraire\Dispo[] |
159
|
|
|
*/ |
160
|
|
|
public function getDispos() |
161
|
|
|
{ |
162
|
|
|
$dispos = []; |
163
|
|
|
|
164
|
|
|
foreach ($this->plages_horaires as $plage_horaire) { |
165
|
|
|
if ($plage_horaire instanceof PlageHoraire\DispoPlageHoraire) { |
166
|
|
|
$dispos[] = $plage_horaire; |
167
|
|
|
} |
168
|
|
|
} |
169
|
|
|
|
170
|
|
|
return $dispos; |
171
|
|
|
} |
172
|
|
|
|
173
|
|
|
/** |
174
|
|
|
* Ajout d'une plage horaire. |
175
|
|
|
* |
176
|
|
|
* @param SDIS62\Core\Ops\Entity\PlageHoraire $plage_horaire |
177
|
|
|
* |
178
|
|
|
* @return self |
179
|
|
|
*/ |
180
|
|
|
public function addPlageHoraire(PlageHoraire $plage_horaire) |
181
|
|
|
{ |
182
|
|
|
$this->plages_horaires->add($plage_horaire); |
|
|
|
|
183
|
|
|
|
184
|
|
|
return $this; |
185
|
|
|
} |
186
|
|
|
|
187
|
|
|
/** |
188
|
|
|
* Get the value of Centre dans lequel le pompier est affecté. |
189
|
|
|
* |
190
|
|
|
* @return SDIS62\Core\Ops\Entity\Centre |
191
|
|
|
*/ |
192
|
|
|
public function getCentre() |
193
|
|
|
{ |
194
|
|
|
return $this->centre; |
195
|
|
|
} |
196
|
|
|
|
197
|
|
|
/** |
198
|
|
|
* Set the value of Centre dans lequel le pompier est affecté. |
199
|
|
|
* |
200
|
|
|
* @param SDIS62\Core\Ops\Entity\Centre centre |
201
|
|
|
* |
202
|
|
|
* @return self |
203
|
|
|
*/ |
204
|
|
|
public function setCentre(Centre $centre) |
205
|
|
|
{ |
206
|
|
|
if (!empty($this->centre)) { |
207
|
|
|
$this->centre->getPompiers()->removeElement($this); |
208
|
|
|
} |
209
|
|
|
|
210
|
|
|
$this->centre = $centre; |
|
|
|
|
211
|
|
|
|
212
|
|
|
$this->centre->addPompier($this); |
213
|
|
|
|
214
|
|
|
return $this; |
215
|
|
|
} |
216
|
|
|
|
217
|
|
|
/** |
218
|
|
|
* Get the value of Matricule du pompier. |
219
|
|
|
* |
220
|
|
|
* @return string |
221
|
|
|
*/ |
222
|
|
|
public function getMatricule() |
223
|
|
|
{ |
224
|
|
|
return $this->matricule; |
225
|
|
|
} |
226
|
|
|
|
227
|
|
|
/** |
228
|
|
|
* Get the value of Nom du pompier. |
229
|
|
|
* |
230
|
|
|
* @return string |
231
|
|
|
*/ |
232
|
|
|
public function getName() |
233
|
|
|
{ |
234
|
|
|
return $this->name; |
235
|
|
|
} |
236
|
|
|
|
237
|
|
|
/** |
238
|
|
|
* Set the value of Nom du pompier. |
239
|
|
|
* |
240
|
|
|
* @param string name |
241
|
|
|
* |
242
|
|
|
* @return self |
243
|
|
|
*/ |
244
|
|
|
public function setName($name) |
245
|
|
|
{ |
246
|
|
|
$this->name = $name; |
247
|
|
|
|
248
|
|
|
return $this; |
249
|
|
|
} |
250
|
|
|
|
251
|
|
|
/** |
252
|
|
|
* Get the value of Grade du pompier. |
253
|
|
|
* |
254
|
|
|
* @return string |
255
|
|
|
*/ |
256
|
|
|
public function getGrade() |
257
|
|
|
{ |
258
|
|
|
return $this->grade; |
259
|
|
|
} |
260
|
|
|
|
261
|
|
|
/** |
262
|
|
|
* Set the value of Grade du pompier. |
263
|
|
|
* |
264
|
|
|
* @param string grade |
265
|
|
|
* |
266
|
|
|
* @return self |
267
|
|
|
*/ |
268
|
|
|
public function setGrade($grade) |
269
|
|
|
{ |
270
|
|
|
$this->grade = $grade; |
271
|
|
|
|
272
|
|
|
return $this; |
273
|
|
|
} |
274
|
|
|
|
275
|
|
|
/** |
276
|
|
|
* Get the value of Liste des engagements du pompier. |
277
|
|
|
* |
278
|
|
|
* @return SDIS62\Core\Ops\Entity\Engagement\PompierEngagement[] |
279
|
|
|
*/ |
280
|
|
|
public function getEngagements() |
281
|
|
|
{ |
282
|
|
|
return $this->engagements; |
283
|
|
|
} |
284
|
|
|
|
285
|
|
|
/** |
286
|
|
|
* Ajoute un engagement au pompier. |
287
|
|
|
* |
288
|
|
|
* @param SDIS62\Core\Ops\Entity\Engagement\PompierEngagement $engagement |
289
|
|
|
* |
290
|
|
|
* @return self |
291
|
|
|
*/ |
292
|
|
|
public function addEngagement(PompierEngagement $engagement) |
293
|
|
|
{ |
294
|
|
|
$this->engagements[] = $engagement; |
295
|
|
|
|
296
|
|
|
return $this; |
297
|
|
|
} |
298
|
|
|
|
299
|
|
|
/** |
300
|
|
|
* Le matériel est il actuellement engagé ? |
301
|
|
|
* |
302
|
|
|
* @return bool |
303
|
|
|
*/ |
304
|
|
|
public function isEngage() |
305
|
|
|
{ |
306
|
|
|
foreach ($this->engagements as $engagement) { |
307
|
|
|
if (!$engagement->isEnded()) { |
308
|
|
|
return true; |
309
|
|
|
} |
310
|
|
|
} |
311
|
|
|
|
312
|
|
|
return false; |
313
|
|
|
} |
314
|
|
|
|
315
|
|
|
/** |
316
|
|
|
* Retourne vrai si le pompier est en garde. |
317
|
|
|
* |
318
|
|
|
* @return bool |
319
|
|
|
*/ |
320
|
|
|
public function isEnGarde() |
321
|
|
|
{ |
322
|
|
|
$date = new Datetime(); |
323
|
|
|
$date = $date->getTimestamp(); |
324
|
|
|
$gardes = $this->getGardes(); |
325
|
|
|
|
326
|
|
|
foreach ($gardes as $garde) { |
327
|
|
|
$from = $garde->getStart()->getTimestamp(); |
328
|
|
|
$to = $garde->getEnd()->getTimestamp(); |
329
|
|
|
if (($date > $from) && ($date < $to)) { |
330
|
|
|
return true; |
331
|
|
|
} |
332
|
|
|
} |
333
|
|
|
|
334
|
|
|
return false; |
335
|
|
|
} |
336
|
|
|
|
337
|
|
|
/** |
338
|
|
|
* Get the value of Type de pompier. |
339
|
|
|
* |
340
|
|
|
* @return string |
341
|
|
|
*/ |
342
|
|
|
final public function getType() |
343
|
|
|
{ |
344
|
|
|
return $this->type; |
345
|
|
|
} |
346
|
|
|
|
347
|
|
|
/** |
348
|
|
|
* Get the value of Numéro de téléphone. |
349
|
|
|
* |
350
|
|
|
* @return string |
351
|
|
|
*/ |
352
|
|
|
public function getPhoneNumber() |
353
|
|
|
{ |
354
|
|
|
return $this->phone_number; |
355
|
|
|
} |
356
|
|
|
|
357
|
|
|
/** |
358
|
|
|
* Set the value of Numéro de téléphone. |
359
|
|
|
* |
360
|
|
|
* @param string|null $phone_number |
361
|
|
|
* |
362
|
|
|
* @throws InvalidPhoneNumberException |
363
|
|
|
* |
364
|
|
|
* @return self |
365
|
|
|
*/ |
366
|
|
|
public function setPhoneNumber($phone_number) |
367
|
|
|
{ |
368
|
|
|
$phone_util = PhoneNumberUtil::getInstance(); |
369
|
|
|
$phone_number_parsed = $phone_util->parse($phone_number, 'FR'); |
370
|
|
|
if (!$phone_util->isValidNumber($phone_number_parsed)) { |
371
|
|
|
throw new InvalidPhoneNumberException('Format du numéro de téléphone professionnel incorrect.'); |
372
|
|
|
} |
373
|
|
|
$this->phone_number = $phone_util->format($phone_number_parsed, PhoneNumberFormat::NATIONAL); |
374
|
|
|
|
375
|
|
|
return $this; |
376
|
|
|
} |
377
|
|
|
|
378
|
|
|
/** |
379
|
|
|
* Get the value of Etat du pompier. |
380
|
|
|
* |
381
|
|
|
* @return SDIS62\Core\Ops\Entity\Statut |
382
|
|
|
*/ |
383
|
|
|
public function getStatut() |
384
|
|
|
{ |
385
|
|
|
return $this->statut instanceof Statut ? $this->statut : Statut::getByName($this->statut); |
386
|
|
|
} |
387
|
|
|
|
388
|
|
|
/** |
389
|
|
|
* Set the value of Etat du pompier. |
390
|
|
|
* |
391
|
|
|
* @param SDIS62\Core\Ops\Entity\Statut statut |
392
|
|
|
* |
393
|
|
|
* @return self |
394
|
|
|
*/ |
395
|
|
|
public function setStatut(Statut $statut) |
396
|
|
|
{ |
397
|
|
|
$this->statut = $statut; |
|
|
|
|
398
|
|
|
|
399
|
|
|
return $this; |
400
|
|
|
} |
401
|
|
|
|
402
|
|
|
/** |
403
|
|
|
* Get the value of Pro ou volontaire ? |
404
|
|
|
* |
405
|
|
|
* @return bool |
406
|
|
|
*/ |
407
|
|
|
public function isPro() |
408
|
|
|
{ |
409
|
|
|
return $this->is_pro == true; |
|
|
|
|
410
|
|
|
} |
411
|
|
|
|
412
|
|
|
/** |
413
|
|
|
* Set the value of Pro ou volontaire ? |
414
|
|
|
* |
415
|
|
|
* @param bool is_pro |
416
|
|
|
* |
417
|
|
|
* @return self |
418
|
|
|
*/ |
419
|
|
|
public function setPro($value = true) |
420
|
|
|
{ |
421
|
|
|
$this->is_pro = $value == true; |
|
|
|
|
422
|
|
|
|
423
|
|
|
return $this; |
424
|
|
|
} |
425
|
|
|
|
426
|
|
|
/** |
427
|
|
|
* Get the value of Coordonnées du pompier. |
428
|
|
|
* |
429
|
|
|
* @return SDIS62\Core\Ops\Entity\Coordinates |
430
|
|
|
*/ |
431
|
|
|
public function getCoordinates() |
432
|
|
|
{ |
433
|
|
|
return $this->coordinates; |
434
|
|
|
} |
435
|
|
|
|
436
|
|
|
/** |
437
|
|
|
* Set the value of Coordonnées du pompier. |
438
|
|
|
* |
439
|
|
|
* @param SDIS62\Core\Ops\Entity\Coordinates $coordinates |
440
|
|
|
* |
441
|
|
|
* @return self |
442
|
|
|
*/ |
443
|
|
|
public function setCoordinates(Coordinates $coordinates) |
444
|
|
|
{ |
445
|
|
|
$current_coordinates = $this->getCoordinates(); |
446
|
|
|
|
447
|
|
|
if (empty($current_coordinates) || $coordinates->getDate() > $current_coordinates->getDate()) { |
448
|
|
|
$this->coordinates = $coordinates; |
|
|
|
|
449
|
|
|
} |
450
|
|
|
|
451
|
|
|
return $this; |
452
|
|
|
} |
453
|
|
|
} |
454
|
|
|
|
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..