src/Entity/Category.php line 49

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