<?php
namespace App\Entity;
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\Common\Collections\Collection;
use Doctrine\ORM\Mapping as ORM;
use Symfony\Component\Serializer\Annotation\Groups;
use Symfony\Component\Serializer\Annotation\SerializedName;
/**
* @ORM\Entity(repositoryClass="App\Repository\TagRepository")
*/
class Tag
{
/**
* @ORM\Id()
* @ORM\GeneratedValue()
* @ORM\Column(type="integer")
* @Groups("simple")
*/
private $id;
/**
* @ORM\Column(type="string", length=255)
*/
private $name;
/**
* @ORM\Column(type="string", length=255)
*/
private $color;
/**
* @ORM\ManyToOne(targetEntity="App\Entity\Tag", inversedBy="tags")
*/
private $parent;
/**
* @ORM\OneToMany(targetEntity="App\Entity\Tag", mappedBy="parent", cascade={"remove"})
*/
private $tags;
/**
* @ORM\ManyToMany(targetEntity="App\Entity\Song", mappedBy="tags")
*/
private $songs;
/**
* @ORM\OneToMany(targetEntity="App\Entity\EventTag", mappedBy="tag", orphanRemoval=false)
*/
private $eventTags;
/**
* @ORM\OneToMany(targetEntity="App\Entity\PlaylistTag", mappedBy="tag", orphanRemoval=false)
*/
private $playlistTags;
/**
* @ORM\OneToMany(targetEntity="App\Entity\PlaylistVideoTag", mappedBy="tag", orphanRemoval=false)
*/
private $playlistVideoTags;
/**
* @ORM\Column(type="boolean")
*/
private $deleted;
/**
* @ORM\Column(type="string", length=10)
*/
private $type;
/**
* @ORM\ManyToMany(targetEntity="App\Entity\Video", mappedBy="tags")
*/
private $videos;
public function __toString(): string
{
return $this->name ?? '';
}
public function __construct()
{
$this->tags = new ArrayCollection();
$this->songs = new ArrayCollection();
$this->videos = new ArrayCollection();
$this->eventTags = new ArrayCollection();
$this->playlistTags = new ArrayCollection();
$this->playlistVideoTags = new ArrayCollection();
$this->deleted = false;
$this->type = 'song';
}
public function getId(): ?int
{
return $this->id;
}
public function getName(): ?string
{
return $this->name;
}
/**
* @return string|null
* @SerializedName("name")
* @Groups("simple")
*/
public function getFullName(): ?string
{
$fullName = $this->name;
if (!empty($this->parent)){
$fullName .= sprintf(' (%s)', $this->getParent()->getName());
}
return $fullName;
}
public function setName(string $name): self
{
$this->name = $name;
return $this;
}
public function getColor(): ?string
{
return $this->color;
}
public function setColor(string $color): self
{
$this->color = $color;
return $this;
}
public function getParent(): ?self
{
return $this->parent;
}
public function setParent(?self $parent): self
{
$this->parent = $parent;
return $this;
}
/**
* @return Collection|self[]
*/
public function getTags(): Collection
{
return $this->tags->filter(function (Tag $tag){
return !$tag->getDeleted();
});
}
public function addTag(self $tag): self
{
if (!$this->tags->contains($tag)) {
$this->tags[] = $tag;
$tag->setParent($this);
}
return $this;
}
public function removeTag(self $tag): self
{
if ($this->tags->contains($tag)) {
$this->tags->removeElement($tag);
// set the owning side to null (unless already changed)
if ($tag->getParent() === $this) {
$tag->setParent(null);
}
}
return $this;
}
/**
* @return Collection|Song[]
*/
public function getSongs(): Collection
{
return $this->songs->filter(function (Song $song){
return !$song->getDeleted();
});
}
public function addSong(Song $song): self
{
if (!$this->songs->contains($song)) {
$this->songs[] = $song;
$song->addTag($this);
}
return $this;
}
public function removeSong(Song $song): self
{
if ($this->songs->contains($song)) {
$this->songs->removeElement($song);
$song->removeTag($this);
}
return $this;
}
/**
* @return Collection|EventTag[]
*/
public function getEventTags(): Collection
{
return $this->eventTags;
}
/**
* @return Collection|PlaylistTag[]
*/
public function getPlaylistTags(): Collection
{
return $this->playlistTags;
}
public function addEventTag(EventTag $eventTag): self
{
if (!$this->eventTags->contains($eventTag)) {
$this->eventTags[] = $eventTag;
$eventTag->setTag($this);
}
return $this;
}
public function removeEventTag(EventTag $eventTag): self
{
if ($this->eventTags->contains($eventTag)) {
$this->eventTags->removeElement($eventTag);
// set the owning side to null (unless already changed)
if ($eventTag->getTag() === $this) {
$eventTag->setTag(null);
}
}
return $this;
}
public function addPlaylistTag(PlaylistTag $playlistTag): self
{
if (!$this->playlistTags->contains($playlistTag)) {
$this->playlistTags[] = $playlistTag;
$playlistTag->setTag($this);
}
return $this;
}
public function removePlaylistTag(PlaylistTag $playlistTag): self
{
if ($this->playlistTags->contains($playlistTag)) {
$this->playlistTags->removeElement($playlistTag);
if ($playlistTag->getTag() === $this) {
$playlistTag->setTag(null);
}
}
return $this;
}
/**
* @return Collection|PlaylistVideoTag[]
*/
public function getPlaylistVideoTags(): Collection
{
return $this->playlistVideoTags;
}
public function addPlaylistVideoTag(PlaylistVideoTag $playlistVideoTag): self
{
if (!$this->playlistVideoTags->contains($playlistVideoTag)) {
$this->playlistVideoTags[] = $playlistVideoTag;
$playlistVideoTag->setTag($this);
}
return $this;
}
public function removePlaylistVideoTag(PlaylistVideoTag $playlistVideoTag): self
{
if ($this->playlistVideoTags->contains($playlistVideoTag)) {
$this->playlistVideoTags->removeElement($playlistVideoTag);
if ($playlistVideoTag->getTag() === $this) {
$playlistVideoTag->setTag(null);
}
}
return $this;
}
public function getDeleted(): ?bool
{
return $this->deleted;
}
public function setDeleted(bool $deleted): self
{
$this->deleted = $deleted;
return $this;
}
public function getType(): ?string
{
return $this->type;
}
public function setType(string $type): self
{
$this->type = $type;
return $this;
}
/**
* @return Collection|Video[]
*/
public function getVideos(): Collection
{
return $this->videos->filter(function (Video $video){
return !$video->getDeleted();
});
}
public function addVideo(Video $video): self
{
if (!$this->videos->contains($video)) {
$this->videos[] = $video;
$video->addTag($this);
}
return $this;
}
public function removeVideo(Video $video): self
{
if ($this->videos->contains($video)) {
$this->videos->removeElement($video);
$video->removeTag($this);
}
return $this;
}
}