src/Evo/Infrastructure/MappingORM/LetterTag.php line 23

Open in your IDE?
  1. <?php
  2. declare(strict_types=1);
  3. namespace Evo\Infrastructure\MappingORM;
  4. use ApiPlatform\Core\Annotation\ApiResource;
  5. use Doctrine\Common\Collections\ArrayCollection;
  6. use Doctrine\Common\Collections\Collection;
  7. use Doctrine\ORM\Mapping as ORM;
  8. use Symfony\Component\Serializer\Annotation\Groups;
  9. /**
  10.  * @ApiResource(
  11.  *    attributes={
  12.  *         "normalization_context"={"groups"={"read_letter_tag"}},
  13.  *         "denormalization_context"={"groups"={"write_letter_tag"}}
  14.  *    },
  15.  * )
  16.  * @ORM\Entity
  17.  * @ORM\Table(name="letter_tag", uniqueConstraints={@ORM\UniqueConstraint(name="unique_tag_name", columns={"name"})})
  18.  */
  19. class LetterTag
  20. {
  21.     /**
  22.      * @ORM\Id
  23.      * @ORM\GeneratedValue
  24.      * @ORM\Column(type="integer")
  25.      * @Groups({"read_letter_tag"})
  26.      */
  27.     private ?int $id null;
  28.     /**
  29.      * @ORM\Column(type="string", length=255, unique=true)
  30.      * @Groups({"read_letter_tag", "read_letter"})
  31.      */
  32.     private string $name;
  33.     /**
  34.      * @ORM\ManyToMany(targetEntity="Letter", mappedBy="tags")
  35.      * @Groups({"read_letter_tag"})
  36.      */
  37.     private ?Collection $letters;
  38.     public function __construct()
  39.     {
  40.         $this->letters = new ArrayCollection();
  41.     }
  42.     public function getId(): ?int
  43.     {
  44.         return $this->id;
  45.     }
  46.     public function getName(): string
  47.     {
  48.         return $this->name;
  49.     }
  50.     public function setName(string $name): self
  51.     {
  52.         $this->name $name;
  53.         return $this;
  54.     }
  55.     public function getLetters(): ?Collection
  56.     {
  57.         return $this->letters;
  58.     }
  59.     public function addLetter(Letter $letter): self
  60.     {
  61.         if (!$this->letters->contains($letter)) {
  62.             $this->letters->add($letter);
  63.             $letter->addTag($this);
  64.         }
  65.         return $this;
  66.     }
  67.     public function removeLetter(Letter $letter): void
  68.     {
  69.         if ($this->letters->contains($letter)) {
  70.             $this->letters->removeElement($letter);
  71.             $letter->removeTag($this);
  72.         }
  73.     }
  74.     public function __toString()
  75.     {
  76.         return $this->name;
  77.     }
  78. }