<?php
namespace App\Entity;
use ApiPlatform\Metadata\ApiResource;
use App\Repository\SiteProductsRepository;
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\Common\Collections\Collection;
use Doctrine\DBAL\Types\Types;
use Doctrine\ORM\Mapping as ORM;
use Symfony\Component\Serializer\Annotation\Groups;
use ApiPlatform\Core\Annotation\ApiProperty;
use ApiPlatform\Metadata\Get;
use ApiPlatform\Metadata\GetCollection;
use ApiPlatform\Metadata\Delete;
use ApiPlatform\Metadata\Put;
use ApiPlatform\Metadata\Post;
use ApiPlatform\Metadata\Patch;
use ApiPlatform\Metadata\ApiFilter;
use ApiPlatform\Doctrine\Orm\Filter\SearchFilter;
#[ORM\Entity(repositoryClass: SiteProductsRepository::class)]
#[ApiResource(
operations: [
new Get(),
new Post(),
new Delete(),
new GetCollection(),
new Put(),
new Patch()
],
normalizationContext: ['groups' => ['site_product:read']],
denormalizationContext: ['groups' => ['site_product:write']],
order: ['id' => 'DESC'],
// paginationPartial: true
paginationEnabled: true,
)]
#[ApiFilter(
SearchFilter::class,
properties: [
'name' => 'ipartial',
'category.name' => 'ipartial',
'category.id' => 'exact',
'products.article' => 'exact',
'code1c' => 'exact',
],
)]
class SiteProducts
{
#[ORM\Id]
#[ORM\GeneratedValue]
#[ORM\Column]
#[Groups(['site_product:read', 'site_product:write', 'cat:read', 'user_like:read', 'product:read'])]
private ?int $id = null;
#[Groups(['site_product:read', 'site_product:write', 'cat:read', 'user_like:read', 'product:read'])]
#[ORM\Column(length: 255, nullable: true)]
private ?string $name = null;
#[Groups(['site_product:read', 'site_product:write', 'cat:read', 'user_like:read'])]
#[ORM\Column(type: Types::TEXT, nullable: true)]
private ?string $description = null;
#[ORM\Column(type: Types::DATETIME_MUTABLE, nullable: true)]
private ?\DateTimeInterface $date_entered = null;
#[ORM\Column(type: Types::DATETIME_MUTABLE, nullable: true)]
private ?\DateTimeInterface $date_modified = null;
#[ORM\ManyToOne]
private ?User $created_by = null;
#[ORM\ManyToOne]
private ?User $modified_user = null;
#[Groups(['site_product:read', 'site_product:write', 'cat:read', 'user_like:read'])]
#[ORM\Column(length: 100, nullable: true)]
private ?string $status = null;
#[Groups(['site_product:read', 'site_product:write', 'cat:read', 'user_like:read'])]
#[ORM\Column(nullable: true)]
private ?float $price = null;
#[Groups(['site_product:read', 'site_product:write', 'cat:read'])]
#[ORM\ManyToOne(inversedBy: 'siteProducts')]
private ?MeasurmentUnit $measurment_unit = null;
#[Groups(['site_product:read', 'site_product:write'])]
#[ORM\OneToMany(mappedBy: 'siteProduct', targetEntity: Products::class)]
#[ApiProperty(writable: true)]
private Collection $products;
#[Groups(['site_product:read', 'site_product:write'])]
#[ORM\ManyToMany(targetEntity: Category::class, inversedBy: 'siteProducts')]
private Collection $category;
#[Groups(['site_product:read', 'site_product:write', 'cat:read', 'user_like:read'])]
#[ORM\OneToMany(mappedBy: 'siteProduct', targetEntity: SiteProductsMedia::class, cascade:['persist', 'remove'])]
private Collection $siteProductsMedia;
#[Groups(['site_product:read', 'site_product:write', 'cat:read'])]
#[ORM\Column(length: 255, nullable: true)]
private ?string $slug = null;
#[Groups(['site_product:read', 'site_product:write', 'cat:read', 'user_like:read'])]
#[ORM\ManyToOne(inversedBy: 'siteProducts', cascade:['persist', 'remove'])]
private ?SiteProductsMedia $mainSiteProductMedia = null;
#[Groups(['site_product:read', 'site_product:write'])]
#[ORM\Column(length: 20, nullable: true)]
private ?string $code1c = null;
#[ORM\OneToMany(mappedBy: 'siteProduct', targetEntity: UserLikeList::class)]
private Collection $userLikeLists;
#[ORM\Column(nullable: true)]
private ?int $categoryCnt = null;
public function __construct()
{
$this->products = new ArrayCollection();
$this->category = new ArrayCollection();
$this->siteProductsMedia = new ArrayCollection();
$this->userLikeLists = new ArrayCollection();
}
public function getId(): ?int
{
return $this->id;
}
public function getName(): ?string
{
return $this->name;
}
public function setName(?string $name): self
{
$this->name = $name;
return $this;
}
public function getDescription(): ?string
{
return $this->description;
}
public function setDescription(?string $description): self
{
$this->description = $description;
return $this;
}
public function getDateEntered(): ?\DateTimeInterface
{
return $this->date_entered;
}
public function setDateEntered(?\DateTimeInterface $date_entered): self
{
$this->date_entered = $date_entered;
return $this;
}
public function getDateModified(): ?\DateTimeInterface
{
return $this->date_modified;
}
public function setDateModified(?\DateTimeInterface $date_modified): self
{
$this->date_modified = $date_modified;
return $this;
}
public function getCreatedBy(): ?User
{
return $this->created_by;
}
public function setCreatedBy(?User $created_by): self
{
$this->created_by = $created_by;
return $this;
}
public function getModifiedUser(): ?User
{
return $this->modified_user;
}
public function setModifiedUser(?User $modified_user): self
{
$this->modified_user = $modified_user;
return $this;
}
public function getStatus(): ?string
{
return $this->status;
}
public function setStatus(?string $status): self
{
$this->status = $status;
return $this;
}
public function getPrice(): ?float
{
return $this->price;
}
public function setPrice(?float $price): self
{
$this->price = $price;
return $this;
}
public function getMeasurmentUnit(): ?MeasurmentUnit
{
return $this->measurment_unit;
}
public function setMeasurmentUnit(?MeasurmentUnit $measurment_unit): self
{
$this->measurment_unit = $measurment_unit;
return $this;
}
/**
* @return Collection<int, Products>
*/
public function getProducts(): Collection
{
return $this->products;
}
public function addProduct(Products $product): self
{
if (!$this->products->contains($product)) {
$this->products->add($product);
$product->setSiteProduct($this);
}
return $this;
}
public function removeProduct(Products $product): self
{
if ($this->products->removeElement($product)) {
// set the owning side to null (unless already changed)
if ($product->getSiteProduct() === $this) {
$product->setSiteProduct(null);
}
}
return $this;
}
/**
* @return Collection<int, Category>
*/
public function getCategory(): Collection
{
return $this->category;
}
public function addCategory(Category $category): static
{
if (!$this->category->contains($category)) {
$this->category->add($category);
}
return $this;
}
public function removeCategory(Category $category): static
{
$this->category->removeElement($category);
return $this;
}
/**
* @return Collection<int, SiteProductsMedia>
*/
public function getSiteProductsMedia(): Collection
{
return $this->siteProductsMedia;
}
public function addSiteProductsMedium(SiteProductsMedia $siteProductsMedium): static
{
if (!$this->siteProductsMedia->contains($siteProductsMedium)) {
$this->siteProductsMedia->add($siteProductsMedium);
$siteProductsMedium->setSiteProduct($this);
}
return $this;
}
public function removeSiteProductsMedium(SiteProductsMedia $siteProductsMedium): static
{
if ($this->siteProductsMedia->removeElement($siteProductsMedium)) {
// set the owning side to null (unless already changed)
if ($siteProductsMedium->getSiteProduct() === $this) {
$siteProductsMedium->setSiteProduct(null);
}
}
return $this;
}
public function getSlug(): ?string
{
return $this->slug;
}
public function setSlug(?string $slug): static
{
$this->slug = $slug;
return $this;
}
public function getMainSiteProductMedia(): ?SiteProductsMedia
{
return $this->mainSiteProductMedia;
}
public function setMainSiteProductMedia(?SiteProductsMedia $mainSiteProductMedia): static
{
$this->mainSiteProductMedia = $mainSiteProductMedia;
return $this;
}
public function getCode1c(): ?string
{
return $this->code1c;
}
public function setCode1c(?string $code1c): static
{
$this->code1c = $code1c;
return $this;
}
/**
* @return Collection<int, UserLikeList>
*/
public function getUserLikeLists(): Collection
{
return $this->userLikeLists;
}
public function addUserLikeList(UserLikeList $userLikeList): static
{
if (!$this->userLikeLists->contains($userLikeList)) {
$this->userLikeLists->add($userLikeList);
$userLikeList->setSiteProduct($this);
}
return $this;
}
public function removeUserLikeList(UserLikeList $userLikeList): static
{
if ($this->userLikeLists->removeElement($userLikeList)) {
// set the owning side to null (unless already changed)
if ($userLikeList->getSiteProduct() === $this) {
$userLikeList->setSiteProduct(null);
}
}
return $this;
}
public function getCategoryCnt(): ?int
{
return $this->categoryCnt;
}
public function setCategoryCnt(?int $categoryCnt): static
{
$this->categoryCnt = $categoryCnt;
return $this;
}
}