<?php
declare(strict_types=1);
namespace Croisiland\CommonBundle\Entity\Tag;
use Crea\ToolsBundle\Entity\LifecycleUserIdentifierTrait;
use Crea\ToolsBundle\Entity\CreaIconIdentifiedInterface;
use Crea\ToolsBundle\Entity\CreaIconTrait;
use Croisiland\CommonBundle\Annotation\Tag\TagFormValidator;
use Croisiland\CommonBundle\Entity\Cruise\TagCruise;
use Croisiland\CommonBundle\Entity\Traits\ColorTrait;
use Croisiland\CommonBundle\Entity\Traits\IsActiveTrait;
use Croisiland\CommonBundle\Entity\Traits\IsVisibleTrait;
use Croisiland\CommonBundle\Entity\Traits\ListOrderTrait;
use Croisiland\CommonBundle\Repository\Tag\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\Bridge\Doctrine\Validator\Constraints\UniqueEntity;
/**
* @ORM\Entity(repositoryClass=TagRepository::class)
*
* @TagFormValidator(groups={"tag_form_validator"})
*
* @UniqueEntity(
* fields={"slug"},
* errorPath="slug",
* message="tag.slug.unique_constraint",
* ignoreNull=true
* )
*/
class Tag implements CreaIconIdentifiedInterface
{
use CreaIconTrait;
use ColorTrait;
use ListOrderTrait;
use IsActiveTrait;
use IsVisibleTrait;
use LifecycleUserIdentifierTrait;
/**
* @ORM\Id
*
* @ORM\GeneratedValue
*
* @ORM\Column(type="integer")
*/
private ?int $id = null;
/**
* @ORM\Column(type="string", length=255, nullable=true)
*/
private ?string $title = null;
/**
* @Gedmo\Slug(fields={"title"}, updatable=false)
*
* @ORM\Column(type="string", length=255, nullable=true, unique=true)
*/
private ?string $slug = null;
/**
* @ORM\Column(type="text", nullable=true)
*/
private ?string $description = null;
/**
* @var Collection<int, TagCruise>
*
* @ORM\OneToMany(targetEntity=TagCruise::class, mappedBy="tag", orphanRemoval=true)
*/
private $tagCruises;
public function __construct()
{
$this->tagCruises = new ArrayCollection();
}
public function getId(): ?int
{
return $this->id;
}
public function getTitle(): ?string
{
return $this->title;
}
public function setTitle(?string $title): self
{
$this->title = $title;
return $this;
}
public function getSlug(): ?string
{
return $this->slug;
}
public function setSlug(?string $slug): self
{
$this->slug = $slug;
return $this;
}
public function getDescription(): ?string
{
return $this->description;
}
public function setDescription(?string $description): self
{
$this->description = $description;
return $this;
}
/**
* @return Collection<int, TagCruise>
*/
public function getTagCruises(): Collection
{
return $this->tagCruises;
}
public function addTagCruise(TagCruise $tagCruise): self
{
if (!$this->tagCruises->contains($tagCruise)) {
$this->tagCruises[] = $tagCruise;
$tagCruise->setTag($this);
}
return $this;
}
public function removeTagCruise(TagCruise $tagCruise): self
{
if ($this->tagCruises->removeElement($tagCruise)) {
// set the owning side to null (unless already changed)
if ($tagCruise->getTag() === $this) {
$tagCruise->setTag(null);
}
}
return $this;
}
public function getIconLabel(): ?string
{
return $this->getTitle();
}
}