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 $name;
  22.     /**
  23.      * @ORM\OneToMany(targetEntity=Product::class, mappedBy="category")
  24.      */
  25.     private $products;
  26.     /**
  27.      * @ORM\Column(type="string", length=255, nullable=true)
  28.      */
  29.     private $name_en;
  30.     /**
  31.      * @ORM\Column(type="string", length=255, nullable=true)
  32.      */
  33.     private $photo;
  34.     /**
  35.      * @ORM\OneToMany(targetEntity=SousCategorie::class, mappedBy="categorie")
  36.      */
  37.     private $sousCategories;
  38.     /**
  39.      * @ORM\ManyToOne(targetEntity=SupCategorie::class, inversedBy="categories")
  40.      */
  41.     private $supCategory;
  42.     public function __construct()
  43.     {
  44.         $this->products = new ArrayCollection();
  45.         $this->sousCategories = new ArrayCollection();
  46.     }
  47.     public function __toString(){
  48.         return $this->getName();
  49.     }
  50.     public function getId(): ?int
  51.     {
  52.         return $this->id;
  53.     }
  54.     public function getName(): ?string
  55.     {
  56.         return $this->name;
  57.     }
  58.     public function setName(string $name): self
  59.     {
  60.         $this->name $name;
  61.         return $this;
  62.     }
  63.     /**
  64.      * @return Collection<int, Product>
  65.      */
  66.     public function getProducts(): Collection
  67.     {
  68.         return $this->products;
  69.     }
  70.     public function addProduct(Product $product): self
  71.     {
  72.         if (!$this->products->contains($product)) {
  73.             $this->products[] = $product;
  74.             $product->setCategory($this);
  75.         }
  76.         return $this;
  77.     }
  78.     public function removeProduct(Product $product): self
  79.     {
  80.         if ($this->products->removeElement($product)) {
  81.             // set the owning side to null (unless already changed)
  82.             if ($product->getCategory() === $this) {
  83.                 $product->setCategory(null);
  84.             }
  85.         }
  86.         return $this;
  87.     }
  88.     public function getNameEn(): ?string
  89.     {
  90.         return $this->name_en;
  91.     }
  92.     public function setNameEn(?string $name_en): self
  93.     {
  94.         $this->name_en $name_en;
  95.         return $this;
  96.     }
  97.     public function getPhoto(): ?string
  98.     {
  99.         return $this->photo;
  100.     }
  101.     public function setPhoto(?string $photo): self
  102.     {
  103.         $this->photo $photo;
  104.         return $this;
  105.     }
  106.     /**
  107.      * @return Collection<int, SousCategorie>
  108.      */
  109.     public function getSousCategories(): Collection
  110.     {
  111.         return $this->sousCategories;
  112.     }
  113.     public function addSousCategory(SousCategorie $sousCategory): self
  114.     {
  115.         if (!$this->sousCategories->contains($sousCategory)) {
  116.             $this->sousCategories[] = $sousCategory;
  117.             $sousCategory->setCategorie($this);
  118.         }
  119.         return $this;
  120.     }
  121.     public function removeSousCategory(SousCategorie $sousCategory): self
  122.     {
  123.         if ($this->sousCategories->removeElement($sousCategory)) {
  124.             // set the owning side to null (unless already changed)
  125.             if ($sousCategory->getCategorie() === $this) {
  126.                 $sousCategory->setCategorie(null);
  127.             }
  128.         }
  129.         return $this;
  130.     }
  131.     public function getSupCategory(): ?SupCategorie
  132.     {
  133.         return $this->supCategory;
  134.     }
  135.     public function setSupCategory(?SupCategorie $supCategory): self
  136.     {
  137.         $this->supCategory $supCategory;
  138.         return $this;
  139.     }
  140. }