src/Entity/Annotation/Tag.php line 17

Open in your IDE?
  1. <?php
  2. namespace App\Entity\Annotation;
  3. use App\Entity\EntityIdTrait;
  4. use Doctrine\Common\Collections\ArrayCollection;
  5. use Doctrine\Common\Collections\Collection;
  6. use Doctrine\ORM\Mapping as ORM;
  7. use Symfony\Bridge\Doctrine\Validator\Constraints\UniqueEntity;
  8. use Symfony\Component\Serializer\Annotation\Groups;
  9. use Symfony\Component\Validator\Constraints as Assert;
  10. /**
  11.  * @ORM\Entity(repositoryClass="App\Repository\Annotation\TagRepository")
  12.  * @UniqueEntity("name")
  13.  */
  14. class Tag
  15. {
  16.     use EntityIdTrait;
  17.     /**
  18.      * @ORM\Column(type="string", length=255, unique=true)
  19.      * @Assert\NotBlank()
  20.      * @Groups({"annotation:read", "tag:read", "tag:write", "resource:read"})
  21.      */
  22.     private $name;
  23.     /**
  24.      * @ORM\ManyToMany(targetEntity="App\Entity\Annotation\Annotation", mappedBy="tags")
  25.      * @Groups({"tag:read"})
  26.      */
  27.     private $annotations;
  28.     public function __construct()
  29.     {
  30.         $this->annotations = new ArrayCollection();
  31.     }
  32.     public function getName(): ?string
  33.     {
  34.         return $this->name;
  35.     }
  36.     public function setName(string $name): void
  37.     {
  38.         $this->name $name;
  39.     }
  40.     /**
  41.      * @return Collection|Annotation[]
  42.      */
  43.     public function getAnnotations(): Collection
  44.     {
  45.         return $this->annotations;
  46.     }
  47.     public function addAnnotation(Annotation $annotation): void
  48.     {
  49.         if (!$this->annotations->contains($annotation)) {
  50.             $this->annotations[] = $annotation;
  51.             $annotation->addTag($this);
  52.         }
  53.     }
  54.     public function removeAnnotation(Annotation $annotation): void
  55.     {
  56.         if ($this->annotations->contains($annotation)) {
  57.             $this->annotations->removeElement($annotation);
  58.             $annotation->removeTag($this);
  59.         }
  60.     }
  61. }