<?php
namespace App\Entity;
use App\Repository\TagRepository;
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\Common\Collections\Collection;
use Doctrine\ORM\Mapping as ORM;
use Gedmo\Mapping\Annotation as Gedmo;
use Symfony\Component\Validator\Constraints as Assert;
use Symfony\Bridge\Doctrine\Validator\Constraints\UniqueEntity;
/**
* @ORM\Entity(repositoryClass=TagRepository::class)
* @UniqueEntity("name")
*/
class Tag
{
/**
* @ORM\Id()
* @ORM\GeneratedValue()
* @ORM\Column(type="integer")
*/
private $id;
/**
* @ORM\Column(type="string", length=255)
*/
private $name;
/**
* @Gedmo\Slug(fields={"name"})
* @ORM\Column(type="string", length=255, unique=true)
*/
protected $slug;
/**
* @var \DateTime $createdAt
*
* @Gedmo\Timestampable(on="create")
* @ORM\Column(type="datetime", nullable=true)
*/
private $createdAt;
/**
* @var \DateTime $updatedAt
*
* @Gedmo\Timestampable(on="update")
* @ORM\Column(type="datetime")
*/
private $updatedAt;
/* relations */
/**
* @ORM\ManyToMany(targetEntity="App\Entity\Theme", mappedBy="tags", cascade={"persist"})
* @ORM\OrderBy({"priority" = "ASC", "name" = "ASC"})
*/
private $themes;
/**
* @ORM\ManyToMany(targetEntity="App\Entity\Article", mappedBy="tags", cascade={"persist"})
* @ORM\OrderBy({"priority" = "ASC", "name" = "ASC"})
*/
private $articles;
/**
* @ORM\ManyToMany(targetEntity="App\Entity\Event", mappedBy="tags", cascade={"persist"})
* @ORM\OrderBy({"priority" = "ASC", "name" = "ASC"})
*/
private $events;
/**
* @ORM\ManyToMany(targetEntity="App\Entity\QuestionAnswer", mappedBy="tags")
* @ORM\OrderBy({"priority" = "ASC", "name" = "ASC"})
*/
private $questionAnswers;
/**
* @ORM\ManyToMany(targetEntity="App\Entity\Structure", mappedBy="tags")
* @ORM\OrderBy({"priority" = "ASC", "name" = "ASC"})
*/
private $structures;
public function __construct()
{
$this->createdAt = new \DateTime('now'); // default
$this->updatedAt = new \DateTime('now'); // default
$this->articles = new ArrayCollection();
$this->events = new ArrayCollection();
$this->structures = new ArrayCollection();
$this->questionAnswers = new ArrayCollection();
$this->themes = new ArrayCollection();
}
public function __toString()
{
return $this->name;
}
public function getId(): ?int
{
return $this->id;
}
public function getName(): ?string
{
return $this->name;
}
public function setName(string $name): self
{
$this->name = trim(strtolower($name));
return $this;
}
/**
* @return Collection|Article[]
*/
public function getArticles(): Collection
{
return $this->articles;
}
public function addArticle(Article $article): self
{
if (!$this->articles->contains($article)) {
$this->articles[] = $article;
}
return $this;
}
public function removeArticle(Article $article): self
{
if ($this->articles->contains($article)) {
$this->articles->removeElement($article);
}
return $this;
}
public function getSlug(): ?string
{
return $this->slug;
}
public function setSlug(string $slug): self
{
$this->slug = $slug;
return $this;
}
/**
* @return Collection|Event[]
*/
public function getEvents(): Collection
{
return $this->events;
}
public function addEvent(Event $event): self
{
if (!$this->events->contains($event)) {
$this->events[] = $event;
$event->addTag($this);
}
return $this;
}
public function removeEvent(Event $event): self
{
if ($this->events->contains($event)) {
$this->events->removeElement($event);
$event->removeTag($this);
}
return $this;
}
/**
* @return Collection|Structure[]
*/
public function getStructures(): Collection
{
return $this->structures;
}
public function addStructure(Structure $structure): self
{
if (!$this->structures->contains($structure)) {
$this->structures[] = $structure;
$structure->addTag($this);
}
return $this;
}
public function removeStructure(Structure $structure): self
{
if ($this->structures->contains($structure)) {
$this->structures->removeElement($structure);
$structure->removeTag($this);
}
return $this;
}
/**
* @return Collection|QuestionAnswer[]
*/
public function getQuestionAnswers(): Collection
{
return $this->questionAnswers;
}
public function addQuestionAnswer(QuestionAnswer $questionAnswer): self
{
if (!$this->questionAnswers->contains($questionAnswer)) {
$this->questionAnswers[] = $questionAnswer;
$questionAnswer->addTag($this);
}
return $this;
}
public function removeQuestionAnswer(QuestionAnswer $questionAnswer): self
{
if ($this->questionAnswers->contains($questionAnswer)) {
$this->questionAnswers->removeElement($questionAnswer);
$questionAnswer->removeTag($this);
}
return $this;
}
/**
* @return Collection|Theme[]
*/
public function getThemes(): Collection
{
return $this->themes;
}
public function addTheme(Theme $theme): self
{
if (!$this->themes->contains($theme)) {
$this->themes[] = $theme;
$theme->addTag($this);
}
return $this;
}
public function removeTheme(Theme $theme): self
{
if ($this->themes->contains($theme)) {
$this->themes->removeElement($theme);
$theme->removeTag($this);
}
return $this;
}
public function getCreatedAt(): ?\DateTimeInterface
{
return $this->createdAt;
}
public function setCreatedAt(?\DateTimeInterface $createdAt): self
{
$this->createdAt = $createdAt;
return $this;
}
public function getUpdatedAt(): ?\DateTimeInterface
{
return $this->updatedAt;
}
public function setUpdatedAt(\DateTimeInterface $updatedAt): self
{
$this->updatedAt = $updatedAt;
return $this;
}
}