<?php
namespace App\Entity;
use App\Entity\Traits\Sortable;
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)]
class Tag
{
use Sortable;
#[ORM\Id]
#[ORM\GeneratedValue]
#[ORM\Column(type: 'integer')]
private $id;
#[ORM\Column(type: 'string', length: 100)]
private $name;
#[ORM\ManyToOne(targetEntity: Section::class, inversedBy: 'tags')]
#[ORM\JoinColumn(nullable: false)]
private $section;
#[ORM\ManyToMany(targetEntity: Person::class, inversedBy: 'tags')]
private $persons;
public function __construct()
{
$this->persons = new ArrayCollection();
}
public function __toString(): string
{
return $this->getName();
}
public function getId(): ?int
{
return $this->id;
}
public function getName($showSection = false): ?string
{
if ($showSection && $this->getSection()) {
return sprintf('%s - %s', $this->name, $this->getSection()->getName());
}
return $this->name;
}
public function setName(string $name): self
{
$this->name = $name;
return $this;
}
public function getSection(): ?Section
{
return $this->section;
}
public function setSection(?Section $section): self
{
$this->section = $section;
return $this;
}
/**
* @return Collection<int, Person>
*/
public function getPersons(): Collection
{
return $this->persons;
}
public function addPerson(Person $person): self
{
if (!$this->persons->contains($person)) {
$this->persons[] = $person;
}
return $this;
}
public function removePerson(Person $person): self
{
$this->persons->removeElement($person);
return $this;
}
}