Groupe.php 7.3 KB
Newer Older
Julien Jorry committed
1 2 3 4 5 6 7 8 9 10
<?php

namespace App\Entity;

use App\Entity\EntityTrait\EnablableEntityTrait;
use App\Entity\EntityTrait\HasCompteEntity;
use App\Entity\EntityTrait\NameSlugContentEntityTrait;
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\ORM\Mapping as ORM;
use Gedmo\Mapping\Annotation as Gedmo;
Julien Jorry committed
11
use Gedmo\Timestampable\Traits\TimestampableEntity;
Julien Jorry committed
12 13 14 15 16 17 18 19 20
use Symfony\Component\Validator\Constraints as Assert;

/**
 * @ORM\Entity
 * @ORM\Table(name="groupe")
 */
class Groupe
{
    use NameSlugContentEntityTrait,
Julien Jorry committed
21
        TimestampableEntity,
22 23
        EnablableEntityTrait,
        HasCompteEntity;
Julien Jorry committed
24 25 26 27 28 29 30 31 32 33 34 35 36

    /**
     * @var int
     *
     * @ORM\Id
     * @ORM\Column(type="integer")
     * @ORM\GeneratedValue(strategy="AUTO")
     */
    protected $id;

    /**
     * @var Siege
     *
37
     * @ORM\ManyToOne(targetEntity="Siege", inversedBy="groupes")
Julien Jorry committed
38 39 40 41 42 43
     * @ORM\JoinColumn(name="siege_id", referencedColumnName="id", nullable=false)
     */
    private $siege;

    /**
     * @var ArrayCollection|Comptoir[]
44
     * @ORM\OneToMany(targetEntity="Comptoir", mappedBy="groupe", fetch="EXTRA_LAZY")
Julien Jorry committed
45
     * @ORM\OrderBy({"name": "ASC"})
Julien Jorry committed
46 47 48
     */
    private $comptoirs;

Julien Jorry committed
49 50
    /**
     * @var ArrayCollection|Prestataire[]
51
     * @ORM\OneToMany(targetEntity="Prestataire", mappedBy="groupe", fetch="EXTRA_LAZY")
52
     * @ORM\OrderBy({"raison": "ASC"})
Julien Jorry committed
53 54 55
     */
    private $prestataires;

56 57 58 59 60 61 62
    /**
     * @var ArrayCollection|Groupeprestataire[]
     * @ORM\OneToMany(targetEntity="Groupeprestataire", mappedBy="groupe", fetch="EXTRA_LAZY")
     * @ORM\OrderBy({"name": "ASC"})
     */
    private $groupeprestataires;

63 64 65 66 67 68 69
    /**
     * @var ArrayCollection|Adherent[]
     * @ORM\OneToMany(targetEntity="Adherent", mappedBy="groupe", fetch="EXTRA_LAZY")
     * @ORM\OrderBy({"updatedAt": "ASC"})
     */
    private $adherents;

70 71
    /**
     * @var ArrayCollection|User[]
Julien Jorry committed
72
     * @ORM\ManyToMany(targetEntity="User", inversedBy="groupesgeres", fetch="EXTRA_LAZY")
73 74 75
     */
    private $gestionnaires;

Julien Jorry committed
76 77
    public function __construct()
    {
Julien Jorry committed
78 79
        $this->comptoirs = new ArrayCollection();
        $this->prestataires = new ArrayCollection();
80
        $this->adherents = new ArrayCollection();
81
        $this->groupeprestataires = new ArrayCollection();
Julien Jorry committed
82
        $this->gestionnaires = new ArrayCollection();
Julien Jorry committed
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
    }

    /**
    * Get siege
    * @return Siege
    */
    public function getSiege()
    {
        return $this->siege;
    }

    /**
    * Set siege
    * @return $this
    */
    public function setSiege($siege)
    {
        $this->siege = $siege;
        return $this;
    }

    /**
     * @return int
     */
    public function getId(): int
    {
        return $this->id;
    }

    /**
     * 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
     */
Julien Jorry committed
134
    public function addComptoir(Comptoir $comptoir): self
Julien Jorry committed
135 136 137
    {
        if (!$this->comptoirs->contains($comptoir)) {
            $this->comptoirs[] = $comptoir;
Julien Jorry committed
138
            $comptoir->setGroupe($this);
Julien Jorry committed
139 140 141 142 143 144 145 146
        }
        return $this;
    }

    /**
     * @param Comptoir $comptoir
     * @return $this
     */
Julien Jorry committed
147
    public function removeComptoir(Comptoir $comptoir): self
Julien Jorry committed
148 149 150
    {
        if ($this->comptoirs->contains($comptoir)) {
            $this->comptoirs->removeElement($comptoir);
Julien Jorry committed
151
            $comptoir->setGroupe(null);
Julien Jorry committed
152 153 154
        }
        return $this;
    }
Julien Jorry committed
155 156 157 158 159 160 161 162 163 164 165 166 167

    /**
     * @return Prestataire[]|ArrayCollection
     */
    public function getPrestataires()
    {
        return $this->prestataires;
    }

    /**
     * @param Prestataire $prestataire
     * @return $this
     */
Julien Jorry committed
168
    public function addPrestataire(Prestataire $prestataire): self
Julien Jorry committed
169 170 171 172 173 174 175 176 177 178 179
    {
        if (!$this->prestataires->contains($prestataire)) {
            $this->prestataires[] = $prestataire;
        }
        return $this;
    }

    /**
     * @param Prestataire $prestataire
     * @return $this
     */
Julien Jorry committed
180
    public function removePrestataire(Prestataire $prestataire): self
Julien Jorry committed
181 182 183
    {
        if ($this->prestataires->contains($prestataire)) {
            $this->prestataires->removeElement($prestataire);
184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199
        }
        return $this;
    }

    /**
     * @return Adherent[]|ArrayCollection
     */
    public function getAdherents()
    {
        return $this->adherents;
    }

    /**
     * @param Adherent $adherent
     * @return $this
     */
Julien Jorry committed
200
    public function addAdherent(Adherent $adherent): self
201 202 203 204 205 206 207 208 209 210 211 212
    {
        if (!$this->adherents->contains($adherent)) {
            $this->adherents[] = $adherent;
            $adherent->setGroupe($this);
        }
        return $this;
    }

    /**
     * @param Adherent $adherent
     * @return $this
     */
Julien Jorry committed
213
    public function removeAdherent(Adherent $adherent): self
214 215 216 217
    {
        if ($this->adherents->contains($adherent)) {
            $this->adherents->removeElement($adherent);
            $adherent->setGroupe(null);
Julien Jorry committed
218 219 220 221
        }
        return $this;
    }

222 223 224 225 226 227 228 229
    /**
     * @return User[]|ArrayCollection
     */
    public function getGestionnaires()
    {
        return $this->gestionnaires;
    }

Julien Jorry committed
230 231 232 233 234 235 236 237 238 239
    /**
     * @param User[]|ArrayCollection
     * @return $this
     */
    public function setGestionnaires($gestionnaires): self
    {
        $this->gestionnaires = $gestionnaires;
        return $this;
    }

240 241 242 243
    /**
     * @param User $gestionnaire
     * @return $this
     */
Julien Jorry committed
244
    public function addGestionnaire(User $gestionnaire): self
245 246 247 248 249 250 251 252 253 254 255
    {
        if (!$this->gestionnaires->contains($gestionnaire)) {
            $this->gestionnaires[] = $gestionnaire;
        }
        return $this;
    }

    /**
     * @param User $gestionnaire
     * @return $this
     */
Julien Jorry committed
256
    public function removeGestionnaire(User $gestionnaire): self
257 258 259 260 261 262 263
    {
        if ($this->gestionnaires->contains($gestionnaire)) {
            $this->gestionnaires->removeElement($gestionnaire);
        }
        return $this;
    }

264 265 266 267 268 269 270 271 272 273 274 275
    /**
     * @return Amap[]|ArrayCollection
     */
    public function getGroupeprestataires()
    {
        return $this->groupeprestataires;
    }

    /**
     * @param Amap $amap
     * @return $this
     */
Julien Jorry committed
276
    public function addGroupeprestataire(Groupeprestataire $groupeprestataire): self
277 278 279 280 281 282 283 284 285 286 287 288
    {
        if (!$this->groupeprestataires->contains($groupeprestataire)) {
            $this->groupeprestataires[] = $groupeprestataire;
            $groupeprestataire->addGroupe($this);
        }
        return $this;
    }

    /**
     * @param Amap $amap
     * @return $this
     */
Julien Jorry committed
289
    public function removeGroupeprestataire(Groupeprestataire $groupeprestataires): self
290 291 292 293 294 295 296 297
    {
        if ($this->groupeprestataires->contains($groupeprestataire)) {
            $this->groupeprestataires->removeElement($groupeprestataire);
            $groupeprestataire->removeGroupe($this);
        }
        return $this;
    }

298

Julien Jorry committed
299 300 301 302 303 304 305 306 307 308
    public function getComptoirsCount()
    {
        return $this->getComptoirs()->count();
    }

    public function getPrestatairesCount()
    {
        return $this->getPrestataires()->count();
    }

309 310 311 312 313
    public function getAdherentsCount()
    {
        return $this->getAdherents()->count();
    }

Julien Jorry committed
314 315
    public function __toString(): string
    {
316
        return !empty($this->getName())?$this->getName():'Groupe';
Julien Jorry committed
317
    }
Julien Jorry committed
318
}