src/Entity/Category.php line 13

Open in your IDE?
  1. <?php
  2. namespace App\Entity;
  3. use App\Repository\CategoryRepository;
  4. use Doctrine\Common\Collections\ArrayCollection;
  5. use Doctrine\Common\Collections\Collection;
  6. use Doctrine\ORM\Mapping as ORM;
  7. /**
  8.  * @ORM\Entity(repositoryClass=CategoryRepository::class)
  9.  */
  10. class Category
  11. {
  12.     /**
  13.      * @ORM\Id
  14.      * @ORM\GeneratedValue
  15.      * @ORM\Column(type="integer")
  16.      */
  17.     private $id;
  18.     /**
  19.      * @ORM\Column(type="string", length=255)
  20.      */
  21.     private $libele;
  22.     /**
  23.      * @ORM\Column(type="string", length=255)
  24.      */
  25.     private $slug;
  26.     /**
  27.      * @ORM\OneToMany(targetEntity=Produits::class, mappedBy="categories")
  28.      */
  29.     private $produits;
  30.     /**
  31.      * @ORM\ManyToOne(targetEntity=Category::class, inversedBy="children")
  32.      */
  33.     private $parent;
  34.     /**
  35.      * @ORM\OneToMany(targetEntity=Category::class, mappedBy="parent")
  36.      * @ORM\JoinColumn(name="parent_id", referencedColumnName="id")
  37.      *
  38.      */
  39.     private $children;
  40.     public function __toString()
  41.     {
  42.         return $this->libele;
  43.     }
  44.     public function __construct()
  45.     {
  46.         $this->produits = new ArrayCollection();
  47.     }
  48.     public function getId(): ?int
  49.     {
  50.         return $this->id;
  51.     }
  52.     public function getLibele(): ?string
  53.     {
  54.         return $this->libele;
  55.     }
  56.     public function setLibele(string $libele): self
  57.     {
  58.         $this->libele $libele;
  59.         return $this;
  60.     }
  61.     public function getSlug(): ?string
  62.     {
  63.         return $this->slug;
  64.     }
  65.     public function setSlug(string $slug): self
  66.     {
  67.         $this->slug $slug;
  68.         return $this;
  69.     }
  70.     /**
  71.      * @return Collection<int, Produits>
  72.      */
  73.     public function getProduits(): Collection
  74.     {
  75.         return $this->produits;
  76.     }
  77.     public function addProduit(Produits $produit): self
  78.     {
  79.         if (!$this->produits->contains($produit)) {
  80.             $this->produits[] = $produit;
  81.             $produit->setCategories($this);
  82.         }
  83.         return $this;
  84.     }
  85.     public function removeProduit(Produits $produit): self
  86.     {
  87.         if ($this->produits->removeElement($produit)) {
  88.             // set the owning side to null (unless already changed)
  89.             if ($produit->getCategories() === $this) {
  90.                 $produit->setCategories(null);
  91.             }
  92.         }
  93.         return $this;
  94.     }
  95. }