<?php
namespace App\Entity;
use App\Repository\ProductRepository;
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\Common\Collections\Collection;
use Doctrine\ORM\Mapping as ORM;
/**
* @ORM\Entity(repositoryClass=ProductRepository::class)
*/
class Product
{
/**
* @ORM\Id
* @ORM\GeneratedValue
* @ORM\Column(type="integer")
*/
private $id;
/**
* @ORM\Column(type="string", length=255)
*/
private $title;
/**
* @ORM\Column(type="decimal", precision=10, scale=2)
*/
private $priceHt = 0.00; // default value
/**
* @ORM\Column(type="integer")
*/
private $stock;
/**
* @ORM\Column(type="text")
*/
private $desctription;
/**
* @ORM\Column(type="string", length=255)
*/
private $picture;
/**
* @ORM\Column(type="string", length=255, nullable=true)
*/
private $linkspictures;
/**
* @ORM\ManyToOne(targetEntity=UserPlatform::class)
* @ORM\JoinColumn(nullable=false)
*/
private $userAdd;
/**
* @ORM\ManyToOne(targetEntity=CategoriProduct::class)
* @ORM\JoinColumn(nullable=false)
*/
private $fkcategorie;
/**
* @ORM\ManyToOne(targetEntity=SousCategorie::class)
*/
private $fksousCategorie;
/**
* @ORM\ManyToOne(targetEntity=Devise::class)
*/
private $fkdevise;
/**
* @ORM\ManyToOne(targetEntity=Shop::class)
*/
private $shop;
/**
* @ORM\OneToMany(targetEntity=PriceProduct::class, mappedBy="product")
*/
private $priceProducts;
/**
* @ORM\Column(type="integer")
*/
private $statdispo;
/**
* @ORM\Column(type="integer")
*/
private $stateval = 1;
/**
* @ORM\Column(type="integer")
*/
private $statetype;
/**
* @ORM\Column(type="json", nullable=true)
*/
private ?array $statetypes = null;
/**
* @ORM\Column(type="integer")
*/
private $points;
/**
* @ORM\Column(type="integer")
*/
private int $searchCount = 0;
/**
* @ORM\OneToMany(targetEntity=Stock::class, mappedBy="produit")
*/
private $stocks;
/**
* @ORM\Column(type="text", nullable=true)
*/
private $keyWord;
/**
* @ORM\Column(type="json", nullable=true)
*/
private ?array $modules = [];
/**
* @ORM\Column(type="boolean")
*/
private bool $enabled = true;
/**
* @ORM\OneToMany(targetEntity=Location::class, mappedBy="product")
*/
private $locations;
/**
* @ORM\OneToMany(targetEntity=FreelanceStock::class, mappedBy="produit")
*/
private $freelanceStocks;
/**
* @ORM\OneToMany(targetEntity=HistoriqueTransactionFreelance::class, mappedBy="produit")
*/
private $historiqueTransactions;
public function __construct()
{
$this->priceProducts = new ArrayCollection();
$this->stocks = new ArrayCollection();
$this->locations = new ArrayCollection();
$this->freelanceStocks = new ArrayCollection();
$this->historiqueTransactions = new ArrayCollection();
}
public function getId(): ?int
{
return $this->id;
}
public function getTitle(): ?string
{
return $this->title;
}
public function setTitle(string $title): self
{
$this->title = $title;
return $this;
}
public function getPriceHt(): ?string
{
return $this->priceHt;
}
public function setPriceHt(string $priceHt): self
{
$this->priceHt = $priceHt;
return $this;
}
public function getStock(): ?int
{
return $this->stock;
}
public function setStock(int $stock): self
{
$this->stock = $stock;
return $this;
}
public function getDesctription(): ?string
{
return $this->desctription;
}
public function setDesctription(string $desctription): self
{
$this->desctription = $desctription;
return $this;
}
public function getPicture(): ?string
{
return $this->picture;
}
public function setPicture(string $picture): self
{
$this->picture = $picture;
return $this;
}
public function getLinkspictures(): ?string
{
return $this->linkspictures;
}
public function getLinkspicturesArrays(): ?array
{
$typevalue = gettype(json_decode($this->linkspictures));
if(gettype(json_decode($this->linkspictures)) == "array"){
return json_decode($this->linkspictures);
} else return null;
}
public function setLinkspictures(?string $linkspictures): self
{
$this->linkspictures = $linkspictures;
return $this;
}
public function getUserAdd(): ?UserPlatform
{
return $this->userAdd;
}
public function setUserAdd(?UserPlatform $userAdd): self
{
$this->userAdd = $userAdd;
return $this;
}
public function getFkcategorie(): ?CategoriProduct
{
return $this->fkcategorie;
}
public function setFkcategorie(?CategoriProduct $fkcategorie): self
{
$this->fkcategorie = $fkcategorie;
return $this;
}
public function getFksousCategorie(): ?SousCategorie
{
return $this->fksousCategorie;
}
public function setFksousCategorie(?SousCategorie $fksousCategorie): self
{
$this->fksousCategorie = $fksousCategorie;
return $this;
}
public function getFkdevise(): ?Devise
{
return $this->fkdevise;
}
public function setFkdevise(?Devise $fkdevise): self
{
$this->fkdevise = $fkdevise;
return $this;
}
public function getShop(): ?Shop
{
return $this->shop;
}
public function setShop(?Shop $shop): self
{
$this->shop = $shop;
return $this;
}
/**
* @return Collection<int, PriceProduct>
*/
public function getPriceProducts(): Collection
{
return $this->priceProducts;
}
public function addPriceProduct(PriceProduct $priceProduct): self
{
if (!$this->priceProducts->contains($priceProduct)) {
$this->priceProducts[] = $priceProduct;
$priceProduct->setProduct($this);
}
return $this;
}
public function removePriceProduct(PriceProduct $priceProduct): self
{
if ($this->priceProducts->removeElement($priceProduct)) {
// set the owning side to null (unless already changed)
if ($priceProduct->getProduct() === $this) {
$priceProduct->setProduct(null);
}
}
return $this;
}
public function getStatdispo(): ?int
{
return $this->statdispo;
}
public function setStatdispo(int $statdispo): self
{
$this->statdispo = $statdispo;
return $this;
}
public function getStateval(): ?int
{
return $this->stateval;
}
public function setStateval(int $stateval): self
{
$this->stateval = $stateval;
return $this;
}
public function getStatetype(): ?int
{
return $this->statetype;
}
public function setStatetype(int $statetype): self
{
$this->statetype = $statetype;
return $this;
}
/**
* @return int[]
*/
public function getStatetypes(): array
{
if (!empty($this->statetypes)) {
return array_map('intval', $this->statetypes);
}
return $this->statetype !== null ? [(int) $this->statetype] : [0];
}
/**
* @param int[]|null $statetypes
*/
public function setStatetypes(?array $statetypes): self
{
$statetypes = array_values(array_unique(array_map('intval', $statetypes ?? [])));
$this->statetypes = $statetypes ?: [0];
// Compatibilité avec les anciens traitements qui utilisent encore statetype.
$this->statetype = in_array(0, $this->statetypes, true) ? 0 : 1;
return $this;
}
/**
* @return string[]
*/
public function getStatetypeLabels(): array
{
$labels = [];
foreach ($this->getStatetypes() as $statetype) {
if ($statetype === 0) {
$labels[] = 'Abonnement';
} elseif ($statetype === 1) {
$labels[] = 'Achat licence';
}
}
return $labels;
}
public function getPoints(): ?int
{
return $this->points;
}
public function setPoints(int $points): self
{
$this->points = $points;
return $this;
}
/**
* @return Collection<int, Stock>
*/
public function getStocks(): Collection
{
return $this->stocks;
}
public function addStock(Stock $stock): self
{
if (!$this->stocks->contains($stock)) {
$this->stocks[] = $stock;
$stock->setProduit($this);
}
return $this;
}
public function removeStock(Stock $stock): self
{
if ($this->stocks->removeElement($stock)) {
// set the owning side to null (unless already changed)
if ($stock->getProduit() === $this) {
$stock->setProduit(null);
}
}
return $this;
}
public function getKeyWord(): ?string
{
return $this->keyWord;
}
public function setKeyWord(?string $keyWord): self
{
$this->keyWord = $keyWord;
return $this;
}
/**
* @return string[]
*/
public function getModules(): array
{
return !empty($this->modules) ? $this->modules : [''];
}
/**
* @param string[]|null $modules
*/
public function setModules(?array $modules): self
{
$this->modules = array_values(array_filter($modules ?? [], static function ($module): bool {
return trim((string) $module) !== '';
}));
return $this;
}
/**
* @return string[]
*/
public function getModulesForDisplay(): array
{
return array_values(array_filter($this->modules ?? [], static function ($module): bool {
return trim((string) $module) !== '';
}));
}
public function isEnabled(): bool
{
return $this->enabled;
}
public function setEnabled(bool $enabled): self
{
$this->enabled = $enabled;
return $this;
}
/* Statistics*/
public function getSearchCount(): int
{
return $this->searchCount;
}
public function setSearchCount(int $searchCount): self
{
$this->searchCount = $searchCount;
return $this;
}
public function incrementSearchCount(): self
{
$this->searchCount++;
return $this;
}
/**
* @return Collection<int, Location>
*/
public function getLocations(): Collection
{
return $this->locations;
}
public function addLocation(Location $location): self
{
if (!$this->locations->contains($location)) {
$this->locations[] = $location;
$location->setProduct($this);
}
return $this;
}
public function removeLocation(Location $location): self
{
if ($this->locations->removeElement($location)) {
// set the owning side to null (unless already changed)
if ($location->getProduct() === $this) {
$location->setProduct(null);
}
}
return $this;
}
/**
* @return Collection<int, FreelanceStock>
*/
public function getFreelanceStocks(): Collection
{
return $this->freelanceStocks;
}
public function addFreelanceStock(FreelanceStock $freelanceStock): self
{
if (!$this->freelanceStocks->contains($freelanceStock)) {
$this->freelanceStocks[] = $freelanceStock;
$freelanceStock->setProduit($this);
}
return $this;
}
public function removeFreelanceStock(FreelanceStock $freelanceStock): self
{
if ($this->freelanceStocks->removeElement($freelanceStock)) {
if ($freelanceStock->getProduit() === $this) {
$freelanceStock->setProduit(null);
}
}
return $this;
}
/**
* @return Collection<int, HistoriqueTransactionFreelance>
*/
public function getHistoriqueTransactions(): Collection
{
return $this->historiqueTransactions;
}
public function addHistoriqueTransaction(HistoriqueTransactionFreelance $historiqueTransaction): self
{
if (!$this->historiqueTransactions->contains($historiqueTransaction)) {
$this->historiqueTransactions[] = $historiqueTransaction;
$historiqueTransaction->setProduit($this);
}
return $this;
}
public function removeHistoriqueTransaction(HistoriqueTransactionFreelance $historiqueTransaction): self
{
if ($this->historiqueTransactions->removeElement($historiqueTransaction)) {
if ($historiqueTransaction->getProduit() === $this) {
$historiqueTransaction->setProduit(null);
}
}
return $this;
}
}