<?phpnamespace App\Entity;use App\Repository\CategoryRepository;use Doctrine\Common\Collections\ArrayCollection;use Doctrine\Common\Collections\Collection;use Doctrine\ORM\Mapping as ORM;use Symfony\Component\String\Slugger\AsciiSlugger;/** * @ORM\Entity(repositoryClass=CategoryRepository::class) */class Category{ /** * @ORM\Id * @ORM\GeneratedValue * @ORM\Column(type="integer") */ private $id; /** * @ORM\ManyToOne(targetEntity="App\Entity\Category", inversedBy="children") * @ORM\JoinColumn(name="parent_id", referencedColumnName="id") */ private $parent; /** * @ORM\OneToMany(targetEntity="App\Entity\Category", mappedBy="parent") */ private $children; /** * @ORM\Column(type="string", length=255) */ private $title; /** * @ORM\Column(type="text", nullable=true) */ private $description; /** * @ORM\Column(type="string", length=255) * @var string */ private $slug; /** * @ORM\OneToMany(targetEntity=Article::class, mappedBy="category") */ private $articles; public function __construct() { $this->articles = new ArrayCollection(); } public function getId(): ?int { return $this->id; } public function getTitle(): ?string { return $this->title; } public function setTitle(string $title): self { $this->title = $title; return $this; } public function getDescription(): ?string { return $this->description; } public function setDescription(?string $description): self { $this->description = $description; return $this; } /** * @return Collection|Article[] */ public function getArticles(): Collection { return $this->articles; } public function addArticle(Article $article): self { if (!$this->articles->contains($article)) { $this->articles[] = $article; $article->setCategory($this); } return $this; } public function removeArticle(Article $article): self { if ($this->articles->contains($article)) { $this->articles->removeElement($article); // set the owning side to null (unless already changed) if ($article->getCategory() === $this) { $article->setCategory(null); } } return $this; } /** * * @return string */ public function getSlug(): ?string { return $this->slug; } /** * * @param string $slug * * @return self */ public function setSlug(string $slug): self { $slugger = new AsciiSlugger('fr'); $this->slug = $slugger->slug(strtolower($slug)); return $this; } public function getParent(): ?Category { return $this->parent; } public function setParent(?Category $parent): self { $this->parent = $parent; return $this; } public function getChildren(): Collection { return $this->children; } public function addChild(Category $child): self { if (!$this->children->contains($child)) { $this->children[] = $child; $child->setParent($this); } return $this; } public function removeChild(Category $child): self { if ($this->children->contains($child)) { $this->children->removeElement($child); if ($child->getParent() === $this) { $child->setParent(null); } } return $this; }}