src/Entity/Contenu/PageAccueil.php line 22

Open in your IDE?
  1. <?php
  2. namespace App\Entity\Contenu;
  3. use App\Application\Sonata\MediaBundle\Entity\Media;
  4. use App\Entity\Bloc\Bloc;
  5. use App\Entity\EntityBase;
  6. use App\Entity\Seo\Seo;
  7. use Doctrine\Common\Collections\Collection;
  8. use Doctrine\ORM\Mapping as ORM;
  9. use Doctrine\Common\Collections\ArrayCollection;
  10. use Symfony\Component\Validator\Constraints as Assert;
  11. use Gedmo\Mapping\Annotation as Gedmo;
  12. use Symfony\Component\Validator\Context\ExecutionContextInterface;
  13. /**
  14.  * @ORM\Table(name="page_accueil")
  15.  * @ORM\Entity(repositoryClass="App\Repository\Contenu\PageAccueilRepository")
  16.  * @ORM\HasLifecycleCallbacks()
  17.  * @Gedmo\TranslationEntity(class="App\Entity\Translation\Contenu\PageAccueilTranslation")
  18.  */
  19. class PageAccueil extends EntityBase
  20. {
  21.     const PAGE_ACCUEIL          1;
  22.     const PAGE_ACCUEIL_GUEST    2;
  23.     /**
  24.      * @ORM\Column(type="integer")
  25.      * @ORM\Id
  26.      * @ORM\GeneratedValue(strategy="AUTO")
  27.      */
  28.     private $id;
  29.     /**
  30.      * @Gedmo\Locale
  31.      * Used locale to override Translation listener`s locale
  32.      * this is not a mapped field of entity metadata, just a simple property
  33.      */
  34.     protected $locale;
  35.     /**
  36.      * @Gedmo\Translatable
  37.      * @ORM\Column(type="string")
  38.      * @Assert\NotBlank()
  39.      */
  40.     private $intitule;
  41.     /**
  42.      * @Gedmo\Translatable
  43.      * @ORM\Column(type="string")
  44.      * @Assert\NotBlank()
  45.      */
  46.     private $titre;
  47.     /**
  48.      * @Gedmo\Translatable
  49.      * @ORM\Column(type="text", nullable=true)
  50.      */
  51.     private $accroche;
  52.     /**
  53.      * @Gedmo\Translatable
  54.      * @ORM\Column(type="text", nullable=true)
  55.      */
  56.     private $texte;
  57.     /**
  58.      * @ORM\ManyToOne(targetEntity="App\Application\Sonata\MediaBundle\Entity\Media", cascade={"persist"})
  59.      * @ORM\JoinColumn(name="image_id", nullable=true, onDelete="SET NULL")
  60.      */
  61.     private $image;
  62.     /**
  63.      * @ORM\OneToMany(targetEntity="App\Entity\Contenu\LienBlocPageAccueil", mappedBy="pageAccueil", cascade={"persist", "remove"}, orphanRemoval=true)
  64.      * @ORM\OrderBy({"position" = "ASC"})
  65.      */
  66.     private $lienBlocPageAccueils;
  67.     /**
  68.      * @ORM\OneToMany(targetEntity="App\Entity\Contenu\LienDiaporamaPageAccueil", mappedBy="pageAccueil", cascade={"persist", "remove"}, orphanRemoval=true)
  69.      * @ORM\OrderBy({"position" = "ASC"})
  70.      */
  71.     private $lienDiaporamaPageAccueils;
  72.     /**
  73.      * @ORM\OneToOne(targetEntity="App\Entity\Seo\Seo", cascade={"persist", "remove"})
  74.      */
  75.     private $seo;
  76.     public function __construct()
  77.     {
  78.         $this->lienBlocPageAccueils         = new ArrayCollection();
  79.         $this->lienDiaporamaPageAccueils    = new ArrayCollection();
  80.     }
  81.     public function setTranslatableLocale($locale)
  82.     {
  83.         $this->locale $locale;
  84.     }
  85.     public function getLienDiaporamaPageAccueilVisibles(): array
  86.     {
  87.         $slides = [];
  88.         foreach ($this->lienDiaporamaPageAccueils as $lienDiaporamaPageAccueil) {
  89.             if (true === $lienDiaporamaPageAccueil->getVisible()) {
  90.                 $slides[] = $lienDiaporamaPageAccueil;
  91.             }
  92.         }
  93.         return $slides;
  94.     }
  95.     /**
  96.      * @Assert\Callback
  97.      */
  98.     public function validate(ExecutionContextInterface $context$payload)
  99.     {
  100.         if (count($this->getLienDiaporamaPageAccueilVisibles()) == 0) {
  101.             $context->buildViolation('Vous devez afficher au moins une slide dans le diaporama')
  102.                 ->addViolation();
  103.         }
  104.     }
  105.     public function __toString()
  106.     {
  107.         return $this->intitule != '' $this->intitule '';
  108.     }
  109.     public function getId(): ?int
  110.     {
  111.         return $this->id;
  112.     }
  113.     public function getIntitule(): ?string
  114.     {
  115.         return $this->intitule;
  116.     }
  117.     public function setIntitule(string $intitule): self
  118.     {
  119.         $this->intitule $intitule;
  120.         return $this;
  121.     }
  122.     public function getTitre(): ?string
  123.     {
  124.         return $this->titre;
  125.     }
  126.     public function setTitre(string $titre): self
  127.     {
  128.         $this->titre $titre;
  129.         return $this;
  130.     }
  131.     public function getAccroche(): ?string
  132.     {
  133.         return $this->accroche;
  134.     }
  135.     public function setAccroche(?string $accroche): self
  136.     {
  137.         $this->accroche $accroche;
  138.         return $this;
  139.     }
  140.     public function getTexte(): ?string
  141.     {
  142.         return $this->texte;
  143.     }
  144.     public function setTexte(?string $texte): self
  145.     {
  146.         $this->texte $texte;
  147.         return $this;
  148.     }
  149.     public function getImage(): ?Media
  150.     {
  151.         return $this->image;
  152.     }
  153.     public function setImage(?Media $image): self
  154.     {
  155.         $this->image $image;
  156.         return $this;
  157.     }
  158.     /**
  159.      * @return Collection|LienBlocPageAccueil[]
  160.      */
  161.     public function getLienBlocPageAccueils(): Collection
  162.     {
  163.         return $this->lienBlocPageAccueils;
  164.     }
  165.     public function addLienBlocPageAccueil(LienBlocPageAccueil $lienBlocPageAccueil): self
  166.     {
  167.         if (!$this->lienBlocPageAccueils->contains($lienBlocPageAccueil)) {
  168.             $this->lienBlocPageAccueils[] = $lienBlocPageAccueil;
  169.             $lienBlocPageAccueil->setPageAccueil($this);
  170.         }
  171.         return $this;
  172.     }
  173.     public function removeLienBlocPageAccueil(LienBlocPageAccueil $lienBlocPageAccueil): self
  174.     {
  175.         if ($this->lienBlocPageAccueils->contains($lienBlocPageAccueil)) {
  176.             $this->lienBlocPageAccueils->removeElement($lienBlocPageAccueil);
  177.             // set the owning side to null (unless already changed)
  178.             if ($lienBlocPageAccueil->getPageAccueil() === $this) {
  179.                 $lienBlocPageAccueil->setPageAccueil(null);
  180.             }
  181.         }
  182.         return $this;
  183.     }
  184.     /**
  185.      * @return Collection|LienDiaporamaPageAccueil[]
  186.      */
  187.     public function getLienDiaporamaPageAccueils(): Collection
  188.     {
  189.         return $this->lienDiaporamaPageAccueils;
  190.     }
  191.     public function addLienDiaporamaPageAccueil(LienDiaporamaPageAccueil $lienDiaporamaPageAccueil): self
  192.     {
  193.         if (!$this->lienDiaporamaPageAccueils->contains($lienDiaporamaPageAccueil)) {
  194.             $this->lienDiaporamaPageAccueils[] = $lienDiaporamaPageAccueil;
  195.             $lienDiaporamaPageAccueil->setPageAccueil($this);
  196.         }
  197.         return $this;
  198.     }
  199.     public function removeLienDiaporamaPageAccueil(LienDiaporamaPageAccueil $lienDiaporamaPageAccueil): self
  200.     {
  201.         if ($this->lienDiaporamaPageAccueils->contains($lienDiaporamaPageAccueil)) {
  202.             $this->lienDiaporamaPageAccueils->removeElement($lienDiaporamaPageAccueil);
  203.             // set the owning side to null (unless already changed)
  204.             if ($lienDiaporamaPageAccueil->getPageAccueil() === $this) {
  205.                 $lienDiaporamaPageAccueil->setPageAccueil(null);
  206.             }
  207.         }
  208.         return $this;
  209.     }
  210.     public function getSeo(): ?Seo
  211.     {
  212.         return $this->seo;
  213.     }
  214.     public function setSeo(?Seo $seo): self
  215.     {
  216.         $this->seo $seo;
  217.         return $this;
  218.     }
  219. }