<?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;
#[ORM\Entity(repositoryClass: SiteProductsRepository::class)]
#[ApiResource(
operations: [
new Get(),
new Post(),
new Delete(),
new GetCollection(),
new Put(),
new Patch()
],
normalizationContext: ['groups' => ['read']],
denormalizationContext: ['groups' => ['write']],
order: ['id' => 'DESC'],
paginationPartial: true
)]
class SiteProducts
{
#[ORM\Id]
#[ORM\GeneratedValue]
#[ORM\Column]
#[Groups(['read', 'write'])]
private ?int $id = null;
#[Groups(['read', 'write'])]
#[ORM\Column(length: 255, nullable: true)]
private ?string $name = null;
#[Groups(['read', 'write'])]
#[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(['read', 'write'])]
#[ORM\Column(length: 100, nullable: true)]
private ?string $status = null;
#[Groups(['read', 'write'])]
#[ORM\Column(nullable: true)]
private ?float $price = null;
#[Groups(['read', 'write'])]
#[ORM\ManyToOne(inversedBy: 'siteProducts')]
private ?MeasurmentUnit $measurment_unit = null;
#[Groups(['read', 'write'])]
#[ORM\OneToMany(mappedBy: 'site_product', targetEntity: Products::class)]
#[ApiProperty(writable: true)]
private Collection $products;
public function __construct()
{
$this->products = 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;
}
}