src/Entity/Category.php line 41

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. #[ORM\Entity(repositoryClassCategoryRepository::class)]
  15. #[ApiResource(
  16.     normalizationContext: ['groups' => ['cat:read']],
  17.     denormalizationContext: ['groups' => ['cat:write']],
  18.     order: ['id' => 'DESC'],
  19.     paginationPartialtrue
  20. )]
  21. #[ApiFilter(SearchFilter::class, properties: [
  22.     'name' => 'ipartial'
  23.     'parent' => 'exact'
  24.     'main' => 'exact'
  25.     'type' => 'exact'
  26.     'slug' => 'exact'
  27.     'products.show' => 'exact',
  28.     'products.id' => 'exact',
  29.     'attributes.id' => 'exact',
  30.     'news.id' => 'exact',
  31.     'pages.id' => 'exact'
  32. ])]
  33. class Category
  34. {
  35.     #[ORM\Id]
  36.     #[ORM\GeneratedValue]
  37.     #[ORM\Column]
  38.     #[Groups(['cat:read''cat:write''attributes:read''attributes_items:read''coupon:read''read''write''news:read''news:write'])]
  39.     private ?int $id null;
  40.     #[Groups(['cat:read'])]
  41.     #[ORM\Column(typeTypes::DATETIME_MUTABLEnullabletrue)]
  42.     private ?\DateTimeInterface $date_entered null;
  43.     #[Groups(['cat:read'])]
  44.     #[ORM\Column(typeTypes::DATETIME_MUTABLEnullabletrue)]
  45.     private ?\DateTimeInterface $date_modified null;
  46.     #[ORM\Column(nullabletrue)]
  47.     private ?int $created_by null;
  48.     #[ORM\Column(nullabletrue)]
  49.     private ?int $modified_user_id null;
  50.     #[Groups(['cat:read''cat:write''attributes:read''attributes_items:read''coupon:read''read''write',  'news:read''news:write'])]
  51.     #[ORM\Column(length255)]
  52.     private ?string $name null;
  53.     #[Groups(['cat:write'])]
  54.     #[ORM\ManyToOne(targetEntityself::class, inversedBy'categories'cascade:['persist'])]
  55.     private ?self $parent null;
  56.     #[Groups(['cat:read'])]
  57.     #[ORM\OneToMany(mappedBy'parent'targetEntityself::class, cascade:['persist''remove'])]
  58.     #[MaxDepth(2)]
  59.     #[ApiProperty(writabletrue)]
  60.     private Collection $categories;
  61.     #[Groups(['cat:read''cat:write''attributes:read''read''write''news:read''news:write'])]
  62.     #[ORM\Column(length100nullabletrue)]
  63.     private ?string $slug null;
  64.     #[Groups(['cat:read''cat:write''read''write''news:read''news:write'])]
  65.     #[ORM\Column(length100nullabletrue)]
  66.     private ?string $status null;
  67.     #[Groups(['cat:read''cat:write''read''write','news:read''news:write'])]
  68.     #[ORM\Column(typeTypes::TEXTnullabletrue)]
  69.     private ?string $description null;
  70.     #[Groups(['cat:read''cat:write''read''write''news:read''news:write'])]
  71.     #[ORM\Column(nullabletrue)]
  72.     private ?bool $main null;
  73.     #[Groups(['cat:read''cat:write''read''write''news:read''news:write'])]
  74.     #[ORM\Column(length20nullabletrue)]
  75.     private ?string $type null;
  76.     #[ApiProperty(writabletrue)]
  77.     #[Groups(['cat:read''cat:write'])]
  78.     #[ORM\ManyToMany(targetEntityProducts::class, mappedBy'category'cascade:['persist'])]
  79.     #[MaxDepth(1)]
  80.     private Collection $products;
  81.     #[Groups(['cat:read''cat:write'])]
  82.     #[ORM\ManyToMany(targetEntityAttributes::class, mappedBy'category'cascade:['persist'])]
  83.     private Collection $attributes;
  84.     #[ORM\ManyToMany(targetEntityAttributeItems::class, mappedBy'categories'cascade:['persist'])]
  85.     private Collection $attributeItems;
  86.     #[ORM\ManyToMany(targetEntityCoupons::class, mappedBy'category'cascade:['persist'])]
  87.     private Collection $coupons;
  88.     #[Groups(['cat:read''cat:write'])]
  89.     #[ORM\ManyToMany(targetEntityPages::class, mappedBy'categories',  cascade:['persist'])]
  90.     private Collection $pages;
  91.     #[Groups(['cat:read''cat:write'])]
  92.     #[ORM\ManyToMany(targetEntityNews::class, inversedBy'categories',  cascade:['persist'])]
  93.     private Collection $news;
  94.     public function __construct()
  95.     {
  96.         $this->categories = new ArrayCollection();
  97.         $this->products = new ArrayCollection();
  98.         $this->attributes = new ArrayCollection();
  99.         $this->attributeItems = new ArrayCollection();
  100.         $this->coupons = new ArrayCollection();
  101.         $this->pages = new ArrayCollection();
  102.         $this->news = new ArrayCollection();
  103.     }
  104.     public function getId(): ?int
  105.     {
  106.         return $this->id;
  107.     }
  108.     public function getDateEntered(): ?\DateTimeInterface
  109.     {
  110.         return $this->date_entered;
  111.     }
  112.     public function setDateEntered(?\DateTimeInterface $date_entered): self
  113.     {
  114.         $this->date_entered $date_entered;
  115.         return $this;
  116.     }
  117.     public function getDateModified(): ?\DateTimeInterface
  118.     {
  119.         return $this->date_modified;
  120.     }
  121.     public function setDateModified(?\DateTimeInterface $date_modified): self
  122.     {
  123.         $this->date_modified $date_modified;
  124.         return $this;
  125.     }
  126.     public function getCreatedBy(): ?int
  127.     {
  128.         return $this->created_by;
  129.     }
  130.     public function setCreatedBy(?int $created_by): self
  131.     {
  132.         $this->created_by $created_by;
  133.         return $this;
  134.     }
  135.     public function getModifiedUserId(): ?int
  136.     {
  137.         return $this->modified_user_id;
  138.     }
  139.     public function setModifiedUserId(?int $modified_user_id): self
  140.     {
  141.         $this->modified_user_id $modified_user_id;
  142.         return $this
  143.     }
  144.     public function getName(): ?string
  145.     {
  146.         return $this->name;
  147.     }
  148.     public function setName(string $name): self
  149.     {
  150.         $this->name $name;
  151.         return $this;
  152.     }
  153.     public function getParent(): ?self
  154.     {
  155.         return $this->parent;
  156.     }
  157.     public function setParent(?self $parent): self
  158.     {
  159.         $this->parent $parent;
  160.         return $this;
  161.     }
  162.     /**
  163.      * @return Collection<int, self>
  164.      */
  165.     public function getCategories(): Collection
  166.     {
  167.         return $this->categories;
  168.     }
  169.     public function addCategory(self $category): self
  170.     {
  171.         if (!$this->categories->contains($category)) {
  172.             $this->categories->add($category);
  173.             $category->setParent($this);
  174.         }
  175.         return $this;
  176.     }
  177.     public function removeCategory(self $category): self
  178.     {
  179.         if ($this->categories->removeElement($category)) {
  180.             // set the owning side to null (unless already changed)
  181.             if ($category->getParent() === $this) {
  182.                 $category->setParent(null);
  183.             }
  184.         }
  185.         return $this;
  186.     }
  187.     public function getSlug(): ?string
  188.     {
  189.         return $this->slug;
  190.     }
  191.     public function setSlug(?string $slug): self
  192.     {
  193.         $this->slug mb_strtolower$slug );
  194.         return $this;
  195.     }
  196.     public function getStatus(): ?string
  197.     {
  198.         return $this->status;
  199.     }
  200.     public function setStatus(?string $status): self
  201.     {
  202.         $this->status $status;
  203.         return $this;
  204.     }
  205.     public function getDescription(): ?string
  206.     {
  207.         return $this->description;
  208.     }
  209.     public function setDescription(?string $description): self
  210.     {
  211.         $this->description $description;
  212.         return $this;
  213.     }
  214.     
  215.     public function isMain(): ?bool
  216.     {
  217.         return $this->main;
  218.     }
  219.     public function setMain(?bool $main): self
  220.     {
  221.         $this->main $main;
  222.         return $this;
  223.     }
  224.     public function getType(): ?string
  225.     {
  226.         return $this->type;
  227.     }
  228.     public function setType(?string $type): self
  229.     {
  230.         $this->type $type;
  231.         return $this;
  232.     }
  233.     /**
  234.      * @return Collection<int, Products>
  235.      */
  236.     public function getProducts(): Collection
  237.     {
  238.         return $this->products;
  239.     }
  240.     public function addProduct(Products $product): self
  241.     {
  242.         if (!$this->products->contains($product)) {
  243.             $this->products->add($product);
  244.             $product->addCategory($this);
  245.         }
  246.         return $this;
  247.     }
  248.     public function removeProduct(Products $product): self
  249.     {
  250.         if ($this->products->removeElement($product)) {
  251.             $product->removeCategory($this);
  252.         }
  253.         return $this;
  254.     }
  255.     /**
  256.      * @return Collection<int, Attributes>
  257.      */
  258.     public function getAttributes(): Collection
  259.     {
  260.         return $this->attributes;
  261.     }
  262.     public function addAttribute(Attributes $attribute): self
  263.     {
  264.         if (!$this->attributes->contains($attribute)) {
  265.             $this->attributes->add($attribute);
  266.             $attribute->addCategory($this);
  267.         }
  268.         return $this;
  269.     }
  270.     public function removeAttribute(Attributes $attribute): self
  271.     {
  272.         if ($this->attributes->removeElement($attribute)) {
  273.             $attribute->removeCategory($this);
  274.         }
  275.         return $this;
  276.     }
  277.     /**
  278.      * @return Collection<int, AttributeItems>
  279.      */
  280.     public function getAttributeItems(): Collection
  281.     {
  282.         return $this->attributeItems;
  283.     }
  284.     public function addAttributeItem(AttributeItems $attributeItem): self
  285.     {
  286.         if (!$this->attributeItems->contains($attributeItem)) {
  287.             $this->attributeItems->add($attributeItem);
  288.             $attributeItem->addCategory($this);
  289.         }
  290.         return $this;
  291.     }
  292.     public function removeAttributeItem(AttributeItems $attributeItem): self
  293.     {
  294.         if ($this->attributeItems->removeElement($attributeItem)) {
  295.             $attributeItem->removeCategory($this);
  296.         }
  297.         return $this;
  298.     }
  299.     /**
  300.      * @return Collection<int, Coupons>
  301.      */
  302.     public function getCoupons(): Collection
  303.     {
  304.         return $this->coupons;
  305.     }
  306.     public function addCoupon(Coupons $coupon): self
  307.     {
  308.         if (!$this->coupons->contains($coupon)) {
  309.             $this->coupons->add($coupon);
  310.             $coupon->addCategory($this);
  311.         }
  312.         return $this;
  313.     }
  314.     public function removeCoupon(Coupons $coupon): self
  315.     {
  316.         if ($this->coupons->removeElement($coupon)) {
  317.             $coupon->removeCategory($this);
  318.         }
  319.         return $this;
  320.     }
  321.     /**
  322.      * @return Collection<int, Pages>
  323.      */
  324.     public function getPages(): Collection
  325.     {
  326.         return $this->pages;
  327.     }
  328.     public function addPage(Pages $page): static
  329.     {
  330.         if (!$this->pages->contains($page)) {
  331.             $this->pages->add($page);
  332.         }
  333.         return $this;
  334.     }
  335.     public function removePage(Pages $page): static
  336.     {
  337.         $this->pages->removeElement($page);
  338.         return $this;
  339.     }
  340.     /**
  341.      * @return Collection<int, News>
  342.      */
  343.     public function getNews(): Collection
  344.     {
  345.         return $this->news;
  346.     }
  347.     public function addNews(News $news): static
  348.     {
  349.         if (!$this->news->contains($news)) {
  350.             $this->news->add($news);
  351.         }
  352.         return $this;
  353.     }
  354.     public function removeNews(News $news): static
  355.     {
  356.         $this->news->removeElement($news);
  357.         return $this;
  358.     }
  359. }