src/Entity/SiteProducts.php line 49

Open in your IDE?
  1. <?php
  2. namespace App\Entity;
  3. use ApiPlatform\Metadata\ApiResource;
  4. use App\Repository\SiteProductsRepository;
  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 Symfony\Component\Serializer\Annotation\Groups;
  10. use ApiPlatform\Core\Annotation\ApiProperty;
  11. use ApiPlatform\Metadata\Get;
  12. use ApiPlatform\Metadata\GetCollection;
  13. use ApiPlatform\Metadata\Delete;
  14. use ApiPlatform\Metadata\Put;
  15. use ApiPlatform\Metadata\Post;
  16. use ApiPlatform\Metadata\Patch;
  17. use ApiPlatform\Metadata\ApiFilter;
  18. use ApiPlatform\Doctrine\Orm\Filter\SearchFilter;
  19. #[ORM\Entity(repositoryClassSiteProductsRepository::class)]
  20. #[ApiResource(
  21.     operations: [
  22.         new Get(),
  23.         new Post(),
  24.         new Delete(),
  25.         new GetCollection(),
  26.         new Put(),
  27.         new Patch()
  28.     ],
  29.     normalizationContext: ['groups' => ['site_product:read']],
  30.     denormalizationContext: ['groups' => ['site_product:write']],
  31.     order: ['id' => 'DESC'],
  32.     // paginationPartial: true
  33.     paginationEnabledtrue,
  34. )]
  35. #[ApiFilter(
  36.     SearchFilter::class, 
  37.     properties: [
  38.         'name' => 'ipartial',
  39.         'category.name' => 'ipartial',
  40.         'category.id' => 'exact',
  41.         'products.article' => 'exact',
  42.         'code1c' => 'exact',
  43.     ],
  44. )]
  45. class SiteProducts
  46. {
  47.     #[ORM\Id]
  48.     #[ORM\GeneratedValue]
  49.     #[ORM\Column]
  50.     #[Groups(['site_product:read''site_product:write''cat:read''user_like:read''product:read'])]
  51.     private ?int $id null;
  52.     #[Groups(['site_product:read''site_product:write''cat:read''user_like:read''product:read'])]
  53.     #[ORM\Column(length255nullabletrue)]
  54.     private ?string $name null;
  55.     #[Groups(['site_product:read''site_product:write''cat:read''user_like:read'])]
  56.     #[ORM\Column(typeTypes::TEXTnullabletrue)]
  57.     private ?string $description null;
  58.     #[ORM\Column(typeTypes::DATETIME_MUTABLEnullabletrue)]
  59.     private ?\DateTimeInterface $date_entered null;
  60.     #[ORM\Column(typeTypes::DATETIME_MUTABLEnullabletrue)]
  61.     private ?\DateTimeInterface $date_modified null;
  62.     #[ORM\ManyToOne]
  63.     private ?User $created_by null;
  64.     #[ORM\ManyToOne]
  65.     private ?User $modified_user null;
  66.     #[Groups(['site_product:read''site_product:write''cat:read''user_like:read'])]
  67.     #[ORM\Column(length100nullabletrue)]
  68.     private ?string $status null;
  69.     #[Groups(['site_product:read''site_product:write''cat:read''user_like:read'])]
  70.     #[ORM\Column(nullabletrue)]
  71.     private ?float $price null;
  72.     #[Groups(['site_product:read''site_product:write''cat:read'])]
  73.     #[ORM\ManyToOne(inversedBy'siteProducts')]
  74.     private ?MeasurmentUnit $measurment_unit null;
  75.     #[Groups(['site_product:read''site_product:write'])]
  76.     #[ORM\OneToMany(mappedBy'siteProduct'targetEntityProducts::class)]
  77.     #[ApiProperty(writabletrue)]
  78.     private Collection $products;
  79.     #[Groups(['site_product:read''site_product:write'])]
  80.     #[ORM\ManyToMany(targetEntityCategory::class, inversedBy'siteProducts')]
  81.     private Collection $category;
  82.     #[Groups(['site_product:read''site_product:write''cat:read''user_like:read'])]
  83.     #[ORM\OneToMany(mappedBy'siteProduct'targetEntitySiteProductsMedia::class, cascade:['persist''remove'])]
  84.     private Collection $siteProductsMedia;
  85.     #[Groups(['site_product:read''site_product:write''cat:read'])]
  86.     #[ORM\Column(length255nullabletrue)]
  87.     private ?string $slug null;
  88.     #[Groups(['site_product:read''site_product:write''cat:read''user_like:read'])]
  89.     #[ORM\ManyToOne(inversedBy'siteProducts'cascade:['persist''remove'])]
  90.     private ?SiteProductsMedia $mainSiteProductMedia null;
  91.     #[Groups(['site_product:read''site_product:write'])]
  92.     #[ORM\Column(length20nullabletrue)]
  93.     private ?string $code1c null;
  94.     #[ORM\OneToMany(mappedBy'siteProduct'targetEntityUserLikeList::class)]
  95.     private Collection $userLikeLists;
  96.     #[ORM\Column(nullabletrue)]
  97.     private ?int $categoryCnt null;
  98.     public function __construct()
  99.     {
  100.         $this->products = new ArrayCollection();
  101.         $this->category = new ArrayCollection();
  102.         $this->siteProductsMedia = new ArrayCollection();
  103.         $this->userLikeLists = new ArrayCollection();
  104.     }
  105.     public function getId(): ?int
  106.     {
  107.         return $this->id;
  108.     }
  109.     public function getName(): ?string
  110.     {
  111.         return $this->name;
  112.     }
  113.     public function setName(?string $name): self
  114.     {
  115.         $this->name $name;
  116.         return $this;
  117.     }
  118.     public function getDescription(): ?string
  119.     {
  120.         return $this->description;
  121.     }
  122.     public function setDescription(?string $description): self
  123.     {
  124.         $this->description $description;
  125.         return $this;
  126.     }
  127.     public function getDateEntered(): ?\DateTimeInterface
  128.     {
  129.         return $this->date_entered;
  130.     }
  131.     public function setDateEntered(?\DateTimeInterface $date_entered): self
  132.     {
  133.         $this->date_entered $date_entered;
  134.         return $this;
  135.     }
  136.     public function getDateModified(): ?\DateTimeInterface
  137.     {
  138.         return $this->date_modified;
  139.     }
  140.     public function setDateModified(?\DateTimeInterface $date_modified): self
  141.     {
  142.         $this->date_modified $date_modified;
  143.         return $this;
  144.     }
  145.     public function getCreatedBy(): ?User
  146.     {
  147.         return $this->created_by;
  148.     }
  149.     public function setCreatedBy(?User $created_by): self
  150.     {
  151.         $this->created_by $created_by;
  152.         return $this;
  153.     }
  154.     public function getModifiedUser(): ?User
  155.     {
  156.         return $this->modified_user;
  157.     }
  158.     public function setModifiedUser(?User $modified_user): self
  159.     {
  160.         $this->modified_user $modified_user;
  161.         return $this;
  162.     }
  163.     public function getStatus(): ?string
  164.     {
  165.         return $this->status;
  166.     }
  167.     public function setStatus(?string $status): self
  168.     {
  169.         $this->status $status;
  170.         return $this;
  171.     }
  172.     public function getPrice(): ?float
  173.     {
  174.         return $this->price;
  175.     }
  176.     public function setPrice(?float $price): self
  177.     {
  178.         $this->price $price;
  179.         return $this;
  180.     }
  181.     public function getMeasurmentUnit(): ?MeasurmentUnit
  182.     {
  183.         return $this->measurment_unit;
  184.     }
  185.     public function setMeasurmentUnit(?MeasurmentUnit $measurment_unit): self
  186.     {
  187.         $this->measurment_unit $measurment_unit;
  188.         return $this;
  189.     }
  190.     /**
  191.      * @return Collection<int, Products>
  192.      */
  193.     public function getProducts(): Collection
  194.     {
  195.         return $this->products;
  196.     }
  197.     public function addProduct(Products $product): self
  198.     {
  199.         if (!$this->products->contains($product)) {
  200.             $this->products->add($product);
  201.             $product->setSiteProduct($this);
  202.         }
  203.         return $this;
  204.     }
  205.     public function removeProduct(Products $product): self
  206.     {
  207.         if ($this->products->removeElement($product)) {
  208.             // set the owning side to null (unless already changed)
  209.             if ($product->getSiteProduct() === $this) {
  210.                 $product->setSiteProduct(null);
  211.             }
  212.         }
  213.         return $this;
  214.     }
  215.     /**
  216.      * @return Collection<int, Category>
  217.      */
  218.     public function getCategory(): Collection
  219.     {
  220.         return $this->category;
  221.     }
  222.     public function addCategory(Category $category): static
  223.     {
  224.         if (!$this->category->contains($category)) {
  225.             $this->category->add($category);
  226.         }
  227.         return $this;
  228.     }
  229.     public function removeCategory(Category $category): static
  230.     {
  231.         $this->category->removeElement($category);
  232.         return $this;
  233.     }
  234.     /**
  235.      * @return Collection<int, SiteProductsMedia>
  236.      */
  237.     public function getSiteProductsMedia(): Collection
  238.     {
  239.         return $this->siteProductsMedia;
  240.     }
  241.     public function addSiteProductsMedium(SiteProductsMedia $siteProductsMedium): static
  242.     {
  243.         if (!$this->siteProductsMedia->contains($siteProductsMedium)) {
  244.             $this->siteProductsMedia->add($siteProductsMedium);
  245.             $siteProductsMedium->setSiteProduct($this);
  246.         }
  247.         return $this;
  248.     }
  249.     public function removeSiteProductsMedium(SiteProductsMedia $siteProductsMedium): static
  250.     {
  251.         if ($this->siteProductsMedia->removeElement($siteProductsMedium)) {
  252.             // set the owning side to null (unless already changed)
  253.             if ($siteProductsMedium->getSiteProduct() === $this) {
  254.                 $siteProductsMedium->setSiteProduct(null);
  255.             }
  256.         }
  257.         return $this;
  258.     }
  259.     public function getSlug(): ?string
  260.     {
  261.         return $this->slug;
  262.     }
  263.     public function setSlug(?string $slug): static
  264.     {
  265.         $this->slug $slug;
  266.         return $this;
  267.     }
  268.     public function getMainSiteProductMedia(): ?SiteProductsMedia
  269.     {
  270.         return $this->mainSiteProductMedia;
  271.     }
  272.     public function setMainSiteProductMedia(?SiteProductsMedia $mainSiteProductMedia): static
  273.     {
  274.         $this->mainSiteProductMedia $mainSiteProductMedia;
  275.         return $this;
  276.     }
  277.     public function getCode1c(): ?string
  278.     {
  279.         return $this->code1c;
  280.     }
  281.     public function setCode1c(?string $code1c): static
  282.     {
  283.         $this->code1c $code1c;
  284.         return $this;
  285.     }
  286.     /**
  287.      * @return Collection<int, UserLikeList>
  288.      */
  289.     public function getUserLikeLists(): Collection
  290.     {
  291.         return $this->userLikeLists;
  292.     }
  293.     public function addUserLikeList(UserLikeList $userLikeList): static
  294.     {
  295.         if (!$this->userLikeLists->contains($userLikeList)) {
  296.             $this->userLikeLists->add($userLikeList);
  297.             $userLikeList->setSiteProduct($this);
  298.         }
  299.         return $this;
  300.     }
  301.     public function removeUserLikeList(UserLikeList $userLikeList): static
  302.     {
  303.         if ($this->userLikeLists->removeElement($userLikeList)) {
  304.             // set the owning side to null (unless already changed)
  305.             if ($userLikeList->getSiteProduct() === $this) {
  306.                 $userLikeList->setSiteProduct(null);
  307.             }
  308.         }
  309.         return $this;
  310.     }
  311.     public function getCategoryCnt(): ?int
  312.     {
  313.         return $this->categoryCnt;
  314.     }
  315.     public function setCategoryCnt(?int $categoryCnt): static
  316.     {
  317.         $this->categoryCnt $categoryCnt;
  318.         return $this;
  319.     }
  320. }