src/Entity/Tag.php line 12

  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 Symfony\Component\Serializer\Annotation\Groups;
  8. #[ORM\Entity(repositoryClassTagRepository::class)]
  9. class Tag
  10. {
  11.     #[Groups(['main'])]
  12.     #[ORM\Id]
  13.     #[ORM\GeneratedValue]
  14.     #[ORM\Column]
  15.     private ?int $id null;
  16.     #[Groups(['main'])]
  17.     #[ORM\Column(length255)]
  18.     private ?string $name null;
  19.     #[ORM\ManyToOne(inversedBy'tags')]
  20.     #[ORM\JoinColumn(nullablefalse)]
  21.     private ?TagCategory $category null;
  22.     #[ORM\ManyToMany(targetEntityVideo::class, mappedBy'tags')]
  23.     private Collection $videos;
  24.     public function __construct()
  25.     {
  26.         $this->videos = new ArrayCollection();
  27.     }
  28.     public function getId(): ?int
  29.     {
  30.         return $this->id;
  31.     }
  32.     public function getName(): ?string
  33.     {
  34.         return $this->name;
  35.     }
  36.     public function setName(string $name): self
  37.     {
  38.         $this->name $name;
  39.         return $this;
  40.     }
  41.     public function getCategory(): ?TagCategory
  42.     {
  43.         return $this->category;
  44.     }
  45.     public function setCategory(?TagCategory $category): self
  46.     {
  47.         $this->category $category;
  48.         return $this;
  49.     }
  50.     #[Groups(['main'])]
  51.     public function getCategoryId(): ?int
  52.     {
  53.         return $this->getCategory()->getId();
  54.     }
  55.     /**
  56.      * @return Collection<int, Video>
  57.      */
  58.     public function getVideos(): Collection
  59.     {
  60.         return $this->videos;
  61.     }
  62.     public function addVideo(Video $video): self
  63.     {
  64.         if (!$this->videos->contains($video)) {
  65.             $this->videos->add($video);
  66.             $video->addTag($this);
  67.         }
  68.         return $this;
  69.     }
  70.     public function removeVideo(Video $video): self
  71.     {
  72.         if ($this->videos->removeElement($video)) {
  73.             $video->removeTag($this);
  74.         }
  75.         return $this;
  76.     }
  77. }