1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
<?php
namespace App\Entity;
use ApiPlatform\Core\Annotation\ApiResource;
use App\Entity\EntityTrait\EnablableEntityTrait;
use App\Entity\EntityTrait\HasAccountsTrait;
use App\Entity\EntityTrait\HasCompteEntity;
use App\Entity\EntityTrait\NameSlugContentEntityTrait;
use App\Flux\AccountableInterface;
use App\Flux\AccountableObject;
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\ORM\Mapping as ORM;
use Gedmo\Timestampable\Traits\TimestampableEntity;
use Ramsey\Uuid\Doctrine\UuidGenerator;
use Symfony\Bridge\Doctrine\Validator\Constraints\UniqueEntity;
use Symfony\Component\Serializer\Annotation\Groups;
/**
* @ApiResource(
* attributes={"security"="is_granted('ROLE_ADMIN_GROUPE_GERER_VIEW') or is_granted('ROLE_API')"},
* collectionOperations={
* "get"={"security"="is_granted('ROLE_ADMIN_GROUPE_GERER_LIST') or is_granted('ROLE_API')"},
* "post"={"security"="is_granted('ROLE_ADMIN_GROUPE_GERER_EDIT')"}
* },
* itemOperations={
* "get"={"security"="is_granted('ROLE_ADMIN_GROUPE_GERER_VIEW') or is_granted('ROLE_API')"},
* "put"={"security"="is_granted('ROLE_ADMIN_GROUPE_GERER_EDIT')"},
* },
* normalizationContext={"groups"={"read"}},
* denormalizationContext={"groups"={"write"}}
* )
* @ORM\Entity
* @UniqueEntity(fields="name", message="Le groupe avec ce nom existe déjà.")
* @ORM\Table(name="groupe")
* @ORM\HasLifecycleCallbacks()
*/
class Groupe extends AccountableObject implements AccountableInterface
{
use NameSlugContentEntityTrait;
use TimestampableEntity;
use EnablableEntityTrait;
use HasCompteEntity;
use HasAccountsTrait;
/**
* @var \Ramsey\Uuid\UuidInterface
*
* @ORM\Id
* @ORM\Column(type="uuid", unique=true)
* @ORM\GeneratedValue(strategy="CUSTOM")
* @ORM\CustomIdGenerator(class=UuidGenerator::class)
*/
protected $id;
/**
* @var string
*
* @ORM\Column(name="idmlc", type="string", length=100, nullable=true)
* @Groups({"read", "write"})
*/
protected $idmlc;
/**
* @var Siege
*
* @ORM\ManyToOne(targetEntity="Siege", inversedBy="groupes")
* @ORM\JoinColumn(name="siege_id", referencedColumnName="id", nullable=false)
*/
private $siege;
/**
* @var ArrayCollection|Comptoir[]
* @ORM\OneToMany(targetEntity="Comptoir", mappedBy="groupe", fetch="EXTRA_LAZY")
* @ORM\OrderBy({"name": "ASC"})
*/
private $comptoirs;
/**
* @var ArrayCollection|Prestataire[]
* @ORM\OneToMany(targetEntity="Prestataire", mappedBy="groupe", fetch="EXTRA_LAZY")
* @ORM\OrderBy({"raison": "ASC"})
*/
private $prestataires;
/**
* @var ArrayCollection|Groupeprestataire[]
* @ORM\OneToMany(targetEntity="Groupeprestataire", mappedBy="groupe", fetch="EXTRA_LAZY")
* @ORM\OrderBy({"name": "ASC"})
*/
private $groupeprestataires;
/**
* @var ArrayCollection|Adherent[]
* @ORM\OneToMany(targetEntity="Adherent", mappedBy="groupe", fetch="EXTRA_LAZY")
* @ORM\OrderBy({"updatedAt": "ASC"})
*/
private $adherents;
/**
* @var ArrayCollection|User[]
* @ORM\ManyToMany(targetEntity="User", inversedBy="groupesgeres", fetch="EXTRA_LAZY")
*/
private $gestionnaires;
/**
* @var ArrayCollection|AccountGroupe[]
* @ORM\OneToMany(targetEntity="AccountGroupe", mappedBy="groupe", fetch="EXTRA_LAZY")
*/
private $accounts;
public function __construct()
{
$this->comptoirs = new ArrayCollection();
$this->prestataires = new ArrayCollection();
$this->adherents = new ArrayCollection();
$this->groupeprestataires = new ArrayCollection();
$this->gestionnaires = new ArrayCollection();
$this->accounts = new ArrayCollection();
}
/**
* Get siege.
*
* @return Siege
*/
public function getSiege()
{
return $this->siege;
}
/**
* Set siege.
*
* @return $this
*/
public function setSiege($siege)
{
$this->siege = $siege;
return $this;
}
public function getId()
{
return $this->id;
}
/**
* Get idmlc.
*
* @return
*/
public function getIdmlc(): ?string
{
return $this->idmlc;
}
/**
* Set idmlc.
*
* @return $this
*/
public function setIdmlc(string $idmlc): self
{
$this->idmlc = $idmlc;
return $this;
}
/**
* Set id.
*
* @param string $id [description]
*/
public function setId(string $id): self
{
$this->id = $id;
return $this;
}
/**
* @return Comptoir[]|ArrayCollection
*/
public function getComptoirs()
{
return $this->comptoirs;
}
/**
* @param Comptoir $comptoir
*
* @return $this
*/
public function addComptoir(Comptoir $comptoir): self
{
if (!$this->comptoirs->contains($comptoir)) {
$this->comptoirs[] = $comptoir;
$comptoir->setGroupe($this);
}
return $this;
}
/**
* @param Comptoir $comptoir
*
* @return $this
*/
public function removeComptoir(Comptoir $comptoir): self
{
if ($this->comptoirs->contains($comptoir)) {
$this->comptoirs->removeElement($comptoir);
$comptoir->setGroupe(null);
}
return $this;
}
/**
* @return Prestataire[]|ArrayCollection
*/
public function getPrestataires()
{
return $this->prestataires;
}
/**
* @param Prestataire $prestataire
*
* @return $this
*/
public function addPrestataire(Prestataire $prestataire): self
{
if (!$this->prestataires->contains($prestataire)) {
$this->prestataires[] = $prestataire;
}
return $this;
}
/**
* @param Prestataire $prestataire
*
* @return $this
*/
public function removePrestataire(Prestataire $prestataire): self
{
if ($this->prestataires->contains($prestataire)) {
$this->prestataires->removeElement($prestataire);
}
return $this;
}
/**
* @return Adherent[]|ArrayCollection
*/
public function getAdherents()
{
return $this->adherents;
}
/**
* @param Adherent $adherent
*
* @return $this
*/
public function addAdherent(Adherent $adherent): self
{
if (!$this->adherents->contains($adherent)) {
$this->adherents[] = $adherent;
$adherent->setGroupe($this);
}
return $this;
}
/**
* @param Adherent $adherent
*
* @return $this
*/
public function removeAdherent(Adherent $adherent): self
{
if ($this->adherents->contains($adherent)) {
$this->adherents->removeElement($adherent);
$adherent->setGroupe(null);
}
return $this;
}
/**
* @return User[]|ArrayCollection
*/
public function getGestionnaires()
{
return $this->gestionnaires;
}
/**
* @param User[]|ArrayCollection
*
* @return $this
*/
public function setGestionnaires($gestionnaires): self
{
$this->gestionnaires = $gestionnaires;
return $this;
}
/**
* @param User $gestionnaire
*
* @return $this
*/
public function addGestionnaire(User $gestionnaire): self
{
if (!$this->gestionnaires->contains($gestionnaire)) {
$this->gestionnaires[] = $gestionnaire;
}
return $this;
}
/**
* @param User $gestionnaire
*
* @return $this
*/
public function removeGestionnaire(User $gestionnaire): self
{
if ($this->gestionnaires->contains($gestionnaire)) {
$this->gestionnaires->removeElement($gestionnaire);
}
return $this;
}
/**
* @return Amap[]|ArrayCollection
*/
public function getGroupeprestataires()
{
return $this->groupeprestataires;
}
/**
* @param Amap $amap
*
* @return $this
*/
public function addGroupeprestataire(Groupeprestataire $groupeprestataire): self
{
if (!$this->groupeprestataires->contains($groupeprestataire)) {
$this->groupeprestataires[] = $groupeprestataire;
$groupeprestataire->addGroupe($this);
}
return $this;
}
/**
* @param Amap $amap
*
* @return $this
*/
public function removeGroupeprestataire(Groupeprestataire $groupeprestataires): self
{
if ($this->groupeprestataires->contains($groupeprestataire)) {
$this->groupeprestataires->removeElement($groupeprestataire);
$groupeprestataire->removeGroupe($this);
}
return $this;
}
public function getComptoirsCount()
{
return $this->getComptoirs()->count();
}
public function getPrestatairesCount()
{
return $this->getPrestataires()->count();
}
public function getAdherentsCount()
{
return $this->getAdherents()->count();
}
public function __toString(): string
{
return !empty($this->getName()) ? $this->getName() : 'Groupe';
}
}