src/Entity/Page.php line 18

Open in your IDE?
  1. <?php
  2. namespace App\Entity;
  3. use Doctrine\Common\Collections\ArrayCollection;
  4. use Doctrine\Common\Collections\Collection;
  5. use Doctrine\ORM\Mapping as ORM;
  6. use Symfony\Component\Validator\Constraints as Assert;
  7. use Symfony\Bridge\Doctrine\Validator\Constraints\UniqueEntity;
  8. use App\Entity\BasePost;
  9. /**
  10.  * @ORM\Entity(repositoryClass="App\Repository\PageRepository")
  11.  * @UniqueEntity("name")
  12.  */
  13. class Page
  14. {
  15.     use BasePost;
  16.     
  17.     /**
  18.      * @ORM\ManyToMany(targetEntity="App\Entity\Media", mappedBy="pages", cascade={"persist", "remove"}))
  19.      */
  20.     private $medias;
  21.     public function __construct()
  22.     {
  23.         $this->medias = new ArrayCollection();
  24.     }
  25.     
  26.     public function __toString()
  27.     {
  28.         return $this->name;    
  29.     }
  30.     /**
  31.      * @return Collection|Media[]
  32.      */
  33.     public function getMedias(): Collection
  34.     {
  35.         return $this->medias;
  36.     }
  37.     public function addMedia(Media $media): self
  38.     {
  39.         if (!$this->medias->contains($media)) {
  40.             $this->medias[] = $media;
  41.         }
  42.         return $this;
  43.     }
  44.     public function removeMedia(Media $media): self
  45.     {
  46.         if ($this->medias->contains($media)) {
  47.             $this->medias->removeElement($media);
  48.         }
  49.         return $this;
  50.     }
  51. }