src/Entity/Tag.php line 12

Open in your IDE?
  1. <?php
  2. namespace App\Entity;
  3. use App\Entity\Traits\Sortable;
  4. use App\Repository\TagRepository;
  5. use Doctrine\Common\Collections\ArrayCollection;
  6. use Doctrine\Common\Collections\Collection;
  7. use Doctrine\ORM\Mapping as ORM;
  8. #[ORM\Entity(repositoryClassTagRepository::class)]
  9. class Tag
  10. {
  11.     use Sortable;
  12.     #[ORM\Id]
  13.     #[ORM\GeneratedValue]
  14.     #[ORM\Column(type'integer')]
  15.     private $id;
  16.     #[ORM\Column(type'string'length100)]
  17.     private $name;
  18.     #[ORM\ManyToOne(targetEntitySection::class, inversedBy'tags')]
  19.     #[ORM\JoinColumn(nullablefalse)]
  20.     private $section;
  21.     #[ORM\ManyToMany(targetEntityPerson::class, inversedBy'tags')]
  22.     private $persons;
  23.     public function __construct()
  24.     {
  25.         $this->persons = new ArrayCollection();
  26.     }
  27.     public function __toString(): string
  28.     {
  29.         return $this->getName();
  30.     }
  31.     public function getId(): ?int
  32.     {
  33.         return $this->id;
  34.     }
  35.     public function getName($showSection false): ?string
  36.     {
  37.         if ($showSection && $this->getSection()) {
  38.             return sprintf('%s - %s'$this->name$this->getSection()->getName());
  39.         }
  40.         return $this->name;
  41.     }
  42.     public function setName(string $name): self
  43.     {
  44.         $this->name $name;
  45.         return $this;
  46.     }
  47.     public function getSection(): ?Section
  48.     {
  49.         return $this->section;
  50.     }
  51.     public function setSection(?Section $section): self
  52.     {
  53.         $this->section $section;
  54.         return $this;
  55.     }
  56.     /**
  57.      * @return Collection<int, Person>
  58.      */
  59.     public function getPersons(): Collection
  60.     {
  61.         return $this->persons;
  62.     }
  63.     public function addPerson(Person $person): self
  64.     {
  65.         if (!$this->persons->contains($person)) {
  66.             $this->persons[] = $person;
  67.         }
  68.         return $this;
  69.     }
  70.     public function removePerson(Person $person): self
  71.     {
  72.         $this->persons->removeElement($person);
  73.         return $this;
  74.     }
  75. }