src/Entity/Shop/Product/ProductCategory.php line 15

Open in your IDE?
  1. <?php
  2. namespace App\Entity\Shop\Product;
  3. use App\Entity\BaseEntity;
  4. use App\Entity\Shop\Shop\Shop;
  5. use App\Repository\Shop\Product\ProductCategoryRepository;
  6. use Doctrine\Common\Collections\ArrayCollection;
  7. use Doctrine\Common\Collections\Collection;
  8. use Doctrine\DBAL\Types\Types;
  9. use Doctrine\ORM\Mapping as ORM;
  10. use Symfony\Bridge\Doctrine\IdGenerator\UuidGenerator;
  11. #[ORM\Entity(repositoryClassProductCategoryRepository::class)]
  12. class ProductCategory extends BaseEntity
  13. {
  14.     #[ORM\Id]
  15.     #[ORM\Column(type'guid'uniquetrue)]
  16.     #[ORM\GeneratedValue(strategy'CUSTOM')]
  17.     #[ORM\CustomIdGenerator(class: UuidGenerator::class)]
  18.     private ?string $id;
  19.     #[ORM\Column(length255)]
  20.     private ?string $name null;
  21.     #[ORM\Column(typeTypes::TEXTnullabletrue)]
  22.     private ?string $description null;
  23.     #[ORM\Column(length255nullabletrue)]
  24.     private ?string $imageUrl null;
  25.     #[ORM\ManyToOne(inversedBy'productCategories')]
  26.     #[ORM\JoinColumn(nullablefalse)]
  27.     private ?Shop $shop null;
  28.     #[ORM\ManyToMany(targetEntityProduct::class, inversedBy'productCategories')]
  29.     private Collection $products;
  30.     #[ORM\ManyToOne(targetEntityself::class, inversedBy'productCategories')]
  31.     private ?self $parent null;
  32.     #[ORM\OneToMany(mappedBy'parent'targetEntityself::class)]
  33.     private Collection $productCategories;
  34.     public function __construct()
  35.     {
  36.         parent::__construct();
  37.         $this->products = new ArrayCollection();
  38.         $this->productCategories = new ArrayCollection();
  39.     }
  40.     public function __toString()
  41.     {
  42.         return (string) $this->getName();
  43.     }
  44.     public function getId(): ?string
  45.     {
  46.         return $this->id;
  47.     }
  48.     public function getName(): ?string
  49.     {
  50.         return $this->name;
  51.     }
  52.     public function setName(string $name): static
  53.     {
  54.         $this->name $name;
  55.         return $this;
  56.     }
  57.     public function getDescription(): ?string
  58.     {
  59.         return $this->description;
  60.     }
  61.     public function setDescription(?string $description): static
  62.     {
  63.         $this->description $description;
  64.         return $this;
  65.     }
  66.     public function getImageUrl(): ?string
  67.     {
  68.         return $this->imageUrl;
  69.     }
  70.     public function setImageUrl(?string $imageUrl): static
  71.     {
  72.         $this->imageUrl $imageUrl;
  73.         return $this;
  74.     }
  75.     public function getShop(): ?Shop
  76.     {
  77.         return $this->shop;
  78.     }
  79.     public function setShop(?Shop $shop): static
  80.     {
  81.         $this->shop $shop;
  82.         return $this;
  83.     }
  84.     public function getParent(): ?self
  85.     {
  86.         return $this->parent;
  87.     }
  88.     public function setParent(?self $parent): static
  89.     {
  90.         $this->parent $parent;
  91.         return $this;
  92.     }
  93.     /**
  94.      * @return Collection<int, self>
  95.      */
  96.     public function getProductCategories(): Collection
  97.     {
  98.         return $this->productCategories;
  99.     }
  100.     public function addProductCategory(self $productCategory): static
  101.     {
  102.         if (!$this->productCategories->contains($productCategory)) {
  103.             $this->productCategories->add($productCategory);
  104.             $productCategory->setParent($this);
  105.         }
  106.         return $this;
  107.     }
  108.     public function removeProductCategory(self $productCategory): static
  109.     {
  110.         if ($this->productCategories->removeElement($productCategory)) {
  111.             // set the owning side to null (unless already changed)
  112.             if ($productCategory->getParent() === $this) {
  113.                 $productCategory->setParent(null);
  114.             }
  115.         }
  116.         return $this;
  117.     }
  118.     /**
  119.      * @return Collection<int, Product>
  120.      */
  121.     public function getProducts(): Collection
  122.     {
  123.         return $this->products;
  124.     }
  125.     public function addProduct(Product $product): static
  126.     {
  127.         if (!$this->products->contains($product)) {
  128.             $this->products->add($product);
  129.         }
  130.         return $this;
  131.     }
  132.     public function removeProduct(Product $product): static
  133.     {
  134.         $this->products->removeElement($product);
  135.         return $this;
  136.     }
  137. }