<?php
namespace App\Entity\Annotation;
use App\Entity\EntityIdTrait;
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\Common\Collections\Collection;
use Doctrine\ORM\Mapping as ORM;
use Symfony\Bridge\Doctrine\Validator\Constraints\UniqueEntity;
use Symfony\Component\Serializer\Annotation\Groups;
use Symfony\Component\Validator\Constraints as Assert;
/**
* @ORM\Entity(repositoryClass="App\Repository\Annotation\TagRepository")
* @UniqueEntity("name")
*/
class Tag
{
use EntityIdTrait;
/**
* @ORM\Column(type="string", length=255, unique=true)
* @Assert\NotBlank()
* @Groups({"annotation:read", "tag:read", "tag:write", "resource:read"})
*/
private $name;
/**
* @ORM\ManyToMany(targetEntity="App\Entity\Annotation\Annotation", mappedBy="tags")
* @Groups({"tag:read"})
*/
private $annotations;
public function __construct()
{
$this->annotations = new ArrayCollection();
}
public function getName(): ?string
{
return $this->name;
}
public function setName(string $name): void
{
$this->name = $name;
}
/**
* @return Collection|Annotation[]
*/
public function getAnnotations(): Collection
{
return $this->annotations;
}
public function addAnnotation(Annotation $annotation): void
{
if (!$this->annotations->contains($annotation)) {
$this->annotations[] = $annotation;
$annotation->addTag($this);
}
}
public function removeAnnotation(Annotation $annotation): void
{
if ($this->annotations->contains($annotation)) {
$this->annotations->removeElement($annotation);
$annotation->removeTag($this);
}
}
}