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

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