<?php
namespace App\Entity;
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\Common\Collections\Collection;
use Doctrine\ORM\Mapping as ORM;
/**
* @ORM\Entity(repositoryClass="App\Repository\TagRepository")
*/
class Tag
{
/**
* @ORM\Id()
* @ORM\GeneratedValue()
* @ORM\Column(type="integer")
*/
private $id;
/**
* @ORM\Column(type="string", length=255, unique=true)
*/
private $name;
/**
* @ORM\Column(type="text")
*/
private $description;
/**
* @ORM\ManyToMany(targetEntity=Category::class, inversedBy="tags")
*/
private $category;
/**
* @ORM\ManyToMany(targetEntity=Post::class, mappedBy="tags")
*/
private $posts;
public function __construct()
{
$this->category = new ArrayCollection();
$this->posts = 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 getDescription(): ?string
{
return $this->description;
}
public function setDescription(string $description): self
{
$this->description = $description;
return $this;
}
public function __toString()
{
return $this->getName();
}
/**
* @return Collection<int, Post>
*/
public function getCategory(): Collection
{
return $this->category;
}
public function addCategory(Category $category): self
{
if (!$this->category->contains($category)) {
$this->category[] = $category;
$category->addTag($this);
}
return $this;
}
public function removeCategory(Category $category): self
{
if ($this->category->removeElement($category)) {
$category->removeTag($this);
}
return $this;
}
/**
* @return Collection<int, Post>
*/
public function getPosts(): Collection
{
return $this->posts;
}
public function addPost(Post $post): self
{
if (!$this->posts->contains($post)) {
$this->posts[] = $post;
$post->addTag($this);
}
return $this;
}
public function removePost(Post $post): self
{
if ($this->posts->removeElement($post)) {
$post->removeTag($this);
}
return $this;
}
}