src/Flexy/ShopBundle/Entity/Product/CategoryProduct.php line 23

  1. <?php
  2. namespace App\Flexy\ShopBundle\Entity\Product;
  3. use ApiPlatform\Core\Annotation\ApiResource;
  4. use App\Flexy\ShopBundle\Entity\Product\Product;
  5. use App\Flexy\ShopBundle\Repository\Product\CategoryProductRepository;
  6. use App\Flexy\ShopBundle\Service\FlexyShopStatisticProvider;
  7. use Doctrine\Common\Collections\ArrayCollection;
  8. use Doctrine\Common\Collections\Collection;
  9. use Doctrine\ORM\Mapping as ORM;
  10. use Doctrine\ORM\Mapping\Table;
  11. use Doctrine\Persistence\ManagerRegistry;
  12. use Symfony\Component\Serializer\Annotation\Groups;
  13. #[ApiResource(
  14.     normalizationContext: ['groups' => ['read','readDeep']],
  15.     denormalizationContext: ['groups' => ['write']],
  16.     
  17.     )]
  18. #[Table(name'flexy_categoryproduct')]
  19. #[ORM\Entity(repositoryClassCategoryProductRepository::class)]
  20. class CategoryProduct implements \Stringable
  21. {
  22.     #[Groups("read")]
  23.     #[ORM\Id]
  24.     #[ORM\GeneratedValue]
  25.     #[ORM\Column(type'integer')]
  26.     private $id;
  27.     #[Groups("read")]
  28.     #[ORM\Column(type'string'length255)]
  29.     private ?string $name null;
  30.     #[Groups("read")]
  31.     #[ORM\Column(type'text'nullabletrue)]
  32.     private ?string $description null;
  33.     #[Groups("read")]
  34.     #[ORM\Column(type'string'length255nullabletrue)]
  35.     private ?string $image null;
  36.     #[Groups("read")]
  37.     #[ORM\ManyToMany(targetEntityProduct::class, mappedBy'categoriesProduct'cascade: ['persist'])]
  38.     private \Doctrine\Common\Collections\Collection|array $products;
  39.     #[Groups("readDeep")]
  40.     #[ORM\ManyToOne(targetEntityCategoryProduct::class, inversedBy'subCategories')]
  41.     private ?\App\Flexy\ShopBundle\Entity\Product\CategoryProduct $parentCategory null;
  42.     #[Groups("readDeep")]
  43.     #[ORM\OneToMany(targetEntityCategoryProduct::class, mappedBy'parentCategory')]
  44.     private $subCategories;
  45.     #[ORM\ManyToMany(targetEntityAttribut::class, inversedBy'categoriesProduct')]
  46.     private \Doctrine\Common\Collections\Collection|array $attributes;
  47.     #[ORM\Column(type'float'nullabletrue)]
  48.     private ?float $commission null;
  49.     #[ORM\OneToMany(targetEntityProduct::class, mappedBy'parentCategory')]
  50.     private \Doctrine\Common\Collections\Collection|array $productsChildrens;
  51.     #[ORM\Column(type'string'length255nullabletrue)]
  52.     private ?string $forProductType null;
  53.     #[ORM\Column(type'integer'nullabletrue)]
  54.     private ?int $oldId null;
  55.    
  56.     public function __construct(
  57.         
  58.     )
  59.     {
  60.         
  61.         $this->products = new ArrayCollection();
  62.         $this->attributes = new ArrayCollection();
  63.         $this->subCategories = new ArrayCollection();
  64.         $this->productsChildrens = new ArrayCollection();
  65.         
  66.     }
  67.     public function __toString(): string
  68.     {
  69.         return (string) $this->name;
  70.     }
  71.     public function getId(): ?int
  72.     {
  73.         return $this->id;
  74.     }
  75.     public function getName(): ?string
  76.     {
  77.         return $this->name;
  78.     }
  79.     public function setName(string $name): self
  80.     {
  81.         $this->name $name;
  82.         return $this;
  83.     }
  84.     public function getDescription(): ?string
  85.     {
  86.         return $this->description;
  87.     }
  88.     public function setDescription(?string $description): self
  89.     {
  90.         $this->description $description;
  91.         return $this;
  92.     }
  93.     public function getImage(): ?string
  94.     {
  95.         return $this->image;
  96.     }
  97.     public function setImage(?string $image): self
  98.     {
  99.         $this->image $image;
  100.         return $this;
  101.     }
  102.     /**
  103.      * @return Collection|Product[]
  104.      */
  105.     public function getProducts(): Collection
  106.     {
  107.         return $this->products;
  108.     }
  109.     public function addProduct(Product $product): self
  110.     {
  111.         if (!$this->products->contains($product)) {
  112.             $this->products[] = $product;
  113.         }
  114.         return $this;
  115.     }
  116.     public function removeProduct(Product $product): self
  117.     {
  118.         $this->products->removeElement($product);
  119.         return $this;
  120.     }
  121.     public function getParentCategory(): ?self
  122.     {
  123.         return $this->parentCategory;
  124.     }
  125.     public function setParentCategory(?self $parentCategory): self
  126.     {
  127.         $this->parentCategory $parentCategory;
  128.         return $this;
  129.     }
  130.     /**
  131.      * Get the value of subCategories
  132.      */ 
  133.     public function getSubCategories()
  134.     {
  135.         return $this->subCategories;
  136.     }
  137.     /**
  138.      * Set the value of subCategories
  139.      *
  140.      * @return  self
  141.      */ 
  142.     public function setSubCategories($subCategories)
  143.     {
  144.         $this->subCategories $subCategories;
  145.         return $this;
  146.     }
  147.     /**
  148.      * @return Collection|Attribut[]
  149.      */
  150.     public function getAttributes(): Collection
  151.     {
  152.         return $this->attributes;
  153.     }
  154.     public function addAttribute(Attribut $attribute): self
  155.     {
  156.         if (!$this->attributes->contains($attribute)) {
  157.             $this->attributes[] = $attribute;
  158.         }
  159.         return $this;
  160.     }
  161.     public function removeAttribute(Attribut $attribute): self
  162.     {
  163.         $this->attributes->removeElement($attribute);
  164.         return $this;
  165.     }
  166.     public function getCommission(): ?float
  167.     {
  168.         return $this->commission;
  169.     }
  170.     public function setCommission(?float $commission): self
  171.     {
  172.         $this->commission $commission;
  173.         return $this;
  174.     }
  175.     public function addSubCategory(CategoryProduct $subCategory): self
  176.     {
  177.         if (!$this->subCategories->contains($subCategory)) {
  178.             $this->subCategories[] = $subCategory;
  179.             $subCategory->setParentCategory($this);
  180.         }
  181.         return $this;
  182.     }
  183.     public function removeSubCategory(CategoryProduct $subCategory): self
  184.     {
  185.         if ($this->subCategories->removeElement($subCategory)) {
  186.             // set the owning side to null (unless already changed)
  187.             if ($subCategory->getParentCategory() === $this) {
  188.                 $subCategory->setParentCategory(null);
  189.             }
  190.         }
  191.         return $this;
  192.     }
  193.     /**
  194.      * @return Collection<int, Product>
  195.      */
  196.     public function getProductsChildrens(): Collection
  197.     {
  198.         return $this->productsChildrens;
  199.     }
  200.     public function addProductsChildren(Product $productsChildren): self
  201.     {
  202.         if (!$this->productsChildrens->contains($productsChildren)) {
  203.             $this->productsChildrens[] = $productsChildren;
  204.             $productsChildren->setParentCategory($this);
  205.         }
  206.         return $this;
  207.     }
  208.     public function removeProductsChildren(Product $productsChildren): self
  209.     {
  210.         if ($this->productsChildrens->removeElement($productsChildren)) {
  211.             // set the owning side to null (unless already changed)
  212.             if ($productsChildren->getParentCategory() === $this) {
  213.                 $productsChildren->setParentCategory(null);
  214.             }
  215.         }
  216.         return $this;
  217.     }
  218.     public function getForProductType(): ?string
  219.     {
  220.         return $this->forProductType;
  221.     }
  222.     public function setForProductType(?string $forProductType): self
  223.     {
  224.         $this->forProductType $forProductType;
  225.         return $this;
  226.     }
  227.     public function getOldId(): ?int
  228.     {
  229.         return $this->oldId;
  230.     }
  231.     public function setOldId(?int $oldId): self
  232.     {
  233.         $this->oldId $oldId;
  234.         return $this;
  235.     }
  236. }