<?php
namespace App\Entity;
use App\Repository\CategoryRepository;
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\Common\Collections\Collection;
use Doctrine\ORM\Mapping as ORM;
/**
* @ORM\Entity(repositoryClass=CategoryRepository::class)
*/
class Category
{
/**
* @ORM\Id
* @ORM\GeneratedValue
* @ORM\Column(type="integer")
*/
private $id;
/**
* @ORM\Column(type="string", length=255)
*/
private $libele;
/**
* @ORM\Column(type="string", length=255)
*/
private $slug;
/**
* @ORM\OneToMany(targetEntity=Produits::class, mappedBy="categories")
*/
private $produits;
/**
* @ORM\ManyToOne(targetEntity=Category::class, inversedBy="children")
*/
private $parent;
/**
* @ORM\OneToMany(targetEntity=Category::class, mappedBy="parent")
* @ORM\JoinColumn(name="parent_id", referencedColumnName="id")
*
*/
private $children;
public function __toString()
{
return $this->libele;
}
public function __construct()
{
$this->produits = new ArrayCollection();
}
public function getId(): ?int
{
return $this->id;
}
public function getLibele(): ?string
{
return $this->libele;
}
public function setLibele(string $libele): self
{
$this->libele = $libele;
return $this;
}
public function getSlug(): ?string
{
return $this->slug;
}
public function setSlug(string $slug): self
{
$this->slug = $slug;
return $this;
}
/**
* @return Collection<int, Produits>
*/
public function getProduits(): Collection
{
return $this->produits;
}
public function addProduit(Produits $produit): self
{
if (!$this->produits->contains($produit)) {
$this->produits[] = $produit;
$produit->setCategories($this);
}
return $this;
}
public function removeProduit(Produits $produit): self
{
if ($this->produits->removeElement($produit)) {
// set the owning side to null (unless already changed)
if ($produit->getCategories() === $this) {
$produit->setCategories(null);
}
}
return $this;
}
}