src/Entity/Category.php line 44

  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.     #[Groups(['cat:read''cat:write'])]
  138.     #[ORM\Column(length255nullabletrue)]
  139.     private ?string $seoTitle null;
  140.     #[Groups(['cat:read''cat:write'])]
  141.     #[ORM\Column(typeTypes::TEXTnullabletrue)]
  142.     private ?string $seoDescription null;
  143.     public function __construct()
  144.     {
  145.         $this->categories = new ArrayCollection();
  146.         $this->products = new ArrayCollection();
  147.         $this->attributes = new ArrayCollection();
  148.         $this->attributeItems = new ArrayCollection();
  149.         $this->coupons = new ArrayCollection();
  150.         $this->faqs = new ArrayCollection();
  151.         $this->pages = new ArrayCollection();
  152.         $this->news = new ArrayCollection();
  153.         $this->siteProducts = new ArrayCollection();
  154.         $this->objects = new ArrayCollection();
  155.         $this->projects = new ArrayCollection();
  156.         $this->translations = new ArrayCollection();
  157.     }
  158.     public function getId(): ?int
  159.     {
  160.         return $this->id;
  161.     }
  162.     public function getDateEntered(): ?\DateTimeInterface
  163.     {
  164.         return $this->date_entered;
  165.     }
  166.     public function setDateEntered(?\DateTimeInterface $date_entered): self
  167.     {
  168.         $this->date_entered $date_entered;
  169.         return $this;
  170.     }
  171.     public function getDateModified(): ?\DateTimeInterface
  172.     {
  173.         return $this->date_modified;
  174.     }
  175.     public function setDateModified(?\DateTimeInterface $date_modified): self
  176.     {
  177.         $this->date_modified $date_modified;
  178.         return $this;
  179.     }
  180.     public function getCreatedBy(): ?int
  181.     {
  182.         return $this->created_by;
  183.     }
  184.     public function setCreatedBy(?int $created_by): self
  185.     {
  186.         $this->created_by $created_by;
  187.         return $this;
  188.     }
  189.     public function getModifiedUserId(): ?int
  190.     {
  191.         return $this->modified_user_id;
  192.     }
  193.     public function setModifiedUserId(?int $modified_user_id): self
  194.     {
  195.         $this->modified_user_id $modified_user_id;
  196.         return $this
  197.     }
  198.     public function getName(): ?string
  199.     {
  200.         return $this->name;
  201.     }
  202.     public function setName(string $name): self
  203.     {
  204.         $this->name $name;
  205.         return $this;
  206.     }
  207.     public function getParent(): ?self
  208.     {
  209.         return $this->parent;
  210.     }
  211.     public function setParent(?self $parent): self
  212.     {
  213.         $this->parent $parent;
  214.         return $this;
  215.     }
  216.     /**
  217.      * @return Collection<int, self>
  218.      */
  219.     public function getCategories(): Collection
  220.     {
  221.         return $this->categories;
  222.     }
  223.     public function addCategory(self $category): self
  224.     {
  225.         if (!$this->categories->contains($category)) {
  226.             $this->categories->add($category);
  227.             $category->setParent($this);
  228.         }
  229.         return $this;
  230.     }
  231.     public function removeCategory(self $category): self
  232.     {
  233.         if ($this->categories->removeElement($category)) {
  234.             // set the owning side to null (unless already changed)
  235.             if ($category->getParent() === $this) {
  236.                 $category->setParent(null);
  237.             }
  238.         }
  239.         return $this;
  240.     }
  241.     public function getSlug(): ?string
  242.     {
  243.         return $this->slug;
  244.     }
  245.     public function setSlug(?string $slug): self
  246.     {
  247.         $this->slug mb_strtolower$slug );
  248.         return $this;
  249.     }
  250.     public function getStatus(): ?string
  251.     {
  252.         return $this->status;
  253.     }
  254.     public function setStatus(?string $status): self
  255.     {
  256.         $this->status $status;
  257.         return $this;
  258.     }
  259.     public function getDescription(): ?string
  260.     {
  261.         return $this->description;
  262.     }
  263.     public function setDescription(?string $description): self
  264.     {
  265.         $this->description $description;
  266.         return $this;
  267.     }
  268.     
  269.     public function isMain(): ?bool
  270.     {
  271.         return $this->main;
  272.     }
  273.     public function setMain(?bool $main): self
  274.     {
  275.         $this->main $main;
  276.         return $this;
  277.     }
  278.     public function getType(): ?string
  279.     {
  280.         return $this->type;
  281.     }
  282.     public function setType(?string $type): self
  283.     {
  284.         $this->type $type;
  285.         return $this;
  286.     }
  287.     /**
  288.      * @return Collection<int, Products>
  289.      */
  290.     public function getProducts(): Collection
  291.     {
  292.         return $this->products;
  293.     }
  294.     public function addProduct(Products $product): self
  295.     {
  296.         if (!$this->products->contains($product)) {
  297.             $this->products->add($product);
  298.             $product->addCategory($this);
  299.         }
  300.         return $this;
  301.     }
  302.     public function removeProduct(Products $product): self
  303.     {
  304.         if ($this->products->removeElement($product)) {
  305.             $product->removeCategory($this);
  306.         }
  307.         return $this;
  308.     }
  309.     /**
  310.      * @return Collection<int, Attributes>
  311.      */
  312.     public function getAttributes(): Collection
  313.     {
  314.         return $this->attributes;
  315.     }
  316.     public function addAttribute(Attributes $attribute): self
  317.     {
  318.         if (!$this->attributes->contains($attribute)) {
  319.             $this->attributes->add($attribute);
  320.             $attribute->addCategory($this);
  321.         }
  322.         return $this;
  323.     }
  324.     public function removeAttribute(Attributes $attribute): self
  325.     {
  326.         if ($this->attributes->removeElement($attribute)) {
  327.             $attribute->removeCategory($this);
  328.         }
  329.         return $this;
  330.     }
  331.     /**
  332.      * @return Collection<int, AttributeItems>
  333.      */
  334.     public function getAttributeItems(): Collection
  335.     {
  336.         return $this->attributeItems;
  337.     }
  338.     public function addAttributeItem(AttributeItems $attributeItem): self
  339.     {
  340.         if (!$this->attributeItems->contains($attributeItem)) {
  341.             $this->attributeItems->add($attributeItem);
  342.             $attributeItem->addCategory($this);
  343.         }
  344.         return $this;
  345.     }
  346.     public function removeAttributeItem(AttributeItems $attributeItem): self
  347.     {
  348.         if ($this->attributeItems->removeElement($attributeItem)) {
  349.             $attributeItem->removeCategory($this);
  350.         }
  351.         return $this;
  352.     }
  353.     /**
  354.      * @return Collection<int, Coupons>
  355.      */
  356.     public function getCoupons(): Collection
  357.     {
  358.         return $this->coupons;
  359.     }
  360.     public function addCoupon(Coupons $coupon): self
  361.     {
  362.         if (!$this->coupons->contains($coupon)) {
  363.             $this->coupons->add($coupon);
  364.             $coupon->addCategory($this);
  365.         }
  366.         return $this;
  367.     }
  368.     public function removeCoupon(Coupons $coupon): self
  369.     {
  370.         if ($this->coupons->removeElement($coupon)) {
  371.             $coupon->removeCategory($this);
  372.         }
  373.         return $this;
  374.     }
  375.     /**
  376.      * @return Collection<int, Faq>
  377.      */
  378.     public function getFaqs(): Collection
  379.     {
  380.         return $this->faqs;
  381.     }
  382.     public function addFaq(Faq $faq): static
  383.     {
  384.         if (!$this->faqs->contains($faq)) {
  385.             $this->faqs->add($faq);
  386.             $faq->addCategory($this);
  387.         }
  388.         return $this;
  389.     }
  390.     /**
  391.      * @return Collection<int, Pages>
  392.      */
  393.     public function getPages(): Collection
  394.     {
  395.         return $this->pages;
  396.     }
  397.     public function addPage(Pages $page): static
  398.     {
  399.         if (!$this->pages->contains($page)) {
  400.             $this->pages->add($page);
  401.         }
  402.         return $this;
  403.     }
  404.     public function removeFaq(Faq $faq): static
  405.     {
  406.         if ($this->faqs->removeElement($faq)) {
  407.             $faq->removeCategory($this);
  408.         }
  409.         return $this;
  410.     }
  411.     public function removePage(Pages $page): static
  412.     {
  413.         $this->pages->removeElement($page);
  414.         return $this;
  415.     }
  416.     /**
  417.      * @return Collection<int, News>
  418.      */
  419.     public function getNews(): Collection
  420.     {
  421.         return $this->news;
  422.     }
  423.     public function addNews(News $news): static
  424.     {
  425.         if (!$this->news->contains($news)) {
  426.             $this->news->add($news);
  427.         }
  428.         return $this;
  429.     }
  430.     public function removeNews(News $news): static
  431.     {
  432.         $this->news->removeElement($news);
  433.         return $this;
  434.     }
  435.     /**
  436.      * @return Collection<int, SiteProducts>
  437.      */
  438.     public function getSiteProducts(): Collection
  439.     {
  440.         return $this->siteProducts;
  441.     }
  442.     public function addSiteProduct(SiteProducts $siteProduct): static
  443.     {
  444.         if (!$this->siteProducts->contains($siteProduct)) {
  445.             $this->siteProducts->add($siteProduct);
  446.             $siteProduct->addCategory($this);
  447.         }
  448.         return $this;
  449.     }
  450.     
  451.     public function getLanguage(): ?Languages
  452.     {
  453.         return $this->language;
  454.     }
  455.     public function setLanguage(?Languages $language): static
  456.     {
  457.         $this->language $language;
  458.         return $this;
  459.     }
  460.     public function removeSiteProduct(SiteProducts $siteProduct): static
  461.     {
  462.         if ($this->siteProducts->removeElement($siteProduct)) {
  463.             $siteProduct->removeCategory($this);
  464.         }
  465.         return $this;
  466.     }
  467.     public function getProductCnt(): ?int
  468.     {
  469.         return $this->productCnt;
  470.     }
  471.     public function setProductCnt(?int $productCnt): static
  472.     {
  473.         $this->productCnt $productCnt;
  474.         return $this;
  475.     }
  476.     public function getSiteProductCnt(): ?int
  477.     {
  478.         return $this->SiteProductCnt;
  479.     }
  480.     public function setSiteProductCnt(?int $SiteProductCnt): static
  481.     {
  482.         $this->SiteProductCnt $SiteProductCnt;
  483.         return $this;
  484.     }
  485.     public function getMedia(): ?MediaObject
  486.     {
  487.         return $this->media;
  488.     }
  489.     public function setMedia(?MediaObject $media): static
  490.     {
  491.         $this->media $media;
  492.         return $this;
  493.     }
  494.     public function getSort(): ?int
  495.     {
  496.         return $this->sort;
  497.     }
  498.     public function setSort(?int $sort): static
  499.     {
  500.         $this->sort $sort;
  501.         return $this;
  502.     }
  503.     
  504.     public function getTranslation(): ?self
  505.     {
  506.         return $this->translation;
  507.     }
  508.     public function setTranslation(?self $translation): static
  509.     {
  510.         $this->translation $translation;
  511.         return $this;
  512.     }
  513.     /**
  514.      * @return Collection<int, Objects>
  515.      */
  516.     public function getObjects(): Collection
  517.     {
  518.         return $this->objects;
  519.     }
  520.     public function addObject(Objects $object): static
  521.     {
  522.         if (!$this->objects->contains($object)) {
  523.             $this->objects->add($object);
  524.             $object->addCategory($this);
  525.         }
  526.         return $this;
  527.     }
  528.     
  529.     /**
  530.      *  @return Collection<int, self>
  531.      */
  532.     public function getTranslations(): Collection
  533.     {
  534.         return $this->translations;
  535.     }
  536.     public function addTranslation(self $translation): static
  537.     {
  538.         if (!$this->translations->contains($translation)) {
  539.             $this->translations->add($translation);
  540.             $translation->setTranslation($this);
  541.         }
  542.         return $this;
  543.     }
  544.     public function removeObject(Objects $object): static
  545.     {
  546.         if ($this->objects->removeElement($object)) {
  547.             $object->removeCategory($this);
  548.         }
  549.         return $this;
  550.     }
  551.     /**
  552.      * @return Collection<int, Projects>
  553.      */
  554.     public function getProjects(): Collection
  555.     {
  556.         return $this->projects;
  557.     }
  558.     public function addProject(Projects $project): static
  559.     {
  560.         if (!$this->projects->contains($project)) {
  561.             $this->projects->add($project);
  562.             $project->addCategory($this);
  563.         }
  564.         return $this;
  565.     }
  566.     public function removeProject(Projects $project): static
  567.     {
  568.         if ($this->projects->removeElement($project)) {
  569.             $project->removeCategory($this);
  570.         }
  571.         return $this;
  572.     }
  573.     public function removeTranslation(self $translation): static
  574.     {
  575.         if ($this->translations->removeElement($translation)) {
  576.             // set the owning side to null (unless already changed)
  577.             if ($translation->getTranslation() === $this) {
  578.                 $translation->setTranslation(null);
  579.             }
  580.         }
  581.         return $this;
  582.     }
  583.     public function getSeoTitle(): ?string
  584.     {
  585.         return $this->seoTitle;
  586.     }
  587.     public function setSeoTitle(?string $seoTitle): static
  588.     {
  589.         $this->seoTitle $seoTitle;
  590.         return $this;
  591.     }
  592.     public function getSeoDescription(): ?string
  593.     {
  594.         return $this->seoDescription;
  595.     }
  596.     public function setSeoDescription(?string $seoDescription): static
  597.     {
  598.         $this->seoDescription $seoDescription;
  599.         return $this;
  600.     }
  601. }