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.                     case 'embed':
  380.                         $editorHTML .= "<iframe src='".$block['data']['embed']."' width='".$block['data']['width']."' height='".$block['data']['height']."' />";
  381.                         break;
  382.                 }
  383.             }
  384.         }
  385.         return $editorHTML;
  386.     }
  387.     public function generateDescription(Lang $lang){
  388.         $descriptionData "";
  389.         foreach ($this->productLangs as $keyProductLang => $productLang) {
  390.             if($productLang->getLang() == $lang){
  391.                 $descriptionData $productLang->getDescription();
  392.             }
  393.         }
  394.         
  395.         $descriptionData json_decode($descriptionDatatrue);
  396.         $descriptionHTML "";
  397.         $descriptionBlocks $descriptionData['blocks'];
  398.         foreach ($descriptionBlocks as $keyBlock => $block) {
  399.             switch ($block['type']) {
  400.                 case 'header':
  401.                     $descriptionHTML .= "<h".$block['data']['level'].">"$block['data']['text'] . "</h" $block['data']['level'] . ">";
  402.                     break;
  403.                 case 'paragraph':
  404.                     $descriptionHTML .= "<p>".$block['data']['text']."</p>";
  405.                     break;
  406.                 case 'list':
  407.                     $this->generateList($block['data']['items'], $descriptionHTML);
  408.                     break;
  409.                 case 'image':
  410.                     $withBorder $block['data']['withBorder'];
  411.                     $stretched $block['data']['stretched'];
  412.                     $withBackground $block['data']['withBackground'];
  413.                     
  414.                     $descriptionHTML .=  "<img";
  415.                     if($withBorder || $stretched){
  416.                         $descriptionHTML .=  " style='";
  417.                         if($withBorder){
  418.                             $descriptionHTML .=  " border:1px solid black;";
  419.                         }
  420.                         if($stretched){
  421.                             $descriptionHTML .=  " width:100%";
  422.                         }
  423.                     }
  424.                     $descriptionHTML .=  " alt='".$block['data']['caption']."' src='".$_ENV['APP_URL'].$block['data']['file']['url']."'>";
  425.                     break;
  426.             
  427.             }
  428.         }
  429.         return $descriptionHTML;
  430.     }
  431.     private function generateList($items, &$descriptionHTML){
  432.     $descriptionHTML .= "<ul class='list-tf'>";
  433.     foreach ($items as $keyItem => $item) {
  434.             $descriptionHTML .= "<li>".$item['content'];
  435.             if(count($item['items'])> 0){
  436.                 $this->generateList($item['items'],$descriptionHTML);
  437.             }
  438.             $descriptionHTML .= "</li>";
  439.         }
  440.         $descriptionHTML .= "</ul>";
  441.     }
  442.     public function getBrand(): ?Brand
  443.     {
  444.         return $this->brand;
  445.     }
  446.     public function setBrand(?Brand $brand): self
  447.     {
  448.         $this->brand $brand;
  449.         return $this;
  450.     }
  451.     /**
  452.      * @return Collection<int, File>
  453.      */
  454.     public function getFiles(): Collection
  455.     {
  456.         return $this->files;
  457.     }
  458.     public function addFile(File $file): self
  459.     {
  460.         if (!$this->files->contains($file)) {
  461.             $this->files->add($file);
  462.             $file->addProduct($this);
  463.         }
  464.         return $this;
  465.     }
  466.     public function removeFile(File $file): self
  467.     {
  468.         if ($this->files->removeElement($file)) {
  469.             $file->removeProduct($this);
  470.         }
  471.         return $this;
  472.     }
  473.     public function getERPCommercialData(): ?ERPCommercialData
  474.     {
  475.         return $this->ERPCommercialData;
  476.     }
  477.     public function setERPCommercialData(?ERPCommercialData $ERPCommercialData): self
  478.     {
  479.         // unset the owning side of the relation if necessary
  480.         if ($ERPCommercialData === null && $this->ERPCommercialData !== null) {
  481.             $this->ERPCommercialData->setProduct(null);
  482.         }
  483.         // set the owning side of the relation if necessary
  484.         if ($ERPCommercialData !== null && $ERPCommercialData->getProduct() !== $this) {
  485.             $ERPCommercialData->setProduct($this);
  486.         }
  487.         $this->ERPCommercialData $ERPCommercialData;
  488.         return $this;
  489.     }
  490.     public function getERPLogisticData(): ?ERPLogisticData
  491.     {
  492.         return $this->ERPLogisticData;
  493.     }
  494.     public function setERPLogisticData(?ERPLogisticData $ERPLogisticData): self
  495.     {
  496.         // unset the owning side of the relation if necessary
  497.         if ($ERPLogisticData === null && $this->ERPLogisticData !== null) {
  498.             $this->ERPLogisticData->setProduct(null);
  499.         }
  500.         // set the owning side of the relation if necessary
  501.         if ($ERPLogisticData !== null && $ERPLogisticData->getProduct() !== $this) {
  502.             $ERPLogisticData->setProduct($this);
  503.         }
  504.         $this->ERPLogisticData $ERPLogisticData;
  505.         return $this;
  506.     }
  507.     /**
  508.      * @return Collection<int, ERPCommercialDataLang>
  509.      */
  510.     public function getERPCommercialDataLangs(): Collection
  511.     {
  512.         return $this->ERPCommercialDataLangs;
  513.     }
  514.     public function addERPCommercialDataLang(ERPCommercialDataLang $eRPCommercialDataLang): self
  515.     {
  516.         if (!$this->ERPCommercialDataLangs->contains($eRPCommercialDataLang)) {
  517.             $this->ERPCommercialDataLangs->add($eRPCommercialDataLang);
  518.             $eRPCommercialDataLang->setProduct($this);
  519.         }
  520.         return $this;
  521.     }
  522.     public function removeERPCommercialDataLang(ERPCommercialDataLang $eRPCommercialDataLang): self
  523.     {
  524.         if ($this->ERPCommercialDataLangs->removeElement($eRPCommercialDataLang)) {
  525.             // set the owning side to null (unless already changed)
  526.             if ($eRPCommercialDataLang->getProduct() === $this) {
  527.                 $eRPCommercialDataLang->setProduct(null);
  528.             }
  529.         }
  530.         return $this;
  531.     }
  532. }