src/Entity/Category.php line 44

Open in your IDE?
  1. <?php
  2. namespace App\Entity;
  3. use ApiPlatform\Metadata\ApiResource;
  4. use App\Repository\CategoryRepository;
  5. use Doctrine\Common\Collections\ArrayCollection;
  6. use Doctrine\Common\Collections\Collection;
  7. use Doctrine\DBAL\Types\Types;
  8. use Doctrine\ORM\Mapping as ORM;
  9. use ApiPlatform\Metadata\ApiFilter;
  10. use ApiPlatform\Doctrine\Orm\Filter\SearchFilter;
  11. use Symfony\Component\Serializer\Annotation\Groups;
  12. use ApiPlatform\Core\Annotation\ApiProperty;
  13. use Symfony\Component\Serializer\Annotation\MaxDepth;
  14. use ApiPlatform\Serializer\Filter\GroupFilter;
  15. #[ORM\Entity(repositoryClassCategoryRepository::class)]
  16. #[ApiResource(
  17.     normalizationContext: ['groups' => ['cat:read']],
  18.     denormalizationContext: ['groups' => ['cat:write']],
  19.     order: ['sort' => 'ASC''name' => 'ASC'],
  20.     paginationPartialtrue
  21. )]
  22. #[ApiFilter(SearchFilter::class, properties: [
  23.     'name' => 'ipartial'
  24.     'parent' => 'exact'
  25.     'main' => 'exact'
  26.     'type' => 'exact'
  27.     'slug' => 'exact'
  28.     'products.show' => 'exact',
  29.     'products.id' => 'exact',
  30.     'attributes.id' => 'exact',
  31.     'news.id' => 'exact',
  32.     'pages.id' => 'exact'
  33.     'siteProducts.id' => 'exact'
  34. ])]
  35. #[ApiFilter(GroupFilter::class, arguments: ['parameterName' => 'g''overrideDefaultGroups' => true])]
  36. class Category
  37.     #[ORM\Id]
  38.     #[ORM\GeneratedValue]
  39.     #[ORM\Column]
  40.     #[Groups(['cat:read''cat:write''prod:medium',  'attributes:read''attributes_items:read''coupon:read''read''write''news:read''news:write''site_product:read''product:read'])]
  41.     private ?int $id null;
  42.     #[Groups(['cat:read'])]
  43.     #[ORM\Column(typeTypes::DATETIME_MUTABLEnullabletrue)]
  44.     private ?\DateTimeInterface $date_entered null;
  45.     #[Groups(['cat:read'])]
  46.     #[ORM\Column(typeTypes::DATETIME_MUTABLEnullabletrue)]
  47.     private ?\DateTimeInterface $date_modified null;
  48.     #[ORM\Column(nullabletrue)]
  49.     private ?int $created_by null;
  50.     #[ORM\Column(nullabletrue)]
  51.     private ?int $modified_user_id null;
  52.     #[Groups(['cat:read''cat:write''prod:medium''attributes:read''attributes_items:read''coupon:read''read''write',  'news:read''news:write''site_product:read''product:read'])]
  53.     #[ORM\Column(length255)]
  54.     private ?string $name null;
  55.     #[Groups(['cat:parent''cat:write'])]
  56.     #[ORM\ManyToOne(targetEntityself::class, inversedBy'categories'cascade:['persist'])]
  57.     private ?self $parent null;
  58.     #[Groups(['cat:categories''cat:write'])]
  59.     #[ORM\OneToMany(mappedBy'parent'targetEntityself::class, cascade:['persist''remove'])]
  60.     #[MaxDepth(1)]
  61.     #[ApiProperty(writabletrue)]
  62.     private Collection $categories;
  63.     #[Groups(['cat:read''cat:write''attributes:read''read''write''news:read''news:write''site_product:read'])]
  64.     #[ORM\Column(length100nullabletrue)]
  65.     private ?string $slug null;
  66.     #[Groups(['cat:read''cat:write''read''write''news:read''news:write''site_product:read'])]
  67.     #[ORM\Column(length100nullabletrue)]
  68.     private ?string $status null;
  69.     #[Groups(['cat:read''cat:write''read''write','news:read''news:write''site_product:read'])]
  70.     #[ORM\Column(typeTypes::TEXTnullabletrue)]
  71.     private ?string $description null;
  72.     #[Groups(['cat:read''cat:write''read''write''news:read''news:write''site_product:read'])]
  73.     #[ORM\Column(nullabletrue)]
  74.     private ?bool $main null;
  75.     #[Groups(['cat:read''cat:write''read''write''news:read''news:write''site_product:read'])]
  76.     #[ORM\Column(length20nullabletrue)]
  77.     private ?string $type null;
  78.     #[ApiProperty(writabletrue)]
  79.     #[Groups(['cat:products''cat:write'])]
  80.     #[ORM\ManyToMany(targetEntityProducts::class, mappedBy'category'cascade:['persist'])]
  81.     #[MaxDepth(1)]
  82.     private Collection $products;
  83.     #[Groups(['cat:attributes''cat:write'])]
  84.     #[ORM\ManyToMany(targetEntityAttributes::class, mappedBy'category'cascade:['persist'])]
  85.     private Collection $attributes;
  86.     #[ORM\ManyToMany(targetEntityAttributeItems::class, mappedBy'categories'cascade:['persist'])]
  87.     private Collection $attributeItems;
  88.     #[ORM\ManyToMany(targetEntityCoupons::class, mappedBy'category'cascade:['persist'])]
  89.     private Collection $coupons;
  90.     #[Groups(['cat:pages''cat:write'])]
  91.     #[ORM\ManyToMany(targetEntityPages::class, mappedBy'categories',  cascade:['persist'])]
  92.     private Collection $pages;
  93.     #[Groups(['cat:news''cat:write'])]
  94.     #[ORM\ManyToMany(targetEntityNews::class, inversedBy'categories',  cascade:['persist'])]
  95.     private Collection $news;
  96.     #[Groups(['cat:siteProducts''cat:write'])]
  97.     #[ORM\ManyToMany(targetEntitySiteProducts::class, mappedBy'category')]
  98.     private Collection $siteProducts;
  99.     #[Groups(['cat:read''cat:write'])]
  100.     #[ORM\Column(nullabletrueoptions: ["default" => 0])]
  101.     private ?int $productCnt null;
  102.     #[Groups(['cat:read''cat:write'])]
  103.     #[ORM\Column(nullabletrue,  options: ["default" => 0])]
  104.     private ?int $SiteProductCnt null;
  105.     #[Groups(['cat:media''cat:write'])]
  106.     #[ORM\ManyToOne(inversedBy'categories')]
  107.     private ?MediaObject $media null;
  108.     #[Groups(['cat:read''cat:write'])]
  109.     #[ORM\Column(nullabletrue)]
  110.     private ?int $sort null;
  111.     public function __construct()
  112.     {
  113.         $this->categories = new ArrayCollection();
  114.         $this->products = new ArrayCollection();
  115.         $this->attributes = new ArrayCollection();
  116.         $this->attributeItems = new ArrayCollection();
  117.         $this->coupons = new ArrayCollection();
  118.         $this->pages = new ArrayCollection();
  119.         $this->news = new ArrayCollection();
  120.         $this->siteProducts = new ArrayCollection();
  121.     }
  122.     public function getId(): ?int
  123.     {
  124.         return $this->id;
  125.     }
  126.     public function getDateEntered(): ?\DateTimeInterface
  127.     {
  128.         return $this->date_entered;
  129.     }
  130.     public function setDateEntered(?\DateTimeInterface $date_entered): self
  131.     {
  132.         $this->date_entered $date_entered;
  133.         return $this;
  134.     }
  135.     public function getDateModified(): ?\DateTimeInterface
  136.     {
  137.         return $this->date_modified;
  138.     }
  139.     public function setDateModified(?\DateTimeInterface $date_modified): self
  140.     {
  141.         $this->date_modified $date_modified;
  142.         return $this;
  143.     }
  144.     public function getCreatedBy(): ?int
  145.     {
  146.         return $this->created_by;
  147.     }
  148.     public function setCreatedBy(?int $created_by): self
  149.     {
  150.         $this->created_by $created_by;
  151.         return $this;
  152.     }
  153.     public function getModifiedUserId(): ?int
  154.     {
  155.         return $this->modified_user_id;
  156.     }
  157.     public function setModifiedUserId(?int $modified_user_id): self
  158.     {
  159.         $this->modified_user_id $modified_user_id;
  160.         return $this
  161.     }
  162.     public function getName(): ?string
  163.     {
  164.         return $this->name;
  165.     }
  166.     public function setName(string $name): self
  167.     {
  168.         $this->name $name;
  169.         return $this;
  170.     }
  171.     public function getParent(): ?self
  172.     {
  173.         return $this->parent;
  174.     }
  175.     public function setParent(?self $parent): self
  176.     {
  177.         $this->parent $parent;
  178.         return $this;
  179.     }
  180.     /**
  181.      * @return Collection<int, self>
  182.      */
  183.     public function getCategories(): Collection
  184.     {
  185.         return $this->categories;
  186.     }
  187.     public function addCategory(self $category): self
  188.     {
  189.         if (!$this->categories->contains($category)) {
  190.             $this->categories->add($category);
  191.             $category->setParent($this);
  192.         }
  193.         return $this;
  194.     }
  195.     public function removeCategory(self $category): self
  196.     {
  197.         if ($this->categories->removeElement($category)) {
  198.             // set the owning side to null (unless already changed)
  199.             if ($category->getParent() === $this) {
  200.                 $category->setParent(null);
  201.             }
  202.         }
  203.         return $this;
  204.     }
  205.     public function getSlug(): ?string
  206.     {
  207.         return $this->slug;
  208.     }
  209.     public function setSlug(?string $slug): self
  210.     {
  211.         $this->slug mb_strtolower$slug );
  212.         return $this;
  213.     }
  214.     public function getStatus(): ?string
  215.     {
  216.         return $this->status;
  217.     }
  218.     public function setStatus(?string $status): self
  219.     {
  220.         $this->status $status;
  221.         return $this;
  222.     }
  223.     public function getDescription(): ?string
  224.     {
  225.         return $this->description;
  226.     }
  227.     public function setDescription(?string $description): self
  228.     {
  229.         $this->description $description;
  230.         return $this;
  231.     }
  232.     
  233.     public function isMain(): ?bool
  234.     {
  235.         return $this->main;
  236.     }
  237.     public function setMain(?bool $main): self
  238.     {
  239.         $this->main $main;
  240.         return $this;
  241.     }
  242.     public function getType(): ?string
  243.     {
  244.         return $this->type;
  245.     }
  246.     public function setType(?string $type): self
  247.     {
  248.         $this->type $type;
  249.         return $this;
  250.     }
  251.     /**
  252.      * @return Collection<int, Products>
  253.      */
  254.     public function getProducts(): Collection
  255.     {
  256.         return $this->products;
  257.     }
  258.     public function addProduct(Products $product): self
  259.     {
  260.         if (!$this->products->contains($product)) {
  261.             $this->products->add($product);
  262.             $product->addCategory($this);
  263.         }
  264.         return $this;
  265.     }
  266.     public function removeProduct(Products $product): self
  267.     {
  268.         if ($this->products->removeElement($product)) {
  269.             $product->removeCategory($this);
  270.         }
  271.         return $this;
  272.     }
  273.     /**
  274.      * @return Collection<int, Attributes>
  275.      */
  276.     public function getAttributes(): Collection
  277.     {
  278.         return $this->attributes;
  279.     }
  280.     public function addAttribute(Attributes $attribute): self
  281.     {
  282.         if (!$this->attributes->contains($attribute)) {
  283.             $this->attributes->add($attribute);
  284.             $attribute->addCategory($this);
  285.         }
  286.         return $this;
  287.     }
  288.     public function removeAttribute(Attributes $attribute): self
  289.     {
  290.         if ($this->attributes->removeElement($attribute)) {
  291.             $attribute->removeCategory($this);
  292.         }
  293.         return $this;
  294.     }
  295.     /**
  296.      * @return Collection<int, AttributeItems>
  297.      */
  298.     public function getAttributeItems(): Collection
  299.     {
  300.         return $this->attributeItems;
  301.     }
  302.     public function addAttributeItem(AttributeItems $attributeItem): self
  303.     {
  304.         if (!$this->attributeItems->contains($attributeItem)) {
  305.             $this->attributeItems->add($attributeItem);
  306.             $attributeItem->addCategory($this);
  307.         }
  308.         return $this;
  309.     }
  310.     public function removeAttributeItem(AttributeItems $attributeItem): self
  311.     {
  312.         if ($this->attributeItems->removeElement($attributeItem)) {
  313.             $attributeItem->removeCategory($this);
  314.         }
  315.         return $this;
  316.     }
  317.     /**
  318.      * @return Collection<int, Coupons>
  319.      */
  320.     public function getCoupons(): Collection
  321.     {
  322.         return $this->coupons;
  323.     }
  324.     public function addCoupon(Coupons $coupon): self
  325.     {
  326.         if (!$this->coupons->contains($coupon)) {
  327.             $this->coupons->add($coupon);
  328.             $coupon->addCategory($this);
  329.         }
  330.         return $this;
  331.     }
  332.     public function removeCoupon(Coupons $coupon): self
  333.     {
  334.         if ($this->coupons->removeElement($coupon)) {
  335.             $coupon->removeCategory($this);
  336.         }
  337.         return $this;
  338.     }
  339.     /**
  340.      * @return Collection<int, Pages>
  341.      */
  342.     public function getPages(): Collection
  343.     {
  344.         return $this->pages;
  345.     }
  346.     public function addPage(Pages $page): static
  347.     {
  348.         if (!$this->pages->contains($page)) {
  349.             $this->pages->add($page);
  350.         }
  351.         return $this;
  352.     }
  353.     public function removePage(Pages $page): static
  354.     {
  355.         $this->pages->removeElement($page);
  356.         return $this;
  357.     }
  358.     /**
  359.      * @return Collection<int, News>
  360.      */
  361.     public function getNews(): Collection
  362.     {
  363.         return $this->news;
  364.     }
  365.     public function addNews(News $news): static
  366.     {
  367.         if (!$this->news->contains($news)) {
  368.             $this->news->add($news);
  369.         }
  370.         return $this;
  371.     }
  372.     public function removeNews(News $news): static
  373.     {
  374.         $this->news->removeElement($news);
  375.         return $this;
  376.     }
  377.     /**
  378.      * @return Collection<int, SiteProducts>
  379.      */
  380.     public function getSiteProducts(): Collection
  381.     {
  382.         return $this->siteProducts;
  383.     }
  384.     public function addSiteProduct(SiteProducts $siteProduct): static
  385.     {
  386.         if (!$this->siteProducts->contains($siteProduct)) {
  387.             $this->siteProducts->add($siteProduct);
  388.             $siteProduct->addCategory($this);
  389.         }
  390.         return $this;
  391.     }
  392.     public function removeSiteProduct(SiteProducts $siteProduct): static
  393.     {
  394.         if ($this->siteProducts->removeElement($siteProduct)) {
  395.             $siteProduct->removeCategory($this);
  396.         }
  397.         return $this;
  398.     }
  399.     public function getProductCnt(): ?int
  400.     {
  401.         return $this->productCnt;
  402.     }
  403.     public function setProductCnt(?int $productCnt): static
  404.     {
  405.         $this->productCnt $productCnt;
  406.         return $this;
  407.     }
  408.     public function getSiteProductCnt(): ?int
  409.     {
  410.         return $this->SiteProductCnt;
  411.     }
  412.     public function setSiteProductCnt(?int $SiteProductCnt): static
  413.     {
  414.         $this->SiteProductCnt $SiteProductCnt;
  415.         return $this;
  416.     }
  417.     public function getMedia(): ?MediaObject
  418.     {
  419.         return $this->media;
  420.     }
  421.     public function setMedia(?MediaObject $media): static
  422.     {
  423.         $this->media $media;
  424.         return $this;
  425.     }
  426.     public function getSort(): ?int
  427.     {
  428.         return $this->sort;
  429.     }
  430.     public function setSort(?int $sort): static
  431.     {
  432.         $this->sort $sort;
  433.         return $this;
  434.     }
  435. }