vendor/store.shopware.com/moorlformbuilder/src/Core/Content/FormElement/FormElement.php line 31

Open in your IDE?
  1. <?php declare(strict_types=1);
  2. namespace MoorlFormBuilder\Core\Content\FormElement;
  3. use Shopware\Core\Framework\DataAbstractionLayer\Entity;
  4. class FormElement extends Entity implements FormElementInterface
  5. {
  6.     protected string $type;
  7.     protected string $id;
  8.     protected string $mediaType 'documents';
  9.     protected ?string $name null;
  10.     protected ?string $mapping null;
  11.     protected $value null;
  12.     protected array $behaviour = [];
  13.     protected array $conditions = [];
  14.     protected array $options = [];
  15.     protected ?bool $useImageSelection false;
  16.     protected ?bool $useCustomTemplate false;
  17.     protected string $gridSizeLg "12";
  18.     /* Date & Time properties */
  19.     protected int $timeStep 0;
  20.     protected int $timeMin 0;
  21.     protected int $timeMax 0;
  22.     protected string $dateMin "";
  23.     protected string $dateMax "";
  24.     protected int $dateStep 0;
  25.     protected array $dateExclude = [];
  26.     public function __construct(array $formElement) {
  27.         foreach ($formElement as $k => $v) {
  28.             if (isset($this->$k)) {
  29.                 if (is_string($this->$k)) {
  30.                     $this->$k = (string) $v;
  31.                 } elseif (is_int($this->$k)) {
  32.                     $this->$k = (int) $v;
  33.                 } elseif (is_bool($this->$k)) {
  34.                     $this->$k = (bool) $v;
  35.                 } else {
  36.                     $this->$k $v;
  37.                 }
  38.             } else {
  39.                 $this->$k $v;
  40.             }
  41.         }
  42.     }
  43.     /**
  44.      * @return int
  45.      */
  46.     public function getTimeStep(): int
  47.     {
  48.         return $this->timeStep;
  49.     }
  50.     /**
  51.      * @return int
  52.      */
  53.     public function getTimeMin(): int
  54.     {
  55.         return $this->timeMin;
  56.     }
  57.     /**
  58.      * @return int
  59.      */
  60.     public function getTimeMax(): int
  61.     {
  62.         return $this->timeMax;
  63.     }
  64.     /**
  65.      * @return string
  66.      */
  67.     public function getDateMin(): string
  68.     {
  69.         return $this->dateMin;
  70.     }
  71.     /**
  72.      * @return string
  73.      */
  74.     public function getDateMax(): string
  75.     {
  76.         return $this->dateMax;
  77.     }
  78.     /**
  79.      * @return int
  80.      */
  81.     public function getDateStep(): int
  82.     {
  83.         return $this->dateStep;
  84.     }
  85.     /**
  86.      * @return array
  87.      */
  88.     public function getDateExclude(): array
  89.     {
  90.         return $this->dateExclude;
  91.     }
  92.     /**
  93.      * @return array
  94.      */
  95.     public function getOptions(): array
  96.     {
  97.         return $this->options;
  98.     }
  99.     /**
  100.      * @param array $options
  101.      */
  102.     public function setOptions(array $options): void
  103.     {
  104.         $this->options $options;
  105.     }
  106.     public function getAppointmentOptions(): array
  107.     {
  108.         return [];
  109.         $timeInterval = new \DateInterval(sprintf("PT%sM"$this->timeStep));
  110.         $timeMin = new \DateTime();
  111.         $timeMax = clone($timeMin);
  112.         $timeRange = new \DatePeriod(
  113.             $timeMin->setTime((int) $this->timeMin,0),
  114.             $timeInterval,
  115.             $timeMax->setTime((int) $this->timeMax,0)
  116.         );
  117.         $dateInterval = new \DateInterval(sprintf("P%sD"$this->dateStep));
  118.         $dateMin = new \DateTime($this->dateMin);
  119.         $dateMax = new \DateTime($this->dateMax);
  120.         $dateRange = new \DatePeriod($dateMin$dateInterval$dateMax);
  121.         $optgroup = [];
  122.         foreach ($dateRange as $date) {
  123.             if (in_array($date->format("w"), $this->dateExclude)) {
  124.                 /*$optgroup[] = ['label' => $date->format('Y-m-d')];*/
  125.                 continue;
  126.             }
  127.             $options = [];
  128.             foreach ($timeRange as $time) {
  129.                 $options[] = [
  130.                     'value' => sprintf(
  131.                         "%sT%s",
  132.                         $date->format('Y-m-d'),
  133.                         $time->format('H:i')
  134.                     ),
  135.                     'disabled' => false
  136.                 ];
  137.             }
  138.             $optgroup[] = [
  139.                 'label' => $date->format('Y-m-d'),
  140.                 'options' => $options,
  141.             ];
  142.         }
  143.         return $optgroup;
  144.     }
  145.     /**
  146.      * @return string|null
  147.      */
  148.     public function getMapping(): ?string
  149.     {
  150.         return $this->mapping;
  151.     }
  152.     /**
  153.      * @param string|null $mapping
  154.      */
  155.     public function setMapping(?string $mapping): void
  156.     {
  157.         $this->mapping $mapping;
  158.     }
  159.     /**
  160.      * @return null
  161.      */
  162.     public function getValue()
  163.     {
  164.         return $this->value;
  165.     }
  166.     /**
  167.      * @param $value
  168.      */
  169.     public function setValue($value null): void
  170.     {
  171.         $this->value $value;
  172.     }
  173.     /**
  174.      * @return string|null
  175.      */
  176.     public function getName(): ?string
  177.     {
  178.         return $this->name;
  179.     }
  180.     /**
  181.      * @return string
  182.      */
  183.     public function getMediaType(): string
  184.     {
  185.         return $this->mediaType ?: 'documents';
  186.     }
  187.     /**
  188.      * @return string
  189.      */
  190.     public function getType(): string
  191.     {
  192.         return $this->type;
  193.     }
  194.     /**
  195.      * @return array
  196.      */
  197.     public function getBehaviour(): array
  198.     {
  199.         return $this->behaviour;
  200.     }
  201.     /**
  202.      * @param array $behaviour
  203.      */
  204.     public function setBehaviour(array $behaviour): void
  205.     {
  206.         $this->behaviour $behaviour;
  207.     }
  208.     /**
  209.      * @return array
  210.      */
  211.     public function getConditions(): array
  212.     {
  213.         return $this->conditions;
  214.     }
  215.     /**
  216.      * @param array $conditions
  217.      */
  218.     public function setConditions(array $conditions): void
  219.     {
  220.         $this->conditions $conditions;
  221.     }
  222.     /**
  223.      * @return bool|null
  224.      */
  225.     public function getUseImageSelection(): ?bool
  226.     {
  227.         return $this->useImageSelection;
  228.     }
  229.     /**
  230.      * @param bool|null $useImageSelection
  231.      */
  232.     public function setUseImageSelection(?bool $useImageSelection): void
  233.     {
  234.         $this->useImageSelection $useImageSelection;
  235.     }
  236.     /**
  237.      * @return bool|null
  238.      */
  239.     public function getUseCustomTemplate(): ?bool
  240.     {
  241.         return $this->useCustomTemplate;
  242.     }
  243.     /**
  244.      * @param bool|null $useCustomTemplate
  245.      */
  246.     public function setUseCustomTemplate(?bool $useCustomTemplate): void
  247.     {
  248.         $this->useCustomTemplate $useCustomTemplate;
  249.     }
  250.     public function getBehaviourClass(): string
  251.     {
  252.         if (empty($this->behaviour)) {
  253.                 return sprintf("col col-lg-%s"$this->gridSizeLg);
  254.         }
  255.         $txt "";
  256.         foreach ($this->behaviour as $breakpoint => $behaviour) {
  257.             if (isset($behaviour['order']) && (int)$behaviour['order'] !== 0) {
  258.                 $txt .= sprintf("order-%s-%d "$breakpoint$behaviour['order']);
  259.             }
  260.             if (isset($behaviour['width']) && (int)$behaviour['width'] !== -1) {
  261.                 $txt .= sprintf("col-%s-%d "$breakpoint$behaviour['width']);
  262.             } else {
  263.                 continue;
  264.             }
  265.             if (isset($behaviour['visible']) && empty($this->conditions)) {
  266.                 $txt .= sprintf("d-%s-%s "$breakpoint$behaviour['visible'] ? 'block' 'none');
  267.             }
  268.         }
  269.         return trim(str_replace(["base-","-0"], ""$txt));
  270.     }
  271.     public function getImageClass(): string
  272.     {
  273.         if ($this->useImageSelection && !$this->useCustomTemplate) {
  274.             return "moorl-form-builder-image-selection";
  275.         }
  276.         return "";
  277.     }
  278. }