src/Entity/Tag.php line 12

Open in your IDE?
  1. <?php
  2. namespace App\Entity;
  3. use Doctrine\Common\Collections\ArrayCollection;
  4. use Doctrine\Common\Collections\Collection;
  5. use Doctrine\ORM\Mapping as ORM;
  6. /**
  7.  * @ORM\Entity(repositoryClass="App\Repository\TagRepository")
  8.  */
  9. class Tag
  10. {
  11.     /**
  12.      * @ORM\Id()
  13.      * @ORM\GeneratedValue()
  14.      * @ORM\Column(type="integer")
  15.      */
  16.     private $id;
  17.     /**
  18.      * @ORM\Column(type="string", length=255, unique=true)
  19.      */
  20.     private $name;
  21.     /**
  22.      * @ORM\Column(type="text")
  23.      */
  24.     private $description;
  25.     /**
  26.      * @ORM\ManyToMany(targetEntity=Category::class, inversedBy="tags")
  27.      */
  28.     private $category;
  29.     /**
  30.      * @ORM\ManyToMany(targetEntity=Post::class, mappedBy="tags")
  31.      */
  32.     private $posts;
  33.     public function __construct()
  34.     {
  35.         $this->category = new ArrayCollection();
  36.         $this->posts = new ArrayCollection();
  37.     }
  38.     public function getId(): ?int
  39.     {
  40.         return $this->id;
  41.     }
  42.     public function getName(): ?string
  43.     {
  44.         return $this->name;
  45.     }
  46.     public function setName(string $name): self
  47.     {
  48.         $this->name $name;
  49.         return $this;
  50.     }
  51.     public function getDescription(): ?string
  52.     {
  53.         return $this->description;
  54.     }
  55.     public function setDescription(string $description): self
  56.     {
  57.         $this->description $description;
  58.         return $this;
  59.     }
  60.     public function __toString()
  61.     {
  62.         return $this->getName();
  63.     }
  64.     /**
  65.      * @return Collection<int, Post>
  66.      */
  67.     public function getCategory(): Collection
  68.     {
  69.         return $this->category;
  70.     }
  71.     public function addCategory(Category $category): self
  72.     {
  73.         if (!$this->category->contains($category)) {
  74.             $this->category[] = $category;
  75.             $category->addTag($this);
  76.         }
  77.         return $this;
  78.     }
  79.     public function removeCategory(Category $category): self
  80.     {
  81.         if ($this->category->removeElement($category)) {
  82.             $category->removeTag($this);
  83.         }
  84.         return $this;
  85.     }
  86.     /**
  87.      * @return Collection<int, Post>
  88.      */
  89.     public function getPosts(): Collection
  90.     {
  91.         return $this->posts;
  92.     }
  93.     public function addPost(Post $post): self
  94.     {
  95.         if (!$this->posts->contains($post)) {
  96.             $this->posts[] = $post;
  97.             $post->addTag($this);
  98.         }
  99.         return $this;
  100.     }
  101.     public function removePost(Post $post): self
  102.     {
  103.         if ($this->posts->removeElement($post)) {
  104.             $post->removeTag($this);
  105.         }
  106.         return $this;
  107.     }
  108. }