src/Entity/Product.php line 12

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\DBAL\Types\Types;
  7. use Doctrine\ORM\Mapping as ORM;
  8. #[ORM\Entity(repositoryClassProductRepository::class)]
  9. class Product
  10. {
  11.     #[ORM\Id]
  12.     #[ORM\GeneratedValue]
  13.     #[ORM\Column]
  14.     private ?int $id null;
  15.     #[ORM\Column(length255)]
  16.     private ?string $reference null;
  17.     #[ORM\Column(length13nullabletrue)]
  18.     private ?string $ean13 null;
  19.     #[ORM\Column(length32nullabletrue)]
  20.     private ?string $isbn null;
  21.     #[ORM\Column(length40nullabletrue)]
  22.     private ?string $mpn null;
  23.     #[ORM\Column(typeTypes::DECIMALprecision26scale6nullabletrue)]
  24.     private ?string $price null;
  25.     #[ORM\Column(typeTypes::DECIMALprecision10scale2nullabletrue)]
  26.     private ?string $width null;
  27.     #[ORM\Column(typeTypes::DECIMALprecision10scale2nullabletrue)]
  28.     private ?string $height null;
  29.     #[ORM\Column(typeTypes::DECIMALprecision10scale2nullabletrue)]
  30.     private ?string $depth null;
  31.     #[ORM\Column(typeTypes::DECIMALprecision10scale2nullabletrue)]
  32.     private ?string $weight null;
  33.     #[ORM\Column(typeTypes::DATETIME_MUTABLE)]
  34.     private ?\DateTimeInterface $date_add null;
  35.     #[ORM\Column(typeTypes::DATETIME_MUTABLE)]
  36.     private ?\DateTimeInterface $date_upd null;
  37.     #[ORM\OneToMany(mappedBy'product'targetEntityProductLang::class)]
  38.     private Collection $productLangs;
  39.     #[ORM\OneToMany(mappedBy'product'targetEntityProductAttribute::class)]
  40.     private Collection $productAttributes;
  41.     #[ORM\OneToMany(mappedBy'product'targetEntityImage::class)]
  42.     private Collection $image;
  43.     #[ORM\ManyToMany(targetEntityFeatureValue::class, inversedBy'products')]
  44.     private Collection $featureValues;
  45.     #[ORM\ManyToMany(targetEntityAdvantage::class, mappedBy'product')]
  46.     private Collection $advantages;
  47.     #[ORM\ManyToOne(inversedBy'products')]
  48.     private ?Brand $brand null;
  49.     #[ORM\ManyToMany(targetEntityFile::class, mappedBy'products')]
  50.     private Collection $files;
  51.     #[ORM\OneToOne(mappedBy'product'targetEntityERPCommercialData::class)]
  52.     private ?ERPCommercialData $ERPCommercialData null;
  53.     #[ORM\OneToOne(mappedBy'product'targetEntityERPLogisticData::class)]
  54.     private ?ERPLogisticData $ERPLogisticData null;
  55.     #[ORM\OneToMany(mappedBy'product'targetEntityERPCommercialDataLang::class)]
  56.     private Collection $ERPCommercialDataLangs;
  57.     public function __construct()
  58.     {
  59.         $this->date_add = new \DateTime();
  60.         $this->date_upd = new \DateTime();
  61.         $this->productLangs = new ArrayCollection();
  62.         $this->productAttributes = new ArrayCollection();
  63.         $this->image = new ArrayCollection();
  64.         $this->featureValues = new ArrayCollection();
  65.         $this->advantages = new ArrayCollection();
  66.         $this->files = new ArrayCollection();
  67.         $this->ERPCommercialDataLangs = new ArrayCollection();
  68.     }
  69.     public function getId(): ?int
  70.     {
  71.         return $this->id;
  72.     }
  73.     public function getReference(): ?string
  74.     {
  75.         return $this->reference;
  76.     }
  77.     public function setReference(string $reference): self
  78.     {
  79.         $this->reference $reference;
  80.         return $this;
  81.     }
  82.     public function getEan13(): ?string
  83.     {
  84.         return $this->ean13;
  85.     }
  86.     public function setEan13(string $ean13): self
  87.     {
  88.         $this->ean13 $ean13;
  89.         return $this;
  90.     }
  91.     public function getIsbn(): ?string
  92.     {
  93.         return $this->isbn;
  94.     }
  95.     public function setIsbn(string $isbn): self
  96.     {
  97.         $this->isbn $isbn;
  98.         return $this;
  99.     }
  100.     public function getMpn(): ?string
  101.     {
  102.         return $this->mpn;
  103.     }
  104.     public function setMpn(?string $mpn): self
  105.     {
  106.         $this->mpn $mpn;
  107.         return $this;
  108.     }
  109.     public function getPrice(): ?string
  110.     {
  111.         return $this->price;
  112.     }
  113.     public function setPrice(?string $price): self
  114.     {
  115.         $this->price $price;
  116.         return $this;
  117.     }
  118.     public function getWidth(): ?string
  119.     {
  120.         return $this->width;
  121.     }
  122.     public function setWidth(?string $width): self
  123.     {
  124.         $this->width $width;
  125.         return $this;
  126.     }
  127.     public function getDateAdd(): ?\DateTimeInterface
  128.     {
  129.         return $this->date_add;
  130.     }
  131.     public function setDateAdd(\DateTimeInterface $date_add): self
  132.     {
  133.         $this->date_add $date_add;
  134.         return $this;
  135.     }
  136.     public function getDateUpd(): ?\DateTimeInterface
  137.     {
  138.         return $this->date_upd;
  139.     }
  140.     public function setDateUpd(\DateTimeInterface $date_upd): self
  141.     {
  142.         $this->date_upd $date_upd;
  143.         return $this;
  144.     }
  145.     /**
  146.      * Get the value of height
  147.      *
  148.      * @return ?string
  149.      */
  150.     public function getHeight(): ?string
  151.     {
  152.         return $this->height;
  153.     }
  154.     /**
  155.      * Set the value of height
  156.      *
  157.      * @param ?string $height
  158.      *
  159.      * @return self
  160.      */
  161.     public function setHeight(?string $height): self
  162.     {
  163.         $this->height $height;
  164.         return $this;
  165.     }
  166.     /**
  167.      * Get the value of depth
  168.      *
  169.      * @return ?string
  170.      */
  171.     public function getDepth(): ?string
  172.     {
  173.         return $this->depth;
  174.     }
  175.     /**
  176.      * Set the value of depth
  177.      *
  178.      * @param ?string $depth
  179.      *
  180.      * @return self
  181.      */
  182.     public function setDepth(?string $depth): self
  183.     {
  184.         $this->depth $depth;
  185.         return $this;
  186.     }
  187.     /**
  188.      * Get the value of weight
  189.      *
  190.      * @return ?string
  191.      */
  192.     public function getWeight(): ?string
  193.     {
  194.         return $this->weight;
  195.     }
  196.     /**
  197.      * Set the value of weight
  198.      *
  199.      * @param ?string $weight
  200.      *
  201.      * @return self
  202.      */
  203.     public function setWeight(?string $weight): self
  204.     {
  205.         $this->weight $weight;
  206.         return $this;
  207.     }
  208.     /**
  209.      * @return Collection<int, ProductLang>
  210.      */
  211.     public function getProductLangs(): Collection
  212.     {
  213.         return $this->productLangs;
  214.     }
  215.     public function addProductLang(ProductLang $productLang): self
  216.     {
  217.         if (!$this->productLangs->contains($productLang)) {
  218.             $this->productLangs->add($productLang);
  219.             $productLang->setProduct($this);
  220.         }
  221.         return $this;
  222.     }
  223.     public function removeProductLang(ProductLang $productLang): self
  224.     {
  225.         if ($this->productLangs->removeElement($productLang)) {
  226.             // set the owning side to null (unless already changed)
  227.             if ($productLang->getProduct() === $this) {
  228.                 $productLang->setProduct(null);
  229.             }
  230.         }
  231.         return $this;
  232.     }
  233.     /**
  234.      * @return Collection<int, ProductAttribute>
  235.      */
  236.     public function getProductAttributes(): Collection
  237.     {
  238.         return $this->productAttributes;
  239.     }
  240.     public function addProductAttribute(ProductAttribute $productAttribute): self
  241.     {
  242.         if (!$this->productAttributes->contains($productAttribute)) {
  243.             $this->productAttributes->add($productAttribute);
  244.             $productAttribute->setProduct($this);
  245.         }
  246.         return $this;
  247.     }
  248.     public function removeProductAttribute(ProductAttribute $productAttribute): self
  249.     {
  250.         if ($this->productAttributes->removeElement($productAttribute)) {
  251.             // set the owning side to null (unless already changed)
  252.             if ($productAttribute->getProduct() === $this) {
  253.                 $productAttribute->setProduct(null);
  254.             }
  255.         }
  256.         return $this;
  257.     }
  258.     /**
  259.      * @return Collection<int, Image>
  260.      */
  261.     public function getImage(): Collection
  262.     {
  263.         //sort images by position
  264.         $images $this->image->toArray();
  265.         usort($images, function ($a$b) {
  266.             return $a->getPosition() <=> $b->getPosition();
  267.         });
  268.         return new ArrayCollection($images);
  269.     }
  270.     public function addImage(Image $image): self
  271.     {
  272.         if (!$this->image->contains($image)) {
  273.             $this->image->add($image);
  274.             $image->setProduct($this);
  275.         }
  276.         return $this;
  277.     }
  278.     public function removeImage(Image $image): self
  279.     {
  280.         if ($this->image->removeElement($image)) {
  281.             // set the owning side to null (unless already changed)
  282.             if ($image->getProduct() === $this) {
  283.                 $image->setProduct(null);
  284.             }
  285.         }
  286.         return $this;
  287.     }
  288.     /**
  289.      * @return Collection<int, FeatureValue>
  290.      */
  291.     public function getFeatureValues(): Collection
  292.     {
  293.         return $this->featureValues;
  294.     }
  295.     public function addFeatureValue(FeatureValue $featureValue): self
  296.     {
  297.         if (!$this->featureValues->contains($featureValue)) {
  298.             $this->featureValues->add($featureValue);
  299.         }
  300.         return $this;
  301.     }
  302.     public function removeFeatureValue(FeatureValue $featureValue): self
  303.     {
  304.         $this->featureValues->removeElement($featureValue);
  305.         return $this;
  306.     }
  307.     /**
  308.      * @return Collection<int, Advantage>
  309.      */
  310.     public function getAdvantages(): Collection
  311.     {
  312.         return $this->advantages;
  313.     }
  314.     public function addAdvantage(Advantage $advantage): self
  315.     {
  316.         if (!$this->advantages->contains($advantage)) {
  317.             $this->advantages->add($advantage);
  318.             $advantage->addProduct($this);
  319.         }
  320.         return $this;
  321.     }
  322.     public function removeAdvantage(Advantage $advantage): self
  323.     {
  324.         if ($this->advantages->removeElement($advantage)) {
  325.             $advantage->removeProduct($this);
  326.         }
  327.         return $this;
  328.     }
  329.     public function editorToHTML($editorContent){
  330.         $editorContent json_decode($editorContenttrue);
  331.         $editorHTML "";
  332.         if(isset($editorContent['blocks'])) {
  333.             $editorBlocks $editorContent['blocks'];
  334.             foreach ($editorBlocks as $keyBlock => $block) {
  335.                 switch ($block['type']) {
  336.                     case 'header':
  337.                         $editorHTML .= "<h".$block['data']['level'].">"$block['data']['text'] . "</h" $block['data']['level'] . ">";
  338.                         break;
  339.                     case 'paragraph':
  340.                         $editorHTML .= "<p>".$block['data']['text']."</p>";
  341.                         break;
  342.                     case 'list':
  343.                         $this->generateList($block['data']['items'], $editorHTML);
  344.                         break;
  345.                     case 'image':
  346.                         $withBorder $block['data']['withBorder'];
  347.                         $stretched $block['data']['stretched'];
  348.                         $withBackground $block['data']['withBackground'];
  349.                         
  350.                         $editorHTML .=  "<img";
  351.                         $editorHTML .=  " style='max-width:100%;";
  352.                         if($withBorder || $stretched) {
  353.                             if($withBorder) {
  354.                                 $editorHTML .=  " border:1px solid black;";
  355.                             }
  356.                             if($stretched) {
  357.                                 $editorHTML .=  " width:100%";
  358.                             }
  359.                         }
  360.                         $editorHTML .=  "' alt='".$block['data']['caption']."' src='".$_ENV['APP_URL'].$block['data']['file']['url']."'>";
  361.                         break;
  362.                     case 'html':
  363.                         $editorHTML .= $block['data']['html'];
  364.                         break;
  365.                     case 'button':
  366.                         $editorHTML .= "<div class='buttonContainer'><a href='".$block['data']['link']."'";
  367.                         if($block['data']['blank']){
  368.                             $editorHTML .= " target='_blank'";
  369.                         }
  370.                         $editorHTML .= " class='btn ";
  371.                         if($block['data']['style'] == "full"){
  372.                             $editorHTML .= "cta1'";
  373.                         } 
  374.                         if($block['data']['style'] == "outline"){
  375.                             $editorHTML .= "cta2'";
  376.                         }
  377.                         $editorHTML .= ">".$block['data']['text']."</a></div>";
  378.                         break;
  379.                 }
  380.             }
  381.         }
  382.         return $editorHTML;
  383.     }
  384.     public function generateDescription(Lang $lang){
  385.         $descriptionData "";
  386.         foreach ($this->productLangs as $keyProductLang => $productLang) {
  387.             if($productLang->getLang() == $lang){
  388.                 $descriptionData $productLang->getDescription();
  389.             }
  390.         }
  391.         
  392.         $descriptionData json_decode($descriptionDatatrue);
  393.         $descriptionHTML "";
  394.         $descriptionBlocks $descriptionData['blocks'];
  395.         foreach ($descriptionBlocks as $keyBlock => $block) {
  396.             switch ($block['type']) {
  397.                 case 'header':
  398.                     $descriptionHTML .= "<h".$block['data']['level'].">"$block['data']['text'] . "</h" $block['data']['level'] . ">";
  399.                     break;
  400.                 case 'paragraph':
  401.                     $descriptionHTML .= "<p>".$block['data']['text']."</p>";
  402.                     break;
  403.                 case 'list':
  404.                     $this->generateList($block['data']['items'], $descriptionHTML);
  405.                     break;
  406.                 case 'image':
  407.                     $withBorder $block['data']['withBorder'];
  408.                     $stretched $block['data']['stretched'];
  409.                     $withBackground $block['data']['withBackground'];
  410.                     
  411.                     $descriptionHTML .=  "<img";
  412.                     if($withBorder || $stretched){
  413.                         $descriptionHTML .=  " style='";
  414.                         if($withBorder){
  415.                             $descriptionHTML .=  " border:1px solid black;";
  416.                         }
  417.                         if($stretched){
  418.                             $descriptionHTML .=  " width:100%";
  419.                         }
  420.                     }
  421.                     $descriptionHTML .=  " alt='".$block['data']['caption']."' src='".$_ENV['APP_URL'].$block['data']['file']['url']."'>";
  422.                     break;
  423.             
  424.             }
  425.         }
  426.         return $descriptionHTML;
  427.     }
  428.     private function generateList($items, &$descriptionHTML){
  429.     $descriptionHTML .= "<ul class='list-tf'>";
  430.     foreach ($items as $keyItem => $item) {
  431.             $descriptionHTML .= "<li>".$item['content'];
  432.             if(count($item['items'])> 0){
  433.                 $this->generateList($item['items'],$descriptionHTML);
  434.             }
  435.             $descriptionHTML .= "</li>";
  436.         }
  437.         $descriptionHTML .= "</ul>";
  438.     }
  439.     public function getBrand(): ?Brand
  440.     {
  441.         return $this->brand;
  442.     }
  443.     public function setBrand(?Brand $brand): self
  444.     {
  445.         $this->brand $brand;
  446.         return $this;
  447.     }
  448.     /**
  449.      * @return Collection<int, File>
  450.      */
  451.     public function getFiles(): Collection
  452.     {
  453.         return $this->files;
  454.     }
  455.     public function addFile(File $file): self
  456.     {
  457.         if (!$this->files->contains($file)) {
  458.             $this->files->add($file);
  459.             $file->addProduct($this);
  460.         }
  461.         return $this;
  462.     }
  463.     public function removeFile(File $file): self
  464.     {
  465.         if ($this->files->removeElement($file)) {
  466.             $file->removeProduct($this);
  467.         }
  468.         return $this;
  469.     }
  470.     public function getERPCommercialData(): ?ERPCommercialData
  471.     {
  472.         return $this->ERPCommercialData;
  473.     }
  474.     public function setERPCommercialData(?ERPCommercialData $ERPCommercialData): self
  475.     {
  476.         // unset the owning side of the relation if necessary
  477.         if ($ERPCommercialData === null && $this->ERPCommercialData !== null) {
  478.             $this->ERPCommercialData->setProduct(null);
  479.         }
  480.         // set the owning side of the relation if necessary
  481.         if ($ERPCommercialData !== null && $ERPCommercialData->getProduct() !== $this) {
  482.             $ERPCommercialData->setProduct($this);
  483.         }
  484.         $this->ERPCommercialData $ERPCommercialData;
  485.         return $this;
  486.     }
  487.     public function getERPLogisticData(): ?ERPLogisticData
  488.     {
  489.         return $this->ERPLogisticData;
  490.     }
  491.     public function setERPLogisticData(?ERPLogisticData $ERPLogisticData): self
  492.     {
  493.         // unset the owning side of the relation if necessary
  494.         if ($ERPLogisticData === null && $this->ERPLogisticData !== null) {
  495.             $this->ERPLogisticData->setProduct(null);
  496.         }
  497.         // set the owning side of the relation if necessary
  498.         if ($ERPLogisticData !== null && $ERPLogisticData->getProduct() !== $this) {
  499.             $ERPLogisticData->setProduct($this);
  500.         }
  501.         $this->ERPLogisticData $ERPLogisticData;
  502.         return $this;
  503.     }
  504.     /**
  505.      * @return Collection<int, ERPCommercialDataLang>
  506.      */
  507.     public function getERPCommercialDataLangs(): Collection
  508.     {
  509.         return $this->ERPCommercialDataLangs;
  510.     }
  511.     public function addERPCommercialDataLang(ERPCommercialDataLang $eRPCommercialDataLang): self
  512.     {
  513.         if (!$this->ERPCommercialDataLangs->contains($eRPCommercialDataLang)) {
  514.             $this->ERPCommercialDataLangs->add($eRPCommercialDataLang);
  515.             $eRPCommercialDataLang->setProduct($this);
  516.         }
  517.         return $this;
  518.     }
  519.     public function removeERPCommercialDataLang(ERPCommercialDataLang $eRPCommercialDataLang): self
  520.     {
  521.         if ($this->ERPCommercialDataLangs->removeElement($eRPCommercialDataLang)) {
  522.             // set the owning side to null (unless already changed)
  523.             if ($eRPCommercialDataLang->getProduct() === $this) {
  524.                 $eRPCommercialDataLang->setProduct(null);
  525.             }
  526.         }
  527.         return $this;
  528.     }
  529. }