src/Entity/Category.php line 45

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