1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace SDIS62\Core\Ops\Entity; |
4
|
|
|
|
5
|
|
|
use Datetime; |
6
|
|
|
use SDIS62\Core\Common\Entity\IdentityTrait; |
7
|
|
|
use SDIS62\Core\Ops\Exception\InvalidDateException; |
8
|
|
|
use SDIS62\Core\Ops\Exception\InvalidPlageHoraireTypeException; |
9
|
|
|
|
10
|
|
|
abstract class PlageHoraire |
11
|
|
|
{ |
12
|
|
|
use IdentityTrait; |
13
|
|
|
|
14
|
|
|
/** |
15
|
|
|
* Début de la plage horaire. |
16
|
|
|
* |
17
|
|
|
* @var Datetime |
18
|
|
|
*/ |
19
|
|
|
protected $start; |
20
|
|
|
|
21
|
|
|
/** |
22
|
|
|
* Fin de la plage horaire. |
23
|
|
|
* |
24
|
|
|
* @var Datetime |
25
|
|
|
*/ |
26
|
|
|
protected $end; |
27
|
|
|
|
28
|
|
|
/** |
29
|
|
|
* Planning. |
30
|
|
|
* |
31
|
|
|
* @var SDIS62\Core\Ops\Entity\Planning |
32
|
|
|
*/ |
33
|
|
|
protected $planning; |
34
|
|
|
|
35
|
|
|
/** |
36
|
|
|
* Pompier concerné. |
37
|
|
|
* |
38
|
|
|
* @var SDIS62\Core\Ops\Entity\Pompier |
39
|
|
|
*/ |
40
|
|
|
protected $pompier; |
41
|
|
|
|
42
|
|
|
/** |
43
|
|
|
* Spécialités de la plage horaire. |
44
|
|
|
* |
45
|
|
|
* @var array |
46
|
|
|
*/ |
47
|
|
|
protected $specialites; |
48
|
|
|
|
49
|
|
|
/** |
50
|
|
|
* Ajout d'une plage horaire. |
51
|
|
|
* |
52
|
|
|
* @param SDIS62\Core\Ops\Entity\Planning $planning |
53
|
|
|
* @param SDIS62\Core\Ops\Entity\Pompier $pompier |
54
|
|
|
* @param Datetime $start |
55
|
|
|
* @param Datetime $end |
56
|
|
|
* @param array $specialites |
57
|
|
|
*/ |
58
|
|
|
public function __construct(Planning $planning, Pompier $pompier, Datetime $start, Datetime $end, array $specialites = []) |
59
|
|
|
{ |
60
|
|
|
$this->start = $start; |
61
|
|
|
$this->end = $end; |
62
|
|
|
$this->specialites = $specialites; |
63
|
|
|
|
64
|
|
|
if ($this->start->diff($this->end)->invert == 1) { |
65
|
|
|
throw new InvalidDateException('Events usually start before they end'); |
66
|
|
|
} |
67
|
|
|
|
68
|
|
|
$this->planning = $planning; |
|
|
|
|
69
|
|
|
$this->pompier = $pompier; |
|
|
|
|
70
|
|
|
|
71
|
|
|
$this->planning->addPlageHoraire($this); |
72
|
|
|
$this->pompier->addPlageHoraire($this); |
73
|
|
|
} |
74
|
|
|
|
75
|
|
|
/** |
76
|
|
|
* Get the value of Début de la garde. |
77
|
|
|
* |
78
|
|
|
* @return Datetime |
79
|
|
|
*/ |
80
|
|
|
public function getStart() |
81
|
|
|
{ |
82
|
|
|
return $this->start; |
83
|
|
|
} |
84
|
|
|
|
85
|
|
|
/** |
86
|
|
|
* Get the value of Fin de la garde. |
87
|
|
|
* |
88
|
|
|
* @return Datetime |
89
|
|
|
*/ |
90
|
|
|
public function getEnd() |
91
|
|
|
{ |
92
|
|
|
return $this->end; |
93
|
|
|
} |
94
|
|
|
|
95
|
|
|
/** |
96
|
|
|
* Check si le Datetime est contenu dans la plage horaire. |
97
|
|
|
* |
98
|
|
|
* @param DateTime $date |
99
|
|
|
* |
100
|
|
|
* @return bool |
101
|
|
|
*/ |
102
|
|
|
public function contains(DateTime $date) |
103
|
|
|
{ |
104
|
|
|
return $this->start <= $date && $date < $this->end; |
105
|
|
|
} |
106
|
|
|
|
107
|
|
|
/** |
108
|
|
|
* Retourne vrai si la plage horaire est contenu dans la place horaire actuelle. |
109
|
|
|
* |
110
|
|
|
* @param PlageHoraire $plage |
111
|
|
|
* @param bool $strict |
112
|
|
|
* |
113
|
|
|
* @return bool |
114
|
|
|
*/ |
115
|
|
|
public function includes(PlageHoraire $plage, $strict = true) |
116
|
|
|
{ |
117
|
|
|
if (true === $strict) { |
118
|
|
|
return $this->getStart() <= $plage->getStart() && $this->getEnd() >= $plage->getEnd(); |
119
|
|
|
} |
120
|
|
|
|
121
|
|
|
return |
122
|
|
|
$this->includes($plage, true) || |
123
|
|
|
$plage->includes($this, true) || |
124
|
|
|
$this->contains($plage->getStart()) || |
125
|
|
|
$this->contains($plage->getEnd()) |
126
|
|
|
; |
127
|
|
|
} |
128
|
|
|
|
129
|
|
|
/** |
130
|
|
|
* Get the value of Type. |
131
|
|
|
* |
132
|
|
|
* @return string |
133
|
|
|
*/ |
134
|
|
|
final public function getType() |
135
|
|
|
{ |
136
|
|
|
if (empty($this->type)) { |
|
|
|
|
137
|
|
|
throw new InvalidPlageHoraireTypeException(get_class($this).' doit avoir un $type'); |
138
|
|
|
} |
139
|
|
|
|
140
|
|
|
return $this->type; |
141
|
|
|
} |
142
|
|
|
|
143
|
|
|
/** |
144
|
|
|
* Get the value of Pompier concerné. |
145
|
|
|
* |
146
|
|
|
* @return SDIS62\Core\Ops\Entity\Pompier |
147
|
|
|
*/ |
148
|
|
|
public function getPompier() |
149
|
|
|
{ |
150
|
|
|
return $this->pompier; |
151
|
|
|
} |
152
|
|
|
|
153
|
|
|
/** |
154
|
|
|
* Get the value of Planning. |
155
|
|
|
* |
156
|
|
|
* @return SDIS62\Core\Ops\Entity\Planning |
157
|
|
|
*/ |
158
|
|
|
public function getPlanning() |
159
|
|
|
{ |
160
|
|
|
return $this->planning; |
161
|
|
|
} |
162
|
|
|
|
163
|
|
|
/** |
164
|
|
|
* Spécialitées de la plage horaire. |
165
|
|
|
* |
166
|
|
|
* @return array |
167
|
|
|
*/ |
168
|
|
|
public function getSpecialites() |
169
|
|
|
{ |
170
|
|
|
if (!($this->getPompier() instanceof Pompier\SpecialistePompier)) { |
171
|
|
|
return []; |
172
|
|
|
} |
173
|
|
|
|
174
|
|
|
return array_intersect(array_values($this->specialites), $this->getPompier()->getSpecialites()); |
175
|
|
|
} |
176
|
|
|
} |
177
|
|
|
|
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..