1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace SDIS62\Core\Ops\Entity; |
4
|
|
|
|
5
|
|
|
use Doctrine\Common\Collections\ArrayCollection; |
6
|
|
|
use SDIS62\Core\Common\Entity\IdentityTrait; |
7
|
|
|
use SDIS62\Core\Ops\Exception\InvalidDateException; |
8
|
|
|
|
9
|
|
|
class Planning |
10
|
|
|
{ |
11
|
|
|
use IdentityTrait; |
12
|
|
|
|
13
|
|
|
/** |
14
|
|
|
* Nom du planning. |
15
|
|
|
* |
16
|
|
|
* @var string |
17
|
|
|
*/ |
18
|
|
|
protected $name; |
19
|
|
|
|
20
|
|
|
/** |
21
|
|
|
* Plages Horaires. |
22
|
|
|
* |
23
|
|
|
* @var SDIS62\Core\Ops\Entity\PlageHoraire[] |
24
|
|
|
*/ |
25
|
|
|
protected $plages_horaires; |
26
|
|
|
|
27
|
|
|
/** |
28
|
|
|
* Création d'un planning. |
29
|
|
|
* |
30
|
|
|
* @param string $name |
31
|
|
|
*/ |
32
|
|
|
public function __construct($name) |
33
|
|
|
{ |
34
|
|
|
$this->name = $name; |
35
|
|
|
$this->plages_horaires = new ArrayCollection(); |
|
|
|
|
36
|
|
|
} |
37
|
|
|
|
38
|
|
|
/** |
39
|
|
|
* Ajout d'une plage horaire. |
40
|
|
|
* |
41
|
|
|
* @param SDIS62\Core\Ops\Entity\PlageHoraire $plage_horaire |
42
|
|
|
* |
43
|
|
|
* @return self |
44
|
|
|
*/ |
45
|
|
|
public function addPlageHoraire(PlageHoraire $plage_horaire) |
46
|
|
|
{ |
47
|
|
|
// Règles d'ajout |
48
|
|
|
if ($plage_horaire instanceof PlageHoraire\GardePlageHoraire) { |
49
|
|
|
// Contrôles des gardes existantes (une dispo ne peut pas être ajoutée sur une garde) |
50
|
|
|
foreach ($plage_horaire->getPompier()->getGardes() as $garde) { |
51
|
|
|
if ($garde->includes($plage_horaire, false)) { |
52
|
|
|
throw new InvalidDateException('Une garde existe aux dates de la garde à ajouter'); |
53
|
|
|
} |
54
|
|
|
} |
55
|
|
|
// Contrôles des dispo existantes (si une garde est posé sur une dispo, on la transforme) |
56
|
|
|
foreach ($plage_horaire->getPompier()->getDispos() as $dispo) { |
57
|
|
|
if ($dispo->includes($plage_horaire, false)) { |
58
|
|
|
$plage_horaire->getPompier()->getPlagesHoraires()->removeElement($dispo); |
59
|
|
|
if ($dispo->getStart() < $plage_horaire->getStart()) { |
60
|
|
|
new PlageHoraire\DispoPlageHoraire($this, $plage_horaire->getPompier(), $dispo->getStart(), $plage_horaire->getStart()); |
61
|
|
|
} |
62
|
|
|
if ($dispo->getEnd() > $plage_horaire->getEnd()) { |
63
|
|
|
new PlageHoraire\DispoPlageHoraire($this, $plage_horaire->getPompier(), $plage_horaire->getEnd(), $dispo->getEnd()); |
64
|
|
|
} |
65
|
|
|
} |
66
|
|
|
} |
67
|
|
|
} elseif ($plage_horaire instanceof PlageHoraire\DispoPlageHoraire) { |
68
|
|
|
// Contrôles des gardes existantes (une dispo ne peut pas être ajoutée sur une garde) |
69
|
|
|
foreach ($plage_horaire->getPompier()->getGardes() as $garde) { |
70
|
|
|
if ($garde->includes($plage_horaire, false)) { |
71
|
|
|
throw new InvalidDateException('Une garde existe aux dates de la dispo'); |
72
|
|
|
} |
73
|
|
|
} |
74
|
|
|
// Contrôles des dispo existantes (une dispo ne peut pas être ajoutée sur une autre dispo) |
75
|
|
|
foreach ($plage_horaire->getPompier()->getDispos() as $dispo) { |
76
|
|
|
if ($dispo->includes($plage_horaire, false)) { |
77
|
|
|
throw new InvalidDateException('Une disponibilité existe aux dates de la dispo'); |
78
|
|
|
} |
79
|
|
|
} |
80
|
|
|
} |
81
|
|
|
|
82
|
|
|
$this->plages_horaires->add($plage_horaire); |
|
|
|
|
83
|
|
|
|
84
|
|
|
return $this; |
85
|
|
|
} |
86
|
|
|
|
87
|
|
|
/** |
88
|
|
|
* Récupération des plages horaires du planning. |
89
|
|
|
* |
90
|
|
|
* @return SDIS62\Core\Ops\Entity\PlageHoraire[] |
91
|
|
|
*/ |
92
|
|
|
public function getPlagesHoraires() |
93
|
|
|
{ |
94
|
|
|
return $this->plages_horaires; |
95
|
|
|
} |
96
|
|
|
|
97
|
|
|
/** |
98
|
|
|
* Get the value of Gardes. |
99
|
|
|
* |
100
|
|
|
* @return SDIS62\Core\Ops\Entity\PlageHoraire\Garde[] |
101
|
|
|
*/ |
102
|
|
|
public function getGardes() |
103
|
|
|
{ |
104
|
|
|
$gardes = []; |
105
|
|
|
|
106
|
|
|
foreach ($this->plages_horaires as $plage_horaire) { |
107
|
|
|
if ($plage_horaire instanceof PlageHoraire\GardePlageHoraire) { |
108
|
|
|
$gardes[] = $plage_horaire; |
109
|
|
|
} |
110
|
|
|
} |
111
|
|
|
|
112
|
|
|
return $gardes; |
113
|
|
|
} |
114
|
|
|
|
115
|
|
|
/** |
116
|
|
|
* Get the value of Dispos. |
117
|
|
|
* |
118
|
|
|
* @return SDIS62\Core\Ops\Entity\PlageHoraire\Dispo[] |
119
|
|
|
*/ |
120
|
|
|
public function getDispos() |
121
|
|
|
{ |
122
|
|
|
$dispos = []; |
123
|
|
|
|
124
|
|
|
foreach ($this->plages_horaires as $plage_horaire) { |
125
|
|
|
if ($plage_horaire instanceof PlageHoraire\GardePlageHoraire) { |
126
|
|
|
$dispos[] = $plage_horaire; |
127
|
|
|
} |
128
|
|
|
} |
129
|
|
|
|
130
|
|
|
return $dispos; |
131
|
|
|
} |
132
|
|
|
|
133
|
|
|
/** |
134
|
|
|
* Get the value of Nom du planning. |
135
|
|
|
* |
136
|
|
|
* @return string |
137
|
|
|
*/ |
138
|
|
|
public function getName() |
139
|
|
|
{ |
140
|
|
|
return $this->name; |
141
|
|
|
} |
142
|
|
|
|
143
|
|
|
/** |
144
|
|
|
* Set the value of Nom du planning. |
145
|
|
|
* |
146
|
|
|
* @param string name |
147
|
|
|
* |
148
|
|
|
* @return self |
149
|
|
|
*/ |
150
|
|
|
public function setName($name) |
151
|
|
|
{ |
152
|
|
|
$this->name = $name; |
153
|
|
|
|
154
|
|
|
return $this; |
155
|
|
|
} |
156
|
|
|
} |
157
|
|
|
|
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..