src/Entity/Configurator/Model.php line 19

Open in your IDE?
  1. <?php
  2. declare(strict_types=1);
  3. namespace App\Entity\Configurator;
  4. use App\Entity\Product\ProductVariant;
  5. use App\Model\ElementType;
  6. use Doctrine\Common\Collections\ArrayCollection;
  7. use Doctrine\Common\Collections\Collection;
  8. use Doctrine\ORM\Mapping as ORM;
  9. use Sylius\Component\Resource\Model\CodeAwareInterface;
  10. use Sylius\Component\Resource\Model\ResourceInterface;
  11. /**
  12.  * @ORM\Entity
  13.  * @ORM\Table(name="app_configurator_model")
  14.  */
  15. class Model implements ResourceInterfaceCodeAwareInterface
  16. {
  17.     const WIDTH_MAX 3200;
  18.     const HEIGHT_MAX 3200;
  19.     const PRINT_FORMAT_PNG "png";
  20.     const PRINT_FORMAT_JPG "jpg";
  21.     const PRINT_FORMAT_PDF "pdf";
  22.     const TYPE_TEXT ElementType::TYPE_TEXT;
  23.     const TYPE_IMAGE_LIBRARY ElementType::TYPE_IMAGE_LIBRARY;
  24.     const TYPE_IMAGE_UPLOAD ElementType::TYPE_IMAGE_UPLOAD;
  25.     /**
  26.      * @ORM\Id()
  27.      * @ORM\GeneratedValue()
  28.      * @ORM\Column(type="integer")
  29.      */
  30.     private ?int $id null;
  31.     /**
  32.      * @ORM\Column(type="string", length=70)
  33.      */
  34.     private ?string $code null;
  35.     /**
  36.      * @ORM\Column(type="string")
  37.      */
  38.     private ?string $name null;
  39.     /**
  40.      * largeur contexte
  41.      * @ORM\Column(type="float", options={"default" : 800})
  42.      */
  43.     private ?float $width 800;
  44.     /**
  45.      * hauteur contexte
  46.      * @ORM\Column(type="float", options={"default" : 800})
  47.      */
  48.     private ?float $height 800;
  49.     /**
  50.      * print zone width (px)
  51.      * @ORM\Column(name="print_zone_width_px", type="float", options={"default" : 253})
  52.      */
  53.     private float $printZoneWidthPx 253;
  54.     /**
  55.      * print zone height (px)
  56.      * @ORM\Column(name="print_zone_height_px", type="float", options={"default" : 350})
  57.      */
  58.     private float $printZoneHeightPx 350;
  59.     /**
  60.      * @ORM\Column(type="integer", nullable=false, name="print_zone_coordinates_x", options={"default" : 0})
  61.      */
  62.     private int $printZoneCoordinatesX 0;
  63.     /**
  64.      * @ORM\Column(type="integer", nullable=false, name="print_zone_coordinates_y", options={"default" : 0})
  65.      */
  66.     private int $printZoneCoordinatesY 0;
  67.     /**
  68.      * @ORM\Column(type="string", nullable=false, name="print_format")
  69.      */
  70.     private string $printFormat;
  71.     /**
  72.      * scale between real sizes and rendering sizes
  73.      * @ORM\Column(type="float", nullable=true)
  74.      */
  75.     private ?float $scale;
  76.     /**
  77.      * @ORM\OneToMany(targetEntity=Element::class, mappedBy="model", orphanRemoval=true, cascade={"persist"})
  78.      */
  79.     private Collection $elements;
  80.     /**
  81.      * @ORM\Column(name="watermark_on_cart_rendering", type="boolean", nullable=true, options={"default" : 1})
  82.      */
  83.     private ?bool $watermarkOnCartRendering true;
  84.     /**
  85.      * 0 => configurateur simple / 1 => configurateur complexe
  86.      * @ORM\Column(type="boolean", nullable=true, options={"default" : 1})
  87.      */
  88.     private ?bool $advanced true;
  89.     /**
  90.      * 0 => configurateur standard / 1 => configurateur libre
  91.      * @ORM\Column(name="free_configuration", type="boolean", nullable=true, options={"default" : 0})
  92.      */
  93.     private ?bool $freeConfiguration false;
  94.     /**
  95.      * @ORM\OneToOne(targetEntity=ProductVariant::class, mappedBy="model", cascade={"persist"})
  96.      * @ORM\JoinColumn(nullable=true, onDelete="SET NULL", name="product_variant_id")
  97.      */
  98.     private ?ProductVariant $productVariant null;
  99.     /**
  100.      * @ORM\Column(type="string", nullable=true)
  101.      */
  102.     private ?string $token null;
  103.     // FREE CONFIGURATOR
  104.     /**
  105.      * 0 => pas de personnalisation du texte possible / 1 => afficher les outils de personnalisation du texte (stroke, shadow, bold, italic...)
  106.      * @ORM\Column(name="text_personalisation", type="boolean", nullable=true, options={"default" : 1})
  107.      */
  108.     private ?bool $textPersonalisation true;
  109.     /**
  110.      * @ORM\Column(type="array", nullable=true)
  111.      */
  112.     private ?array $type;
  113.     /**
  114.      * @ORM\ManyToMany(targetEntity=Font::class, mappedBy="models")
  115.      * @ORM\JoinTable(
  116.      *      name="app_configurator_model_font",
  117.      *      joinColumns={@ORM\JoinColumn(name="model_id", referencedColumnName="id", nullable=false, onDelete="CASCADE")},
  118.      *      inverseJoinColumns={@ORM\JoinColumn(name="font_id", referencedColumnName="id", nullable=false, onDelete="CASCADE")}
  119.      *      )
  120.      */
  121.     private Collection $fonts;
  122.     /**
  123.      * @ORM\ManyToMany(targetEntity=FontColor::class, mappedBy="models")
  124.      * @ORM\JoinTable(
  125.      *      name="app_configurator_model_font_color",
  126.      *      joinColumns={@ORM\JoinColumn(name="model_id", referencedColumnName="id", nullable=false, onDelete="CASCADE")},
  127.      *      inverseJoinColumns={@ORM\JoinColumn(name="font_color_id", referencedColumnName="id", nullable=false, onDelete="CASCADE")}
  128.      *      )
  129.      */
  130.     private Collection $fontColors;
  131.     /**
  132.      * @ORM\ManyToMany(targetEntity="App\Entity\Configurator\FontColor")
  133.      * @ORM\JoinTable(
  134.      *      name="app_configurator_model_stroke_color",
  135.      *      joinColumns={@ORM\JoinColumn(name="model_id", referencedColumnName="id", nullable=false, onDelete="CASCADE")},
  136.      *      inverseJoinColumns={@ORM\JoinColumn(name="font_color_id", referencedColumnName="id", nullable=false, onDelete="CASCADE")}
  137.      *      )
  138.      */
  139.     private $strokeColors;
  140.     /**
  141.      * @ORM\ManyToMany(targetEntity="App\Entity\Configurator\FontColor")
  142.      * @ORM\JoinTable(
  143.      *      name="app_configurator_model_shadow_color",
  144.      *      joinColumns={@ORM\JoinColumn(name="model_id", referencedColumnName="id", nullable=false, onDelete="CASCADE")},
  145.      *      inverseJoinColumns={@ORM\JoinColumn(name="font_color_id", referencedColumnName="id", nullable=false, onDelete="CASCADE")}
  146.      *      )
  147.      */
  148.     private $shadowColors;
  149.     /**
  150.      * @ORM\ManyToOne(targetEntity=Font::class)
  151.      * @ORM\JoinColumn(nullable=true, name="default_font_id")
  152.      */
  153.     private ?Font $defaultFont;
  154.     /**
  155.      * @ORM\ManyToOne(targetEntity=FontColor::class)
  156.      * @ORM\JoinColumn(nullable=true, name="default_font_color_id")
  157.      */
  158.     private ?FontColor $defaultFontColor;
  159.     /**
  160.      * @ORM\ManyToOne(targetEntity=FontColor::class)
  161.      * @ORM\JoinColumn(nullable=true, name="default_stroke_color_id")
  162.      */
  163.     private ?FontColor $defaultStrokeColor;
  164.     /**
  165.      * @ORM\ManyToOne(targetEntity=FontColor::class)
  166.      * @ORM\JoinColumn(nullable=true, name="default_shadow_color_id")
  167.      */
  168.     private ?FontColor $defaultShadowColor;
  169.     /**
  170.      * @ORM\ManyToMany(targetEntity=Library::class)
  171.      * @ORM\JoinTable(
  172.      *      name="app_configurator_model_library",
  173.      *      joinColumns={@ORM\JoinColumn(name="model_id", referencedColumnName="id", nullable=false, onDelete="CASCADE")},
  174.      *      inverseJoinColumns={@ORM\JoinColumn(name="library_id", referencedColumnName="id", nullable=false, onDelete="CASCADE")}
  175.      *      )
  176.      */
  177.     private Collection $libraries;
  178.     // ----- END FREE CONFIGURATOR
  179.     public function __construct()
  180.     {
  181.         $this->elements = new ArrayCollection();
  182.         $this->fonts = new ArrayCollection();
  183.         $this->fontColors = new ArrayCollection();
  184.         $this->strokeColors = new ArrayCollection();
  185.         $this->shadowColors = new ArrayCollection();
  186.         $this->libraries = new ArrayCollection();
  187.     }
  188.     /**
  189.      * @return int|null
  190.      */
  191.     public function getId(): ?int
  192.     {
  193.         return $this->id;
  194.     }
  195.     /**
  196.      * @param int|null $id
  197.      */
  198.     public function setId(?int $id): void
  199.     {
  200.         $this->id $id;
  201.     }
  202.     /**
  203.      * @return string|null
  204.      */
  205.     public function getName(): ?string
  206.     {
  207.         return $this->name;
  208.     }
  209.     /**
  210.      * @param string|null $name
  211.      */
  212.     public function setName(?string $name): void
  213.     {
  214.         $this->name $name;
  215.     }
  216.     /**
  217.      * @return float|null
  218.      */
  219.     public function getWidth(): ?float
  220.     {
  221.         return $this->width;
  222.     }
  223.     /**
  224.      * @param float|null $width
  225.      */
  226.     public function setWidth(?float $width): void
  227.     {
  228.         $this->width $width;
  229.     }
  230.     /**
  231.      * @return float|null
  232.      */
  233.     public function getHeight(): ?float
  234.     {
  235.         return $this->height;
  236.     }
  237.     /**
  238.      * @param float|null $height
  239.      */
  240.     public function setHeight(?float $height): void
  241.     {
  242.         $this->height $height;
  243.     }
  244.     /**
  245.      * @return Collection<int, Element>
  246.      */
  247.     public function getElements(): Collection
  248.     {
  249.         return $this->elements;
  250.     }
  251.     public function addElement(Element $element): self
  252.     {
  253.         if (!$this->elements->contains($element)) {
  254.             $this->elements[] = $element;
  255.             $element->setModel($this);
  256.         }
  257.         return $this;
  258.     }
  259.     public function removeElement(Element $element): self
  260.     {
  261.         $this->elements->removeElement($element);
  262.         return $this;
  263.     }
  264.     public function getProductVariant(): ?ProductVariant
  265.     {
  266.         return $this->productVariant;
  267.     }
  268.     /**
  269.      * @param ProductVariant|null $productVariant
  270.      */
  271.     public function setProductVariant(?ProductVariant $productVariant): self
  272.     {
  273.         // unset the owning side of the relation if necessary
  274.         if ($productVariant === null && $this->productVariant !== null) {
  275.             $this->productVariant->setModel(null);
  276.         }
  277.         // set the owning side of the relation if necessary
  278.         if ($productVariant !== null && $productVariant->getModel() !== $this) {
  279.             $this->productVariant?->setModel(null);
  280.             $productVariant->setModel($this);
  281.         }
  282.         $this->productVariant $productVariant;
  283.         return $this;
  284.     }
  285.     /**
  286.      * @return float
  287.      */
  288.     public function getPrintZoneWidthPx(): float
  289.     {
  290.         return $this->printZoneWidthPx;
  291.     }
  292.     /**
  293.      * @param float $printZoneWidthPx
  294.      */
  295.     public function setPrintZoneWidthPx(float $printZoneWidthPx): void
  296.     {
  297.         $this->printZoneWidthPx $printZoneWidthPx;
  298.     }
  299.     /**
  300.      * @return float
  301.      */
  302.     public function getPrintZoneHeightPx(): float
  303.     {
  304.         return $this->printZoneHeightPx;
  305.     }
  306.     /**
  307.      * @param float $printZoneHeightPx
  308.      */
  309.     public function setPrintZoneHeightPx(float $printZoneHeightPx): void
  310.     {
  311.         $this->printZoneHeightPx $printZoneHeightPx;
  312.     }
  313.     /**
  314.      * @return float|null
  315.      */
  316.     public function getScale(): ?float
  317.     {
  318.         return $this->scale;
  319.     }
  320.     /**
  321.      * @param null|float $scale
  322.      */
  323.     public function setScale(?float $scale): void
  324.     {
  325.         $this->scale $scale;
  326.     }
  327.     /**
  328.      * @return int
  329.      */
  330.     public function getPrintZoneCoordinatesX(): int
  331.     {
  332.         return $this->printZoneCoordinatesX;
  333.     }
  334.     /**
  335.      * @param int $printZoneCoordinatesX
  336.      */
  337.     public function setPrintZoneCoordinatesX(int $printZoneCoordinatesX): void
  338.     {
  339.         $this->printZoneCoordinatesX $printZoneCoordinatesX;
  340.     }
  341.     /**
  342.      * @return int
  343.      */
  344.     public function getPrintZoneCoordinatesY(): int
  345.     {
  346.         return $this->printZoneCoordinatesY;
  347.     }
  348.     /**
  349.      * @param int $printZoneCoordinatesY
  350.      */
  351.     public function setPrintZoneCoordinatesY(int $printZoneCoordinatesY): void
  352.     {
  353.         $this->printZoneCoordinatesY $printZoneCoordinatesY;
  354.     }
  355.     /**
  356.      * @return string
  357.      */
  358.     public function getPrintFormat(): string
  359.     {
  360.         return $this->printFormat;
  361.     }
  362.     /**
  363.      * @param string $printFormat
  364.      */
  365.     public function setPrintFormat(string $printFormat): void
  366.     {
  367.         $this->printFormat $printFormat;
  368.     }
  369.     /**
  370.      * @return string|null
  371.      */
  372.     public function getToken(): ?string
  373.     {
  374.         return $this->token;
  375.     }
  376.     /**
  377.      * @param string|null $token
  378.      */
  379.     public function setToken(?string $token): void
  380.     {
  381.         $this->token $token;
  382.     }
  383.     /**
  384.      * @return bool|null
  385.      */
  386.     public function getWatermarkOnCartRendering(): ?bool
  387.     {
  388.         return $this->watermarkOnCartRendering;
  389.     }
  390.     /**
  391.      * @param bool|null $watermarkOnCartRendering
  392.      */
  393.     public function setWatermarkOnCartRendering(?bool $watermarkOnCartRendering): void
  394.     {
  395.         $this->watermarkOnCartRendering $watermarkOnCartRendering;
  396.     }
  397.     /**
  398.      * @return bool|null
  399.      */
  400.     public function getAdvanced(): ?bool
  401.     {
  402.         return $this->advanced;
  403.     }
  404.     /**
  405.      * @param bool|null $advanced
  406.      */
  407.     public function setAdvanced(?bool $advanced): void
  408.     {
  409.         $this->advanced $advanced;
  410.     }
  411.     /**
  412.      * @return array|null
  413.      */
  414.     public function getType(): ?array
  415.     {
  416.         return $this->type;
  417.     }
  418.     /**
  419.      * @param array|null $type
  420.      */
  421.     public function setType(?array $type): void
  422.     {
  423.         $this->type $type;
  424.     }
  425.     /**
  426.      * @return bool|null
  427.      */
  428.     public function getFreeConfiguration(): ?bool
  429.     {
  430.         return $this->freeConfiguration;
  431.     }
  432.     /**
  433.      * @param bool|null $freeConfiguration
  434.      */
  435.     public function setFreeConfiguration(?bool $freeConfiguration): void
  436.     {
  437.         $this->freeConfiguration $freeConfiguration;
  438.     }
  439.     public function getFonts(): Collection
  440.     {
  441.         return $this->fonts;
  442.     }
  443.     public function addFont(Font $font): self
  444.     {
  445.         if (!$this->fonts->contains($font))
  446.         {
  447.             $this->fonts[] = $font;
  448.             $font->addModel($this);
  449.         }
  450.         return $this;
  451.     }
  452.     public function removeFont(Font $font): self
  453.     {
  454.         $this->fonts->removeElement($font);
  455.         $font->removeModel($this);
  456.         return $this;
  457.     }
  458.     public function clearFonts(): void {
  459.         foreach ($this->fonts as $font) {
  460.             $this->removeFont($font);
  461.         }
  462.     }
  463.     /**
  464.      * @return Font|null
  465.      */
  466.     public function getDefaultFont(): ?Font
  467.     {
  468.         return $this->defaultFont;
  469.     }
  470.     /**
  471.      * @param Font|null $defaultFont
  472.      */
  473.     public function setDefaultFont(?Font $defaultFont): void
  474.     {
  475.         $this->defaultFont $defaultFont;
  476.     }
  477.     public function getFontColors(): Collection
  478.     {
  479.         return $this->fontColors;
  480.     }
  481.     public function addFontColor(FontColor $fontColor): self
  482.     {
  483.         if (!$this->fontColors->contains($fontColor)) {
  484.             $this->fontColors[] = $fontColor;
  485.             $fontColor->addModel($this);
  486.         }
  487.         return $this;
  488.     }
  489.     public function removeFontColor(FontColor $fontColor): self
  490.     {
  491.         $this->fontColors->removeElement($fontColor);
  492.         $fontColor->removeModel($this);
  493.         return $this;
  494.     }
  495.     public function clearFontColors(): void {
  496.         foreach ($this->fontColors as $fontColor) {
  497.             $this->removeFontColor($fontColor);
  498.         }
  499.     }
  500.     /**
  501.      * @return FontColor|null
  502.      */
  503.     public function getDefaultFontColor(): ?FontColor
  504.     {
  505.         return $this->defaultFontColor;
  506.     }
  507.     /**
  508.      * @param FontColor|null $defaultFontColor
  509.      */
  510.     public function setDefaultFontColor(?FontColor $defaultFontColor): void
  511.     {
  512.         $this->defaultFontColor $defaultFontColor;
  513.     }
  514.     public function getLibraries(): Collection
  515.     {
  516.         return $this->libraries;
  517.     }
  518.     public function addLibrary(Library $library): self
  519.     {
  520.         if (!$this->libraries->contains($library))
  521.         {
  522.             $this->libraries[] = $library;
  523.         }
  524.         return $this;
  525.     }
  526.     public function removeLibrary(Library $library): self
  527.     {
  528.         $this->libraries->removeElement($library);
  529.         return $this;
  530.     }
  531.     public function clearLibraries(): void {
  532.         foreach ($this->libraries as $library) {
  533.             $this->removeLibrary($library);
  534.         }
  535.     }
  536.     public function getCode(): ?string
  537.     {
  538.         return $this->code;
  539.     }
  540.     public function setCode(?string $code): void
  541.     {
  542.         $this->code $code;
  543.     }
  544.     /**
  545.      * @return bool|null
  546.      */
  547.     public function getTextPersonalisation(): ?bool
  548.     {
  549.         return $this->textPersonalisation;
  550.     }
  551.     /**
  552.      * @param bool|null $textPersonalisation
  553.      */
  554.     public function setTextPersonalisation(?bool $textPersonalisation): void
  555.     {
  556.         $this->textPersonalisation $textPersonalisation;
  557.     }
  558.     public function getStrokeColors(): Collection
  559.     {
  560.         return $this->strokeColors;
  561.     }
  562.     public function addStrokeColor(FontColor $fontColor): self
  563.     {
  564.         if (!$this->strokeColors->contains($fontColor))
  565.         {
  566.             $this->strokeColors[] = $fontColor;
  567.         }
  568.         return $this;
  569.     }
  570.     public function removeStrokeColor(FontColor $fontColor): self
  571.     {
  572.         $this->strokeColors->removeElement($fontColor);
  573.         return $this;
  574.     }
  575.     public function clearStrokeColors(): void
  576.     {
  577.         foreach ($this->strokeColors as $fontColor) {
  578.             $this->removeStrokeColor($fontColor);
  579.         }
  580.     }
  581.     public function getShadowColors(): Collection
  582.     {
  583.         return $this->shadowColors;
  584.     }
  585.     public function addShadowColor(FontColor $fontColor): self
  586.     {
  587.         if (!$this->shadowColors->contains($fontColor))
  588.         {
  589.             $this->shadowColors[] = $fontColor;
  590.         }
  591.         return $this;
  592.     }
  593.     public function removeShadowColor(FontColor $fontColor): self
  594.     {
  595.         $this->shadowColors->removeElement($fontColor);
  596.         return $this;
  597.     }
  598.     public function clearShadowColors(): void
  599.     {
  600.         foreach ($this->shadowColors as $fontColor) {
  601.             $this->removeShadowColor($fontColor);
  602.         }
  603.     }
  604.     /**
  605.      * @return FontColor|null
  606.      */
  607.     public function getDefaultStrokeColor(): ?FontColor
  608.     {
  609.         return $this->defaultStrokeColor;
  610.     }
  611.     /**
  612.      * @param FontColor|null $defaultStrokeColor
  613.      */
  614.     public function setDefaultStrokeColor(?FontColor $defaultStrokeColor): void
  615.     {
  616.         $this->defaultStrokeColor $defaultStrokeColor;
  617.     }
  618.     /**
  619.      * @return FontColor|null
  620.      */
  621.     public function getDefaultShadowColor(): ?FontColor
  622.     {
  623.         return $this->defaultShadowColor;
  624.     }
  625.     /**
  626.      * @param FontColor|null $defaultShadowColor
  627.      */
  628.     public function setDefaultShadowColor(?FontColor $defaultShadowColor): void
  629.     {
  630.         $this->defaultShadowColor $defaultShadowColor;
  631.     }
  632. }