vendor/croisiland/common-bundle/src/Entity/Tag/Tag.php line 35

Open in your IDE?
  1. <?php
  2. declare(strict_types=1);
  3. namespace Croisiland\CommonBundle\Entity\Tag;
  4. use Crea\ToolsBundle\Entity\LifecycleUserIdentifierTrait;
  5. use Crea\ToolsBundle\Entity\CreaIconIdentifiedInterface;
  6. use Crea\ToolsBundle\Entity\CreaIconTrait;
  7. use Croisiland\CommonBundle\Annotation\Tag\TagFormValidator;
  8. use Croisiland\CommonBundle\Entity\Cruise\TagCruise;
  9. use Croisiland\CommonBundle\Entity\Traits\ColorTrait;
  10. use Croisiland\CommonBundle\Entity\Traits\IsActiveTrait;
  11. use Croisiland\CommonBundle\Entity\Traits\IsVisibleTrait;
  12. use Croisiland\CommonBundle\Entity\Traits\ListOrderTrait;
  13. use Croisiland\CommonBundle\Repository\Tag\TagRepository;
  14. use Doctrine\Common\Collections\ArrayCollection;
  15. use Doctrine\Common\Collections\Collection;
  16. use Doctrine\ORM\Mapping as ORM;
  17. use Gedmo\Mapping\Annotation as Gedmo;
  18. use Symfony\Bridge\Doctrine\Validator\Constraints\UniqueEntity;
  19. /**
  20. * @ORM\Entity(repositoryClass=TagRepository::class)
  21. *
  22. * @TagFormValidator(groups={"tag_form_validator"})
  23. *
  24. * @UniqueEntity(
  25. * fields={"slug"},
  26. * errorPath="slug",
  27. * message="tag.slug.unique_constraint",
  28. * ignoreNull=true
  29. * )
  30. */
  31. class Tag implements CreaIconIdentifiedInterface
  32. {
  33. use CreaIconTrait;
  34. use ColorTrait;
  35. use ListOrderTrait;
  36. use IsActiveTrait;
  37. use IsVisibleTrait;
  38. use LifecycleUserIdentifierTrait;
  39. /**
  40. * @ORM\Id
  41. *
  42. * @ORM\GeneratedValue
  43. *
  44. * @ORM\Column(type="integer")
  45. */
  46. private ?int $id = null;
  47. /**
  48. * @ORM\Column(type="string", length=255, nullable=true)
  49. */
  50. private ?string $title = null;
  51. /**
  52. * @Gedmo\Slug(fields={"title"}, updatable=false)
  53. *
  54. * @ORM\Column(type="string", length=255, nullable=true, unique=true)
  55. */
  56. private ?string $slug = null;
  57. /**
  58. * @ORM\Column(type="text", nullable=true)
  59. */
  60. private ?string $description = null;
  61. /**
  62. * @var Collection<int, TagCruise>
  63. *
  64. * @ORM\OneToMany(targetEntity=TagCruise::class, mappedBy="tag", orphanRemoval=true)
  65. */
  66. private $tagCruises;
  67. public function __construct()
  68. {
  69. $this->tagCruises = new ArrayCollection();
  70. }
  71. public function getId(): ?int
  72. {
  73. return $this->id;
  74. }
  75. public function getTitle(): ?string
  76. {
  77. return $this->title;
  78. }
  79. public function setTitle(?string $title): self
  80. {
  81. $this->title = $title;
  82. return $this;
  83. }
  84. public function getSlug(): ?string
  85. {
  86. return $this->slug;
  87. }
  88. public function setSlug(?string $slug): self
  89. {
  90. $this->slug = $slug;
  91. return $this;
  92. }
  93. public function getDescription(): ?string
  94. {
  95. return $this->description;
  96. }
  97. public function setDescription(?string $description): self
  98. {
  99. $this->description = $description;
  100. return $this;
  101. }
  102. /**
  103. * @return Collection<int, TagCruise>
  104. */
  105. public function getTagCruises(): Collection
  106. {
  107. return $this->tagCruises;
  108. }
  109. public function addTagCruise(TagCruise $tagCruise): self
  110. {
  111. if (!$this->tagCruises->contains($tagCruise)) {
  112. $this->tagCruises[] = $tagCruise;
  113. $tagCruise->setTag($this);
  114. }
  115. return $this;
  116. }
  117. public function removeTagCruise(TagCruise $tagCruise): self
  118. {
  119. if ($this->tagCruises->removeElement($tagCruise)) {
  120. // set the owning side to null (unless already changed)
  121. if ($tagCruise->getTag() === $this) {
  122. $tagCruise->setTag(null);
  123. }
  124. }
  125. return $this;
  126. }
  127. public function getIconLabel(): ?string
  128. {
  129. return $this->getTitle();
  130. }
  131. }