Implement snip tags with very elegant tags form
This commit is contained in:
94
src/Entity/Tag.php
Normal file
94
src/Entity/Tag.php
Normal file
@ -0,0 +1,94 @@
|
||||
<?php
|
||||
|
||||
namespace App\Entity;
|
||||
|
||||
use App\Repository\TagRepository;
|
||||
use Doctrine\Common\Collections\ArrayCollection;
|
||||
use Doctrine\Common\Collections\Collection;
|
||||
use Doctrine\ORM\Mapping as ORM;
|
||||
|
||||
#[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)]
|
||||
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;
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user