src/Entity/Categories.php line 12

  1. <?php
  2. namespace App\Entity;
  3. use App\Entity\Trait\SlugTrait;
  4. use App\Repository\CategoriesRepository;
  5. use Doctrine\Common\Collections\ArrayCollection;
  6. use Doctrine\Common\Collections\Collection;
  7. use Doctrine\ORM\Mapping as ORM;
  8. #[ORM\Entity(repositoryClass: CategoriesRepository::class)]
  9. class Categories
  10. {
  11.     use SlugTrait;
  12.     #[ORM\Id]
  13.     #[ORM\GeneratedValue]
  14.     #[ORM\Column]
  15.     private ?int $id = null;
  16.     #[ORM\Column(length: 100)]
  17.     private ?string $name = null;
  18.     #[ORM\Column()]
  19.     private ?int $categoryOrder = null;
  20.     #[ORM\ManyToOne(targetEntity: self::class, inversedBy: 'categories')]
  21.     #[ORM\JoinColumn(onDelete: 'CASCADE')]
  22.     private ?self $parent = null;
  23.     #[ORM\OneToMany(mappedBy: 'parent', targetEntity: self::class)]
  24.     private Collection $categories;
  25.     #[ORM\OneToMany(mappedBy: 'categories', targetEntity: Products::class)]
  26.     private Collection $products;
  27.     public function __construct()
  28.     {
  29.         $this->categories = new ArrayCollection();
  30.         $this->products = new ArrayCollection();
  31.     }
  32.     public function getId(): ?int
  33.     {
  34.         return $this->id;
  35.     }
  36.     public function getName(): ?string
  37.     {
  38.         return $this->name;
  39.     }
  40.     public function setName(string $name): self
  41.     {
  42.         $this->name = $name;
  43.         return $this;
  44.     }
  45.     public function getcategoryOrder(): ?int
  46.     {
  47.         return $this->categoryOrder;
  48.     }
  49.     public function setcategoryOrder(int $categoryOrder): self
  50.     {
  51.         $this->categoryOrder = $categoryOrder;
  52.         return $this;
  53.     }
  54.     public function getParent(): ?self
  55.     {
  56.         return $this->parent;
  57.     }
  58.     public function setParent(?self $parent): self
  59.     {
  60.         $this->parent = $parent;
  61.         return $this;
  62.     }
  63.     /**
  64.      * @return Collection<int, self>
  65.      */
  66.     public function getCategories(): Collection
  67.     {
  68.         return $this->categories;
  69.     }
  70.     public function addCategory(self $category): self
  71.     {
  72.         if (!$this->categories->contains($category)) {
  73.             $this->categories->add($category);
  74.             $category->setParent($this);
  75.         }
  76.         return $this;
  77.     }
  78.     public function removeCategory(self $category): self
  79.     {
  80.         if ($this->categories->removeElement($category)) {
  81.             // set the owning side to null (unless already changed)
  82.             if ($category->getParent() === $this) {
  83.                 $category->setParent(null);
  84.             }
  85.         }
  86.         return $this;
  87.     }
  88.     /**
  89.      * @return Collection<int, Products>
  90.      */
  91.     public function getProducts(): Collection
  92.     {
  93.         return $this->products;
  94.     }
  95.     public function addProduct(Products $product): self
  96.     {
  97.         if (!$this->products->contains($product)) {
  98.             $this->products->add($product);
  99.             $product->setCategories($this);
  100.         }
  101.         return $this;
  102.     }
  103.     public function removeProduct(Products $product): self
  104.     {
  105.         if ($this->products->removeElement($product)) {
  106.             // set the owning side to null (unless already changed)
  107.             if ($product->getCategories() === $this) {
  108.                 $product->setCategories(null);
  109.             }
  110.         }
  111.         return $this;
  112.     }
  113. }