<?php
namespace App\Entity;
use App\Traits\Activeable;
use App\Traits\Creatable;
use App\Traits\Deleteable;
use App\Traits\Sortable;
use App\Traits\Updateable;
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\Common\Collections\Collection;
use Doctrine\ORM\Mapping as ORM;
use Gedmo\Mapping\Annotation as Gedmo;
use Symfony\Bridge\Doctrine\Validator\Constraints\UniqueEntity;
/**
* @ORM\Table(name="`product`")
* @ORM\Entity(repositoryClass="App\Repository\ProductRepository")
* @Gedmo\SoftDeleteable(fieldName="deletedAt")
* @UniqueEntity("reference")
*/
class Product
{
use Creatable, Updateable, Deleteable, Activeable, Sortable;
const PRODUCT_REF_PAQRC = 'paqrc';
const PRODUCT_REF_SF = 'SF';
const PRODUCT_REF_MF = 'MF';
/**
* @ORM\Id
* @ORM\Column(type="integer")
* @ORM\GeneratedValue(strategy="AUTO")
*/
private ?int $id = null;
/**
* @var string
*
* @ORM\Column(name="name", type="string")
*/
private string $name;
/**
* @var string
*
* @ORM\Column(name="reference", type="string", unique=true)
*/
private string $reference;
/**
* @var ?string
*
* @ORM\Column(type="text", nullable=true)
*/
private ?string $description = null;
/**
* @var ?string
*
* @ORM\Column(name="carrier_algorithm", type="text", nullable=true)
*/
private ?string $carrierAlgorithm = null;
/**
* @var ?string
*
* @ORM\Column(name="carrier_algorithm_supplier", type="text", nullable=true)
*/
private ?string $carrierAlgorithmSupplier = null;
/**
* @var boolean
*
* @ORM\Column(name="show_qr_code_letter", type="boolean")
*/
private bool $showQrCodeLetter;
/**
* @ORM\ManyToOne(targetEntity="App\Entity\CategoryType")
* @ORM\JoinColumn(name="category_type_id", referencedColumnName="id")
*/
private ?CategoryType $categoryType = null;
/**
* @ORM\ManyToOne(targetEntity="App\Entity\Tax")
*/
private ?Tax $tax = null;
/**
* @var integer
*
* @ORM\Column(name="making_price_ht", type="integer")
*/
private int $makingPriceHt;
/**
* @var boolean
*
* @ORM\Column(type="boolean")
*/
private bool $oldBuilder;
/**
* @ORM\ManyToOne(targetEntity="App\Entity\File")
*/
private ?File $file = null;
/**
* @ORM\ManyToMany(targetEntity="App\Entity\Category", inversedBy="products")
*/
private Collection $categories;
/**
* @ORM\ManyToMany(targetEntity="App\Entity\ModelCategory", inversedBy="products")
*/
private Collection $modelCategories;
/**
* @ORM\ManyToMany(targetEntity="Attribut")
*/
private Collection $attributs;
/**
* @ORM\OneToMany(targetEntity="App\Entity\ProductStep", mappedBy="product")
* @ORM\OrderBy({"position" = "ASC"})
*/
private Collection $productSteps;
/**
* @ORM\OneToMany(targetEntity="App\Entity\ProductFeature", mappedBy="product")
* @ORM\OrderBy({"position" = "ASC"})
*/
private Collection $productFeatures;
/**
* @ORM\OneToMany(targetEntity="App\Entity\ProductPrice", mappedBy="product")
* @ORM\OrderBy({"quantity" = "ASC"})
*/
private Collection $productPrices;
/**
* @ORM\OneToMany(targetEntity="App\Entity\ProductMenuMaker", mappedBy="product")
*/
private Collection $productMenuMakers;
/**
* @ORM\ManyToMany(targetEntity="App\Entity\ComponentCategory", inversedBy="products")
*/
private Collection $componentCategories;
/**
* @ORM\ManyToMany(targetEntity="App\Entity\Component", inversedBy="products")
*/
private Collection $favoriteComponents;
/**
* @ORM\ManyToMany(targetEntity="App\Entity\IngredientCategory", inversedBy="products")
*/
private Collection $ingredientCategories;
/**
* @ORM\ManyToMany(targetEntity="App\Entity\Folder")
*/
private Collection $folders;
/**
* @ORM\ManyToMany(targetEntity="App\Entity\Folder")
* @ORM\JoinTable(name="`product_background`")
*/
private Collection $backgrounds;
/**
* @var boolean
*
* @ORM\Column(type="boolean")
*/
private bool $isFullyEditable;
/**
* @var array
*/
private array $categoryPaths;
public function __construct()
{
$this->active = false;
$this->modelCategories = new ArrayCollection();
$this->attributs = new ArrayCollection();
$this->categoryPaths = [];
$this->productSteps = new ArrayCollection();
$this->categories = new ArrayCollection();
$this->productFeatures = new ArrayCollection();
$this->productPrices = new ArrayCollection();
$this->productMenuMakers = new ArrayCollection();
$this->componentCategories = new ArrayCollection();
$this->folders = new ArrayCollection();
$this->backgrounds = new ArrayCollection();
$this->ingredientCategories = new ArrayCollection();
$this->favoriteComponents = new ArrayCollection();
$this->showQrCodeLetter = true;
$this->makingPriceHt = 0;
$this->isFullyEditable = false;
}
public function __clone()
{
$this->id = null;
$this->name .= ' - Copie';
$this->reference .= '-copie';
$this->active = false;
$this->modelCategories = new ArrayCollection();
$this->attributs = new ArrayCollection();
$this->productSteps = new ArrayCollection();
$this->categories = new ArrayCollection();
$this->productFeatures = new ArrayCollection();
$this->productPrices = new ArrayCollection();
$this->productMenuMakers = new ArrayCollection();
$this->componentCategories = new ArrayCollection();
$this->folders = 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 getReference(): ?string
{
return $this->reference;
}
public function setReference(string $reference): self
{
$this->reference = $reference;
return $this;
}
public function getDescription(): ?string
{
return $this->description;
}
public function setDescription(?string $description): self
{
$this->description = $description;
return $this;
}
public function getCarrierAlgorithm(): ?string
{
return $this->carrierAlgorithm;
}
public function setCarrierAlgorithm(?string $carrierAlgorithm): self
{
$this->carrierAlgorithm = $carrierAlgorithm;
return $this;
}
public function getCarrierAlgorithmSupplier(): ?string
{
return $this->carrierAlgorithmSupplier;
}
public function setCarrierAlgorithmSupplier(?string $carrierAlgorithmSupplier): self
{
$this->carrierAlgorithmSupplier = $carrierAlgorithmSupplier;
return $this;
}
public function getTax(): ?Tax
{
return $this->tax;
}
public function setTax(?Tax $tax): self
{
$this->tax = $tax;
return $this;
}
public function getFile(): ?File
{
return $this->file;
}
public function setFile(?File $file): self
{
$this->file = $file;
return $this;
}
/**
* @return Collection|Category[]
*/
public function getCategories(): Collection
{
return $this->categories;
}
public function addCategory(Category $category): self
{
if (!$this->categories->contains($category)) {
$this->categories[] = $category;
}
return $this;
}
public function removeCategory(Category $category): self
{
if ($this->categories->contains($category)) {
$this->categories->removeElement($category);
}
return $this;
}
/**
* @return Collection|ModelCategory[]
*/
public function getModelCategories(): Collection
{
return $this->modelCategories;
}
public function addModelCategory(ModelCategory $modelCategory): self
{
if (!$this->modelCategories->contains($modelCategory)) {
$this->modelCategories[] = $modelCategory;
}
return $this;
}
public function removeModelCategory(ModelCategory $modelCategory): self
{
if ($this->modelCategories->contains($modelCategory)) {
$this->modelCategories->removeElement($modelCategory);
}
return $this;
}
/**
* @return Collection|Attribut[]
*/
public function getAttributs(): Collection
{
return $this->attributs;
}
public function addAttribut(Attribut $attribut): self
{
if (!$this->attributs->contains($attribut)) {
$this->attributs[] = $attribut;
}
return $this;
}
public function removeAttribut(Attribut $attribut): self
{
if ($this->attributs->contains($attribut)) {
$this->attributs->removeElement($attribut);
}
return $this;
}
/**
* @return Collection|ProductStep[]
*/
public function getProductSteps(): Collection
{
return $this->productSteps;
}
public function addProductStep(ProductStep $productStep): self
{
if (!$this->productSteps->contains($productStep)) {
$this->productSteps[] = $productStep;
$productStep->setProduct($this);
}
return $this;
}
public function removeProductStep(ProductStep $productStep): self
{
if ($this->productSteps->contains($productStep)) {
$this->productSteps->removeElement($productStep);
// set the owning side to null (unless already changed)
if ($productStep->getProduct() === $this) {
$productStep->setProduct(null);
}
}
return $this;
}
/**
* @return Collection|ProductFeature[]
*/
public function getProductFeatures(): Collection
{
return $this->productFeatures;
}
public function addProductFeature(ProductFeature $productFeature): self
{
if (!$this->productFeatures->contains($productFeature)) {
$this->productFeatures[] = $productFeature;
$productFeature->setProduct($this);
}
return $this;
}
public function removeProductFeature(ProductFeature $productFeature): self
{
if ($this->productFeatures->contains($productFeature)) {
$this->productFeatures->removeElement($productFeature);
// set the owning side to null (unless already changed)
if ($productFeature->getProduct() === $this) {
$productFeature->setProduct(null);
}
}
return $this;
}
/**
* @return Collection|ProductMenuMaker[]
*/
public function getProductMenuMakers(): Collection
{
return $this->productMenuMakers;
}
public function addProductMenuMaker(ProductMenuMaker $productMenuMaker): self
{
if (!$this->productMenuMakers->contains($productMenuMaker)) {
$this->productMenuMakers[] = $productMenuMaker;
$productMenuMaker->setProduct($this);
}
return $this;
}
public function removeProductMenuMaker(ProductMenuMaker $productMenuMaker): self
{
if ($this->productMenuMakers->contains($productMenuMaker)) {
$this->productMenuMakers->removeElement($productMenuMaker);
// set the owning side to null (unless already changed)
if ($productMenuMaker->getProduct() === $this) {
$productMenuMaker->setProduct(null);
}
}
return $this;
}
/**
* @return Collection|ComponentCategory[]
*/
public function getComponentCategories(): Collection
{
return $this->componentCategories;
}
public function addComponentCategory(ComponentCategory $componentCategory): self
{
if (!$this->componentCategories->contains($componentCategory)) {
$this->componentCategories[] = $componentCategory;
}
return $this;
}
public function removeComponentCategory(ComponentCategory $componentCategory): self
{
if ($this->componentCategories->contains($componentCategory)) {
$this->componentCategories->removeElement($componentCategory);
}
return $this;
}
/**
* @return Collection|IngredientCategory[]
*/
public function getIngredientCategories(): Collection
{
return $this->ingredientCategories;
}
public function addIngredientCategory(IngredientCategory $ingredientCategory): self
{
if (!$this->ingredientCategories->contains($ingredientCategory)) {
$this->ingredientCategories[] = $ingredientCategory;
}
return $this;
}
public function removeIngredientCategory(IngredientCategory $ingredientCategory): self
{
if ($this->ingredientCategories->contains($ingredientCategory)) {
$this->ingredientCategories->removeElement($ingredientCategory);
}
return $this;
}
/**
* @return Collection|Folder[]
*/
public function getFolders(): Collection
{
return $this->folders;
}
public function addFolder(Folder $folder): self
{
if (!$this->folders->contains($folder)) {
$this->folders[] = $folder;
}
return $this;
}
public function removeFolder(Folder $folder): self
{
if ($this->folders->contains($folder)) {
$this->folders->removeElement($folder);
}
return $this;
}
/**
* @return Collection|Folder[]
*/
public function getBackgrounds(): Collection
{
return $this->backgrounds;
}
public function addBackground(Folder $background): self
{
if (!$this->backgrounds->contains($background)) {
$this->backgrounds[] = $background;
}
return $this;
}
public function removeBackground(Folder $background): self
{
if ($this->backgrounds->contains($background)) {
$this->backgrounds->removeElement($background);
}
return $this;
}
public function setCategoryPaths(array $path)
{
$this->categoryPaths = $path;
}
public function getCategoryPaths()
{
return $this->categoryPaths;
}
/**
* @return Collection|Attribut[]
*/
public function getAttributValids(): Collection
{
$attributs = new ArrayCollection();
/** @var Attribut $attribut */
foreach ($this->attributs as $attribut) {
if ($attribut->getAttributValueActives()->count() > 0) {
if (!$attributs->contains($attribut)) {
$attributs->add($attribut);
}
}
}
return $attributs;
}
/**
* @return bool
*/
public function hasProductPriceActive()
{
$productPriceActive = false;
/** @var ProductPrice $productPrice */
foreach ($this->productPrices as $productPrice) {
if ($productPrice->isActive()) {
$productPriceActive = true;
break;
}
}
return $productPriceActive;
}
/**
* @return bool
*/
public function isCustomizable()
{
$isCustomizable = false;
/** @var ProductFeature $productFeature */
foreach ($this->productFeatures as $productFeature) {
if ($productFeature->getFeature()->getFeatureFamily()->getConstName() == FeatureFamily::CUSTOMIZABLE) {
$isCustomizable = true;
break;
}
}
return $isCustomizable;
}
/**
* @return bool
*/
public function isPrintable()
{
$isPrintable = false;
/** @var ProductFeature $productFeature */
foreach ($this->productFeatures as $productFeature) {
if ($productFeature->getFeature()->getFeatureFamily()->getConstName() == FeatureFamily::PRINTABLE) {
$isPrintable = true;
break;
}
}
return $isPrintable;
}
/**
* @return bool
*/
public function isClassic()
{
$isCustomizable = false;
/** @var ProductFeature $productFeature */
foreach ($this->productFeatures as $productFeature) {
if ($productFeature->getFeature()->getFeatureFamily()->getConstName() == FeatureFamily::CLASSIC) {
$isCustomizable = true;
break;
}
}
return $isCustomizable;
}
/**
* @return ProductFeature[]
*/
public function getProductFeaturesIndexed()
{
$productFeatures = [];
foreach ($this->getProductFeatures() as $productFeature) {
$productFeatures[$productFeature->getFeature()->getId()] = $productFeature;
}
return $productFeatures;
}
/**
* @return ProductPrice|null
*/
public function getMinProductPrice()
{
$minProductPrice = null;
foreach ($this->getProductPrices() as $productPrice) {
if (is_null($minProductPrice)) {
$minProductPrice = $productPrice;
}
if ($productPrice->getPriceHt() < $minProductPrice->getPriceHt()) {
$minProductPrice = $productPrice;
}
}
return $minProductPrice;
}
/**
* @return Collection|Component[]
*/
public function getFavoriteComponents(): Collection
{
return $this->favoriteComponents;
}
public function addFavoriteComponent(Component $favoriteComponent): self
{
if (!$this->favoriteComponents->contains($favoriteComponent)) {
$this->favoriteComponents[] = $favoriteComponent;
}
return $this;
}
public function removeFavoriteComponent(Component $favoriteComponent): self
{
if ($this->favoriteComponents->contains($favoriteComponent)) {
$this->favoriteComponents->removeElement($favoriteComponent);
}
return $this;
}
public function getShowQrCodeLetter(): ?bool
{
return $this->showQrCodeLetter;
}
public function setShowQrCodeLetter(bool $showQrCodeLetter): self
{
$this->showQrCodeLetter = $showQrCodeLetter;
return $this;
}
public function getCategoryType(): ?CategoryType
{
return $this->categoryType;
}
public function setCategoryType(?CategoryType $categoryType): self
{
$this->categoryType = $categoryType;
return $this;
}
public function getMakingPriceHt(): ?int
{
return $this->makingPriceHt;
}
public function setMakingPriceHt(int $makingPriceHt): self
{
$this->makingPriceHt = $makingPriceHt;
return $this;
}
public function isShowQrCodeLetter(): ?bool
{
return $this->showQrCodeLetter;
}
public function isOldBuilder(): ?bool
{
return $this->oldBuilder;
}
public function setOldBuilder(bool $oldBuilder): static
{
$this->oldBuilder = $oldBuilder;
return $this;
}
public function isFullyEditable(): ?bool
{
return $this->isFullyEditable;
}
public function setIsFullyEditable(bool $isFullyEditable): static
{
$this->isFullyEditable = $isFullyEditable;
return $this;
}
public function isIsFullyEditable(): ?bool
{
return $this->isFullyEditable;
}
/**
* @return Collection<int, ProductPrice>
*/
public function getProductPrices(): Collection
{
return $this->productPrices;
}
public function addProductPrice(ProductPrice $productPrice): static
{
if (!$this->productPrices->contains($productPrice)) {
$this->productPrices->add($productPrice);
$productPrice->setProduct($this);
}
return $this;
}
public function removeProductPrice(ProductPrice $productPrice): static
{
if ($this->productPrices->removeElement($productPrice)) {
// set the owning side to null (unless already changed)
if ($productPrice->getProduct() === $this) {
$productPrice->setProduct(null);
}
}
return $this;
}
}