src/Entity/Product.php line 235

Open in your IDE?
  1. <?php
  2. namespace App\Entity;
  3. use App\Repository\ProductRepository;
  4. use Doctrine\Common\Collections\ArrayCollection;
  5. use Doctrine\Common\Collections\Collection;
  6. use Doctrine\ORM\Mapping as ORM;
  7. /**
  8.  * @ORM\Entity(repositoryClass=ProductRepository::class)
  9.  */
  10. class Product
  11. {
  12.     /**
  13.      * @ORM\Id
  14.      * @ORM\GeneratedValue
  15.      * @ORM\Column(type="integer")
  16.      */
  17.     private $id;
  18.     /**
  19.      * @ORM\Column(type="string", length=255)
  20.      */
  21.     private $title; 
  22.     /**
  23.      * @ORM\Column(type="decimal", precision=10, scale=2)
  24.      */
  25.     private $priceHt = 0.00; // default value
  26.     /**
  27.      * @ORM\Column(type="integer")
  28.      */
  29.     private $stock = 0;
  30.     /**
  31.      * @ORM\Column(type="text")
  32.      */
  33.     private $desctription;
  34.     /**
  35.      * @ORM\Column(type="string", length=255)
  36.      */
  37.     private $picture;
  38.     /**
  39.      * @ORM\Column(type="string", length=255, nullable=true)
  40.      */
  41.     private $linkspictures;
  42.     /**
  43.      * @ORM\ManyToOne(targetEntity=UserPlatform::class)
  44.      * @ORM\JoinColumn(nullable=false)
  45.      */
  46.     private $userAdd;
  47.     /**
  48.      * @ORM\ManyToOne(targetEntity=CategoriProduct::class)
  49.      * @ORM\JoinColumn(nullable=false)
  50.      */
  51.     private $fkcategorie;
  52.     /**
  53.      * @ORM\ManyToOne(targetEntity=SousCategorie::class)
  54.      */
  55.     private $fksousCategorie;
  56.     /**
  57.      * @ORM\ManyToOne(targetEntity=Devise::class)
  58.      */
  59.     private $fkdevise;
  60.     /**
  61.      * @ORM\ManyToOne(targetEntity=Shop::class)
  62.      */
  63.     private $shop;
  64.     /**
  65.      * @ORM\OneToMany(targetEntity=PriceProduct::class, mappedBy="product")
  66.      */
  67.     private $priceProducts;
  68.     /**
  69.      * @ORM\Column(type="integer")
  70.      */
  71.     private $statdispo;
  72.     /**
  73.      * @ORM\Column(type="integer")
  74.      */
  75.     private $stateval = 1;
  76.     /**
  77.      * @ORM\Column(type="integer")
  78.      */
  79.     private $statetype;
  80.     /**
  81.      * @ORM\Column(type="integer")
  82.      */
  83.     private $points;
  84.     /**
  85.      * @ORM\Column(type="integer")
  86.      */
  87.     private int $searchCount = 0;
  88.     /**
  89.      * @ORM\OneToMany(targetEntity=Stock::class, mappedBy="produit")
  90.      */
  91.     private $stocks;
  92.     /**
  93.      * @ORM\Column(type="text", nullable=true)
  94.      */
  95.     private $keyWord;
  96.     /**
  97.      * @ORM\Column(type="json", nullable=true)
  98.      */
  99.     private ?array $modules = [];
  100.     /**
  101.      * @ORM\Column(type="boolean")
  102.      */
  103.     private bool $enabled = true;
  104.     /**
  105.      * @ORM\Column(type="boolean", options={"default": false})
  106.      */
  107.     private bool $showPrice = false;
  108.     /**
  109.      * @ORM\OneToMany(targetEntity=ProductSubscriptionPrice::class, mappedBy="product", cascade={"persist", "remove"}, orphanRemoval=true)
  110.      */
  111.     private Collection $subscriptionPrices;
  112.     /**
  113.      * @ORM\OneToMany(targetEntity=Location::class, mappedBy="product")
  114.      */
  115.     private $locations;
  116.     /**
  117.      * @ORM\OneToMany(targetEntity=FreelanceStock::class, mappedBy="produit")
  118.      */
  119.     private $freelanceStocks;
  120.     /**
  121.      * @ORM\OneToMany(targetEntity=HistoriqueTransactionFreelance::class, mappedBy="produit")
  122.      */
  123.     private $historiqueTransactions;
  124.     public function __construct()
  125.     {
  126.         $this->priceProducts = new ArrayCollection();
  127.         $this->stocks = new ArrayCollection();
  128.         $this->locations = new ArrayCollection();
  129.         $this->freelanceStocks = new ArrayCollection();
  130.         $this->historiqueTransactions = new ArrayCollection();
  131.         $this->subscriptionPrices = new ArrayCollection();
  132.     }
  133.     public function getId(): ?int
  134.     {
  135.         return $this->id;
  136.     }
  137.     public function getTitle(): ?string
  138.     {
  139.         return $this->title;
  140.     }
  141.     public function setTitle(string $title): self
  142.     {
  143.         $this->title = $title;
  144.         return $this;
  145.     }
  146.     public function getPriceHt(): ?string
  147.     {
  148.         return $this->priceHt;
  149.     }
  150.     public function setPriceHt(string $priceHt): self
  151.     {
  152.         $this->priceHt = $priceHt;
  153.         return $this;
  154.     }
  155.     public function getStock(): ?int
  156.     {
  157.         return $this->stock;
  158.     }
  159.     public function setStock(int $stock): self
  160.     {
  161.         $this->stock = $stock;
  162.         return $this;
  163.     }
  164.     public function getDesctription(): ?string
  165.     {
  166.         return $this->desctription;
  167.     }
  168.     public function setDesctription(string $desctription): self
  169.     {
  170.         $this->desctription = $desctription;
  171.         return $this;
  172.     }
  173.     public function getPicture(): ?string
  174.     {
  175.         return $this->picture;
  176.     }
  177.     public function setPicture(string $picture): self
  178.     {
  179.         $this->picture = $picture;
  180.         return $this;
  181.     }
  182.     public function getLinkspictures(): ?string
  183.     {
  184.         return $this->linkspictures;
  185.     }
  186.     
  187.     public function getLinkspicturesArrays(): ?array
  188.                    {
  189.                        $typevalue = gettype(json_decode($this->linkspictures));
  190.                         if(gettype(json_decode($this->linkspictures)) == "array"){
  191.                              return json_decode($this->linkspictures);
  192.                         } else return null;
  193.                    }
  194.     public function setLinkspictures(?string $linkspictures): self
  195.     {
  196.         $this->linkspictures = $linkspictures;
  197.         return $this;
  198.     }
  199.     public function getUserAdd(): ?UserPlatform
  200.     {
  201.         return $this->userAdd;
  202.     }
  203.     public function setUserAdd(?UserPlatform $userAdd): self
  204.     {
  205.         $this->userAdd = $userAdd;
  206.         return $this;
  207.     }
  208.     public function getFkcategorie(): ?CategoriProduct
  209.     {
  210.         return $this->fkcategorie;
  211.     }
  212.     public function setFkcategorie(?CategoriProduct $fkcategorie): self
  213.     {
  214.         $this->fkcategorie = $fkcategorie;
  215.         return $this;
  216.     }
  217.     public function getFksousCategorie(): ?SousCategorie
  218.     {
  219.         return $this->fksousCategorie;
  220.     }
  221.     public function setFksousCategorie(?SousCategorie $fksousCategorie): self
  222.     {
  223.         $this->fksousCategorie = $fksousCategorie;
  224.         return $this;
  225.     }
  226.     public function getFkdevise(): ?Devise
  227.     {
  228.         return $this->fkdevise;
  229.     }
  230.     public function setFkdevise(?Devise $fkdevise): self
  231.     {
  232.         $this->fkdevise = $fkdevise;
  233.         return $this;
  234.     }
  235.     public function getShop(): ?Shop
  236.     {
  237.         return $this->shop;
  238.     }
  239.     public function setShop(?Shop $shop): self
  240.     {
  241.         $this->shop = $shop;
  242.         return $this;
  243.     }
  244.     /**
  245.      * @return Collection<int, PriceProduct>
  246.      */
  247.     public function getPriceProducts(): Collection
  248.     {
  249.         return $this->priceProducts;
  250.     }
  251.     public function addPriceProduct(PriceProduct $priceProduct): self
  252.     {
  253.         if (!$this->priceProducts->contains($priceProduct)) {
  254.             $this->priceProducts[] = $priceProduct;
  255.             $priceProduct->setProduct($this);
  256.         }
  257.         return $this;
  258.     }
  259.     public function removePriceProduct(PriceProduct $priceProduct): self
  260.     {
  261.         if ($this->priceProducts->removeElement($priceProduct)) {
  262.             // set the owning side to null (unless already changed)
  263.             if ($priceProduct->getProduct() === $this) {
  264.                 $priceProduct->setProduct(null);
  265.             }
  266.         }
  267.         return $this;
  268.     }
  269.     public function getStatdispo(): ?int
  270.     {
  271.         return $this->statdispo;
  272.     }
  273.     public function setStatdispo(int $statdispo): self
  274.     {
  275.         $this->statdispo = $statdispo;
  276.         return $this;
  277.     }
  278.     public function getStateval(): ?int
  279.     {
  280.         return $this->stateval;
  281.     }
  282.     public function setStateval(int $stateval): self
  283.     {
  284.         $this->stateval = $stateval;
  285.         return $this;
  286.     }
  287.     public function getStatetype(): ?int
  288.     {
  289.         return $this->statetype;
  290.     }
  291.     public function setStatetype(int $statetype): self
  292.     {
  293.         $this->statetype = $statetype;
  294.         return $this;
  295.     }
  296.     /**
  297.      * @return string[]
  298.      */
  299.     public function getStatetypeLabels(): array
  300.     {
  301.         $labels = [0 => 'Abonnement', 1 => 'Achat licence', 2 => 'Produit'];
  302.         $statetype = $this->getStatetype();
  303.         return isset($labels[$statetype]) ? [$labels[$statetype]] : [];
  304.     }
  305.     
  306.     public function getPoints(): ?int
  307.     {
  308.         return $this->points;
  309.     }
  310.     public function setPoints(int $points): self
  311.     {
  312.         $this->points = $points;
  313.         return $this;
  314.     }
  315.     /**
  316.      * @return Collection<int, Stock>
  317.      */
  318.     public function getStocks(): Collection
  319.     {
  320.         return $this->stocks;
  321.     }
  322.     public function addStock(Stock $stock): self
  323.     {
  324.         if (!$this->stocks->contains($stock)) {
  325.             $this->stocks[] = $stock;
  326.             $stock->setProduit($this);
  327.         }
  328.         return $this;
  329.     }
  330.     public function removeStock(Stock $stock): self
  331.     {
  332.         if ($this->stocks->removeElement($stock)) {
  333.             // set the owning side to null (unless already changed)
  334.             if ($stock->getProduit() === $this) {
  335.                 $stock->setProduit(null);
  336.             }
  337.         }
  338.         return $this;
  339.     }
  340.     public function getKeyWord(): ?string
  341.     {
  342.         return $this->keyWord;
  343.     }
  344.     public function setKeyWord(?string $keyWord): self
  345.     {
  346.         $this->keyWord = $keyWord;
  347.         return $this;
  348.     }
  349.     /**
  350.      * @return string[]
  351.      */
  352.     public function getModules(): array
  353.     {
  354.         return !empty($this->modules) ? $this->modules : [''];
  355.     }
  356.     /**
  357.      * @param string[]|null $modules
  358.      */
  359.     public function setModules(?array $modules): self
  360.     {
  361.         $this->modules = array_values(array_filter($modules ?? [], static function ($module): bool {
  362.             return trim((string) $module) !== '';
  363.         }));
  364.         return $this;
  365.     }
  366.     /**
  367.      * @return string[]
  368.      */
  369.     public function getModulesForDisplay(): array
  370.     {
  371.         return array_values(array_filter($this->modules ?? [], static function ($module): bool {
  372.             return trim((string) $module) !== '';
  373.         }));
  374.     }
  375.     public function isEnabled(): bool
  376.     {
  377.         return $this->enabled;
  378.     }
  379.     public function setEnabled(bool $enabled): self
  380.     {
  381.         $this->enabled = $enabled;
  382.         return $this;
  383.     }
  384.     public function getShowPrice(): bool
  385.     {
  386.         return $this->showPrice;
  387.     }
  388.     public function setShowPrice(bool $showPrice): self
  389.     {
  390.         $this->showPrice = $showPrice;
  391.         return $this;
  392.     }
  393.     public function getSubscriptionPrices(): Collection
  394.     {
  395.         return $this->subscriptionPrices;
  396.     }
  397.     public function addSubscriptionPrice(ProductSubscriptionPrice $price): self
  398.     {
  399.         if (!$this->subscriptionPrices->contains($price)) {
  400.             $this->subscriptionPrices->add($price);
  401.             $price->setProduct($this);
  402.         }
  403.         return $this;
  404.     }
  405.     public function removeSubscriptionPrice(ProductSubscriptionPrice $price): self
  406.     {
  407.         if ($this->subscriptionPrices->removeElement($price)) {
  408.             if ($price->getProduct() === $this) {
  409.                 $price->setProduct(null);
  410.             }
  411.         }
  412.         return $this;
  413.     }
  414.     public function getLowestSubscriptionPrice(): ?ProductSubscriptionPrice
  415.     {
  416.         $lowest = null;
  417.         foreach ($this->subscriptionPrices as $offer) {
  418.             if (!$offer->getSubscriptionType() || !$offer->getSubscriptionType()->isEnabled()) {
  419.                 continue;
  420.             }
  421.             if ($lowest === null || (float) $offer->getPrice() < (float) $lowest->getPrice()) {
  422.                 $lowest = $offer;
  423.             }
  424.         }
  425.         return $lowest;
  426.     }
  427.     /* Statistics*/
  428.     public function getSearchCount(): int
  429.     {
  430.         return $this->searchCount;
  431.     }
  432.     public function setSearchCount(int $searchCount): self
  433.     {
  434.         $this->searchCount = $searchCount;
  435.         return $this;
  436.     }
  437.     public function incrementSearchCount(): self
  438.     {
  439.         $this->searchCount++;
  440.         return $this;
  441.     }
  442.     /**
  443.      * @return Collection<int, Location>
  444.      */
  445.     public function getLocations(): Collection
  446.     {
  447.         return $this->locations;
  448.     }
  449.     public function addLocation(Location $location): self
  450.     {
  451.         if (!$this->locations->contains($location)) {
  452.             $this->locations[] = $location;
  453.             $location->setProduct($this);
  454.         }
  455.         return $this;
  456.     }
  457.     public function removeLocation(Location $location): self
  458.     {
  459.         if ($this->locations->removeElement($location)) {
  460.             // set the owning side to null (unless already changed)
  461.             if ($location->getProduct() === $this) {
  462.                 $location->setProduct(null);
  463.             }
  464.         }
  465.         return $this;
  466.     }
  467.     /**
  468.      * @return Collection<int, FreelanceStock>
  469.      */
  470.     public function getFreelanceStocks(): Collection
  471.     {
  472.         return $this->freelanceStocks;
  473.     }
  474.     public function addFreelanceStock(FreelanceStock $freelanceStock): self
  475.     {
  476.         if (!$this->freelanceStocks->contains($freelanceStock)) {
  477.             $this->freelanceStocks[] = $freelanceStock;
  478.             $freelanceStock->setProduit($this);
  479.         }
  480.         return $this;
  481.     }
  482.     public function removeFreelanceStock(FreelanceStock $freelanceStock): self
  483.     {
  484.         if ($this->freelanceStocks->removeElement($freelanceStock)) {
  485.             if ($freelanceStock->getProduit() === $this) {
  486.                 $freelanceStock->setProduit(null);
  487.             }
  488.         }
  489.         return $this;
  490.     }
  491.     /**
  492.      * @return Collection<int, HistoriqueTransactionFreelance>
  493.      */
  494.     public function getHistoriqueTransactions(): Collection
  495.     {
  496.         return $this->historiqueTransactions;
  497.     }
  498.     public function addHistoriqueTransaction(HistoriqueTransactionFreelance $historiqueTransaction): self
  499.     {
  500.         if (!$this->historiqueTransactions->contains($historiqueTransaction)) {
  501.             $this->historiqueTransactions[] = $historiqueTransaction;
  502.             $historiqueTransaction->setProduit($this);
  503.         }
  504.         return $this;
  505.     }
  506.     public function removeHistoriqueTransaction(HistoriqueTransactionFreelance $historiqueTransaction): self
  507.     {
  508.         if ($this->historiqueTransactions->removeElement($historiqueTransaction)) {
  509.             if ($historiqueTransaction->getProduit() === $this) {
  510.                 $historiqueTransaction->setProduit(null);
  511.             }
  512.         }
  513.         return $this;
  514.     }
  515. }