<?php
declare(strict_types=1);
namespace Evo\Infrastructure\MappingORM;
use ApiPlatform\Core\Annotation\ApiResource;
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\Common\Collections\Collection;
use Doctrine\ORM\Mapping as ORM;
use Symfony\Component\Serializer\Annotation\Groups;
/**
* @ApiResource(
* attributes={
* "normalization_context"={"groups"={"read_letter_tag"}},
* "denormalization_context"={"groups"={"write_letter_tag"}}
* },
* )
* @ORM\Entity
* @ORM\Table(name="letter_tag", uniqueConstraints={@ORM\UniqueConstraint(name="unique_tag_name", columns={"name"})})
*/
class LetterTag
{
/**
* @ORM\Id
* @ORM\GeneratedValue
* @ORM\Column(type="integer")
* @Groups({"read_letter_tag"})
*/
private ?int $id = null;
/**
* @ORM\Column(type="string", length=255, unique=true)
* @Groups({"read_letter_tag", "read_letter"})
*/
private string $name;
/**
* @ORM\ManyToMany(targetEntity="Letter", mappedBy="tags")
* @Groups({"read_letter_tag"})
*/
private ?Collection $letters;
public function __construct()
{
$this->letters = new ArrayCollection();
}
public function getId(): ?int
{
return $this->id;
}
public function getName(): string
{
return $this->name;
}
public function setName(string $name): self
{
$this->name = $name;
return $this;
}
public function getLetters(): ?Collection
{
return $this->letters;
}
public function addLetter(Letter $letter): self
{
if (!$this->letters->contains($letter)) {
$this->letters->add($letter);
$letter->addTag($this);
}
return $this;
}
public function removeLetter(Letter $letter): void
{
if ($this->letters->contains($letter)) {
$this->letters->removeElement($letter);
$letter->removeTag($this);
}
}
public function __toString()
{
return $this->name;
}
}