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