320 lines
7.0 KiB
PHP
320 lines
7.0 KiB
PHP
<?php
|
|
|
|
namespace App\Entity;
|
|
|
|
use App\Repository\ProductRepository;
|
|
use Cocur\Slugify\Slugify;
|
|
use Doctrine\Common\Collections\ArrayCollection;
|
|
use Doctrine\Common\Collections\Collection;
|
|
use Doctrine\DBAL\Types\Types;
|
|
use Doctrine\ORM\Mapping as ORM;
|
|
use Symfony\Component\HttpFoundation\File\File;
|
|
use Vich\UploaderBundle\Mapping\Attribute\Uploadable;
|
|
use Vich\UploaderBundle\Mapping\Attribute\UploadableField;
|
|
|
|
#[ORM\Entity(repositoryClass: ProductRepository::class)]
|
|
#[Uploadable]
|
|
class Product
|
|
{
|
|
#[ORM\Id]
|
|
#[ORM\GeneratedValue]
|
|
#[ORM\Column]
|
|
private ?int $id = null;
|
|
|
|
#[ORM\Column(length: 255)]
|
|
private ?string $ref = null;
|
|
|
|
#[ORM\Column(length: 255)]
|
|
private ?string $category = null;
|
|
|
|
#[ORM\Column(length: 255)]
|
|
private ?string $name = null;
|
|
|
|
#[ORM\Column]
|
|
private ?float $priceDay = null;
|
|
|
|
#[ORM\Column]
|
|
private ?float $priceSup = null;
|
|
|
|
#[ORM\Column]
|
|
private ?float $installation = null;
|
|
|
|
#[ORM\Column]
|
|
private ?float $caution = null;
|
|
|
|
|
|
#[UploadableField(mapping: 'image_product', fileNameProperty: 'imageName', size: 'imageSize')]
|
|
private ?File $imageFile = null;
|
|
#[ORM\Column(nullable: true)]
|
|
private ?string $imageName = null;
|
|
|
|
#[ORM\Column(nullable: true)]
|
|
private ?int $imageSize = null;
|
|
|
|
#[ORM\Column(nullable: true)]
|
|
private ?\DateTimeImmutable $updatedAt = null;
|
|
|
|
#[ORM\Column(length: 255, nullable: true)]
|
|
private ?string $productId = null;
|
|
|
|
/**
|
|
* @var Collection<int, DevisLine>
|
|
*/
|
|
#[ORM\OneToMany(targetEntity: DevisLine::class, mappedBy: 'product')]
|
|
private Collection $devisLines;
|
|
|
|
/**
|
|
* @var Collection<int, ProductReserve>
|
|
*/
|
|
#[ORM\OneToMany(targetEntity: ProductReserve::class, mappedBy: 'product')]
|
|
private Collection $productReserves;
|
|
|
|
#[ORM\Column(type: Types::TEXT, nullable: true)]
|
|
private ?string $description = null;
|
|
|
|
#[ORM\Column(nullable: true)]
|
|
private ?int $qt = null;
|
|
|
|
public function __construct()
|
|
{
|
|
$this->devisLines = new ArrayCollection();
|
|
$this->productReserves = new ArrayCollection();
|
|
}
|
|
public function slug()
|
|
{
|
|
$s = new Slugify();
|
|
|
|
return$s->slugify($this->id."-".$this->name);
|
|
}
|
|
|
|
public function json()
|
|
{
|
|
return json_encode([
|
|
'id' => $this->id,
|
|
'ref' => $this->ref,
|
|
'name' => $this->name,
|
|
]);
|
|
}
|
|
|
|
public function getId(): ?int
|
|
{
|
|
return $this->id;
|
|
}
|
|
|
|
public function getRef(): ?string
|
|
{
|
|
return $this->ref;
|
|
}
|
|
|
|
public function setRef(string $ref): static
|
|
{
|
|
$this->ref = $ref;
|
|
|
|
return $this;
|
|
}
|
|
|
|
public function getCategory(): ?string
|
|
{
|
|
return $this->category;
|
|
}
|
|
|
|
public function setCategory(string $category): static
|
|
{
|
|
$this->category = $category;
|
|
|
|
return $this;
|
|
}
|
|
|
|
public function getName(): ?string
|
|
{
|
|
return $this->name;
|
|
}
|
|
|
|
public function setName(string $name): static
|
|
{
|
|
$this->name = $name;
|
|
|
|
return $this;
|
|
}
|
|
|
|
public function getPriceDay(): ?float
|
|
{
|
|
return $this->priceDay;
|
|
}
|
|
|
|
public function setPriceDay(float $priceDay): static
|
|
{
|
|
$this->priceDay = $priceDay;
|
|
|
|
return $this;
|
|
}
|
|
|
|
public function getPriceSup(): ?float
|
|
{
|
|
return $this->priceSup;
|
|
}
|
|
|
|
public function setPriceSup(float $priceSup): static
|
|
{
|
|
$this->priceSup = $priceSup;
|
|
|
|
return $this;
|
|
}
|
|
|
|
public function getInstallation(): ?float
|
|
{
|
|
return $this->installation;
|
|
}
|
|
|
|
public function setInstallation(float $installation): static
|
|
{
|
|
$this->installation = $installation;
|
|
|
|
return $this;
|
|
}
|
|
|
|
public function getCaution(): ?float
|
|
{
|
|
return $this->caution;
|
|
}
|
|
|
|
public function setCaution(float $caution): static
|
|
{
|
|
$this->caution = $caution;
|
|
|
|
return $this;
|
|
}
|
|
|
|
public function setImageFile(?File $imageFile = null): void
|
|
{
|
|
$this->imageFile = $imageFile;
|
|
|
|
if (null !== $imageFile) {
|
|
// It is required that at least one field changes if you are using doctrine
|
|
// otherwise the event listeners won't be called and the file is lost
|
|
$this->updatedAt = new \DateTimeImmutable();
|
|
}
|
|
}
|
|
|
|
public function getImageFile(): ?File
|
|
{
|
|
return $this->imageFile;
|
|
}
|
|
|
|
public function setImageName(?string $imageName): void
|
|
{
|
|
$this->imageName = $imageName;
|
|
}
|
|
|
|
public function getImageName(): ?string
|
|
{
|
|
return $this->imageName;
|
|
}
|
|
|
|
public function setImageSize(?int $imageSize): void
|
|
{
|
|
$this->imageSize = $imageSize;
|
|
}
|
|
|
|
public function getImageSize(): ?int
|
|
{
|
|
return $this->imageSize;
|
|
}
|
|
|
|
public function getProductId(): ?string
|
|
{
|
|
return $this->productId;
|
|
}
|
|
|
|
public function setProductId(?string $productId): static
|
|
{
|
|
$this->productId = $productId;
|
|
|
|
return $this;
|
|
}
|
|
|
|
/**
|
|
* @return Collection<int, DevisLine>
|
|
*/
|
|
public function getDevisLines(): Collection
|
|
{
|
|
return $this->devisLines;
|
|
}
|
|
|
|
public function addDevisLine(DevisLine $devisLine): static
|
|
{
|
|
if (!$this->devisLines->contains($devisLine)) {
|
|
$this->devisLines->add($devisLine);
|
|
$devisLine->setProduct($this);
|
|
}
|
|
|
|
return $this;
|
|
}
|
|
|
|
public function removeDevisLine(DevisLine $devisLine): static
|
|
{
|
|
if ($this->devisLines->removeElement($devisLine)) {
|
|
// set the owning side to null (unless already changed)
|
|
if ($devisLine->getProduct() === $this) {
|
|
$devisLine->setProduct(null);
|
|
}
|
|
}
|
|
|
|
return $this;
|
|
}
|
|
|
|
/**
|
|
* @return Collection<int, ProductReserve>
|
|
*/
|
|
public function getProductReserves(): Collection
|
|
{
|
|
return $this->productReserves;
|
|
}
|
|
|
|
public function addProductReserf(ProductReserve $productReserf): static
|
|
{
|
|
if (!$this->productReserves->contains($productReserf)) {
|
|
$this->productReserves->add($productReserf);
|
|
$productReserf->setProduct($this);
|
|
}
|
|
|
|
return $this;
|
|
}
|
|
|
|
public function removeProductReserf(ProductReserve $productReserf): static
|
|
{
|
|
if ($this->productReserves->removeElement($productReserf)) {
|
|
// set the owning side to null (unless already changed)
|
|
if ($productReserf->getProduct() === $this) {
|
|
$productReserf->setProduct(null);
|
|
}
|
|
}
|
|
|
|
return $this;
|
|
}
|
|
|
|
public function getDescription(): ?string
|
|
{
|
|
return $this->description;
|
|
}
|
|
|
|
public function setDescription(?string $description): static
|
|
{
|
|
$this->description = $description;
|
|
|
|
return $this;
|
|
}
|
|
|
|
public function getQt(): ?int
|
|
{
|
|
return $this->qt;
|
|
}
|
|
|
|
public function setQt(?int $qt): static
|
|
{
|
|
$this->qt = $qt;
|
|
|
|
return $this;
|
|
}
|
|
}
|