<?php
namespace App\Entity;
use App\Repository\CategoryRepository;
use Behat\Transliterator\Transliterator;
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=CategoryRepository::class)
*/
class Category
{
/**
* @ORM\Id
* @ORM\GeneratedValue
* @ORM\Column(type="integer")
*/
private $id;
/**
* @ORM\Column(type="string", length=255)
* @Assert\NotBlank()
*/
private $name;
/**
* @ORM\Column(type="integer")
*/
private $position = 0;
/**
* @ORM\Column(type="string", length=255)
*/
private $uri;
/**
* @ORM\ManyToMany(targetEntity=Speaker::class, mappedBy="categories")
*/
private $speakers;
private $speakersCount = 0;
public function __construct()
{
$this->speakers = new ArrayCollection();
}
public function getId(): ?int
{
return $this->id;
}
public function getName(): ?string
{
return $this->name;
}
public function setName(string $name): self
{
$this->name = $name;
return $this;
}
public function getPosition(): ?int
{
return $this->position;
}
public function setPosition(int $position): self
{
$this->position = $position;
return $this;
}
public function getUri(): string
{
return $this->uri;
}
public function setUri(string $uri): self
{
$this->uri = $uri;
return $this;
}
/**
* @return Collection|Speaker[]
*/
public function getSpeakers(): Collection
{
return $this->speakers;
}
public function addSpeaker(Speaker $speaker): self
{
if (!$this->speakers->contains($speaker)) {
$this->speakers[] = $speaker;
$speaker->addCategory($this);
}
return $this;
}
public function removeSpeaker(Speaker $speaker): self
{
if ($this->speakers->removeElement($speaker)) {
$speaker->removeCategory($this);
}
return $this;
}
public function setSpeakersCount(int $speakersCount): self
{
$this->speakersCount = $speakersCount;
return $this;
}
public function getSpeakersCount(): int
{
return $this->speakersCount;
}
public function __toString(): string
{
return $this->getName();
}
/**
* @ORM\PrePersist
*/
public function updateUri(): void
{
$this->setUri(Transliterator::transliterate($this->getName()));
}
}