src/Entity/Article.php line 20

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 App\Repository\ArticleRepository;
  7. // use Symfony\Component\DependencyInjection\Loader\Configurator\Traits\ParentTrait;
  8. // use Gedmo\Mapping\Annotation as Gedmo;
  9. // use Symfony\Component\String\Slugger\AsciiSlugger;
  10. use Symfony\Bridge\Doctrine\Validator\Constraints\UniqueEntity;
  11. use App\Entity\BasePost;
  12. /**
  13.  * @ORM\Entity(repositoryClass=ArticleRepository::class)
  14.  * @UniqueEntity("name")
  15.  */
  16. class Article
  17. {
  18.     use BasePost;
  19.     /**
  20.      * @ORM\Column(type="boolean", nullable=true)
  21.      */
  22.     private $important;
  23.     /* overriden relations */
  24.     /**
  25.      * @see BasePost
  26.      * @ORM\ManyToMany(targetEntity="App\Entity\Tag", inversedBy="articles")
  27.      */
  28.     private $tags;
  29.     /* new relations */
  30.     
  31.     /**
  32.      * @ORM\ManyToOne(targetEntity="App\Entity\ArticleType", inversedBy="articles")
  33.      * @ORM\JoinColumn(nullable=false)
  34.      */
  35.     private $type;
  36.     /**
  37.      * @ORM\ManyToMany(targetEntity="App\Entity\Media", mappedBy="articles", cascade={"persist", "remove"})
  38.      */
  39.     private $medias;
  40.     
  41.     // /**
  42.     //  * @ORM\ManyToMany(targetEntity="App\Entity\Structure", mappedBy="articles")
  43.     //  * @ORM\OrderBy({"name" = "ASC"})
  44.     //  */
  45.     // private $structures;
  46.     public function __construct()
  47.     {
  48.         // BasePost::__construct();
  49.         // $this->structures = new ArrayCollection();
  50.         $this->medias = new ArrayCollection();
  51.     }
  52.     
  53.     public function __toString()
  54.     {
  55.         return $this->name;
  56.     }
  57.     public function getImportant(): ?bool
  58.     {
  59.         return $this->important;
  60.     }
  61.     public function isImportant(): ?bool
  62.     {
  63.         return $this->important == true;
  64.     }
  65.     public function setImportant(?bool $important): self
  66.     {
  67.         $this->important $important;
  68.         return $this;
  69.     }
  70.     public function getType(): ?ArticleType
  71.     {
  72.         return $this->type;
  73.     }
  74.     public function setType(?ArticleType $type): self
  75.     {
  76.         $this->type $type;
  77.         return $this;
  78.     }
  79.     
  80.     // /**
  81.     //  * @return Collection|Structure[]
  82.     //  */
  83.     // public function getStructures(): Collection
  84.     // {
  85.     //     return $this->structures;
  86.     // }
  87.     // public function addStructure(Structure $structure): self
  88.     // {
  89.     //     if (!$this->structures->contains($structure)) {
  90.     //         $this->structures[] = $structure;
  91.     //         $structure->addArticle($this);
  92.     //     }
  93.     //     return $this;
  94.     // }
  95.     // public function removeStructure(Structure $structure): self
  96.     // {
  97.     //     if ($this->structures->contains($structure)) {
  98.     //         $this->structures->removeElement($structure);
  99.     //         $structure->removeArticle($this);
  100.     //     }
  101.     //     return $this;
  102.     // }
  103.     /**
  104.      * @return Collection|Media[]
  105.      */
  106.     public function getMedias(): Collection
  107.     {
  108.         return $this->medias;
  109.     }
  110.     public function addMedia(Media $media): self
  111.     {
  112.         if (!$this->medias->contains($media)) {
  113.             $this->medias[] = $media;
  114.             $media->addArticle($this);
  115.         }
  116.         return $this;
  117.     }
  118.     public function removeMedia(Media $media): self
  119.     {
  120.         if ($this->medias->contains($media)) {
  121.             $this->medias->removeElement($media);
  122.             $media->removeArticle($this);
  123.         }
  124.         return $this;
  125.     }
  126.     // override BasePost
  127.     
  128.     // /**
  129.     //  * @return Collection|Tag[]
  130.     //  */
  131.     // public function getTags(): Collection
  132.     // {
  133.     //     return $this->tags;
  134.     // }
  135.     // public function addTag(Tag $tag): self
  136.     // {
  137.     //     if (!$this->tags->contains($tag)) {
  138.     //         $this->tags[] = $tag;
  139.     //     }
  140.     //     return $this;
  141.     // }
  142.     // public function removeTag(Tag $tag): self
  143.     // {
  144.     //     if ($this->tags->contains($tag)) {
  145.     //         $this->tags->removeElement($tag);
  146.     //     }
  147.     //     return $this;
  148.     // }
  149. }