src/Entity/Category.php line 15

Open in your IDE?
  1. <?php
  2. namespace App\Entity;
  3. use App\Repository\CategoryRepository;
  4. use Behat\Transliterator\Transliterator;
  5. use Doctrine\Common\Collections\ArrayCollection;
  6. use Doctrine\Common\Collections\Collection;
  7. use Doctrine\ORM\Mapping as ORM;
  8. use Symfony\Component\Validator\Constraints as Assert;
  9. /**
  10.  * @ORM\Entity(repositoryClass=CategoryRepository::class)
  11.  */
  12. class Category
  13. {
  14.     /**
  15.      * @ORM\Id
  16.      * @ORM\GeneratedValue
  17.      * @ORM\Column(type="integer")
  18.      */
  19.     private $id;
  20.     /**
  21.      * @ORM\Column(type="string", length=255)
  22.      * @Assert\NotBlank()
  23.      */
  24.     private $name;
  25.     /**
  26.      * @ORM\Column(type="integer")
  27.      */
  28.     private $position 0;
  29.     /**
  30.      * @ORM\Column(type="string", length=255)
  31.      */
  32.     private $uri;
  33.     /**
  34.      * @ORM\ManyToMany(targetEntity=Speaker::class, mappedBy="categories")
  35.      */
  36.     private $speakers;
  37.     private $speakersCount 0;
  38.     public function __construct()
  39.     {
  40.         $this->speakers = new ArrayCollection();
  41.     }
  42.     public function getId(): ?int
  43.     {
  44.         return $this->id;
  45.     }
  46.     public function getName(): ?string
  47.     {
  48.         return $this->name;
  49.     }
  50.     public function setName(string $name): self
  51.     {
  52.         $this->name $name;
  53.         return $this;
  54.     }
  55.     public function getPosition(): ?int
  56.     {
  57.         return $this->position;
  58.     }
  59.     public function setPosition(int $position): self
  60.     {
  61.         $this->position $position;
  62.         return $this;
  63.     }
  64.     public function getUri(): string
  65.     {
  66.         return $this->uri;
  67.     }
  68.     public function setUri(string $uri): self
  69.     {
  70.         $this->uri $uri;
  71.         return $this;
  72.     }
  73.     /**
  74.      * @return Collection|Speaker[]
  75.      */
  76.     public function getSpeakers(): Collection
  77.     {
  78.         return $this->speakers;
  79.     }
  80.     public function addSpeaker(Speaker $speaker): self
  81.     {
  82.         if (!$this->speakers->contains($speaker)) {
  83.             $this->speakers[] = $speaker;
  84.             $speaker->addCategory($this);
  85.         }
  86.         return $this;
  87.     }
  88.     public function removeSpeaker(Speaker $speaker): self
  89.     {
  90.         if ($this->speakers->removeElement($speaker)) {
  91.             $speaker->removeCategory($this);
  92.         }
  93.         return $this;
  94.     }
  95.     public function setSpeakersCount(int $speakersCount): self
  96.     {
  97.         $this->speakersCount $speakersCount;
  98.         return $this;
  99.     }
  100.     public function getSpeakersCount(): int
  101.     {
  102.         return $this->speakersCount;
  103.     }
  104.     public function __toString(): string
  105.     {
  106.         return $this->getName();
  107.     }
  108.     /**
  109.      * @ORM\PrePersist
  110.      */
  111.     public function updateUri(): void
  112.     {
  113.         $this->setUri(Transliterator::transliterate($this->getName()));
  114.     }
  115. }