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

namespace App\Entity;

use App\Entity\Comptoir;
use App\Entity\EntityTrait\EnablableEntityTrait;
use App\Entity\EntityTrait\HasCompteEntity;
use App\Entity\EntityTrait\NameSlugContentEntityTrait;
Julien Jorry committed
9
use App\Entity\Prestataire;
Julien Jorry committed
10 11 12 13 14
use App\Entity\Siege;
use App\Entity\User;
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\ORM\Mapping as ORM;
use Gedmo\Mapping\Annotation as Gedmo;
Julien Jorry committed
15
use Gedmo\Timestampable\Traits\TimestampableEntity;
Julien Jorry committed
16 17 18 19 20 21 22 23 24
use Symfony\Component\Validator\Constraints as Assert;

/**
 * @ORM\Entity
 * @ORM\Table(name="groupe")
 */
class Groupe
{
    use NameSlugContentEntityTrait,
Julien Jorry committed
25
        TimestampableEntity,
Julien Jorry committed
26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46
        EnablableEntityTrait;

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

    /**
     * @var Siege
     *
     * @ORM\ManyToOne(targetEntity="Siege", inversedBy="groupes")
     * @ORM\JoinColumn(name="siege_id", referencedColumnName="id", nullable=false)
     */
    private $siege;

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

Julien Jorry committed
52 53 54
    /**
     * @var ArrayCollection|Prestataire[]
     * @ORM\OneToMany(targetEntity="Prestataire", mappedBy="prestataireGroup", cascade={"persist"}, fetch="EXTRA_LAZY")
55
     * @ORM\OrderBy({"raison": "ASC"})
Julien Jorry committed
56 57 58
     */
    private $prestataires;

Julien Jorry committed
59 60
    public function __construct()
    {
Julien Jorry committed
61 62
        $this->comptoirs = new ArrayCollection();
        $this->prestataires = new ArrayCollection();
Julien Jorry committed
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
    }

    /**
    * 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
     */
    public function addComptoir(Comptoir $comptoir)
    {
        if (!$this->comptoirs->contains($comptoir)) {
            $this->comptoirs[] = $comptoir;
Julien Jorry committed
118
            $comptoir->setGroupe($this);
Julien Jorry committed
119 120 121 122 123 124 125 126 127 128 129 130
        }
        return $this;
    }

    /**
     * @param Comptoir $comptoir
     * @return $this
     */
    public function removeComptoir(Comptoir $comptoir)
    {
        if ($this->comptoirs->contains($comptoir)) {
            $this->comptoirs->removeElement($comptoir);
Julien Jorry committed
131
            $comptoir->setGroupe(null);
Julien Jorry committed
132 133 134
        }
        return $this;
    }
Julien Jorry committed
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

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

    /**
     * @param Prestataire $prestataire
     * @return $this
     */
    public function addPrestataire(Prestataire $prestataire)
    {
        if (!$this->prestataires->contains($prestataire)) {
            $this->prestataires[] = $prestataire;
            $prestataire->setPrestataireGroup($this);
        }
        return $this;
    }

    /**
     * @param Prestataire $prestataire
     * @return $this
     */
    public function removePrestataire(Prestataire $prestataire)
    {
        if ($this->prestataires->contains($prestataire)) {
            $this->prestataires->removeElement($prestataire);
            $prestataire->setPrestataireGroup(null);
        }
        return $this;
    }

    public function getComptoirsCount()
    {
        return $this->getComptoirs()->count();
    }

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

    public function __toString(): string
    {
182
        return (!empty($this->getName())?$this->getName():'Groupe');
Julien Jorry committed
183
    }
Julien Jorry committed
184
}