src/Entity/Tag.php line 18

Open in your IDE?
  1. <?php
  2. namespace App\Entity;
  3. use App\Repository\TagRepository;
  4. use Doctrine\Common\Collections\ArrayCollection;
  5. use Doctrine\Common\Collections\Collection;
  6. use Doctrine\ORM\Mapping as ORM;
  7. use Gedmo\Mapping\Annotation as Gedmo;
  8. use Symfony\Component\Validator\Constraints as Assert;
  9. use Symfony\Bridge\Doctrine\Validator\Constraints\UniqueEntity;
  10. /**
  11.  * @ORM\Entity(repositoryClass=TagRepository::class)
  12.  * @UniqueEntity("name")
  13.  */
  14. class Tag
  15. {
  16.     /**
  17.      * @ORM\Id()
  18.      * @ORM\GeneratedValue()
  19.      * @ORM\Column(type="integer")
  20.      */
  21.     private $id;
  22.     /**
  23.      * @ORM\Column(type="string", length=255)
  24.      */
  25.     private $name;
  26.     /**
  27.      * @Gedmo\Slug(fields={"name"})
  28.      * @ORM\Column(type="string", length=255, unique=true)
  29.      */
  30.     protected $slug;
  31.             
  32.     /**
  33.      * @var \DateTime $createdAt
  34.      *
  35.      * @Gedmo\Timestampable(on="create")
  36.      * @ORM\Column(type="datetime", nullable=true)
  37.      */
  38.     private $createdAt;
  39.     /**
  40.      * @var \DateTime $updatedAt
  41.      *
  42.      * @Gedmo\Timestampable(on="update")
  43.      * @ORM\Column(type="datetime")
  44.      */
  45.     private $updatedAt;
  46.     /* relations */
  47.     
  48.     /**
  49.      * @ORM\ManyToMany(targetEntity="App\Entity\Theme", mappedBy="tags", cascade={"persist"})
  50.      * @ORM\OrderBy({"priority" = "ASC", "name" = "ASC"})
  51.      */
  52.     private $themes;
  53.     
  54.     /**
  55.      * @ORM\ManyToMany(targetEntity="App\Entity\Article", mappedBy="tags", cascade={"persist"})
  56.      * @ORM\OrderBy({"priority" = "ASC", "name" = "ASC"})
  57.      */
  58.     private $articles;
  59.     
  60.     /**
  61.      * @ORM\ManyToMany(targetEntity="App\Entity\Event", mappedBy="tags", cascade={"persist"})
  62.      * @ORM\OrderBy({"priority" = "ASC", "name" = "ASC"})
  63.      */
  64.     private $events;
  65.     
  66.     /**
  67.      * @ORM\ManyToMany(targetEntity="App\Entity\QuestionAnswer", mappedBy="tags")
  68.      * @ORM\OrderBy({"priority" = "ASC", "name" = "ASC"})
  69.      */
  70.     private $questionAnswers;
  71.     
  72.     /**
  73.      * @ORM\ManyToMany(targetEntity="App\Entity\Structure", mappedBy="tags")
  74.      * @ORM\OrderBy({"priority" = "ASC", "name" = "ASC"})
  75.      */
  76.     private $structures;
  77.     public function __construct()
  78.     {
  79.         $this->createdAt = new \DateTime('now'); // default 
  80.         $this->updatedAt = new \DateTime('now'); // default
  81.         $this->articles = new ArrayCollection();
  82.         $this->events = new ArrayCollection();
  83.         $this->structures = new ArrayCollection();
  84.         $this->questionAnswers = new ArrayCollection();
  85.         $this->themes = new ArrayCollection();
  86.     }
  87.     public function __toString()
  88.     {
  89.         return $this->name;    
  90.     }
  91.     public function getId(): ?int
  92.     {
  93.         return $this->id;
  94.     }
  95.     public function getName(): ?string
  96.     {
  97.         return $this->name;
  98.     }
  99.     public function setName(string $name): self
  100.     {
  101.         $this->name trim(strtolower($name));
  102.         return $this;
  103.     }
  104.     /**
  105.      * @return Collection|Article[]
  106.      */
  107.     public function getArticles(): Collection
  108.     {
  109.         return $this->articles;
  110.     }
  111.     public function addArticle(Article $article): self
  112.     {
  113.         if (!$this->articles->contains($article)) {
  114.             $this->articles[] = $article;
  115.         }
  116.         return $this;
  117.     }
  118.     public function removeArticle(Article $article): self
  119.     {
  120.         if ($this->articles->contains($article)) {
  121.             $this->articles->removeElement($article);
  122.         }
  123.         return $this;
  124.     }
  125.     public function getSlug(): ?string
  126.     {
  127.         return $this->slug;
  128.     }
  129.     public function setSlug(string $slug): self
  130.     {
  131.         $this->slug $slug;
  132.         return $this;
  133.     }
  134.     /**
  135.      * @return Collection|Event[]
  136.      */
  137.     public function getEvents(): Collection
  138.     {
  139.         return $this->events;
  140.     }
  141.     public function addEvent(Event $event): self
  142.     {
  143.         if (!$this->events->contains($event)) {
  144.             $this->events[] = $event;
  145.             $event->addTag($this);
  146.         }
  147.         return $this;
  148.     }
  149.     public function removeEvent(Event $event): self
  150.     {
  151.         if ($this->events->contains($event)) {
  152.             $this->events->removeElement($event);
  153.             $event->removeTag($this);
  154.         }
  155.         return $this;
  156.     }
  157.     /**
  158.      * @return Collection|Structure[]
  159.      */
  160.     public function getStructures(): Collection
  161.     {
  162.         return $this->structures;
  163.     }
  164.     public function addStructure(Structure $structure): self
  165.     {
  166.         if (!$this->structures->contains($structure)) {
  167.             $this->structures[] = $structure;
  168.             $structure->addTag($this);
  169.         }
  170.         return $this;
  171.     }
  172.     public function removeStructure(Structure $structure): self
  173.     {
  174.         if ($this->structures->contains($structure)) {
  175.             $this->structures->removeElement($structure);
  176.             $structure->removeTag($this);
  177.         }
  178.         return $this;
  179.     }
  180.     /**
  181.      * @return Collection|QuestionAnswer[]
  182.      */
  183.     public function getQuestionAnswers(): Collection
  184.     {
  185.         return $this->questionAnswers;
  186.     }
  187.     public function addQuestionAnswer(QuestionAnswer $questionAnswer): self
  188.     {
  189.         if (!$this->questionAnswers->contains($questionAnswer)) {
  190.             $this->questionAnswers[] = $questionAnswer;
  191.             $questionAnswer->addTag($this);
  192.         }
  193.         return $this;
  194.     }
  195.     public function removeQuestionAnswer(QuestionAnswer $questionAnswer): self
  196.     {
  197.         if ($this->questionAnswers->contains($questionAnswer)) {
  198.             $this->questionAnswers->removeElement($questionAnswer);
  199.             $questionAnswer->removeTag($this);
  200.         }
  201.         return $this;
  202.     }
  203.     /**
  204.      * @return Collection|Theme[]
  205.      */
  206.     public function getThemes(): Collection
  207.     {
  208.         return $this->themes;
  209.     }
  210.     public function addTheme(Theme $theme): self
  211.     {
  212.         if (!$this->themes->contains($theme)) {
  213.             $this->themes[] = $theme;
  214.             $theme->addTag($this);
  215.         }
  216.         return $this;
  217.     }
  218.     public function removeTheme(Theme $theme): self
  219.     {
  220.         if ($this->themes->contains($theme)) {
  221.             $this->themes->removeElement($theme);
  222.             $theme->removeTag($this);
  223.         }
  224.         return $this;
  225.     }
  226.     public function getCreatedAt(): ?\DateTimeInterface
  227.     {
  228.         return $this->createdAt;
  229.     }
  230.     public function setCreatedAt(?\DateTimeInterface $createdAt): self
  231.     {
  232.         $this->createdAt $createdAt;
  233.         return $this;
  234.     }
  235.     public function getUpdatedAt(): ?\DateTimeInterface
  236.     {
  237.         return $this->updatedAt;
  238.     }
  239.     public function setUpdatedAt(\DateTimeInterface $updatedAt): self
  240.     {
  241.         $this->updatedAt $updatedAt;
  242.         return $this;
  243.     }
  244.     
  245. }