src/Entity/Product.php line 232

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;
  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="json", nullable=true)
  82.      */
  83.     private ?array $statetypes = null;
  84.     /**
  85.      * @ORM\Column(type="integer")
  86.      */
  87.     private $points;
  88.     /**
  89.      * @ORM\Column(type="integer")
  90.      */
  91.     private int $searchCount = 0;
  92.     /**
  93.      * @ORM\OneToMany(targetEntity=Stock::class, mappedBy="produit")
  94.      */
  95.     private $stocks;
  96.     /**
  97.      * @ORM\Column(type="text", nullable=true)
  98.      */
  99.     private $keyWord;
  100.     /**
  101.      * @ORM\Column(type="json", nullable=true)
  102.      */
  103.     private ?array $modules = [];
  104.     /**
  105.      * @ORM\Column(type="boolean")
  106.      */
  107.     private bool $enabled = true;
  108.     /**
  109.      * @ORM\OneToMany(targetEntity=Location::class, mappedBy="product")
  110.      */
  111.     private $locations;
  112.     /**
  113.      * @ORM\OneToMany(targetEntity=FreelanceStock::class, mappedBy="produit")
  114.      */
  115.     private $freelanceStocks;
  116.     /**
  117.      * @ORM\OneToMany(targetEntity=HistoriqueTransactionFreelance::class, mappedBy="produit")
  118.      */
  119.     private $historiqueTransactions;
  120.     public function __construct()
  121.     {
  122.         $this->priceProducts = new ArrayCollection();
  123.         $this->stocks = new ArrayCollection();
  124.         $this->locations = new ArrayCollection();
  125.         $this->freelanceStocks = new ArrayCollection();
  126.         $this->historiqueTransactions = new ArrayCollection();
  127.     }
  128.     public function getId(): ?int
  129.     {
  130.         return $this->id;
  131.     }
  132.     public function getTitle(): ?string
  133.     {
  134.         return $this->title;
  135.     }
  136.     public function setTitle(string $title): self
  137.     {
  138.         $this->title = $title;
  139.         return $this;
  140.     }
  141.     public function getPriceHt(): ?string
  142.     {
  143.         return $this->priceHt;
  144.     }
  145.     public function setPriceHt(string $priceHt): self
  146.     {
  147.         $this->priceHt = $priceHt;
  148.         return $this;
  149.     }
  150.     public function getStock(): ?int
  151.     {
  152.         return $this->stock;
  153.     }
  154.     public function setStock(int $stock): self
  155.     {
  156.         $this->stock = $stock;
  157.         return $this;
  158.     }
  159.     public function getDesctription(): ?string
  160.     {
  161.         return $this->desctription;
  162.     }
  163.     public function setDesctription(string $desctription): self
  164.     {
  165.         $this->desctription = $desctription;
  166.         return $this;
  167.     }
  168.     public function getPicture(): ?string
  169.     {
  170.         return $this->picture;
  171.     }
  172.     public function setPicture(string $picture): self
  173.     {
  174.         $this->picture = $picture;
  175.         return $this;
  176.     }
  177.     public function getLinkspictures(): ?string
  178.     {
  179.         return $this->linkspictures;
  180.     }
  181.     
  182.     public function getLinkspicturesArrays(): ?array
  183.                    {
  184.                        $typevalue = gettype(json_decode($this->linkspictures));
  185.                         if(gettype(json_decode($this->linkspictures)) == "array"){
  186.                              return json_decode($this->linkspictures);
  187.                         } else return null;
  188.                    }
  189.     public function setLinkspictures(?string $linkspictures): self
  190.     {
  191.         $this->linkspictures = $linkspictures;
  192.         return $this;
  193.     }
  194.     public function getUserAdd(): ?UserPlatform
  195.     {
  196.         return $this->userAdd;
  197.     }
  198.     public function setUserAdd(?UserPlatform $userAdd): self
  199.     {
  200.         $this->userAdd = $userAdd;
  201.         return $this;
  202.     }
  203.     public function getFkcategorie(): ?CategoriProduct
  204.     {
  205.         return $this->fkcategorie;
  206.     }
  207.     public function setFkcategorie(?CategoriProduct $fkcategorie): self
  208.     {
  209.         $this->fkcategorie = $fkcategorie;
  210.         return $this;
  211.     }
  212.     public function getFksousCategorie(): ?SousCategorie
  213.     {
  214.         return $this->fksousCategorie;
  215.     }
  216.     public function setFksousCategorie(?SousCategorie $fksousCategorie): self
  217.     {
  218.         $this->fksousCategorie = $fksousCategorie;
  219.         return $this;
  220.     }
  221.     public function getFkdevise(): ?Devise
  222.     {
  223.         return $this->fkdevise;
  224.     }
  225.     public function setFkdevise(?Devise $fkdevise): self
  226.     {
  227.         $this->fkdevise = $fkdevise;
  228.         return $this;
  229.     }
  230.     public function getShop(): ?Shop
  231.     {
  232.         return $this->shop;
  233.     }
  234.     public function setShop(?Shop $shop): self
  235.     {
  236.         $this->shop = $shop;
  237.         return $this;
  238.     }
  239.     /**
  240.      * @return Collection<int, PriceProduct>
  241.      */
  242.     public function getPriceProducts(): Collection
  243.     {
  244.         return $this->priceProducts;
  245.     }
  246.     public function addPriceProduct(PriceProduct $priceProduct): self
  247.     {
  248.         if (!$this->priceProducts->contains($priceProduct)) {
  249.             $this->priceProducts[] = $priceProduct;
  250.             $priceProduct->setProduct($this);
  251.         }
  252.         return $this;
  253.     }
  254.     public function removePriceProduct(PriceProduct $priceProduct): self
  255.     {
  256.         if ($this->priceProducts->removeElement($priceProduct)) {
  257.             // set the owning side to null (unless already changed)
  258.             if ($priceProduct->getProduct() === $this) {
  259.                 $priceProduct->setProduct(null);
  260.             }
  261.         }
  262.         return $this;
  263.     }
  264.     public function getStatdispo(): ?int
  265.     {
  266.         return $this->statdispo;
  267.     }
  268.     public function setStatdispo(int $statdispo): self
  269.     {
  270.         $this->statdispo = $statdispo;
  271.         return $this;
  272.     }
  273.     public function getStateval(): ?int
  274.     {
  275.         return $this->stateval;
  276.     }
  277.     public function setStateval(int $stateval): self
  278.     {
  279.         $this->stateval = $stateval;
  280.         return $this;
  281.     }
  282.     public function getStatetype(): ?int
  283.     {
  284.         return $this->statetype;
  285.     }
  286.     public function setStatetype(int $statetype): self
  287.     {
  288.         $this->statetype = $statetype;
  289.         return $this;
  290.     }
  291.     /**
  292.      * @return int[]
  293.      */
  294.     public function getStatetypes(): array
  295.     {
  296.         if (!empty($this->statetypes)) {
  297.             return array_map('intval', $this->statetypes);
  298.         }
  299.         return $this->statetype !== null ? [(int) $this->statetype] : [0];
  300.     }
  301.     /**
  302.      * @param int[]|null $statetypes
  303.      */
  304.     public function setStatetypes(?array $statetypes): self
  305.     {
  306.         $statetypes = array_values(array_unique(array_map('intval', $statetypes ?? [])));
  307.         $this->statetypes = $statetypes ?: [0];
  308.         // Compatibilité avec les anciens traitements qui utilisent encore statetype.
  309.         $this->statetype = in_array(0, $this->statetypes, true) ? 0 : 1;
  310.         return $this;
  311.     }
  312.     /**
  313.      * @return string[]
  314.      */
  315.     public function getStatetypeLabels(): array
  316.     {
  317.         $labels = [];
  318.         foreach ($this->getStatetypes() as $statetype) {
  319.             if ($statetype === 0) {
  320.                 $labels[] = 'Abonnement';
  321.             } elseif ($statetype === 1) {
  322.                 $labels[] = 'Achat licence';
  323.             }
  324.         }
  325.         return $labels;
  326.     }
  327.     
  328.     public function getPoints(): ?int
  329.     {
  330.         return $this->points;
  331.     }
  332.     public function setPoints(int $points): self
  333.     {
  334.         $this->points = $points;
  335.         return $this;
  336.     }
  337.     /**
  338.      * @return Collection<int, Stock>
  339.      */
  340.     public function getStocks(): Collection
  341.     {
  342.         return $this->stocks;
  343.     }
  344.     public function addStock(Stock $stock): self
  345.     {
  346.         if (!$this->stocks->contains($stock)) {
  347.             $this->stocks[] = $stock;
  348.             $stock->setProduit($this);
  349.         }
  350.         return $this;
  351.     }
  352.     public function removeStock(Stock $stock): self
  353.     {
  354.         if ($this->stocks->removeElement($stock)) {
  355.             // set the owning side to null (unless already changed)
  356.             if ($stock->getProduit() === $this) {
  357.                 $stock->setProduit(null);
  358.             }
  359.         }
  360.         return $this;
  361.     }
  362.     public function getKeyWord(): ?string
  363.     {
  364.         return $this->keyWord;
  365.     }
  366.     public function setKeyWord(?string $keyWord): self
  367.     {
  368.         $this->keyWord = $keyWord;
  369.         return $this;
  370.     }
  371.     /**
  372.      * @return string[]
  373.      */
  374.     public function getModules(): array
  375.     {
  376.         return !empty($this->modules) ? $this->modules : [''];
  377.     }
  378.     /**
  379.      * @param string[]|null $modules
  380.      */
  381.     public function setModules(?array $modules): self
  382.     {
  383.         $this->modules = array_values(array_filter($modules ?? [], static function ($module): bool {
  384.             return trim((string) $module) !== '';
  385.         }));
  386.         return $this;
  387.     }
  388.     /**
  389.      * @return string[]
  390.      */
  391.     public function getModulesForDisplay(): array
  392.     {
  393.         return array_values(array_filter($this->modules ?? [], static function ($module): bool {
  394.             return trim((string) $module) !== '';
  395.         }));
  396.     }
  397.     public function isEnabled(): bool
  398.     {
  399.         return $this->enabled;
  400.     }
  401.     public function setEnabled(bool $enabled): self
  402.     {
  403.         $this->enabled = $enabled;
  404.         return $this;
  405.     }
  406.     /* Statistics*/
  407.     public function getSearchCount(): int
  408.     {
  409.         return $this->searchCount;
  410.     }
  411.     public function setSearchCount(int $searchCount): self
  412.     {
  413.         $this->searchCount = $searchCount;
  414.         return $this;
  415.     }
  416.     public function incrementSearchCount(): self
  417.     {
  418.         $this->searchCount++;
  419.         return $this;
  420.     }
  421.     /**
  422.      * @return Collection<int, Location>
  423.      */
  424.     public function getLocations(): Collection
  425.     {
  426.         return $this->locations;
  427.     }
  428.     public function addLocation(Location $location): self
  429.     {
  430.         if (!$this->locations->contains($location)) {
  431.             $this->locations[] = $location;
  432.             $location->setProduct($this);
  433.         }
  434.         return $this;
  435.     }
  436.     public function removeLocation(Location $location): self
  437.     {
  438.         if ($this->locations->removeElement($location)) {
  439.             // set the owning side to null (unless already changed)
  440.             if ($location->getProduct() === $this) {
  441.                 $location->setProduct(null);
  442.             }
  443.         }
  444.         return $this;
  445.     }
  446.     /**
  447.      * @return Collection<int, FreelanceStock>
  448.      */
  449.     public function getFreelanceStocks(): Collection
  450.     {
  451.         return $this->freelanceStocks;
  452.     }
  453.     public function addFreelanceStock(FreelanceStock $freelanceStock): self
  454.     {
  455.         if (!$this->freelanceStocks->contains($freelanceStock)) {
  456.             $this->freelanceStocks[] = $freelanceStock;
  457.             $freelanceStock->setProduit($this);
  458.         }
  459.         return $this;
  460.     }
  461.     public function removeFreelanceStock(FreelanceStock $freelanceStock): self
  462.     {
  463.         if ($this->freelanceStocks->removeElement($freelanceStock)) {
  464.             if ($freelanceStock->getProduit() === $this) {
  465.                 $freelanceStock->setProduit(null);
  466.             }
  467.         }
  468.         return $this;
  469.     }
  470.     /**
  471.      * @return Collection<int, HistoriqueTransactionFreelance>
  472.      */
  473.     public function getHistoriqueTransactions(): Collection
  474.     {
  475.         return $this->historiqueTransactions;
  476.     }
  477.     public function addHistoriqueTransaction(HistoriqueTransactionFreelance $historiqueTransaction): self
  478.     {
  479.         if (!$this->historiqueTransactions->contains($historiqueTransaction)) {
  480.             $this->historiqueTransactions[] = $historiqueTransaction;
  481.             $historiqueTransaction->setProduit($this);
  482.         }
  483.         return $this;
  484.     }
  485.     public function removeHistoriqueTransaction(HistoriqueTransactionFreelance $historiqueTransaction): self
  486.     {
  487.         if ($this->historiqueTransactions->removeElement($historiqueTransaction)) {
  488.             if ($historiqueTransaction->getProduit() === $this) {
  489.                 $historiqueTransaction->setProduit(null);
  490.             }
  491.         }
  492.         return $this;
  493.     }
  494. }