src/Entity/Tag.php line 14

Open in your IDE?
  1. <?php
  2. namespace App\Entity;
  3. use Doctrine\Common\Collections\ArrayCollection;
  4. use Doctrine\Common\Collections\Collection;
  5. use Doctrine\ORM\Mapping as ORM;
  6. use Symfony\Component\Serializer\Annotation\Groups;
  7. use Symfony\Component\Serializer\Annotation\SerializedName;
  8. /**
  9. * @ORM\Entity(repositoryClass="App\Repository\TagRepository")
  10. */
  11. class Tag
  12. {
  13. /**
  14. * @ORM\Id()
  15. * @ORM\GeneratedValue()
  16. * @ORM\Column(type="integer")
  17. * @Groups("simple")
  18. */
  19. private $id;
  20. /**
  21. * @ORM\Column(type="string", length=255)
  22. */
  23. private $name;
  24. /**
  25. * @ORM\Column(type="string", length=255)
  26. */
  27. private $color;
  28. /**
  29. * @ORM\ManyToOne(targetEntity="App\Entity\Tag", inversedBy="tags")
  30. */
  31. private $parent;
  32. /**
  33. * @ORM\OneToMany(targetEntity="App\Entity\Tag", mappedBy="parent", cascade={"remove"})
  34. */
  35. private $tags;
  36. /**
  37. * @ORM\ManyToMany(targetEntity="App\Entity\Song", mappedBy="tags")
  38. */
  39. private $songs;
  40. /**
  41. * @ORM\OneToMany(targetEntity="App\Entity\EventTag", mappedBy="tag", orphanRemoval=false)
  42. */
  43. private $eventTags;
  44. /**
  45. * @ORM\OneToMany(targetEntity="App\Entity\PlaylistTag", mappedBy="tag", orphanRemoval=false)
  46. */
  47. private $playlistTags;
  48. /**
  49. * @ORM\OneToMany(targetEntity="App\Entity\PlaylistVideoTag", mappedBy="tag", orphanRemoval=false)
  50. */
  51. private $playlistVideoTags;
  52. /**
  53. * @ORM\Column(type="boolean")
  54. */
  55. private $deleted;
  56. /**
  57. * @ORM\Column(type="string", length=10)
  58. */
  59. private $type;
  60. /**
  61. * @ORM\ManyToMany(targetEntity="App\Entity\Video", mappedBy="tags")
  62. */
  63. private $videos;
  64. public function __toString(): string
  65. {
  66. return $this->name ?? '';
  67. }
  68. public function __construct()
  69. {
  70. $this->tags = new ArrayCollection();
  71. $this->songs = new ArrayCollection();
  72. $this->videos = new ArrayCollection();
  73. $this->eventTags = new ArrayCollection();
  74. $this->playlistTags = new ArrayCollection();
  75. $this->playlistVideoTags = new ArrayCollection();
  76. $this->deleted = false;
  77. $this->type = 'song';
  78. }
  79. public function getId(): ?int
  80. {
  81. return $this->id;
  82. }
  83. public function getName(): ?string
  84. {
  85. return $this->name;
  86. }
  87. /**
  88. * @return string|null
  89. * @SerializedName("name")
  90. * @Groups("simple")
  91. */
  92. public function getFullName(): ?string
  93. {
  94. $fullName = $this->name;
  95. if (!empty($this->parent)){
  96. $fullName .= sprintf(' (%s)', $this->getParent()->getName());
  97. }
  98. return $fullName;
  99. }
  100. public function setName(string $name): self
  101. {
  102. $this->name = $name;
  103. return $this;
  104. }
  105. public function getColor(): ?string
  106. {
  107. return $this->color;
  108. }
  109. public function setColor(string $color): self
  110. {
  111. $this->color = $color;
  112. return $this;
  113. }
  114. public function getParent(): ?self
  115. {
  116. return $this->parent;
  117. }
  118. public function setParent(?self $parent): self
  119. {
  120. $this->parent = $parent;
  121. return $this;
  122. }
  123. /**
  124. * @return Collection|self[]
  125. */
  126. public function getTags(): Collection
  127. {
  128. return $this->tags->filter(function (Tag $tag){
  129. return !$tag->getDeleted();
  130. });
  131. }
  132. public function addTag(self $tag): self
  133. {
  134. if (!$this->tags->contains($tag)) {
  135. $this->tags[] = $tag;
  136. $tag->setParent($this);
  137. }
  138. return $this;
  139. }
  140. public function removeTag(self $tag): self
  141. {
  142. if ($this->tags->contains($tag)) {
  143. $this->tags->removeElement($tag);
  144. // set the owning side to null (unless already changed)
  145. if ($tag->getParent() === $this) {
  146. $tag->setParent(null);
  147. }
  148. }
  149. return $this;
  150. }
  151. /**
  152. * @return Collection|Song[]
  153. */
  154. public function getSongs(): Collection
  155. {
  156. return $this->songs->filter(function (Song $song){
  157. return !$song->getDeleted();
  158. });
  159. }
  160. public function addSong(Song $song): self
  161. {
  162. if (!$this->songs->contains($song)) {
  163. $this->songs[] = $song;
  164. $song->addTag($this);
  165. }
  166. return $this;
  167. }
  168. public function removeSong(Song $song): self
  169. {
  170. if ($this->songs->contains($song)) {
  171. $this->songs->removeElement($song);
  172. $song->removeTag($this);
  173. }
  174. return $this;
  175. }
  176. /**
  177. * @return Collection|EventTag[]
  178. */
  179. public function getEventTags(): Collection
  180. {
  181. return $this->eventTags;
  182. }
  183. /**
  184. * @return Collection|PlaylistTag[]
  185. */
  186. public function getPlaylistTags(): Collection
  187. {
  188. return $this->playlistTags;
  189. }
  190. public function addEventTag(EventTag $eventTag): self
  191. {
  192. if (!$this->eventTags->contains($eventTag)) {
  193. $this->eventTags[] = $eventTag;
  194. $eventTag->setTag($this);
  195. }
  196. return $this;
  197. }
  198. public function removeEventTag(EventTag $eventTag): self
  199. {
  200. if ($this->eventTags->contains($eventTag)) {
  201. $this->eventTags->removeElement($eventTag);
  202. // set the owning side to null (unless already changed)
  203. if ($eventTag->getTag() === $this) {
  204. $eventTag->setTag(null);
  205. }
  206. }
  207. return $this;
  208. }
  209. public function addPlaylistTag(PlaylistTag $playlistTag): self
  210. {
  211. if (!$this->playlistTags->contains($playlistTag)) {
  212. $this->playlistTags[] = $playlistTag;
  213. $playlistTag->setTag($this);
  214. }
  215. return $this;
  216. }
  217. public function removePlaylistTag(PlaylistTag $playlistTag): self
  218. {
  219. if ($this->playlistTags->contains($playlistTag)) {
  220. $this->playlistTags->removeElement($playlistTag);
  221. if ($playlistTag->getTag() === $this) {
  222. $playlistTag->setTag(null);
  223. }
  224. }
  225. return $this;
  226. }
  227. /**
  228. * @return Collection|PlaylistVideoTag[]
  229. */
  230. public function getPlaylistVideoTags(): Collection
  231. {
  232. return $this->playlistVideoTags;
  233. }
  234. public function addPlaylistVideoTag(PlaylistVideoTag $playlistVideoTag): self
  235. {
  236. if (!$this->playlistVideoTags->contains($playlistVideoTag)) {
  237. $this->playlistVideoTags[] = $playlistVideoTag;
  238. $playlistVideoTag->setTag($this);
  239. }
  240. return $this;
  241. }
  242. public function removePlaylistVideoTag(PlaylistVideoTag $playlistVideoTag): self
  243. {
  244. if ($this->playlistVideoTags->contains($playlistVideoTag)) {
  245. $this->playlistVideoTags->removeElement($playlistVideoTag);
  246. if ($playlistVideoTag->getTag() === $this) {
  247. $playlistVideoTag->setTag(null);
  248. }
  249. }
  250. return $this;
  251. }
  252. public function getDeleted(): ?bool
  253. {
  254. return $this->deleted;
  255. }
  256. public function setDeleted(bool $deleted): self
  257. {
  258. $this->deleted = $deleted;
  259. return $this;
  260. }
  261. public function getType(): ?string
  262. {
  263. return $this->type;
  264. }
  265. public function setType(string $type): self
  266. {
  267. $this->type = $type;
  268. return $this;
  269. }
  270. /**
  271. * @return Collection|Video[]
  272. */
  273. public function getVideos(): Collection
  274. {
  275. return $this->videos->filter(function (Video $video){
  276. return !$video->getDeleted();
  277. });
  278. }
  279. public function addVideo(Video $video): self
  280. {
  281. if (!$this->videos->contains($video)) {
  282. $this->videos[] = $video;
  283. $video->addTag($this);
  284. }
  285. return $this;
  286. }
  287. public function removeVideo(Video $video): self
  288. {
  289. if ($this->videos->contains($video)) {
  290. $this->videos->removeElement($video);
  291. $video->removeTag($this);
  292. }
  293. return $this;
  294. }
  295. }