vendor/crea/media-bundle/src/Entity/MediaTag.php line 18

Open in your IDE?
  1. <?php
  2. declare(strict_types=1);
  3. namespace Crea\MediaBundle\Entity;
  4. use Crea\MediaBundle\Repository\MediaTagRepository;
  5. use Crea\ToolsBundle\Entity\LifecycleUserIdentifierTrait;
  6. use Doctrine\Common\Collections\ArrayCollection;
  7. use Doctrine\Common\Collections\Collection;
  8. use Doctrine\ORM\Mapping as ORM;
  9. /**
  10. * @ORM\Entity(repositoryClass=MediaTagRepository::class)
  11. *
  12. * @ORM\Table(name="media_tag")
  13. */
  14. class MediaTag
  15. {
  16. use LifecycleUserIdentifierTrait;
  17. /**
  18. * @ORM\Id
  19. *
  20. * @ORM\GeneratedValue
  21. *
  22. * @ORM\Column(type="integer")
  23. */
  24. private ?int $id = null;
  25. /**
  26. * @ORM\Column(type="string", length=512, nullable=true)
  27. */
  28. private ?string $projectContentFqcn = null;
  29. /**
  30. * @ORM\Column(type="integer", nullable=true)
  31. */
  32. private ?int $projectContentId = null;
  33. /**
  34. * @ORM\Column(type="string", length=512, nullable=true, unique=true)
  35. */
  36. private ?string $label = null;
  37. /**
  38. * @ORM\Column(type="string", length=64, nullable=true)
  39. */
  40. private ?string $color = MediaTagRepository::DEFAULTTAGCOLOR;
  41. /**
  42. * @var string[]|null
  43. *
  44. * @ORM\Column(type="simple_array", nullable=true)
  45. */
  46. private ?array $mergedTagLabels = null;
  47. /**
  48. * @var Collection<int, MediaFile>
  49. *
  50. * @ORM\ManyToMany(targetEntity=MediaFile::class, inversedBy="mediaTags")
  51. */
  52. private Collection $mediaFiles;
  53. public function __construct()
  54. {
  55. $this->mediaFiles = new ArrayCollection();
  56. $this->mergedTagLabels = [];
  57. }
  58. public function getId(): ?int
  59. {
  60. return $this->id;
  61. }
  62. public function setId(?int $id): self
  63. {
  64. $this->id = $id;
  65. return $this;
  66. }
  67. public function getProjectContentFqcn(): ?string
  68. {
  69. return $this->projectContentFqcn;
  70. }
  71. public function setProjectContentFqcn(?string $projectContentFqcn): self
  72. {
  73. $this->projectContentFqcn = $projectContentFqcn;
  74. return $this;
  75. }
  76. public function getProjectContentId(): ?int
  77. {
  78. return $this->projectContentId;
  79. }
  80. public function setProjectContentId(?int $projectContentId): self
  81. {
  82. $this->projectContentId = $projectContentId;
  83. return $this;
  84. }
  85. public function getLabel(): ?string
  86. {
  87. return $this->label;
  88. }
  89. public function setLabel(?string $label): self
  90. {
  91. $this->label = $label;
  92. return $this;
  93. }
  94. public function getColor(): ?string
  95. {
  96. return $this->color;
  97. }
  98. public function setColor(?string $color): self
  99. {
  100. $this->color = $color;
  101. return $this;
  102. }
  103. /**
  104. * @return string[]
  105. */
  106. public function getMergedTagLabels(): array
  107. {
  108. return $this->mergedTagLabels;
  109. }
  110. /**
  111. * @param array<string> $mergedTagLabels
  112. *
  113. * @return $this
  114. */
  115. public function setMergedTagLabels(array $mergedTagLabels): self
  116. {
  117. $this->mergedTagLabels = $mergedTagLabels;
  118. return $this;
  119. }
  120. /**
  121. * @param string $delimitedTagLabel tag label delimited to avoid miss match
  122. */
  123. public function addMergedTagLabel(string $delimitedTagLabel): self
  124. {
  125. if (!in_array($delimitedTagLabel, $this->mergedTagLabels, true)) {
  126. $this->mergedTagLabels[] = $delimitedTagLabel;
  127. }
  128. return $this;
  129. }
  130. /**
  131. * @return Collection<int,MediaFile>
  132. */
  133. public function getMediaFiles(): Collection
  134. {
  135. return $this->mediaFiles;
  136. }
  137. public function addMediaFile(MediaFile $mediaFile): self
  138. {
  139. if (!$this->mediaFiles->contains($mediaFile)) {
  140. $this->mediaFiles[] = $mediaFile;
  141. $mediaFile->addMediaTag($this);
  142. }
  143. return $this;
  144. }
  145. public function removeMediaFile(MediaFile $mediaFile): self
  146. {
  147. if ($this->mediaFiles->removeElement($mediaFile)) {
  148. $mediaFile->removeMediaTag($this);
  149. }
  150. return $this;
  151. }
  152. }