|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace SDIS62\Core\Ops\Entity; |
|
4
|
|
|
|
|
5
|
|
|
use Datetime; |
|
6
|
|
|
use Doctrine\Common\Collections\ArrayCollection; |
|
7
|
|
|
use SDIS62\Core\Common\Entity\IdentityTrait; |
|
8
|
|
|
use SDIS62\Core\Ops\Exception\InvalidEngagementException; |
|
9
|
|
|
|
|
10
|
|
|
abstract class Engagement |
|
11
|
|
|
{ |
|
12
|
|
|
use IdentityTrait; |
|
13
|
|
|
|
|
14
|
|
|
/** |
|
15
|
|
|
* Création de l'engagement. |
|
16
|
|
|
* |
|
17
|
|
|
* @var Datetime |
|
18
|
|
|
*/ |
|
19
|
|
|
protected $created; |
|
20
|
|
|
|
|
21
|
|
|
/** |
|
22
|
|
|
* Date de mise à jour. |
|
23
|
|
|
* |
|
24
|
|
|
* @var Datetime |
|
25
|
|
|
*/ |
|
26
|
|
|
protected $updated; |
|
27
|
|
|
|
|
28
|
|
|
/** |
|
29
|
|
|
* Fin de l'engagement. |
|
30
|
|
|
* |
|
31
|
|
|
* @var Datetime |
|
32
|
|
|
*/ |
|
33
|
|
|
protected $ended; |
|
34
|
|
|
|
|
35
|
|
|
/** |
|
36
|
|
|
* Evenements particuliers de l'engagement. |
|
37
|
|
|
* |
|
38
|
|
|
* @var SDIS62\Core\Ops\Entity\Evenement[] |
|
39
|
|
|
*/ |
|
40
|
|
|
protected $evenements; |
|
41
|
|
|
|
|
42
|
|
|
/** |
|
43
|
|
|
* Intervention concernée. |
|
44
|
|
|
* |
|
45
|
|
|
* @var SDIS62\Core\Ops\Entity\Intervention |
|
46
|
|
|
*/ |
|
47
|
|
|
protected $intervention; |
|
48
|
|
|
|
|
49
|
|
|
/** |
|
50
|
|
|
* Ajout d'un engagement à une intervention. |
|
51
|
|
|
* |
|
52
|
|
|
* @param SDIS62\Core\Ops\Entity\Intervention $intervention |
|
53
|
|
|
*/ |
|
54
|
|
|
public function __construct(Intervention $intervention) |
|
55
|
|
|
{ |
|
56
|
|
|
$this->intervention = $intervention; |
|
|
|
|
|
|
57
|
|
|
$this->intervention->addEngagement($this); |
|
58
|
|
|
|
|
59
|
|
|
$this->evenements = new ArrayCollection(); |
|
|
|
|
|
|
60
|
|
|
|
|
61
|
|
|
$this->created = new Datetime('NOW'); |
|
62
|
|
|
} |
|
63
|
|
|
|
|
64
|
|
|
/** |
|
65
|
|
|
* Get the value of Type de l'engagement. |
|
66
|
|
|
* |
|
67
|
|
|
* @return string |
|
68
|
|
|
*/ |
|
69
|
|
|
final public function getType() |
|
70
|
|
|
{ |
|
71
|
|
|
if (empty($this->type)) { |
|
|
|
|
|
|
72
|
|
|
throw new InvalidEngagementException(get_class($this).' doit avoir un $type'); |
|
73
|
|
|
} |
|
74
|
|
|
|
|
75
|
|
|
return $this->type; |
|
76
|
|
|
} |
|
77
|
|
|
|
|
78
|
|
|
/** |
|
79
|
|
|
* Get the value of Création de l'engagement. |
|
80
|
|
|
* |
|
81
|
|
|
* @return Datetime |
|
82
|
|
|
*/ |
|
83
|
|
|
public function getCreated() |
|
84
|
|
|
{ |
|
85
|
|
|
return $this->created; |
|
86
|
|
|
} |
|
87
|
|
|
|
|
88
|
|
|
/** |
|
89
|
|
|
* Get the value of Date de mise à jour. |
|
90
|
|
|
* |
|
91
|
|
|
* @return Datetime|null |
|
92
|
|
|
*/ |
|
93
|
|
|
public function getUpdated() |
|
94
|
|
|
{ |
|
95
|
|
|
return $this->updated; |
|
96
|
|
|
} |
|
97
|
|
|
|
|
98
|
|
|
/** |
|
99
|
|
|
* Set the value of Date de mise à jour (la date doit être supérieure à la date de création). |
|
100
|
|
|
* |
|
101
|
|
|
* @param Datetime|string updated Format d-m-Y H:i:s |
|
102
|
|
|
* |
|
103
|
|
|
* @return self |
|
104
|
|
|
*/ |
|
105
|
|
|
public function setUpdated($updated = null) |
|
106
|
|
|
{ |
|
107
|
|
|
if (empty($updated)) { |
|
108
|
|
|
$this->setUpdated(new Datetime()); |
|
109
|
|
|
} else { |
|
110
|
|
|
$updated = $updated instanceof Datetime ? $updated : DateTime::createFromFormat('d-m-Y H:i:s', (string) $updated); |
|
111
|
|
|
} |
|
112
|
|
|
|
|
113
|
|
|
if ($updated > $this->created) { |
|
114
|
|
|
$this->updated = $updated; |
|
115
|
|
|
} |
|
116
|
|
|
|
|
117
|
|
|
return $this; |
|
118
|
|
|
} |
|
119
|
|
|
|
|
120
|
|
|
/** |
|
121
|
|
|
* Get the value of Date de fin. |
|
122
|
|
|
* |
|
123
|
|
|
* @return Datetime|null |
|
124
|
|
|
*/ |
|
125
|
|
|
public function getEnded() |
|
126
|
|
|
{ |
|
127
|
|
|
return $this->ended; |
|
128
|
|
|
} |
|
129
|
|
|
|
|
130
|
|
|
/** |
|
131
|
|
|
* Set the value of Date de fin (la date doit être supérieure à la date de création). |
|
132
|
|
|
* |
|
133
|
|
|
* @param Datetime|string ended Format d-m-Y H:i:s |
|
134
|
|
|
* |
|
135
|
|
|
* @return self |
|
136
|
|
|
*/ |
|
137
|
|
|
public function setEnded($ended) |
|
138
|
|
|
{ |
|
139
|
|
|
$ended = $ended instanceof Datetime ? $ended : DateTime::createFromFormat('d-m-Y H:i:s', (string) $ended); |
|
140
|
|
|
|
|
141
|
|
|
if ($ended > $this->created) { |
|
142
|
|
|
$this->ended = $ended; |
|
|
|
|
|
|
143
|
|
|
$this->setUpdated(); |
|
144
|
|
|
} |
|
145
|
|
|
|
|
146
|
|
|
return $this; |
|
147
|
|
|
} |
|
148
|
|
|
|
|
149
|
|
|
/** |
|
150
|
|
|
* Retourne vrai si l'engagement est terminée. |
|
151
|
|
|
* |
|
152
|
|
|
* @return bool |
|
153
|
|
|
*/ |
|
154
|
|
|
public function isEnded() |
|
155
|
|
|
{ |
|
156
|
|
|
return !empty($this->ended); |
|
157
|
|
|
} |
|
158
|
|
|
|
|
159
|
|
|
/** |
|
160
|
|
|
* Get the value of Evenements particuliers de l'engagement. |
|
161
|
|
|
* |
|
162
|
|
|
* @return SDIS62\Core\Ops\Entity\Evenement[] |
|
163
|
|
|
*/ |
|
164
|
|
|
public function getEvenements() |
|
165
|
|
|
{ |
|
166
|
|
|
if (count($this->evenements) == 0) { |
|
167
|
|
|
return []; |
|
168
|
|
|
} |
|
169
|
|
|
|
|
170
|
|
|
$evenements = $this->evenements->toArray(); |
|
|
|
|
|
|
171
|
|
|
|
|
172
|
|
|
@usort($evenements, function ($a, $b) { |
|
|
|
|
|
|
173
|
|
|
return $a->getDate()->format('U') < $b->getDate()->format('U') ? -1 : 1; |
|
174
|
|
|
}); |
|
175
|
|
|
|
|
176
|
|
|
return $evenements; |
|
177
|
|
|
} |
|
178
|
|
|
|
|
179
|
|
|
/** |
|
180
|
|
|
* Ajoute un evenement à l'engagement. |
|
181
|
|
|
* |
|
182
|
|
|
* @param SDIS62\Core\Ops\Entity\Evenement $evenement |
|
183
|
|
|
* |
|
184
|
|
|
* @return self |
|
185
|
|
|
*/ |
|
186
|
|
|
public function addEvenement(Evenement $evenement) |
|
187
|
|
|
{ |
|
188
|
|
|
$this->evenements[] = $evenement; |
|
189
|
|
|
|
|
190
|
|
|
$this->setUpdated(); |
|
191
|
|
|
|
|
192
|
|
|
return $this; |
|
193
|
|
|
} |
|
194
|
|
|
|
|
195
|
|
|
/** |
|
196
|
|
|
* Get the value of Intervention. |
|
197
|
|
|
* |
|
198
|
|
|
* @return SDIS62\Core\Ops\Entity\Intervention |
|
199
|
|
|
*/ |
|
200
|
|
|
public function getIntervention() |
|
201
|
|
|
{ |
|
202
|
|
|
return $this->intervention; |
|
203
|
|
|
} |
|
204
|
|
|
} |
|
205
|
|
|
|
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..