src/Filtration/Trait/FilterTrait.php line 725

Open in your IDE?
  1. <?php
  2. namespace App\Filtration\Trait;
  3. use App\Entity\Product;
  4. use App\Entity\ProductCategory;
  5. use App\Entity\ProductFamily;
  6. use App\Enum\FilterEnum;
  7. use App\Repository\ProductVariantRepository;
  8. use Doctrine\ORM\QueryBuilder;
  9. use Symfony\Contracts\Translation\TranslatorInterface;
  10. /**
  11.  * Trait FilterTrait
  12.  *
  13.  * This trait expects the following properties to be defined in the using class:
  14.  * @property QueryBuilder $qb
  15.  * @property string $webspace
  16.  * @property string $locale
  17.  * @property array|null $types
  18.  * @property array|null $fixations
  19.  * @property int|null $minLuminousFlux
  20.  * @property int|null $maxLuminousFlux
  21.  * @property array|null $cris
  22.  * @property array|null $chromaticities
  23.  * @property array|null $dispersionVariants
  24.  * @property array|null $ips
  25.  * @property array|null $radiationDirects
  26.  * @property array|null $shapes
  27.  * @property int|null $minLength
  28.  * @property int|null $maxLength
  29.  * @property int|null $minWidth
  30.  * @property int|null $maxWidth
  31.  * @property int|null $minHeight
  32.  * @property int|null $maxHeight
  33.  * @property array|null $colors
  34.  * @property array|null $usages
  35.  * @property array|null $maxTemperatures
  36.  * @property array|null $minTemperatures
  37.  * @property int|null $minInputPower
  38.  * @property int|null $maxInputPower
  39.  * @property int|null $minEfficiency
  40.  * @property int|null $maxEfficiency
  41.  * @property array|null $elProtects
  42.  * @property array|null $powerMethods
  43.  * @property array|null $resourceTypes
  44. // * @property array|null $lightSources
  45.  * @property array|null $statuses
  46.  * @property array|null $mechanicalDurabilities
  47.  * @property array|null $dispersions
  48.  * @property array|null $drivers
  49.  * @property array|null $accessories
  50.  * @property ProductVariantRepository $productVariantRepository
  51.  * @property TranslatorInterface $translator
  52.  */
  53. trait FilterTrait
  54. {
  55.     use FiltrationCriteriaTrait;
  56.     private function renderMultiSelect(string $keystring $label, array $options = []): array
  57.     {
  58.         return [
  59.             'checkbox_select' => [
  60.                 'id' => $key,
  61.                 'label' => $label,
  62.                 'title' => 'Vybrat',
  63.                 'full_name' => $key '[]',
  64.                 'choices' => $options
  65.             ]
  66.         ];
  67.     }
  68.     private function renderSlider(
  69.         string $key,
  70.         string $label,
  71.         int $minLimit,
  72.         int $maxLimit,
  73.         ?int $min null,
  74.         ?int $max null
  75.     ): array
  76.     {
  77.         return [
  78.             'range' => [
  79.                 'id' => $key,
  80.                 'label' => $label,
  81.                 'min' => $minLimit,
  82.                 'max' => $maxLimit,
  83.                 'from' => [
  84.                     'full_name' => $key '_min',
  85.                     'value' => $min ?? $minLimit,
  86.                 ],
  87.                 'to' => [
  88.                     'full_name' => $key '_max',
  89.                     'value' => $max ?? $maxLimit,
  90.                 ],
  91.             ],
  92.         ];
  93.     }
  94.     // Typ
  95.     // **********************************
  96.     private function getTypeCounts(?array $types null): array
  97.     {
  98.         if($types === null) {
  99.             $types $this->productVariantRepository->getAllTypes($this->webspace$this->locale);
  100.         }
  101.         $results = [];
  102.         foreach($types as $type) {
  103.             $tempQb = clone $this->qb;
  104.             $this->productVariantRepository->addTypesToQueryBuilder($tempQb, [$type]);
  105.             $this->putAllCriteriaToQueryBuilder($tempQb, ['pv.type']);
  106.             $results[$type] = count($tempQb->getQuery()->getScalarResult());
  107.         }
  108.         return $results;
  109.     }
  110.     private function renderTypeFilter(): array
  111.     {
  112.         $types $this->productVariantRepository->getAllTypes($this->webspace$this->locale);
  113.         $typeCounts $this->getTypeCounts($types);
  114.         $options = [];
  115.         if($types) {
  116.             foreach($types as $option) {
  117.                 $options[] = [
  118.                     'label' => $option,
  119.                     'value' => $option,
  120.                     'checked' => $checked in_array($option$this->types ?? []),
  121.                     'disabled' => $typeCounts[$option] === && !$checked,
  122.                 ];
  123.             }
  124.         }
  125.         return $this->renderMultiSelect(FilterEnum::TYPE->getQueryKey(), FilterEnum::TYPE->trans($this->translator), $options);
  126.     }
  127.     // **********************************
  128.     // Způsob montáže
  129.     // **********************************
  130.     private function getFixationCounts(?array $fixations null): array
  131.     {
  132.         if($fixations === null) {
  133.             $fixations $this->productVariantRepository->getAllFixations($this->webspace$this->locale);
  134.         }
  135.         $results = [];
  136.         foreach($fixations as $fixation) {
  137.             $tempQb = clone $this->qb;
  138.             $this->productVariantRepository->addFixationsToQueryBuilder($tempQb, [$fixation]);
  139.             $this->putAllCriteriaToQueryBuilder($tempQb, ['pv.fixation']);
  140.             $results[$fixation] = count($tempQb->getQuery()->getScalarResult());
  141.         }
  142.         return $results;
  143.     }
  144.     private function renderFixationFilter(): array
  145.     {
  146.         $fixations $this->productVariantRepository->getAllFixations($this->webspace$this->locale);
  147.         $fixationCounts $this->getFixationCounts($fixations);
  148.         $options = [];
  149.         if($fixations) {
  150.             foreach($fixations as $option) {
  151.                 $options[] = [
  152.                     'label' => $option,
  153.                     'value' => $option,
  154.                     'checked' => $checked in_array($option$this->fixations ?? []),
  155.                     'disabled' => $fixationCounts[$option] === && !$checked,
  156.                 ];
  157.             }
  158.         }
  159.         return $this->renderMultiSelect(FilterEnum::FIXATION->getQueryKey(), FilterEnum::FIXATION->trans($this->translator), $options);
  160.     }
  161.     // **********************************
  162.     // Světelný tok [lm]
  163.     // **********************************
  164.     private function renderLuminousFluxFilter(
  165.         ?ProductCategory $productCategory null,
  166.         ?ProductFamily $productFamily null,
  167.         ?Product $product null,
  168.     ): array
  169.     {
  170.         $minLuminousFluxLimit $this->productVariantRepository->getMinLuminousFlux(
  171.             webspace$this->webspace,
  172.             locale$this->locale,
  173.             productCategory$productCategory,
  174.             productFamily$productFamily,
  175.             product$product,
  176.         );
  177.         $maxLuminousFluxLimit $this->productVariantRepository->getMaxLuminousFlux(
  178.             webspace$this->webspace,
  179.             locale$this->locale,
  180.             productCategory$productCategory,
  181.             productFamily$productFamily,
  182.             product$product,
  183.         );
  184.         return $this->renderSlider(
  185.             keyFilterEnum::LUMINOUS_FLUX->getQueryKey(),
  186.             labelFilterEnum::LUMINOUS_FLUX->trans($this->translator),
  187.             minLimit$minLuminousFluxLimit,
  188.             maxLimit$maxLuminousFluxLimit,
  189.             min$this->minLuminousFlux,
  190.             max$this->maxLuminousFlux,
  191.         );
  192.     }
  193.     // **********************************
  194.     // Index podání barev
  195.     // **********************************
  196.     private function getCriCounts(?array $cris null): array
  197.     {
  198.         if($cris === null) {
  199.             $cris $this->productVariantRepository->getAllCris($this->webspace$this->locale);
  200.         }
  201.         $results = [];
  202.         foreach($cris as $cri) {
  203.             $tempQb = clone $this->qb;
  204.             $this->productVariantRepository->addCrisToQueryBuilder($tempQb, [$cri]);
  205.             $this->putAllCriteriaToQueryBuilder($tempQb, ['pv.cri']);
  206.             $results[$cri] = count($tempQb->getQuery()->getScalarResult());
  207.         }
  208.         return $results;
  209.     }
  210.     private function renderCriFilter(): array
  211.     {
  212.         $cris $this->productVariantRepository->getAllCris($this->webspace$this->locale);
  213.         $criCounts $this->getCriCounts($cris);
  214.         $options = [];
  215.         if($cris) {
  216.             foreach($cris as $option) {
  217.                 $options[] = [
  218.                     'label' => $option,
  219.                     'value' => $option,
  220.                     'checked' => $checked in_array($option$this->cris ?? []),
  221.                     'disabled' => $criCounts[$option] === && !$checked,
  222.                 ];
  223.             }
  224.         }
  225.         return $this->renderMultiSelect(FilterEnum::CRI->getQueryKey(), FilterEnum::CRI->trans($this->translator), $options);
  226.     }
  227.     // **********************************
  228.     // Teplota chromatičnosti
  229.     // **********************************
  230.     private function getChromaticityCounts(?array $chromaticities null): array
  231.     {
  232.         if($chromaticities === null) {
  233.             $chromaticities $this->productVariantRepository->getAllCris($this->webspace$this->locale);
  234.         }
  235.         $results = [];
  236.         foreach($chromaticities as $chromaticity) {
  237.             $tempQb = clone $this->qb;
  238.             $this->productVariantRepository->addChromaticitiesToQueryBuilder($tempQb, [$chromaticity]);
  239.             $this->putAllCriteriaToQueryBuilder($tempQb, ['pv.chromaticity']);
  240.             $results[$chromaticity] = count($tempQb->getQuery()->getScalarResult());
  241.         }
  242.         return $results;
  243.     }
  244.     private function renderChromaticityFilter(): array
  245.     {
  246.         $chromaticities $this->productVariantRepository->getAllChromaticities($this->webspace$this->locale);
  247.         $chromaticityCounts $this->getChromaticityCounts($chromaticities);
  248.         $options = [];
  249.         if($chromaticities) {
  250.             foreach($chromaticities as $option) {
  251.                 $options[] = [
  252.                     'label' => $option,
  253.                     'value' => $option,
  254.                     'checked' => $checked in_array($option$this->chromaticities ?? []),
  255.                     'disabled' => $chromaticityCounts[$option] === && !$checked,
  256.                 ];
  257.             }
  258.         }
  259.         return $this->renderMultiSelect(FilterEnum::CHROMATICITY->getQueryKey(), FilterEnum::CHROMATICITY->trans($this->translator), $options);
  260.     }
  261.     // **********************************
  262.     // Varianta difúzoru
  263.     // **********************************
  264.     private function getDispersionVariantCounts(?array $dispersionVariants null): array
  265.     {
  266.         if($dispersionVariants === null) {
  267.             $dispersionVariants $this->productVariantRepository->getAllDispersionVariants($this->webspace$this->locale);
  268.         }
  269.         $results = [];
  270.         foreach($dispersionVariants as $dispersionVariant) {
  271.             $tempQb = clone $this->qb;
  272.             $this->productVariantRepository->addDispersionVariantsToQueryBuilder($tempQb, [$dispersionVariant]);
  273.             $this->putAllCriteriaToQueryBuilder($tempQb, ['pv.dispersionVariant']);
  274.             $results[$dispersionVariant] = count($tempQb->getQuery()->getScalarResult());
  275.         }
  276.         return $results;
  277.     }
  278.     private function renderDispersionVariantFilter(): array
  279.     {
  280.         $dispersionVariants $this->productVariantRepository->getAllDispersionVariants($this->webspace$this->locale);
  281.         $dispersionVariantCounts $this->getDispersionVariantCounts($dispersionVariants);
  282.         $options = [];
  283.         if($dispersionVariants) {
  284.             foreach($dispersionVariants as $option) {
  285.                 $options[] = [
  286.                     'label' => $option,
  287.                     'value' => $option,
  288.                     'checked' => $checked in_array($option$this->dispersionVariants ?? []),
  289.                     'disabled' => $dispersionVariantCounts[$option] === && !$checked,
  290.                 ];
  291.             }
  292.         }
  293.         return $this->renderMultiSelect(FilterEnum::DISPERSION_VARIANT->getQueryKey(), FilterEnum::DISPERSION_VARIANT->trans($this->translator), $options);
  294.     }
  295.     // **********************************
  296.     // IP stupeň krytí
  297.     // **********************************
  298.     private function getIPCounts(?array $ips null): array
  299.     {
  300.         if($ips === null) {
  301.             $ips $this->productVariantRepository->getAllIps($this->webspace$this->locale);
  302.         }
  303.         $results = [];
  304.         foreach($ips as $ip) {
  305.             $tempQb = clone $this->qb;
  306.             $this->productVariantRepository->addIpsToQueryBuilder($tempQb, [$ip]);
  307.             $this->putAllCriteriaToQueryBuilder($tempQb, ['pv.protectClass']);
  308.             $results[$ip] = count($tempQb->getQuery()->getScalarResult());
  309.         }
  310.         return $results;
  311.     }
  312.     private function renderIPFilter(): array
  313.     {
  314.         $ips $this->productVariantRepository->getAllIps($this->webspace$this->locale);
  315.         $ipCounts $this->getIPCounts($ips);
  316.         $options = [];
  317.         if($ips) {
  318.             foreach($ips as $option) {
  319.                 $options[] = [
  320.                     'label' => $option,
  321.                     'value' => $option,
  322.                     'checked' => $checked in_array($option$this->ips ?? []),
  323.                     'disabled' => $ipCounts[$option] === && !$checked,
  324.                 ];
  325.             }
  326.         }
  327.         return $this->renderMultiSelect(FilterEnum::IP->getQueryKey(), FilterEnum::IP->trans($this->translator), $options);
  328.     }
  329.     // **********************************
  330.     // Směr svícení
  331.     // **********************************
  332.     private function getRadiationDirectCounts(?array $radiationDirects null): array
  333.     {
  334.         if($radiationDirects === null) {
  335.             $radiationDirects $this->productVariantRepository->getAllRadiationDirects($this->webspace$this->locale);
  336.         }
  337.         $results = [];
  338.         foreach($radiationDirects as $radiationDirect) {
  339.             $tempQb = clone $this->qb;
  340.             $this->productVariantRepository->addRadiationDirectsToQueryBuilder($tempQb, [$radiationDirect]);
  341.             $this->putAllCriteriaToQueryBuilder($tempQb, ['pv.radiationDirect']);
  342.             $results[$radiationDirect] = count($tempQb->getQuery()->getScalarResult());
  343.         }
  344.         return $results;
  345.     }
  346.     private function renderRadiationDirectFilter(): array
  347.     {
  348.         $radiationDirects $this->productVariantRepository->getAllRadiationDirects($this->webspace$this->locale);
  349.         $radiationDirectCounts $this->getRadiationDirectCounts($radiationDirects);
  350.         $options = [];
  351.         if($radiationDirects) {
  352.             foreach($radiationDirects as $option) {
  353.                 $options[] = [
  354.                     'label' => $option,
  355.                     'value' => $option,
  356.                     'checked' => $checked in_array($option$this->radiationDirects ?? []),
  357.                     'disabled' => $radiationDirectCounts[$option] === && !$checked,
  358.                 ];
  359.             }
  360.         }
  361.         return $this->renderMultiSelect(FilterEnum::RADIATION_DIRECT->getQueryKey(), FilterEnum::RADIATION_DIRECT->trans($this->translator), $options);
  362.     }
  363.     // **********************************
  364.     // Tvar
  365.     // **********************************
  366.     private function getShapeCounts(?array $shapes null): array
  367.     {
  368.         if($shapes === null) {
  369.             $shapes $this->productVariantRepository->getAllShapes($this->webspace$this->locale);
  370.         }
  371.         $results = [];
  372.         foreach($shapes as $shape) {
  373.             $tempQb = clone $this->qb;
  374.             $this->productVariantRepository->addShapesToQueryBuilder($tempQb, [$shape]);
  375.             $this->putAllCriteriaToQueryBuilder($tempQb, ['pv.shape']);
  376.             $results[$shape] = count($tempQb->getQuery()->getScalarResult());
  377.         }
  378.         return $results;
  379.     }
  380.     private function renderShapeFilter(): array
  381.     {
  382.         $shapes $this->productVariantRepository->getAllShapes($this->webspace$this->locale);
  383.         $shapeCounts $this->getShapeCounts($shapes);
  384.         $options = [];
  385.         if($shapes) {
  386.             foreach($shapes as $option) {
  387.                 $options[] = [
  388.                     'label' => $option,
  389.                     'value' => $option,
  390.                     'checked' => $checked in_array($option$this->shapes ?? []),
  391.                     'disabled' => $shapeCounts[$option] === && !$checked,
  392.                 ];
  393.             }
  394.         }
  395.         return $this->renderMultiSelect(FilterEnum::SHAPE->getQueryKey(), FilterEnum::SHAPE->trans($this->translator), $options);
  396.     }
  397.     // **********************************
  398.     // Délka [mm]
  399.     // **********************************
  400.     private function renderLengthFilter(
  401.         ?ProductCategory $productCategory null,
  402.         ?ProductFamily $productFamily null,
  403.         ?Product $product null,
  404.     ): array
  405.     {
  406.         $minLengthLimit $this->productVariantRepository->getMinLength(
  407.             webspace$this->webspace,
  408.             locale$this->locale,
  409.             productCategory$productCategory,
  410.             productFamily$productFamily,
  411.             product$product,
  412.         );
  413.         $maxLengthLimit $this->productVariantRepository->getMaxLength(
  414.             webspace$this->webspace,
  415.             locale$this->locale,
  416.             productCategory$productCategory,
  417.             productFamily$productFamily,
  418.             product$product,
  419.         );
  420.         return $this->renderSlider(
  421.             keyFilterEnum::LENGTH->getQueryKey(),
  422.             labelFilterEnum::LENGTH->trans($this->translator),
  423.             minLimit$minLengthLimit,
  424.             maxLimit$maxLengthLimit,
  425.             min$this->minLength,
  426.             max$this->maxLength,
  427.         );
  428.     }
  429.     // **********************************
  430.     // Šířka, Průměr [mm]
  431.     // **********************************
  432.     private function renderWidthFilter(
  433.         ?ProductCategory $productCategory null,
  434.         ?ProductFamily $productFamily null,
  435.         ?Product $product null,
  436.     ): array
  437.     {
  438.         $minWidthLimit $this->productVariantRepository->getMinWidth(
  439.             webspace$this->webspace,
  440.             locale$this->locale,
  441.             productCategory$productCategory,
  442.             productFamily$productFamily,
  443.             product$product,
  444.         );
  445.         $maxWidthLimit $this->productVariantRepository->getMaxWidth(
  446.             webspace$this->webspace,
  447.             locale$this->locale,
  448.             productCategory$productCategory,
  449.             productFamily$productFamily,
  450.             product$product,
  451.         );
  452.         return $this->renderSlider(
  453.             keyFilterEnum::WIDTH->getQueryKey(),
  454.             labelFilterEnum::WIDTH->trans($this->translator),
  455.             minLimit$minWidthLimit,
  456.             maxLimit$maxWidthLimit,
  457.             min$this->minWidth,
  458.             max$this->maxWidth,
  459.         );
  460.     }
  461.     // **********************************
  462.     // Výška [mm]
  463.     // **********************************
  464.     private function renderHeightFilter(
  465.         ?ProductCategory $productCategory null,
  466.         ?ProductFamily $productFamily null,
  467.         ?Product $product null,
  468.     ): array
  469.     {
  470.         $minHeightLimit $this->productVariantRepository->getMinHeight(
  471.             webspace$this->webspace,
  472.             locale$this->locale,
  473.             productCategory$productCategory,
  474.             productFamily$productFamily,
  475.             product$product,
  476.         );
  477.         $maxHeightLimit $this->productVariantRepository->getMaxHeight(
  478.             webspace$this->webspace,
  479.             locale$this->locale,
  480.             productCategory$productCategory,
  481.             productFamily$productFamily,
  482.             product$product,
  483.         );
  484.         return $this->renderSlider(
  485.             keyFilterEnum::HEIGHT->getQueryKey(),
  486.             labelFilterEnum::HEIGHT->trans($this->translator),
  487.             minLimit$minHeightLimit,
  488.             maxLimit$maxHeightLimit,
  489.             min$this->minHeight,
  490.             max$this->maxHeight,
  491.         );
  492.     }
  493.     // **********************************
  494.     // Barva svítidla
  495.     // **********************************
  496.     private function getColorCounts(?array $colors null): array
  497.     {
  498.         if($colors === null) {
  499.             $colors $this->productVariantRepository->getAllColors($this->webspace$this->locale);
  500.         }
  501.         $results = [];
  502.         foreach($colors as $color) {
  503.             $tempQb = clone $this->qb;
  504.             $this->productVariantRepository->addColorsToQueryBuilder($tempQb, [$color]);
  505.             $this->putAllCriteriaToQueryBuilder($tempQb, ['pv.color']);
  506.             $results[$color] = count($tempQb->getQuery()->getScalarResult());
  507.         }
  508.         return $results;
  509.     }
  510.     private function renderColorFilter(): array
  511.     {
  512.         $colors $this->productVariantRepository->getAllColors($this->webspace$this->locale);
  513.         $colorCounts $this->getColorCounts($colors);
  514.         $options = [];
  515.         if($colors) {
  516.             foreach($colors as $option) {
  517.                 $options[] = [
  518.                     'label' => $option,
  519.                     'value' => $option,
  520.                     'checked' => $checked in_array($option$this->colors ?? []),
  521.                     'disabled' => $colorCounts[$option] === && !$checked,
  522.                 ];
  523.             }
  524.         }
  525.     return $this->renderMultiSelect(FilterEnum::COLOR->getQueryKey(), FilterEnum::COLOR->trans($this->translator), $options);
  526.     }
  527.     // **********************************
  528.     // Použití
  529.     // **********************************
  530.     private function getUsageCounts(?array $usages null): array
  531.     {
  532.         if($usages === null) {
  533.             $usages $this->productVariantRepository->getAllUsages($this->webspace$this->locale);
  534.         }
  535.         $results = [];
  536.         foreach($usages as $usage) {
  537.             $tempQb = clone $this->qb;
  538.             $this->productVariantRepository->addUsagesToQueryBuilder($tempQb, [$usage]);
  539.             $this->putAllCriteriaToQueryBuilder($tempQb, ['pv.variantUse']);
  540.             $results[$usage] = count($tempQb->getQuery()->getScalarResult());
  541.         }
  542.         return $results;
  543.     }
  544.     private function renderUsageFilter(): array
  545.     {
  546.         $usages $this->productVariantRepository->getAllUsages($this->webspace$this->locale);
  547.         $usageCounts $this->getUsageCounts($usages);
  548.         $options = [];
  549.         if($usages) {
  550.             foreach($usages as $option) {
  551.                 $options[] = [
  552.                     'label' => $option,
  553.                     'value' => $option,
  554.                     'checked' => $checked in_array($option$this->usages ?? []),
  555.                     'disabled' => $usageCounts[$option] === && !$checked,
  556.                 ];
  557.             }
  558.         }
  559.         return $this->renderMultiSelect(FilterEnum::USAGE->getQueryKey(), FilterEnum::USAGE->trans($this->translator), $options);
  560.     }
  561.     // **********************************
  562.     // Maximální teplota okolí
  563.     // **********************************
  564.     private function getMaxTemperatureCounts(?array $maxTemperatures null): array
  565.     {
  566.         if($maxTemperatures === null) {
  567.             $maxTemperatures $this->productVariantRepository->getAllMaxTemperatures($this->webspace$this->locale);
  568.         }
  569.         $results = [];
  570.         foreach($maxTemperatures as $maxTemperature) {
  571.             $tempQb = clone $this->qb;
  572.             $this->productVariantRepository->addMaxTemperaturesToQueryBuilder($tempQb, [$maxTemperature]);
  573.             $this->putAllCriteriaToQueryBuilder($tempQb, ['pv.tempMax']);
  574.             $results[$maxTemperature] = count($tempQb->getQuery()->getScalarResult());
  575.         }
  576.         return $results;
  577.     }
  578.     private function renderMaxTemperatureFilter(): array
  579.     {
  580.         $maxTemperatures $this->productVariantRepository->getAllMaxTemperatures($this->webspace$this->locale);
  581.         $maxTemperatureCounts $this->getMaxTemperatureCounts($maxTemperatures);
  582.         $options = [];
  583.         if($maxTemperatures) {
  584.             foreach($maxTemperatures as $option) {
  585.                 $options[] = [
  586.                     'label' => $option,
  587.                     'value' => $option,
  588.                     'checked' => $checked in_array($option$this->maxTemperatures ?? []),
  589.                     'disabled' => $maxTemperatureCounts[$option] === && !$checked,
  590.                 ];
  591.             }
  592.         }
  593.         return $this->renderMultiSelect(FilterEnum::MAX_TEMPERATURE->getQueryKey(), FilterEnum::MAX_TEMPERATURE->trans($this->translator), $options);
  594.     }
  595.     // **********************************
  596.     // Minimální teplota okolí
  597.     // **********************************
  598.     private function getMinTemperatureCounts(?array $minTemperatures null): array
  599.     {
  600.         if($minTemperatures === null) {
  601.             $minTemperatures $this->productVariantRepository->getAllMinTemperatures($this->webspace$this->locale);
  602.         }
  603.         $results = [];
  604.         foreach($minTemperatures as $minTemperature) {
  605.             $tempQb = clone $this->qb;
  606.             $this->productVariantRepository->addMinTemperaturesToQueryBuilder($tempQb, [$minTemperature]);
  607.             $this->putAllCriteriaToQueryBuilder($tempQb, ['pv.tempMin']);
  608.             $results[$minTemperature] = count($tempQb->getQuery()->getScalarResult());
  609.         }
  610.         return $results;
  611.     }
  612.     private function renderMinTemperatureFilter(): array
  613.     {
  614.         $minTemperatures $this->productVariantRepository->getAllMinTemperatures($this->webspace$this->locale);
  615.         $minTemperatureCounts $this->getMinTemperatureCounts($minTemperatures);
  616.         $options = [];
  617.         if($minTemperatures) {
  618.             foreach($minTemperatures as $option) {
  619.                 $options[] = [
  620.                     'label' => $option,
  621.                     'value' => $option,
  622.                     'checked' => $checked in_array($option$this->minTemperatures ?? []),
  623.                     'disabled' => $minTemperatureCounts[$option] === && !$checked,
  624.                 ];
  625.             }
  626.         }
  627.         return $this->renderMultiSelect(FilterEnum::MIN_TEMPERATURE->getQueryKey(), FilterEnum::MIN_TEMPERATURE->trans($this->translator), $options);
  628.     }
  629.     // **********************************
  630.     // Příkon svítidla [W]
  631.     // **********************************
  632.     private function renderInputPowerFilter(
  633.         ?ProductCategory $productCategory null,
  634.         ?ProductFamily $productFamily null,
  635.         ?Product $product null,
  636.     ): array
  637.     {
  638.         $minInputPowerLimit $this->productVariantRepository->getMinInputPower(
  639.             webspace$this->webspace,
  640.             locale$this->locale,
  641.             productCategory$productCategory,
  642.             productFamily$productFamily,
  643.             product$product,
  644.         );
  645.         $maxInputPowerLimit $this->productVariantRepository->getMaxInputPower(
  646.             webspace$this->webspace,
  647.             locale$this->locale,
  648.             productCategory$productCategory,
  649.             productFamily$productFamily,
  650.             product$product,
  651.         );
  652.         return $this->renderSlider(
  653.             keyFilterEnum::INPUT_POWER->getQueryKey(),
  654.             labelFilterEnum::INPUT_POWER->trans($this->translator),
  655.             minLimit$minInputPowerLimit,
  656.             maxLimit$maxInputPowerLimit,
  657.             min$this->minInputPower,
  658.             max$this->maxInputPower,
  659.         );
  660.     }
  661.     // **********************************
  662.     // Měrný výkon [lm/W]
  663.     // **********************************
  664.     private function renderEfficiencyFilter(
  665.         ?ProductCategory $productCategory null,
  666.         ?ProductFamily $productFamily null,
  667.         ?Product $product null,
  668.     ): array
  669.     {
  670.         $minEfficiencyLimit $this->productVariantRepository->getMinEfficiency(
  671.             webspace$this->webspace,
  672.             locale$this->locale,
  673.             productCategory$productCategory,
  674.             productFamily$productFamily,
  675.             product$product,
  676.         );
  677.         $maxEfficiencyLimit $this->productVariantRepository->getMaxEfficiency(
  678.             webspace$this->webspace,
  679.             locale$this->locale,
  680.             productCategory$productCategory,
  681.             productFamily$productFamily,
  682.             product$product,
  683.         );
  684.         return $this->renderSlider(
  685.             keyFilterEnum::EFFICIENCY->getQueryKey(),
  686.             labelFilterEnum::EFFICIENCY->trans($this->translator),
  687.             minLimit$minEfficiencyLimit,
  688.             maxLimit$maxEfficiencyLimit,
  689.             min$this->minEfficiency,
  690.             max$this->maxEfficiency,
  691.         );
  692.     }
  693.     // **********************************
  694.     // Elektrická třída ochrany
  695.     // **********************************
  696.     private function getElProtectCounts(?array $elProtects null): array
  697.     {
  698.         if($elProtects === null) {
  699.             $elProtects $this->productVariantRepository->getAllElProtects($this->webspace$this->locale);
  700.         }
  701.         $results = [];
  702.         foreach($elProtects as $elProtect) {
  703.             $tempQb = clone $this->qb;
  704.             $this->productVariantRepository->addElProtectsToQueryBuilder($tempQb, [$elProtect]);
  705.             $this->putAllCriteriaToQueryBuilder($tempQb, ['pv.protectClassEl']);
  706.             $results[$elProtect] = count($tempQb->getQuery()->getScalarResult());
  707.         }
  708.         return $results;
  709.     }
  710.     private function renderElProtectFilter(): array
  711.     {
  712.         $elProtects $this->productVariantRepository->getAllElProtects($this->webspace$this->locale);
  713.         $elProtectCounts $this->getElProtectCounts($elProtects);
  714.         $options = [];
  715.         if($elProtects) {
  716.             foreach($elProtects as $option) {
  717.                 $options[] = [
  718.                     'label' => $option,
  719.                     'value' => $option,
  720.                     'checked' => $checked in_array($option$this->elProtects ?? []),
  721.                     'disabled' => $elProtectCounts[$option] === && !$checked,
  722.                 ];
  723.             }
  724.         }
  725.         return $this->renderMultiSelect(FilterEnum::EL_PROTECT->getQueryKey(), FilterEnum::EL_PROTECT->trans($this->translator), $options);
  726.     }
  727.     // **********************************
  728.     // Metoda napájení
  729.     // **********************************
  730.     private function getPowerMethodCounts(?array $powerMethods null): array
  731.     {
  732.         if($powerMethods === null) {
  733.             $powerMethods $this->productVariantRepository->getAllPowerMethods($this->webspace$this->locale);
  734.         }
  735.         $results = [];
  736.         foreach($powerMethods as $powerMethod) {
  737.             $tempQb = clone $this->qb;
  738.             $this->productVariantRepository->addPowerMethodsToQueryBuilder($tempQb, [$powerMethod]);
  739.             $this->putAllCriteriaToQueryBuilder($tempQb, ['pv.supplyVoltage']);
  740.             $results[$powerMethod] = count($tempQb->getQuery()->getScalarResult());
  741.         }
  742.         return $results;
  743.     }
  744.     private function renderPowerMethodFilter(): array
  745.     {
  746.         $powerMethods $this->productVariantRepository->getAllPowerMethods($this->webspace$this->locale);
  747.         $powerMethodCounts $this->getPowerMethodCounts($powerMethods);
  748.         $options = [];
  749.         if($powerMethods) {
  750.             foreach($powerMethods as $option) {
  751.                 $options[] = [
  752.                     'label' => $option,
  753.                     'value' => $option,
  754.                     'checked' => $checked in_array($option$this->powerMethods ?? []),
  755.                     'disabled' => $powerMethodCounts[$option] === && !$checked,
  756.                 ];
  757.             }
  758.         }
  759.         return $this->renderMultiSelect(FilterEnum::POWER_METHOD->getQueryKey(), FilterEnum::POWER_METHOD->trans($this->translator), $options);
  760.     }
  761.     // **********************************
  762.     // Světelný zdroj
  763.     // **********************************
  764.     private function getResourceTypeCounts(?array $resourceTypes null): array
  765.     {
  766.         if($resourceTypes === null) {
  767.             $resourceTypes $this->productVariantRepository->getAllResourceTypes($this->webspace$this->locale);
  768.         }
  769.         $results = [];
  770.         foreach($resourceTypes as $resourceType) {
  771.             $tempQb = clone $this->qb;
  772.             $this->productVariantRepository->addResourceTypesToQueryBuilder($tempQb, [$resourceType]);
  773.             $this->putAllCriteriaToQueryBuilder($tempQb, ['pv.resourceType']);
  774.             $results[$resourceType] = count($tempQb->getQuery()->getScalarResult());
  775.         }
  776.         return $results;
  777.     }
  778.     private function renderResourceTypeFilter(): array
  779.     {
  780.         $resourceTypes $this->productVariantRepository->getAllResourceTypes($this->webspace$this->locale);
  781.         $resourceTypeCounts $this->getResourceTypeCounts($resourceTypes);
  782.         $options = [];
  783.         if($resourceTypes) {
  784.             foreach($resourceTypes as $option) {
  785.                 $options[] = [
  786.                     'label' => $option,
  787.                     'value' => $option,
  788.                     'checked' => $checked in_array($option$this->resourceTypes ?? []),
  789.                     'disabled' => $resourceTypeCounts[$option] === && !$checked,
  790.                 ];
  791.             }
  792.         }
  793.         return $this->renderMultiSelect(FilterEnum::RESOURCE_TYPE->getQueryKey(), FilterEnum::RESOURCE_TYPE->trans($this->translator), $options);
  794.     }
  795. //    private function getLightSourceCounts(?array $lightSources = null): array
  796. //    {
  797. //        if($lightSources === null) {
  798. //            $lightSources = $this->productVariantRepository->getAllLightSources($this->webspace, $this->locale);
  799. //        }
  800. //
  801. //        $results = [];
  802. //        foreach($lightSources as $lightSource) {
  803. //            $tempQb = clone $this->qb;
  804. //            $this->productVariantRepository->addLightSourcesToQueryBuilder($tempQb, [$lightSource]);
  805. //            $this->putAllCriteriaToQueryBuilder($tempQb, ['pv.luminousFluxSupply']);
  806. //            $results[$lightSource] = count($tempQb->getQuery()->getScalarResult());
  807. //        }
  808. //
  809. //        return $results;
  810. //    }
  811. //    private function renderLightSourceFilter(): array
  812. //    {
  813. //        $lightSources = $this->productVariantRepository->getAllLightSources($this->webspace, $this->locale);
  814. //        $lightSourceCounts = $this->getLightSourceCounts($lightSources);
  815. //
  816. //        $options = [];
  817. //        if($lightSources) {
  818. //            foreach($lightSources as $option) {
  819. //                $options[] = [
  820. //                    'label' => $option,
  821. //                    'value' => $option,
  822. //                    'checked' => $checked = in_array($option, $this->lightSources ?? []),
  823. //                    'disabled' => $lightSourceCounts[$option] === 0 && !$checked,
  824. //                ];
  825. //            }
  826. //        }
  827. //
  828. //        return $this->renderMultiSelect(FilterEnum::LIGHT_SOURCE->getQueryKey(), FilterEnum::LIGHT_SOURCE->trans($this->translator), $options);
  829. //    }
  830.     // **********************************
  831.     // Stav produktu
  832.     // **********************************
  833.     private function getStatusCounts(?array $statuses null): array
  834.     {
  835.         if($statuses === null) {
  836.             $statuses $this->productVariantRepository->getAllStatuses($this->webspace$this->locale);
  837.         }
  838.         $results = [];
  839.         foreach($statuses as $status) {
  840.             $tempQb = clone $this->qb;
  841.             $this->productVariantRepository->addStatusesToQueryBuilder($tempQb, [$status]);
  842.             $this->putAllCriteriaToQueryBuilder($tempQb, ['pv.statusNew']);
  843.             $results[$status] = count($tempQb->getQuery()->getScalarResult());
  844.         }
  845.         return $results;
  846.     }
  847.     private function renderStatusFilter(): array
  848.     {
  849.         $statuses $this->productVariantRepository->getAllStatuses($this->webspace$this->locale);
  850.         $statusCounts $this->getStatusCounts($statuses);
  851.         $options = [];
  852.         if($statuses) {
  853.             foreach($statuses as $option) {
  854.                 $options[] = [
  855.                     'label' => $option == true 'Novinka' $option,
  856.                     'value' => $option,
  857.                     'checked' => $checked in_array($option$this->statuses ?? []),
  858.                     'disabled' => $statusCounts[$option] === && !$checked,
  859.                 ];
  860.             }
  861.         }
  862.         return $this->renderMultiSelect(FilterEnum::STATUS->getQueryKey(), FilterEnum::STATUS->trans($this->translator), $options);
  863.     }
  864.     // **********************************
  865.     // Mechanická odolnost
  866.     // **********************************
  867.     private function getMechanicalDurabilityCounts(?array $mechanicalDurabilities null): array
  868.     {
  869.         if($mechanicalDurabilities === null) {
  870.             $mechanicalDurabilities $this->productVariantRepository->getAllMechanicalDurabilities($this->webspace$this->locale);
  871.         }
  872.         $results = [];
  873.         foreach($mechanicalDurabilities as $mechanicalDurability) {
  874.             $tempQb = clone $this->qb;
  875.             $this->productVariantRepository->addMechanicalDurabilitiesToQueryBuilder($tempQb, [$mechanicalDurability]);
  876.             $this->putAllCriteriaToQueryBuilder($tempQb, ['pv.mechanicalDurability']);
  877.             $results[$mechanicalDurability] = count($tempQb->getQuery()->getScalarResult());
  878.         }
  879.         return $results;
  880.     }
  881.     private function renderMechanicalDurabilityFilter(): array
  882.     {
  883.         $mechanicalDurabilities $this->productVariantRepository->getAllMechanicalDurabilities($this->webspace$this->locale);
  884.         $mechanicalDurabilityCounts $this->getMechanicalDurabilityCounts($mechanicalDurabilities);
  885.         $options = [];
  886.         if($mechanicalDurabilities) {
  887.             foreach($mechanicalDurabilities as $option) {
  888.                 $options[] = [
  889.                     'label' => $option,
  890.                     'value' => $option,
  891.                     'checked' => $checked in_array($option$this->mechanicalDurabilities ?? []),
  892.                     'disabled' => $mechanicalDurabilityCounts[$option] === && !$checked,
  893.                 ];
  894.             }
  895.         }
  896.         return $this->renderMultiSelect(FilterEnum::MECHANICAL_DURABILITY->getQueryKey(), FilterEnum::MECHANICAL_DURABILITY->trans($this->translator), $options);
  897.     }
  898.     // **********************************
  899.     // Typ difúzoru
  900.     // **********************************
  901.     private function getDispersionCounts(?array $dispersions null): array
  902.     {
  903.         if($dispersions === null) {
  904.             $dispersions $this->productVariantRepository->getAllDispersions($this->webspace$this->locale);
  905.         }
  906.         $results = [];
  907.         foreach($dispersions as $dispersion) {
  908.             $tempQb = clone $this->qb;
  909.             $this->productVariantRepository->addDispersionsToQueryBuilder($tempQb, [$dispersion]);
  910.             $this->putAllCriteriaToQueryBuilder($tempQb, ['pv.dispersion']);
  911.             $results[$dispersion] = count($tempQb->getQuery()->getScalarResult());
  912.         }
  913.         return $results;
  914.     }
  915.     private function renderDispersionFilter(): array
  916.     {
  917.         $dispersions $this->productVariantRepository->getAllDispersions($this->webspace$this->locale);
  918.         $dispersionCounts $this->getDispersionCounts($dispersions);
  919.         $options = [];
  920.         if($dispersions) {
  921.             foreach($dispersions as $option) {
  922.                 $options[] = [
  923.                     'label' => $option,
  924.                     'value' => $option,
  925.                     'checked' => $checked in_array($option$this->dispersions ?? []),
  926.                     'disabled' => $dispersionCounts[$option] === && !$checked,
  927.                 ];
  928.             }
  929.         }
  930.         return $this->renderMultiSelect(FilterEnum::DISPERSION->getQueryKey(), FilterEnum::DISPERSION->trans($this->translator), $options);
  931.     }
  932.     // **********************************
  933.     // Předřadník
  934.     // **********************************
  935.     private function getDriverCounts(?array $drivers null): array
  936.     {
  937.         if($drivers === null) {
  938.             $drivers $this->productVariantRepository->getAllDrivers($this->webspace$this->locale);
  939.         }
  940.         $results = [];
  941.         foreach($drivers as $driver) {
  942.             $tempQb = clone $this->qb;
  943.             $this->productVariantRepository->addDriversToQueryBuilder($tempQb, [$driver]);
  944.             $this->putAllCriteriaToQueryBuilder($tempQb, ['pv.driver']);
  945.             $results[$driver] = count($tempQb->getQuery()->getScalarResult());
  946.         }
  947.         return $results;
  948.     }
  949.     private function renderDriverFilter(): array
  950.     {
  951.         $drivers $this->productVariantRepository->getAllDrivers($this->webspace$this->locale);
  952.         $driverCounts $this->getDriverCounts($drivers);
  953.         $options = [];
  954.         if($drivers) {
  955.             foreach($drivers as $option) {
  956.                 $options[] = [
  957.                     'label' => $option,
  958.                     'value' => $option,
  959.                     'checked' => $checked in_array($option$this->drivers ?? []),
  960.                     'disabled' => $driverCounts[$option] === && !$checked,
  961.                 ];
  962.             }
  963.         }
  964.         return $this->renderMultiSelect(FilterEnum::DRIVER->getQueryKey(), FilterEnum::DRIVER->trans($this->translator), $options);
  965.     }
  966.     // **********************************
  967.     // Doplňující výbava
  968.     // **********************************
  969.     private function getAccessoryCounts(?array $accessories null): array
  970.     {
  971.         if($accessories === null) {
  972.             $accessories $this->productVariantRepository->getAllAccessories($this->webspace$this->locale);
  973.         }
  974.         $results = [];
  975.         foreach($accessories as $accessory) {
  976.             $tempQb = clone $this->qb;
  977.             $this->productVariantRepository->addAccessoriesToQueryBuilder($tempQb, [$accessory]);
  978.             $this->putAllCriteriaToQueryBuilder($tempQb, ['pv.supplements']);
  979.             $results[$accessory] = count($tempQb->getQuery()->getScalarResult());
  980.         }
  981.         return $results;
  982.     }
  983.     private function renderAccessoryFilter(): array
  984.     {
  985.         $accessories $this->productVariantRepository->getAllAccessories($this->webspace$this->locale);
  986.         $accessoryCounts $this->getAccessoryCounts($accessories);
  987.         $options = [];
  988.         if($accessories) {
  989.             $titles $this->productVariantRepository->getTitlesByAccessoryCodes($this->webspace$this->locale$accessories);
  990.             foreach($accessories as $option) {
  991.                 $options[] = [
  992.                     'label' => $titles[$option] ?? $option,
  993.                     'value' => $option,
  994.                     'checked' => $checked in_array($option$this->accessories ?? []),
  995.                     'disabled' => $accessoryCounts[$option] === && !$checked,
  996.                 ];
  997.             }
  998.         }
  999.         return $this->renderMultiSelect(FilterEnum::ACCESSORY->getQueryKey(), FilterEnum::ACCESSORY->trans($this->translator), $options);
  1000.     }
  1001.     // **********************************
  1002. }