src/Entity/Category.php line 49

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