99 lines
2.0 KiB
PHP
99 lines
2.0 KiB
PHP
<?php
|
|
|
|
namespace App\Entity;
|
|
|
|
use App\Dto\SnipFilterRequest;
|
|
use App\Repository\TagRepository;
|
|
use Doctrine\Common\Collections\ArrayCollection;
|
|
use Doctrine\Common\Collections\Collection;
|
|
use Doctrine\ORM\Mapping as ORM;
|
|
use Symfony\Component\Validator\Constraints as Assert;
|
|
|
|
#[ORM\Entity(repositoryClass: TagRepository::class)]
|
|
#[ORM\UniqueConstraint(name: 'user_tag_unique', columns: ['name', 'user_id'])]
|
|
class Tag
|
|
{
|
|
#[ORM\Id]
|
|
#[ORM\GeneratedValue]
|
|
#[ORM\Column]
|
|
private ?int $id = null;
|
|
|
|
#[ORM\Column(length: 255)]
|
|
#[Assert\NotEqualTo(SnipFilterRequest::TAG_ALL)]
|
|
#[Assert\NotEqualTo(SnipFilterRequest::TAG_NONE)]
|
|
private ?string $name = null;
|
|
|
|
#[ORM\ManyToOne]
|
|
#[ORM\JoinColumn(nullable: false)]
|
|
private ?User $user = null;
|
|
|
|
/**
|
|
* @var Collection<int, Snip>
|
|
*/
|
|
#[ORM\ManyToMany(targetEntity: Snip::class, inversedBy: 'tags')]
|
|
private Collection $snips;
|
|
|
|
public function __construct()
|
|
{
|
|
$this->snips = new ArrayCollection();
|
|
}
|
|
|
|
public function __toString(): string
|
|
{
|
|
return $this->name ?? '';
|
|
}
|
|
|
|
public function getId(): ?int
|
|
{
|
|
return $this->id;
|
|
}
|
|
|
|
public function getName(): ?string
|
|
{
|
|
return $this->name;
|
|
}
|
|
|
|
public function setName(string $name): static
|
|
{
|
|
$this->name = $name;
|
|
|
|
return $this;
|
|
}
|
|
|
|
public function getUser(): ?User
|
|
{
|
|
return $this->user;
|
|
}
|
|
|
|
public function setUser(?User $user): static
|
|
{
|
|
$this->user = $user;
|
|
|
|
return $this;
|
|
}
|
|
|
|
/**
|
|
* @return Collection<int, Snip>
|
|
*/
|
|
public function getSnips(): Collection
|
|
{
|
|
return $this->snips;
|
|
}
|
|
|
|
public function addSnip(Snip $snip): static
|
|
{
|
|
if (!$this->snips->contains($snip)) {
|
|
$this->snips->add($snip);
|
|
}
|
|
|
|
return $this;
|
|
}
|
|
|
|
public function removeSnip(Snip $snip): static
|
|
{
|
|
$this->snips->removeElement($snip);
|
|
|
|
return $this;
|
|
}
|
|
}
|