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:read''cat:write''attributes:read''attributes_items:read''coupon:read''read''write',  'news:read''news: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.     #[Groups(['cat:read''cat:write''attributes:read''read''write''news:read''news:write'])]
  95.     #[ORM\Column(length100nullabletrue)]
  96.     private ?string $code1c null;
  97.     public function __construct()
  98.     {
  99.         $this->categories = new ArrayCollection();
  100.         $this->products = new ArrayCollection();
  101.         $this->attributes = new ArrayCollection();
  102.         $this->attributeItems = new ArrayCollection();
  103.         $this->coupons = new ArrayCollection();
  104.         $this->pages = new ArrayCollection();
  105.         $this->news = new ArrayCollection();
  106.     }
  107.     public function getId(): ?int
  108.     {
  109.         return $this->id;
  110.     }
  111.     public function getDateEntered(): ?\DateTimeInterface
  112.     {
  113.         return $this->date_entered;
  114.     }
  115.     public function setDateEntered(?\DateTimeInterface $date_entered): self
  116.     {
  117.         $this->date_entered $date_entered;
  118.         return $this;
  119.     }
  120.     public function getDateModified(): ?\DateTimeInterface
  121.     {
  122.         return $this->date_modified;
  123.     }
  124.     public function setDateModified(?\DateTimeInterface $date_modified): self
  125.     {
  126.         $this->date_modified $date_modified;
  127.         return $this;
  128.     }
  129.     public function getCreatedBy(): ?int
  130.     {
  131.         return $this->created_by;
  132.     }
  133.     public function setCreatedBy(?int $created_by): self
  134.     {
  135.         $this->created_by $created_by;
  136.         return $this;
  137.     }
  138.     public function getModifiedUserId(): ?int
  139.     {
  140.         return $this->modified_user_id;
  141.     }
  142.     public function setModifiedUserId(?int $modified_user_id): self
  143.     {
  144.         $this->modified_user_id $modified_user_id;
  145.         return $this
  146.     }
  147.     public function getName(): ?string
  148.     {
  149.         return $this->name;
  150.     }
  151.     public function setName(string $name): self
  152.     {
  153.         $this->name $name;
  154.         return $this;
  155.     }
  156.     public function getParent(): ?self
  157.     {
  158.         return $this->parent;
  159.     }
  160.     public function setParent(?self $parent): self
  161.     {
  162.         $this->parent $parent;
  163.         return $this;
  164.     }
  165.     /**
  166.      * @return Collection<int, self>
  167.      */
  168.     public function getCategories(): Collection
  169.     {
  170.         return $this->categories;
  171.     }
  172.     public function addCategory(self $category): self
  173.     {
  174.         if (!$this->categories->contains($category)) {
  175.             $this->categories->add($category);
  176.             $category->setParent($this);
  177.         }
  178.         return $this;
  179.     }
  180.     public function removeCategory(self $category): self
  181.     {
  182.         if ($this->categories->removeElement($category)) {
  183.             // set the owning side to null (unless already changed)
  184.             if ($category->getParent() === $this) {
  185.                 $category->setParent(null);
  186.             }
  187.         }
  188.         return $this;
  189.     }
  190.     public function getSlug(): ?string
  191.     {
  192.         return $this->slug;
  193.     }
  194.     public function setSlug(?string $slug): self
  195.     {
  196.         $this->slug mb_strtolower$slug );
  197.         return $this;
  198.     }
  199.     public function getStatus(): ?string
  200.     {
  201.         return $this->status;
  202.     }
  203.     public function setStatus(?string $status): self
  204.     {
  205.         $this->status $status;
  206.         return $this;
  207.     }
  208.     public function getDescription(): ?string
  209.     {
  210.         return $this->description;
  211.     }
  212.     public function setDescription(?string $description): self
  213.     {
  214.         $this->description $description;
  215.         return $this;
  216.     }
  217.     
  218.     public function isMain(): ?bool
  219.     {
  220.         return $this->main;
  221.     }
  222.     public function setMain(?bool $main): self
  223.     {
  224.         $this->main $main;
  225.         return $this;
  226.     }
  227.     public function getType(): ?string
  228.     {
  229.         return $this->type;
  230.     }
  231.     public function setType(?string $type): self
  232.     {
  233.         $this->type $type;
  234.         return $this;
  235.     }
  236.     /**
  237.      * @return Collection<int, Products>
  238.      */
  239.     public function getProducts(): Collection
  240.     {
  241.         return $this->products;
  242.     }
  243.     public function addProduct(Products $product): self
  244.     {
  245.         if (!$this->products->contains($product)) {
  246.             $this->products->add($product);
  247.             $product->addCategory($this);
  248.         }
  249.         return $this;
  250.     }
  251.     public function removeProduct(Products $product): self
  252.     {
  253.         if ($this->products->removeElement($product)) {
  254.             $product->removeCategory($this);
  255.         }
  256.         return $this;
  257.     }
  258.     /**
  259.      * @return Collection<int, Attributes>
  260.      */
  261.     public function getAttributes(): Collection
  262.     {
  263.         return $this->attributes;
  264.     }
  265.     public function addAttribute(Attributes $attribute): self
  266.     {
  267.         if (!$this->attributes->contains($attribute)) {
  268.             $this->attributes->add($attribute);
  269.             $attribute->addCategory($this);
  270.         }
  271.         return $this;
  272.     }
  273.     public function removeAttribute(Attributes $attribute): self
  274.     {
  275.         if ($this->attributes->removeElement($attribute)) {
  276.             $attribute->removeCategory($this);
  277.         }
  278.         return $this;
  279.     }
  280.     /**
  281.      * @return Collection<int, AttributeItems>
  282.      */
  283.     public function getAttributeItems(): Collection
  284.     {
  285.         return $this->attributeItems;
  286.     }
  287.     public function addAttributeItem(AttributeItems $attributeItem): self
  288.     {
  289.         if (!$this->attributeItems->contains($attributeItem)) {
  290.             $this->attributeItems->add($attributeItem);
  291.             $attributeItem->addCategory($this);
  292.         }
  293.         return $this;
  294.     }
  295.     public function removeAttributeItem(AttributeItems $attributeItem): self
  296.     {
  297.         if ($this->attributeItems->removeElement($attributeItem)) {
  298.             $attributeItem->removeCategory($this);
  299.         }
  300.         return $this;
  301.     }
  302.     /**
  303.      * @return Collection<int, Coupons>
  304.      */
  305.     public function getCoupons(): Collection
  306.     {
  307.         return $this->coupons;
  308.     }
  309.     public function addCoupon(Coupons $coupon): self
  310.     {
  311.         if (!$this->coupons->contains($coupon)) {
  312.             $this->coupons->add($coupon);
  313.             $coupon->addCategory($this);
  314.         }
  315.         return $this;
  316.     }
  317.     public function removeCoupon(Coupons $coupon): self
  318.     {
  319.         if ($this->coupons->removeElement($coupon)) {
  320.             $coupon->removeCategory($this);
  321.         }
  322.         return $this;
  323.     }
  324.     /**
  325.      * @return Collection<int, Pages>
  326.      */
  327.     public function getPages(): Collection
  328.     {
  329.         return $this->pages;
  330.     }
  331.     public function addPage(Pages $page): static
  332.     {
  333.         if (!$this->pages->contains($page)) {
  334.             $this->pages->add($page);
  335.         }
  336.         return $this;
  337.     }
  338.     public function removePage(Pages $page): static
  339.     {
  340.         $this->pages->removeElement($page);
  341.         return $this;
  342.     }
  343.     /**
  344.      * @return Collection<int, News>
  345.      */
  346.     public function getNews(): Collection
  347.     {
  348.         return $this->news;
  349.     }
  350.     public function addNews(News $news): static
  351.     {
  352.         if (!$this->news->contains($news)) {
  353.             $this->news->add($news);
  354.         }
  355.         return $this;
  356.     }
  357.     public function removeNews(News $news): static
  358.     {
  359.         $this->news->removeElement($news);
  360.         return $this;
  361.     }
  362.     public function getCode1c(): ?string
  363.     {
  364.         return $this->code1c;
  365.     }
  366.     public function setCode1c(?string $code1c): static
  367.     {
  368.         $this->code1c $code1c;
  369.         return $this;
  370.     }
  371. }