src/Entity/Diaporama.php line 219

Open in your IDE?
  1. <?php
  2. namespace App\Entity;
  3. use App\Entity\Common\AutoTimestampTrait;
  4. use Doctrine\Common\Collections\ArrayCollection;
  5. use Doctrine\Common\Collections\Collection;
  6. use Doctrine\ORM\Mapping as ORM;
  7. use Symfony\Component\Validator\Constraints as Assert;
  8. use Vich\UploaderBundle\Mapping\Annotation as Vich;
  9. /**
  10.  * @ORM\Entity(repositoryClass="App\Repository\DiaporamaRepository")
  11.  * @ORM\HasLifecycleCallbacks
  12.  * @Vich\Uploadable
  13.  */
  14. class Diaporama
  15. {
  16.     use AutoTimestampTrait;
  17.     /**
  18.      * @ORM\Id()
  19.      * @ORM\GeneratedValue()
  20.      * @ORM\Column(type="integer")
  21.      */
  22.     private $id;
  23.     /**
  24.      * @ORM\Column(type="string", length=255)
  25.      */
  26.     private $titre;
  27.     /**
  28.      * @ORM\Column(type="text", nullable=true)
  29.      */
  30.     private $texte;
  31.     /**
  32.      * @ORM\Column(type="boolean", options={"default" : false}, nullable=true)
  33.      */
  34.     private $actif;
  35.     /**
  36.      * @ORM\Column(type="integer", nullable=true)
  37.      */
  38.     private $position;
  39.     /**
  40.      * @Assert\Valid
  41.      * @ORM\OneToMany(targetEntity="App\Entity\DiaporamaPhoto", mappedBy="diaporama", orphanRemoval=true, cascade={"persist"})
  42.      * @ORM\OrderBy({"position": "ASC"})
  43.      */
  44.     private $photo;
  45.     /**
  46.      * @ORM\Column(type="boolean", nullable=true)
  47.      */
  48.     private $principal;
  49.     /**
  50.      * @ORM\ManyToMany(targetEntity=Etablissement::class, inversedBy="diaporamas")
  51.      */
  52.     private $etablissements;
  53.     /**
  54.      * @ORM\OneToMany(targetEntity=Etablissement::class, mappedBy="diapoPrincipal")
  55.      */
  56.     private $etabs;
  57.     public function __construct()
  58.     {
  59.         $this->photo = new ArrayCollection();
  60.         $this->etablissements = new ArrayCollection();
  61.         $this->etabs = new ArrayCollection();
  62.     }
  63.     public function getId(): ?int
  64.     {
  65.         return $this->id;
  66.     }
  67.     public function getTitre(): ?string
  68.     {
  69.         return $this->titre;
  70.     }
  71.     public function setTitre(string $titre): self
  72.     {
  73.         $this->titre $titre;
  74.         return $this;
  75.     }
  76.     public function getTexte(): ?string
  77.     {
  78.         return $this->texte;
  79.     }
  80.     public function setTexte(?string $texte): self
  81.     {
  82.         $this->texte $texte;
  83.         return $this;
  84.     }
  85.     public function getActif(): ?bool
  86.     {
  87.         return $this->actif;
  88.     }
  89.     public function setActif(bool $actif): self
  90.     {
  91.         $this->actif $actif;
  92.         return $this;
  93.     }
  94.     public function getPosition(): ?int
  95.     {
  96.         return $this->position;
  97.     }
  98.     public function setPosition(?int $position): self
  99.     {
  100.         $this->position $position;
  101.         return $this;
  102.     }
  103. //    public function getEtablissement(): ?Etablissement
  104. //    {
  105. //        return $this->etablissement;
  106. //    }
  107. //
  108. //    public function setEtablissement(?Etablissement $etablissement): self
  109. //    {
  110. //        $this->etablissement = $etablissement;
  111. //
  112. //        return $this;
  113. //    }
  114.     /**
  115.      * @return Collection|DiaporamaPhoto[]
  116.      */
  117.     public function getPhoto(): Collection
  118.     {
  119.         return $this->photo;
  120.     }
  121.     public function addPhoto(DiaporamaPhoto $photo): self
  122.     {
  123.         if (!$this->photo->contains($photo)) {
  124.             $this->photo[] = $photo;
  125.             $photo->setDiaporama($this);
  126.         }
  127.         return $this;
  128.     }
  129.     public function setPhoto(Collection $photo): self
  130.     {
  131.         $this->photo $photo;
  132.         return $this;
  133.     }
  134.     public function removePhoto(DiaporamaPhoto $photo): self
  135.     {
  136.         if ($this->photo->contains($photo)) {
  137.             $this->photo->removeElement($photo);
  138.             // set the owning side to null (unless already changed)
  139.             if ($photo->getDiaporama() === $this) {
  140.                 $photo->setDiaporama(null);
  141.             }
  142.         }
  143.         return $this;
  144.     }
  145.     public function getPrincipal(): ?bool
  146.     {
  147.         return $this->principal;
  148.     }
  149.     public function setPrincipal(bool $principal): self
  150.     {
  151.         $this->principal $principal;
  152.         return $this;
  153.     }
  154.     /**
  155.      * @return Collection<int, Etablissement>
  156.      */
  157.     public function getEtablissements(): Collection
  158.     {
  159.         return $this->etablissements;
  160.     }
  161.     public function addEtablissement(Etablissement $etablissement): self
  162.     {
  163.         if (!$this->etablissements->contains($etablissement)) {
  164.             $this->etablissements[] = $etablissement;
  165.         }
  166.         return $this;
  167.     }
  168.     public function removeEtablissement(Etablissement $etablissement): self
  169.     {
  170.         $this->etablissements->removeElement($etablissement);
  171.         return $this;
  172.     }
  173.     // Rétro-compaitiblité avec la nouvelle relation, cf getter commenté par Yosser
  174.     public function getEtablissement() {
  175.         return $this->etablissements[0];
  176.     }
  177.     /**
  178.      * @return Collection<int, Etablissement>
  179.      */
  180.     public function getEtabs(): Collection
  181.     {
  182.         return $this->etabs;
  183.     }
  184.     public function addEtab(Etablissement $etab): self
  185.     {
  186.         if (!$this->etabs->contains($etab)) {
  187.             $this->etabs[] = $etab;
  188.             $etab->setDiapoPrincipal($this);
  189.         }
  190.         return $this;
  191.     }
  192.     public function removeEtab(Etablissement $etab): self
  193.     {
  194.         if ($this->etabs->removeElement($etab)) {
  195.             // set the owning side to null (unless already changed)
  196.             if ($etab->getDiapoPrincipal() === $this) {
  197.                 $etab->setDiapoPrincipal(null);
  198.             }
  199.         }
  200.         return $this;
  201.     }
  202. }