src/Repository/ProductVariantRepository.php line 1338

Open in your IDE?
  1. <?php
  2. namespace App\Repository;
  3. use App\Entity\Product;
  4. use App\Entity\ProductCategory;
  5. use App\Entity\ProductFamily;
  6. use App\Entity\ProductVariant;
  7. use App\Utils\uString;
  8. use Doctrine\Bundle\DoctrineBundle\Repository\ServiceEntityRepository;
  9. use Doctrine\ORM\QueryBuilder;
  10. use Doctrine\Persistence\ManagerRegistry;
  11. use Sulu\Bundle\MediaBundle\Entity\MediaRepositoryInterface;
  12. use Sulu\Bundle\MediaBundle\Media\Manager\MediaManagerInterface;
  13. use Sulu\Bundle\RouteBundle\Manager\RouteManagerInterface;
  14. use PHPCR\Util\UUIDHelper;
  15. /**
  16.  * @extends ServiceEntityRepository<ProductVariant>
  17.  *
  18.  * @method ProductVariant|null find($id, $lockMode = null, $lockVersion = null)
  19.  * @method ProductVariant|null findOneBy(array $criteria, array $orderBy = null)
  20.  * @method ProductVariant[]    findAll()
  21.  * @method ProductVariant[]    findBy(array $criteria, array $orderBy = null, $limit = null, $offset = null)
  22.  */
  23. class ProductVariantRepository extends ServiceEntityRepository
  24. {
  25.     public function __construct(
  26.         ManagerRegistry $registry,
  27.         protected readonly RouteManagerInterface $routeManager,
  28.         protected readonly ProductCategoryRepository $productCategoryRepository,
  29.         protected readonly ProductFamilyRepository $productFamilyRepository,
  30.         protected readonly MediaRepositoryInterface $mediaRepository,
  31.         protected readonly MediaManagerInterface $mediaManager,
  32.     )
  33.     {
  34.         parent::__construct($registryProductVariant::class);
  35.     }
  36.     public function save(ProductVariant $entitybool $flush false): void
  37.     {
  38.         $this->getEntityManager()->persist($entity);
  39.         if ($flush) {
  40.             $this->getEntityManager()->flush();
  41.         }
  42.     }
  43.     public function remove(ProductVariant $entitybool $flush false): void
  44.     {
  45.         $this->getEntityManager()->remove($entity);
  46.         if ($flush) {
  47.             $this->getEntityManager()->flush();
  48.         }
  49.     }
  50.     public function createFromImport(array $data): void
  51.     {
  52.         $entity = new ProductVariant();
  53.         $entity->setUuid(UUIDHelper::generateUUID());
  54.         $entity->setProductCode($data[0]);
  55.         $entity->setTitle($data[1]);
  56.         $entity->setCategory($data[2] ?? null);
  57.         $entity->setFamily($data[3] ?? null);
  58.         $entity->setActive($data[4] ?? null);
  59.         $entity->setDescription($data[5] ?? null);
  60.         $entity->setAccessories($data[8] ?? null);
  61.         $entity->setType($data[9] ?? null);
  62.         $entity->setFixation($data[12] ?? null);
  63.         $entity->setLuminousFlux((int)$data[15] ?? null);
  64.         $entity->setCri($data[16] ?? null);
  65.         $entity->setChromaticity($data[17] ?? null);
  66.         $entity->setDispersionVariant($data[20] ?? null);
  67.         $entity->setProtectClass($data[23] ?? null);
  68.         $entity->setRadiationDirect($data[24] ?? null);
  69.         $entity->setShape($data[27] ?? null);
  70.         $entity->setDimensionA((int)$data[30] ?? null);
  71.         $entity->setDimensionB((int)$data[31] ?? null);
  72.         $entity->setDimensionC((int)$data[32] ?? null);
  73.         $entity->setColor($data[33] ?? null);
  74.         $entity->setTempMax($data[39] ?? null);
  75.         $entity->setTempMin($data[40] ?? null);
  76.         $inputPower str_replace(',''.'$data[41]);
  77.         $entity->setInputPower((float)$inputPower ?? null);
  78.         $entity->setEfficiency((int)$data[42] ?? null);
  79.         $entity->setProtectClassEl($data[43] ?? null);
  80.         $entity->setSupplyVoltage($data[44] ?? null);
  81.         $entity->setResourceType($data[45] ?? null);
  82.         if ($data[48] == 'Novinka' || $data[48] == 'New') {
  83.             $entity->setStatusNew(true);
  84.         } else {
  85.             $entity->setStatusNew(false);
  86.         }
  87.         $entity->setMechanicalDurability($data[51] ?? null);
  88.         $entity->setDispersion($data[52] ?? null);
  89.         $entity->setDriver($data[55] ?? null);
  90.         $entity->setSupplements($data[58] ?? null);
  91.         $entity->setDimension($data[61] ?? null);
  92.         $entity->setColorRal($data[63] ?? null);
  93.         $entity->setMaterial($data[64] ?? null);
  94.         $entity->setDriverFunction($data[67] ?? null);
  95.         $weight str_replace(',''.'$data[62]);
  96.         $entity->setWeight((float)$weight ?? null);
  97.         $entity->setLuminousFluxSupply((int)$data[70] ?? null);
  98.         $entity->setAliveLed($data[71] ?? null);
  99.         $entity->setGuarantee((int)$data[72] ?? null);
  100.         $entity->setUsage($data[36] ?? null);
  101.         $entity->setWebspace('hormen');
  102.         $entity->setLocale('cs');
  103.         $entity->setState('published');
  104.         $this->updateProduct($entity$data[1]);
  105.         $this->updateProductFamily($entity$data[3]);
  106.         $this->updateProductCategory($entity$data[2]);
  107.         // Schema
  108.         if (!empty($data[75])) {
  109.             $media $this->mediaRepository->findMediaWithFilenameInCollectionWithId($data[75], 14);
  110.             if ($media) {
  111.                 $this->updateImageSchemaFromImport($entity$media);
  112.             }
  113.         }
  114.         // Curves
  115.         if (!empty($data[76])) {
  116.             $media $this->mediaRepository->findMediaWithFilenameInCollectionWithId($data[76], 15);
  117.             if ($media) {
  118.                 $this->updateImageCurvesFromImport($entity$media);
  119.             }
  120.         }
  121.         if (!empty($data[77])) {
  122.             $media $this->mediaRepository->findMediaWithFilenameInCollectionWithId($data[77], 15);
  123.             if ($media) {
  124.                 $this->updateLtdCurvesFromImport($entity$media);
  125.             }
  126.         }
  127.         // Images
  128.         if ($data[73]) {
  129.             $images explode(','$data[73]);
  130.             $media $this->mediaRepository->findMediaWithFilenameInCollectionWithId($images[0], 10);
  131.             if ($media) {
  132.                 $this->updateImageFromImport($entity$media);
  133.             }
  134.             if (count($images) > 1) {
  135.                 array_shift($images);
  136.                 if ($images) {
  137.                     $this->updateImagesFromImport($entity$images);
  138.                 }
  139.             }
  140.         }
  141.         // Renders
  142.         if ($data[74]) {
  143.             $images explode(','$data[74]);
  144.             if ($images) {
  145.                 $this->updateRendersFromImport($entity$images);
  146.             }
  147.         }
  148.         // Files
  149.         if ($data[78]) {
  150.             $files explode(','$data[78]);
  151.             if ($files) {
  152.                 $this->updateFilesFromImport($entity$files);
  153.             }
  154.         }
  155.         $this->save($entitytrue);
  156.     }
  157.     public function updateFromImport(ProductVariant $entity, array $data): void
  158.     {
  159.         $entity->setProductCode($data[0]);
  160.         $entity->setTitle($data[1]);
  161.         $entity->setCategory($data[2] ?? null);
  162.         $entity->setFamily($data[3] ?? null);
  163.         $entity->setActive($data[4] ?? null);
  164.         $entity->setDescription($data[5] ?? null);
  165.         $entity->setAccessories($data[8] ?? null);
  166.         $entity->setType($data[9] ?? null);
  167.         $entity->setFixation($data[12] ?? null);
  168.         $entity->setLuminousFlux((int)$data[15] ?? null);
  169.         $entity->setCri($data[16] ?? null);
  170.         $entity->setChromaticity($data[17] ?? null);
  171.         $entity->setDispersionVariant($data[20] ?? null);
  172.         $entity->setProtectClass($data[23] ?? null);
  173.         $entity->setRadiationDirect($data[24] ?? null);
  174.         $entity->setShape($data[27] ?? null);
  175.         $entity->setDimensionA((int)$data[30] ?? null);
  176.         $entity->setDimensionB((int)$data[31] ?? null);
  177.         $entity->setDimensionC((int)$data[32] ?? null);
  178.         $entity->setColor($data[33] ?? null);
  179.         $entity->setTempMax($data[39] ?? null);
  180.         $entity->setTempMin($data[40] ?? null);
  181.         $inputPower str_replace(',''.'$data[41]);
  182.         $entity->setInputPower((float)$inputPower ?? null);
  183.         $entity->setEfficiency((int)$data[42] ?? null);
  184.         $entity->setProtectClassEl($data[43] ?? null);
  185.         $entity->setSupplyVoltage($data[44] ?? null);
  186.         $entity->setResourceType($data[45] ?? null);
  187.         if ($data[48] == 'Novinka' || $data[48] == 'New') {
  188.             $entity->setStatusNew(true);
  189.         } else {
  190.             $entity->setStatusNew(false);
  191.         }
  192.         $entity->setMechanicalDurability($data[51] ?? null);
  193.         $entity->setDispersion($data[52] ?? null);
  194.         $entity->setDriver($data[55] ?? null);
  195.         $entity->setSupplements($data[58] ?? null);
  196.         $entity->setDimension($data[61] ?? null);
  197.         $entity->setColorRal($data[63] ?? null);
  198.         $entity->setMaterial($data[64] ?? null);
  199.         $entity->setDriverFunction($data[67] ?? null);
  200.         $weight str_replace(',''.'$data[62]);
  201.         $entity->setWeight((float)$weight ?? null);
  202.         $entity->setLuminousFluxSupply((int)$data[70] ?? null);
  203.         $entity->setAliveLed($data[71] ?? null);
  204.         $entity->setGuarantee((int)$data[72] ?? null);
  205.         $entity->setUsage($data[36] ?? null);
  206.         $this->updateProduct($entity$data[1]);
  207.         $this->updateProductFamily($entity$data[3]);
  208.         $this->updateProductCategory($entity$data[2]);
  209.         // Schema
  210.         if (!empty($data[75])) {
  211.             $media $this->mediaRepository->findMediaWithFilenameInCollectionWithId($data[75], 14);
  212.             if ($media) {
  213.                 $this->updateImageSchemaFromImport($entity$media);
  214.             }
  215.         }
  216.         // Curves
  217.         if (!empty($data[76])) {
  218.             $media $this->mediaRepository->findMediaWithFilenameInCollectionWithId($data[76], 15);
  219.             if ($media) {
  220.                 $this->updateImageCurvesFromImport($entity$media);
  221.             }
  222.         }
  223.         if (!empty($data[77])) {
  224.             $media $this->mediaRepository->findMediaWithFilenameInCollectionWithId($data[77], 15);
  225.             if ($media) {
  226.                 $this->updateLtdCurvesFromImport($entity$media);
  227.             }
  228.         }
  229.         // Images
  230.         if ($data[73]) {
  231.             $images explode(','$data[73]);
  232.             $media $this->mediaRepository->findMediaWithFilenameInCollectionWithId($images[0], 10);
  233.             if ($media) {
  234.                 $this->updateImageFromImport($entity$media);
  235.             }
  236.             if (count($images) > 1) {
  237.                 array_shift($images);
  238.                 if ($images) {
  239.                     $this->updateImagesFromImport($entity$images);
  240.                 }
  241.             }
  242.         }
  243.         // Renders
  244.         if ($data[74]) {
  245.             $images explode(','$data[74]);
  246.             if ($images) {
  247.                 $this->updateRendersFromImport($entity$images);
  248.             }
  249.         }
  250.         // Files
  251.         if ($data[78]) {
  252.             $files explode(','$data[78]);
  253.             if ($files) {
  254.                 $this->updateFilesFromImport($entity$files);
  255.             }
  256.         }
  257.         $entity->setWebspace('hormen');
  258.         $entity->setLocale('cs');
  259.         $entity->setState('published');
  260.         $this->save($entitytrue);
  261.     }
  262.     public function update(ProductVariant $entity, array $databool $preview false): void
  263.     {
  264.         $entity->setTitle($data['title']);
  265.         $entity->setProductCode($data['product_code']);
  266.         $entity->setActive($data['active']);
  267.         $entity->setDescription($data['description'] ?? null);
  268.         $entity->setCategory($data['category'] ?? null);
  269.         $entity->setFamily($data['family'] ?? null);
  270.         $entity->setType($data['type'] ?? null);
  271.         $entity->setFixation($data['fixation'] ?? null);
  272.         $entity->setLuminousFlux($data['luminous_flux'] ?? null);
  273.         $entity->setCri($data['cri'] ?? null);
  274.         $entity->setChromaticity($data['chromaticity'] ?? null);
  275.         $entity->setDispersionVariant($data['dispersion_variant'] ?? null);
  276.         $entity->setProtectClass($data['protect_class'] ?? null);
  277.         $entity->setRadiationDirect($data['radiation_direct'] ?? null);
  278.         $entity->setShape($data['shape'] ?? null);
  279.         $entity->setDimensionA($data['dimension_a'] ?? null);
  280.         $entity->setDimensionB($data['dimension_b'] ?? null);
  281.         $entity->setDimensionC($data['dimension_c'] ?? null);
  282.         $entity->setColor($data['color'] ?? null);
  283.         $entity->setTempMax($data['temp_max'] ?? null);
  284.         $entity->setTempMin($data['temp_min'] ?? null);
  285.         $entity->setInputPower($data['input_power'] ?? null);
  286.         $entity->setEfficiency($data['efficiency'] ?? null);
  287.         $entity->setProtectClassEl($data['protect_class_el'] ?? null);
  288.         $entity->setSupplyVoltage($data['supply_voltage'] ?? null);
  289.         $entity->setResourceType($data['resource_type'] ?? null);
  290.         $entity->setStatusNew($data['status_new']);
  291.         $entity->setMechanicalDurability($data['mechanical_durability'] ?? null);
  292.         $entity->setDispersion($data['dispersion'] ?? null);
  293.         $entity->setDriver($data['driver'] ?? null);
  294.         $entity->setSupplements($data['supplements'] ?? null);
  295.         $entity->setDimension($data['dimension'] ?? null);
  296.         $entity->setColorRal($data['color_ral'] ?? null);
  297.         $entity->setMaterial($data['material'] ?? null);
  298.         $entity->setDriverFunction($data['driver_function'] ?? null);
  299.         $entity->setWeight($data['weight'] ?? null);
  300.         $entity->setLuminousFluxSupply($data['luminous_flux_supply'] ?? null);
  301.         $entity->setAliveLed($data['alive_led'] ?? null);
  302.         $entity->setGuarantee($data['guarantee'] ?? null);
  303.         $entity->setUsage($data['variant_use'] ?? null);
  304.         $entity->setAccessories($data['accessories'] ?? null);
  305.         $this->updateImage($entity$data['image'] ?? null);
  306.         $this->updateImageSchema($entity$data['image_schema'] ?? null);
  307.         $this->updateImageCurves($entity$data['image_curves'] ?? null);
  308.         $this->updateLtdCurves($entity$data['ltd_curves'] ?? null);
  309.         if (!$preview) {
  310.             $this->updateImages($entity$data['images'] ?? null);
  311.             $this->updateRenders($entity$data['renders'] ?? null);
  312.             $this->updateFiles($entity$data['files'] ?? null);
  313.             $this->updateProduct($entity$data['title']);
  314.             $this->updateProductFamily($entity$data['family']);
  315.             $this->updateProductCategory($entity$data['category']);
  316.             $this->save($entitytrue);
  317.         }
  318.     }
  319.     public function updateImages(ProductVariant $entity, ?array $icons null)
  320.     {
  321.         $entity->getImages()->clear();
  322.         if ($icons) {
  323.             if (isset($icons['ids'])) {
  324.                 $iconsIds $icons['ids'];
  325.             } else {
  326.                 $iconsIds $icons;
  327.             }
  328.             foreach ($iconsIds as $iconId) {
  329.                 $icon $this->mediaRepository->findMediaById($iconId);
  330.                 if ($icon) {
  331.                     $entity->addImage($icon);
  332.                 }
  333.             }
  334.         }
  335.     }
  336.     public function updateImagesFromImport(ProductVariant $entity, ?array $icons null)
  337.     {
  338.         $entity->getImages()->clear();
  339.         if ($icons) {
  340.             foreach ($icons as $icon) {
  341.                 if ($icon) {
  342.                     $media $this->mediaRepository->findMediaWithFilenameInCollectionWithId($icon10);
  343.                     if ($media) {
  344.                         $entity->addImage($media);
  345.                     }
  346.                 }
  347.             }
  348.         }
  349.     }
  350.     public function updateRenders(ProductVariant $entity, ?array $renders null)
  351.     {
  352.         $entity->getRenders()->clear();
  353.         if ($renders) {
  354.             if (isset($renders['ids'])) {
  355.                 $rendersIds $renders['ids'];
  356.             } else {
  357.                 $rendersIds $renders;
  358.             }
  359.             foreach ($rendersIds as $renderId) {
  360.                 $render $this->mediaRepository->findMediaById($renderId);
  361.                 if ($render) {
  362.                     $entity->addRender($render);
  363.                 }
  364.             }
  365.         }
  366.     }
  367.     public function updateRendersFromImport(ProductVariant $entity, ?array $renders null)
  368.     {
  369.         $entity->getRenders()->clear();
  370.         if ($renders) {
  371.             foreach ($renders as $render) {
  372.                 if ($render) {
  373.                     $media $this->mediaRepository->findMediaWithFilenameInCollectionWithId($render12);
  374.                     if ($media) {
  375.                         $entity->addRender($media);
  376.                     }
  377.                 }
  378.             }
  379.         }
  380.     }
  381.     public function updateFiles(ProductVariant $entity, ?array $files null)
  382.     {
  383.         $entity->getFiles()->clear();
  384.         if ($files) {
  385.             if (isset($files['ids'])) {
  386.                 $filesIds $files['ids'];
  387.             } else {
  388.                 $filesIds $files;
  389.             }
  390.             foreach ($filesIds as $fileId) {
  391.                 $file $this->mediaRepository->findMediaById($fileId);
  392.                 if ($file) {
  393.                     $entity->addFile($file);
  394.                 }
  395.             }
  396.         }
  397.     }
  398.     public function updateFilesFromImport(ProductVariant $entity, ?array $files null)
  399.     {
  400.         $entity->getFiles()->clear();
  401.         if ($files) {
  402.             foreach ($files as $file) {
  403.                 if ($file) {
  404.                     $media $this->mediaRepository->findMediaWithFilenameInCollectionWithId($file13);
  405.                     if ($media) {
  406.                         $entity->addFile($media);
  407.                     }
  408.                 }
  409.             }
  410.         }
  411.     }
  412.     public function updateImage(ProductVariant $entity, ?array $mediaData): void
  413.     {
  414.         $media null;
  415.         if (isset($mediaData['id']) && $mediaData['id']) {
  416.             $media $this->mediaRepository->find($mediaData['id']);
  417.         }
  418.         $entity->setImage($media);
  419.     }
  420.     public function updateProduct(ProductVariant $entity, ?string $title): void
  421.     {
  422.         if (isset($title)) {
  423.             $product $this->getEntityManager()->getRepository(Product::class)->findOneByTitle($title'cs');
  424.             $entity->setProduct($product);
  425.         } else {
  426.             $entity->setProduct(null);
  427.         }
  428.     }
  429.     public function updateProductFamily(ProductVariant $entity, ?string $importId): void
  430.     {
  431.         if (isset($importId)) {
  432.             $productFamily $this->productFamilyRepository->findOneByImportId($importId'cs');
  433.             $entity->setProductFamily($productFamily);
  434.         } else {
  435.             $entity->setProductFamily(null);
  436.         }
  437.     }
  438.     public function updateProductCategory(ProductVariant $entity, ?string $importId): void
  439.     {
  440.         if (isset($importId)) {
  441.             $productCategory $this->productCategoryRepository->findOneByImportId($importId'cs');
  442.             $entity->setProductCategory($productCategory);
  443.         } else {
  444.             $entity->setProductCategory(null);
  445.         }
  446.     }
  447.     public function updateImageFromImport(ProductVariant $entity$media): void
  448.     {
  449.         $entity->setImage($media);
  450.     }
  451.     public function updateImageSchema(ProductVariant $entity, ?array $mediaData): void
  452.     {
  453.         $media null;
  454.         if (isset($mediaData['id']) && $mediaData['id']) {
  455.             $media $this->mediaRepository->find($mediaData['id']);
  456.         }
  457.         $entity->setImageSchema($media);
  458.     }
  459.     public function updateImageSchemaFromImport(ProductVariant $entity$media): void
  460.     {
  461.         $entity->setImageSchema($media);
  462.     }
  463.     public function updateImageCurves(ProductVariant $entity, ?array $mediaData): void
  464.     {
  465.         $media null;
  466.         if (isset($mediaData['id']) && $mediaData['id']) {
  467.             $media $this->mediaRepository->find($mediaData['id']);
  468.         }
  469.         $entity->setImageCurves($media);
  470.     }
  471.     public function updateImageCurvesFromImport(ProductVariant $entity$media): void
  472.     {
  473.         $entity->setImageCurves($media);
  474.     }
  475.     public function updateLtdCurves(ProductVariant $entity, ?array $mediaData): void
  476.     {
  477.         $media null;
  478.         if (isset($mediaData['id']) && $mediaData['id']) {
  479.             $media $this->mediaRepository->find($mediaData['id']);
  480.         }
  481.         $entity->setLtdCurves($media);
  482.     }
  483.     public function updateLtdCurvesFromImport(ProductVariant $entity$media): void
  484.     {
  485.         $entity->setLtdCurves($media);
  486.     }
  487.     public function findOneByUuid(string $uuidstring $locale): ?ProductVariant
  488.     {
  489.         return $this->findOneBy([
  490.             'uuid' => $uuid,
  491.             'locale' => $locale,
  492.         ]);
  493.     }
  494.     public function findOneByProductCode(string $productCodestring $locale): ?ProductVariant
  495.     {
  496.         return $this->findOneBy([
  497.             'productCode' => $productCode,
  498.             'locale' => $locale,
  499.         ]);
  500.     }
  501.     public function exists(string $productCodestring $locale): ?ProductVariant
  502.     {
  503.         $productVariant self::findOneByProductCode($productCode$locale);
  504.         if ($productVariant) {
  505.             return $productVariant;
  506.         } else {
  507.             return null;
  508.         }
  509.     }
  510.     // TODO: move to ProductVariantFacade
  511.     public function getCodes(): ?array
  512.     {
  513.         $qb $this->createQueryBuilder('i')
  514.             ->select('i.productCode')
  515.             ->getQuery();
  516.         $resultsForImport = [];
  517.         $result =  $qb->getResult();
  518.         foreach ($result as $item) {
  519.             array_push($resultsForImport$item['productCode']);
  520.         }
  521.         return $resultsForImport;
  522.     }
  523.     public function isNewProductVariant(?string $productName): bool
  524.     {
  525.         if ($productName) {
  526.             $productVariants $this->findBy(['title' => $productName'active' => true]);
  527.             foreach ($productVariants as $productVariant) {
  528.                 if ($productVariant->getStatusNew()) {
  529.                     return true;
  530.                 }
  531.             }
  532.         }
  533.         return false;
  534.     }
  535.     // TODO: move to ProductVariantFacade
  536.     public function getAccessories(?string $productNamestring $webspacestring $locale): array
  537.     {
  538.         $accessories = [];
  539.         if ($productName) {
  540.             $productVariants $this->findBy(['title' => $productName'active' => true]);
  541.             foreach ($productVariants as $productVariant) {
  542.                 $variantAccessories explode(","$productVariant->getAccessories());
  543.                 foreach ($variantAccessories as $variantAccessory) {
  544.                     array_push($accessories$variantAccessory);
  545.                 }
  546.             }
  547.         }
  548.         $accessories array_unique($accessories);
  549.         return $accessories;
  550.     }
  551.     private function andWhereInIn(QueryBuilder $qbstring $field, array $values): QueryBuilder
  552.     {
  553.         if (!empty($values)) {
  554.             $conditions = [];
  555.             foreach ($values as $value) {
  556.                 $conditions[] = $qb->expr()->orX(
  557.                     $qb->expr()->eq($field$qb->expr()->literal($value)),
  558.                     $qb->expr()->like($field$qb->expr()->literal($value ',%')),
  559.                     $qb->expr()->like($field$qb->expr()->literal('%,' $value ',%')),
  560.                     $qb->expr()->like($field$qb->expr()->literal('%,' $value)),
  561.                 );
  562.             }
  563.             $qb->andWhere($qb->expr()->orX(...$conditions));
  564.         }
  565.         return $qb;
  566.     }
  567.     private function prepareQueryBuilder(
  568.         string $webspace,
  569.         string $locale,
  570.         ?ProductCategory $productCategory null,
  571.         ?ProductFamily $productFamily null,
  572.         ?Product $product null,
  573.     ): QueryBuilder
  574.     {
  575.         $qb $this->createQueryBuilder('pv');
  576.         $qb->andWhere('pv.webspace = :webspace')
  577.             ->setParameter('webspace'$webspace);
  578.         $qb->andWhere('pv.locale = :locale')
  579.             ->setParameter('locale'$locale);
  580.         $qb->andWhere('pv.state = :state')
  581.             ->setParameter('state''published');
  582.         $qb->andWhere('pv.active = :active')
  583.             ->setParameter('active'true);
  584.         if ($productCategory !== null) {
  585.             $qb->andWhere('pv.productCategory = :productCategory')
  586.                 ->setParameter('productCategory'$productCategory);
  587.         }
  588.         if ($productFamily !== null) {
  589.             $qb->andWhere('pv.productFamily = :productFamily')
  590.                 ->setParameter('productFamily'$productFamily);
  591.         }
  592.         if ($product !== null) {
  593.             $qb->andWhere('pv.product = :product')
  594.                 ->setParameter('product'$product);
  595.         }
  596.         return $qb;
  597.     }
  598.     public function getProductVariantsQueryBuilder(
  599.         string $webspace,
  600.         string $locale,
  601.         ?array $excludedIds null,
  602.         ?array $products null,
  603.         ?array $types null,
  604.         ?array $fixations null,
  605.         ?int   $minLuminousFlux null,
  606.         ?int   $maxLuminousFlux null,
  607.         ?array $cris null,
  608.         ?array $chromaticities null,
  609.         ?array $dispersionVariants null,
  610.         ?array $ips null,
  611.         ?array $radiationDirects null,
  612.         ?array $shapes null,
  613.         ?int   $minLength null,
  614.         ?int   $maxLength null,
  615.         ?int   $minWidth null,
  616.         ?int   $maxWidth null,
  617.         ?int   $minHeight null,
  618.         ?int   $maxHeight null,
  619.         ?array $colors null,
  620.         ?array $usages null,
  621.         ?array $maxTemperatures null,
  622.         ?array $minTemperatures null,
  623.         ?int   $minInputPower null,
  624.         ?int   $maxInputPower null,
  625.         ?int   $minEfficiency null,
  626.         ?int   $maxEfficiency null,
  627.         ?array $elProtects null,
  628.         ?array $powerMethods null,
  629.         ?array $resourceTypes null,
  630. //        ?array $lightSources = null,
  631.         ?array $statuses null,
  632.         ?array $mechanicalDurabilities null,
  633.         ?array $dispersions null,
  634.         ?array $drivers null,
  635.         ?array $accessories null,
  636.     ): QueryBuilder
  637.     {
  638.         $qb $this->prepareQueryBuilder($webspace$locale);
  639.         $qb->orderBy('pv.productCode''ASC');
  640.         if($excludedIds !== null) {
  641.             $qb->andWhere($qb->expr()->notIn('pv.id'':excludedIds'))
  642.                 ->setParameter('excludedIds'$excludedIds);
  643.         }
  644.         if($products !== null) {
  645.             $qb->andWhere($qb->expr()->in('pv.product'':products'))
  646.                 ->setParameter('products'$products);
  647.         }
  648.         $this->addTypesToQueryBuilder($qb$types);
  649.         $this->addFixationsToQueryBuilder($qb$fixations);
  650.         $this->addMinLuminousFluxToQueryBuilder($qb$minLuminousFlux);
  651.         $this->addMaxLuminousFluxToQueryBuilder($qb$maxLuminousFlux);
  652.         $this->addCrisToQueryBuilder($qb$cris);
  653.         $this->addChromaticitiesToQueryBuilder($qb$chromaticities);
  654.         $this->addDispersionVariantsToQueryBuilder($qb$dispersionVariants);
  655.         $this->addIpsToQueryBuilder($qb$ips);
  656.         $this->addRadiationDirectsToQueryBuilder($qb$radiationDirects);
  657.         $this->addShapesToQueryBuilder($qb$shapes);
  658.         $this->addMinLengthToQueryBuilder($qb$minLength);
  659.         $this->addMaxLengthToQueryBuilder($qb$maxLength);
  660.         $this->addMinWidthToQueryBuilder($qb$minWidth);
  661.         $this->addMaxWidthToQueryBuilder($qb$maxWidth);
  662.         $this->addMinHeightToQueryBuilder($qb$minHeight);
  663.         $this->addMaxHeightToQueryBuilder($qb$maxHeight);
  664.         $this->addColorsToQueryBuilder($qb$colors);
  665.         $this->addUsagesToQueryBuilder($qb$usages);
  666.         $this->addMaxTemperaturesToQueryBuilder($qb$maxTemperatures);
  667.         $this->addMinTemperaturesToQueryBuilder($qb$minTemperatures);
  668.         $this->addMinInputPowerToQueryBuilder($qb$minInputPower);
  669.         $this->addMaxInputPowerToQueryBuilder($qb$maxInputPower);
  670.         $this->addMinEfficiencyToQueryBuilder($qb$minEfficiency);
  671.         $this->addMaxEfficiencyToQueryBuilder($qb$maxEfficiency);
  672.         $this->addElProtectsToQueryBuilder($qb$elProtects);
  673.         $this->addPowerMethodsToQueryBuilder($qb$powerMethods);
  674.         $this->addResourceTypesToQueryBuilder($qb$resourceTypes);
  675. //        $this->addLightSourcesToQueryBuilder($qb, $lightSources);
  676.         $this->addStatusesToQueryBuilder($qb$statuses);
  677.         $this->addMechanicalDurabilitiesToQueryBuilder($qb$mechanicalDurabilities);
  678.         $this->addDispersionsToQueryBuilder($qb$dispersions);
  679.         $this->addDriversToQueryBuilder($qb$drivers);
  680.         $this->addAccessoriesToQueryBuilder($qb$accessories);
  681.         return $qb;
  682.     }
  683.     // Typ
  684.     // **********************************
  685.     public function getAllTypes(string $webspacestring $locale): array
  686.     {
  687.         $qb $this->prepareQueryBuilder($webspace$locale)
  688.             ->select('pv.type')
  689.             ->distinct();
  690.         $results $qb->getQuery()->getSingleColumnResult();
  691.         $types = [];
  692.         foreach ($results as $result) {
  693.             $items array_map('trim'explode(','$result));
  694.             $types array_merge($types$items);
  695.         }
  696.         $types uString::asort($types);
  697.         return array_unique($types);
  698.     }
  699.     public function addTypesToQueryBuilder(QueryBuilder $qb, ?array $types): void
  700.     {
  701.         if($types !== null) {
  702.             $this->andWhereInIn($qb'pv.type'$types);
  703.         }
  704.     }
  705.     // **********************************
  706.     // Způsob montáže
  707.     // **********************************
  708.     public function getAllFixations(string $webspacestring $locale): array
  709.     {
  710.         $qb $this->prepareQueryBuilder($webspace$locale)
  711.             ->andWhere('pv.fixation <> \'\'')
  712.             ->select('pv.fixation')
  713.             ->distinct();
  714.         $results $qb->getQuery()->getSingleColumnResult();
  715.         $fixations = [];
  716.         foreach ($results as $result) {
  717.             $items array_map('trim'explode(','$result));
  718.             $fixations array_merge($fixations$items);
  719.         }
  720.         $fixations uString::asort($fixations);
  721.         return array_unique($fixations);
  722.     }
  723.     public function addFixationsToQueryBuilder(QueryBuilder $qb, ?array $fixations): void
  724.     {
  725.         if($fixations !== null) {
  726.             $this->andWhereInIn($qb'pv.fixation'$fixations);
  727.         }
  728.     }
  729.     // **********************************
  730.     // Světelný tok [lm]
  731.     // **********************************
  732.     public function getMinLuminousFlux(
  733.         string $webspace,
  734.         string $locale,
  735.         ?ProductCategory $productCategory null,
  736.         ?ProductFamily $productFamily null,
  737.         ?Product $product null,
  738.     ): int
  739.     {
  740.         $qb $this->prepareQueryBuilder(
  741.             webspace$webspace,
  742.             locale$locale,
  743.             productCategory$productCategory,
  744.             productFamily$productFamily,
  745.             product$product,
  746.         );
  747.         $qb->select('MIN(pv.luminousFlux)');
  748.         return $qb->getQuery()->getSingleScalarResult() ?? 0;
  749.     }
  750.     public function getMaxLuminousFlux(
  751.         string $webspace,
  752.         string $locale,
  753.         ?ProductCategory $productCategory null,
  754.         ?ProductFamily $productFamily null,
  755.         ?Product $product null,
  756.     ): int
  757.     {
  758.         $qb $this->prepareQueryBuilder(
  759.             webspace$webspace,
  760.             locale$locale,
  761.             productCategory$productCategory,
  762.             productFamily$productFamily,
  763.             product$product,
  764.         );
  765.         $qb->select('MAX(pv.luminousFlux)');
  766.         return $qb->getQuery()->getSingleScalarResult() ?? 0;
  767.     }
  768.     public function addMinLuminousFluxToQueryBuilder(QueryBuilder $qb, ?int $minLuminousFlux): void
  769.     {
  770.         if($minLuminousFlux !== null) {
  771.             $qb->andWhere('pv.luminousFlux >= :minLuminousFlux')
  772.                 ->setParameter('minLuminousFlux'$minLuminousFlux);
  773.         }
  774.     }
  775.     public function addMaxLuminousFluxToQueryBuilder(QueryBuilder $qb, ?int $maxLuminousFlux): void
  776.     {
  777.         if($maxLuminousFlux !== null) {
  778.             $qb->andWhere('pv.luminousFlux <= :maxLuminousFlux')
  779.                 ->setParameter('maxLuminousFlux'$maxLuminousFlux);
  780.         }
  781.     }
  782.     // **********************************
  783.     // Index podání barev
  784.     // **********************************
  785.     public function getAllCris(string $webspacestring $locale): array
  786.     {
  787.         $qb $this->prepareQueryBuilder($webspace$locale)
  788.             ->andWhere('pv.cri <> \'\'')
  789.             ->select('pv.cri')
  790.             ->distinct();
  791.         $results $qb->getQuery()->getSingleColumnResult();
  792.         $cris = [];
  793.         foreach ($results as $result) {
  794.             $items array_map('trim'explode(','$result));
  795.             $cris array_merge($cris$items);
  796.         }
  797.         $cris uString::asort($cris);
  798.         return array_unique($cris);
  799.     }
  800.     public function addCrisToQueryBuilder(QueryBuilder $qb, ?array $cris): void
  801.     {
  802.         if($cris !== null) {
  803.             $this->andWhereInIn($qb'pv.cri'$cris);
  804.         }
  805.     }
  806.     // **********************************
  807.     // Teplota chromatičnosti
  808.     // **********************************
  809.     public function getAllChromaticities(string $webspacestring $locale): array
  810.     {
  811.         $qb $this->prepareQueryBuilder($webspace$locale)
  812.             ->andWhere('pv.chromaticity <> \'\'')
  813.             ->select('pv.chromaticity')
  814.             ->orderBy('pv.chromaticity''ASC')
  815.             ->distinct();
  816.         return $qb->getQuery()->getSingleColumnResult();
  817.     }
  818.     public function addChromaticitiesToQueryBuilder(QueryBuilder $qb, ?array $chromaticities): void
  819.     {
  820.         if($chromaticities !== null) {
  821.             $qb->andWhere($qb->expr()->in('pv.chromaticity'':chromaticities'))
  822.                 ->setParameter('chromaticities'$chromaticities);
  823.         }
  824.     }
  825.     // **********************************
  826.     // Varianta difúzoru
  827.     // **********************************
  828.     public function getAllDispersionVariants(string $webspacestring $locale): array
  829.     {
  830.         $qb $this->prepareQueryBuilder($webspace$locale)
  831.             ->andWhere('pv.dispersionVariant <> \'\'')
  832.             ->select('pv.dispersionVariant')
  833.             ->distinct();
  834.         $results $qb->getQuery()->getSingleColumnResult();
  835.         $dispersionVariants = [];
  836.         foreach ($results as $result) {
  837.             $items array_map('trim'explode(','$result));
  838.             $dispersionVariants array_merge($dispersionVariants$items);
  839.         }
  840.         $dispersionVariants uString::asort($dispersionVariants);
  841.         return array_unique($dispersionVariants);
  842.     }
  843.     public function addDispersionVariantsToQueryBuilder(QueryBuilder $qb, ?array $dispersionVariants): void
  844.     {
  845.         if($dispersionVariants !== null) {
  846.             $this->andWhereInIn($qb'pv.dispersionVariant'$dispersionVariants);
  847.         }
  848.     }
  849.     // **********************************
  850.     // IP stupeň krytí
  851.     // **********************************
  852.     public function getAllIps(string $webspacestring $locale): array
  853.     {
  854.         $qb $this->prepareQueryBuilder($webspace$locale)
  855.             ->andWhere('pv.protectClass <> \'\'')
  856.             ->select('pv.protectClass')
  857.             ->distinct();
  858.         $results $qb->getQuery()->getSingleColumnResult();
  859.         $ips = [];
  860.         foreach ($results as $result) {
  861.             $items array_map('trim'explode(','$result));
  862.             $ips array_merge($ips$items);
  863.         }
  864.         $ips uString::asort($ips);
  865.         return array_unique($ips);
  866.     }
  867.     public function addIpsToQueryBuilder(QueryBuilder $qb, ?array $ips): void
  868.     {
  869.         if($ips !== null) {
  870.             $this->andWhereInIn($qb'pv.protectClass'$ips);
  871.         }
  872.     }
  873.     // **********************************
  874.     // Směr svícení
  875.     // **********************************
  876.     public function getAllRadiationDirects(string $webspacestring $locale): array
  877.     {
  878.         $qb $this->prepareQueryBuilder($webspace$locale)
  879.             ->andWhere('pv.radiationDirect <> \'\'')
  880.             ->select('pv.radiationDirect')
  881.             ->orderBy('pv.radiationDirect''ASC')
  882.             ->distinct();
  883.         return $qb->getQuery()->getSingleColumnResult();
  884.     }
  885.     public function addRadiationDirectsToQueryBuilder(QueryBuilder $qb, ?array $radiationDirects): void
  886.     {
  887.         if($radiationDirects !== null) {
  888.             $qb->andWhere($qb->expr()->in('pv.radiationDirect'':radiationDirects'))
  889.                 ->setParameter('radiationDirects'$radiationDirects);
  890.         }
  891.     }
  892.     // **********************************
  893.     // Tvar
  894.     // **********************************
  895.     public function getAllShapes(string $webspacestring $locale): array
  896.     {
  897.         $qb $this->prepareQueryBuilder($webspace$locale)
  898.             ->andWhere('pv.shape <> \'\'')
  899.             ->select('pv.shape')
  900.             ->distinct();
  901.         $results $qb->getQuery()->getSingleColumnResult();
  902.         $shapes = [];
  903.         foreach ($results as $result) {
  904.             $items array_map('trim'explode(','$result));
  905.             $shapes array_merge($shapes$items);
  906.         }
  907.         $shapes uString::asort($shapes);
  908.         return array_unique($shapes);
  909.     }
  910.     public function addShapesToQueryBuilder(QueryBuilder $qb, ?array $shapes): void
  911.     {
  912.         if($shapes !== null) {
  913.             $this->andWhereInIn($qb'pv.shape'$shapes);
  914.         }
  915.     }
  916.     // **********************************
  917.     // Délka [mm]
  918.     // **********************************
  919.     public function getMinLength(
  920.         string $webspace,
  921.         string $locale,
  922.         ?ProductCategory $productCategory null,
  923.         ?ProductFamily $productFamily null,
  924.         ?Product $product null,
  925.     ): int
  926.     {
  927.         $qb $this->prepareQueryBuilder(
  928.             webspace$webspace,
  929.             locale$locale,
  930.             productCategory$productCategory,
  931.             productFamily$productFamily,
  932.             product$product,
  933.         );
  934.         $qb->select('MIN(pv.dimensionA)');
  935.         return $qb->getQuery()->getSingleScalarResult() ?? 0;
  936.     }
  937.     public function getMaxLength(
  938.         string $webspace,
  939.         string $locale,
  940.         ?ProductCategory $productCategory null,
  941.         ?ProductFamily $productFamily null,
  942.         ?Product $product null,
  943.     ): int
  944.     {
  945.         $qb $this->prepareQueryBuilder(
  946.             webspace$webspace,
  947.             locale$locale,
  948.             productCategory$productCategory,
  949.             productFamily$productFamily,
  950.             product$product,
  951.         );
  952.         $qb->select('MAX(pv.dimensionA)');
  953.         return $qb->getQuery()->getSingleScalarResult() ?? 0;
  954.     }
  955.     public function addMinLengthToQueryBuilder(QueryBuilder $qb, ?int $minLength): void
  956.     {
  957.         if($minLength !== null) {
  958.             $qb->andWhere('pv.dimensionA >= :minLength')
  959.                 ->setParameter('minLength'$minLength);
  960.         }
  961.     }
  962.     public function addMaxLengthToQueryBuilder(QueryBuilder $qb, ?int $maxLength): void
  963.     {
  964.         if($maxLength !== null) {
  965.             $qb->andWhere('pv.dimensionA <= :maxLength')
  966.                 ->setParameter('maxLength'$maxLength);
  967.         }
  968.     }
  969.     // **********************************
  970.     // Šířka, Průměr [mm]
  971.     // **********************************
  972.     public function getMinWidth(
  973.         string $webspace,
  974.         string $locale,
  975.         ?ProductCategory $productCategory null,
  976.         ?ProductFamily $productFamily null,
  977.         ?Product $product null,
  978.     ): int
  979.     {
  980.         $qb $this->prepareQueryBuilder(
  981.             webspace$webspace,
  982.             locale$locale,
  983.             productCategory$productCategory,
  984.             productFamily$productFamily,
  985.             product$product,
  986.         );
  987.         $qb->select('MIN(pv.dimensionB)');
  988.         return $qb->getQuery()->getSingleScalarResult() ?? 0;
  989.     }
  990.     public function getMaxWidth(
  991.         string $webspace,
  992.         string $locale,
  993.         ?ProductCategory $productCategory null,
  994.         ?ProductFamily $productFamily null,
  995.         ?Product $product null,
  996.     ): int
  997.     {
  998.         $qb $this->prepareQueryBuilder(
  999.             webspace$webspace,
  1000.             locale$locale,
  1001.             productCategory$productCategory,
  1002.             productFamily$productFamily,
  1003.             product$product,
  1004.         );
  1005.         $qb->select('MAX(pv.dimensionB)');
  1006.         return $qb->getQuery()->getSingleScalarResult() ?? 0;
  1007.     }
  1008.     public function addMinWidthToQueryBuilder(QueryBuilder $qb, ?int $minWidth): void
  1009.     {
  1010.         if($minWidth !== null) {
  1011.             $qb->andWhere('pv.dimensionB >= :minWidth')
  1012.                 ->setParameter('minWidth'$minWidth);
  1013.         }
  1014.     }
  1015.     public function addMaxWidthToQueryBuilder(QueryBuilder $qb, ?int $maxWidth): void
  1016.     {
  1017.         if($maxWidth !== null) {
  1018.             $qb->andWhere('pv.dimensionB <= :maxWidth')
  1019.                 ->setParameter('maxWidth'$maxWidth);
  1020.         }
  1021.     }
  1022.     // **********************************
  1023.     // Výška [mm]
  1024.     // **********************************
  1025.     public function getMinHeight(
  1026.         string $webspace,
  1027.         string $locale,
  1028.         ?ProductCategory $productCategory null,
  1029.         ?ProductFamily $productFamily null,
  1030.         ?Product $product null,
  1031.     ): int
  1032.     {
  1033.         $qb $this->prepareQueryBuilder(
  1034.             webspace$webspace,
  1035.             locale$locale,
  1036.             productCategory$productCategory,
  1037.             productFamily$productFamily,
  1038.             product$product,
  1039.         );
  1040.         $qb->select('MIN(pv.dimensionC)');
  1041.         return $qb->getQuery()->getSingleScalarResult() ?? 0;
  1042.     }
  1043.     public function getMaxHeight(
  1044.         string $webspace,
  1045.         string $locale,
  1046.         ?ProductCategory $productCategory null,
  1047.         ?ProductFamily $productFamily null,
  1048.         ?Product $product null,
  1049.     ): int
  1050.     {
  1051.         $qb $this->prepareQueryBuilder(
  1052.             webspace$webspace,
  1053.             locale$locale,
  1054.             productCategory$productCategory,
  1055.             productFamily$productFamily,
  1056.             product$product,
  1057.         );
  1058.         $qb->select('MAX(pv.dimensionC)');
  1059.         return $qb->getQuery()->getSingleScalarResult() ?? 0;
  1060.     }
  1061.     public function addMinHeightToQueryBuilder(QueryBuilder $qb, ?int $minHeight): void
  1062.     {
  1063.         if($minHeight !== null) {
  1064.             $qb->andWhere('pv.dimensionC >= :minHeight')
  1065.                 ->setParameter('minHeight'$minHeight);
  1066.         }
  1067.     }
  1068.     public function addMaxHeightToQueryBuilder(QueryBuilder $qb, ?int $maxHeight): void
  1069.     {
  1070.         if($maxHeight !== null) {
  1071.             $qb->andWhere('pv.dimensionC <= :maxHeight')
  1072.                 ->setParameter('maxHeight'$maxHeight);
  1073.         }
  1074.     }
  1075.     // **********************************
  1076.     // Barva svítidla
  1077.     // **********************************
  1078.     public function getAllColors(string $webspacestring $locale): array
  1079.     {
  1080.         $qb $this->prepareQueryBuilder($webspace$locale)
  1081.             ->andWhere('pv.color <> \'\'')
  1082.             ->select('pv.color')
  1083.             ->distinct();
  1084.         $results $qb->getQuery()->getSingleColumnResult();
  1085.         $colors = [];
  1086.         foreach ($results as $result) {
  1087.             $items array_map('trim'explode(','$result));
  1088.             $colors array_merge($colors$items);
  1089.         }
  1090.         $colors uString::asort($colors);
  1091.         return array_unique($colors);
  1092.     }
  1093.     public function addColorsToQueryBuilder(QueryBuilder $qb, ?array $colors): void
  1094.     {
  1095.         if($colors !== null) {
  1096.             $this->andWhereInIn($qb'pv.color'$colors);
  1097.         }
  1098.     }
  1099.     // **********************************
  1100.     // Použití
  1101.     // **********************************
  1102.     public function getAllUsages(string $webspacestring $locale): array
  1103.     {
  1104.         $qb $this->prepareQueryBuilder($webspace$locale)
  1105.             ->andWhere('pv.variantUse <> \'\'')
  1106.             ->select('pv.variantUse')
  1107.             ->distinct();
  1108.         $results $qb->getQuery()->getSingleColumnResult();
  1109.         $usages = [];
  1110.         foreach ($results as $result) {
  1111.             $items array_map('trim'explode(','$result));
  1112.             $usages array_merge($usages$items);
  1113.         }
  1114.         $usages uString::asort($usages);
  1115.         return array_unique($usages);
  1116.     }
  1117.     public function addUsagesToQueryBuilder(QueryBuilder $qb, ?array $usages): void
  1118.     {
  1119.         if($usages !== null) {
  1120.             $this->andWhereInIn($qb'pv.variantUse'$usages);
  1121.         }
  1122.     }
  1123.     // **********************************
  1124.     // Maximální teplota okolí
  1125.     // **********************************
  1126.     public function getAllMaxTemperatures(string $webspacestring $locale): array
  1127.     {
  1128.         $qb $this->prepareQueryBuilder($webspace$locale)
  1129.             ->andWhere('pv.tempMax <> \'\'')
  1130.             ->select('pv.tempMax')
  1131.             ->distinct();
  1132.         $results $qb->getQuery()->getSingleColumnResult();
  1133.         $maxTemperatures = [];
  1134.         foreach ($results as $result) {
  1135.             $items array_map('trim'explode(','$result));
  1136.             $maxTemperatures array_merge($maxTemperatures$items);
  1137.         }
  1138.         $maxTemperatures uString::asort($maxTemperatures);
  1139.         return array_unique($maxTemperatures);
  1140.     }
  1141.     public function addMaxTemperaturesToQueryBuilder(QueryBuilder $qb, ?array $maxTemperatures): void
  1142.     {
  1143.         if($maxTemperatures !== null) {
  1144.             $this->andWhereInIn($qb'pv.tempMax'$maxTemperatures);
  1145.         }
  1146.     }
  1147.     // **********************************
  1148.     // Minimální teplota okolí
  1149.     // **********************************
  1150.     public function getAllMinTemperatures(string $webspacestring $locale): array
  1151.     {
  1152.         $qb $this->prepareQueryBuilder($webspace$locale)
  1153.             ->andWhere('pv.tempMin <> \'\'')
  1154.             ->select('pv.tempMin')
  1155.             ->distinct();
  1156.         $results $qb->getQuery()->getSingleColumnResult();
  1157.         $minTemperatures = [];
  1158.         foreach ($results as $result) {
  1159.             $items array_map('trim'explode(','$result));
  1160.             $minTemperatures array_merge($minTemperatures$items);
  1161.         }
  1162.         $minTemperatures uString::asort($minTemperatures);
  1163.         return array_unique($minTemperatures);
  1164.     }
  1165.     public function addMinTemperaturesToQueryBuilder(QueryBuilder $qb, ?array $minTemperatures): void
  1166.     {
  1167.         if($minTemperatures !== null) {
  1168.             $this->andWhereInIn($qb'pv.tempMin'$minTemperatures);
  1169.         }
  1170.     }
  1171.     // **********************************
  1172.     // Příkon svítidla [W]
  1173.     // **********************************
  1174.     public function getMinInputPower(
  1175.         string $webspace,
  1176.         string $locale,
  1177.         ?ProductCategory $productCategory null,
  1178.         ?ProductFamily $productFamily null,
  1179.         ?Product $product null,
  1180.     ): int
  1181.     {
  1182.         $qb $this->prepareQueryBuilder(
  1183.             webspace$webspace,
  1184.             locale$locale,
  1185.             productCategory$productCategory,
  1186.             productFamily$productFamily,
  1187.             product$product,
  1188.         );
  1189.         $qb->select('MIN(pv.inputPower)');
  1190.         return $qb->getQuery()->getSingleScalarResult() ?? 0;
  1191.     }
  1192.     public function getMaxInputPower(
  1193.         string $webspace,
  1194.         string $locale,
  1195.         ?ProductCategory $productCategory null,
  1196.         ?ProductFamily $productFamily null,
  1197.         ?Product $product null,
  1198.     ): int
  1199.     {
  1200.         $qb $this->prepareQueryBuilder(
  1201.             webspace$webspace,
  1202.             locale$locale,
  1203.             productCategory$productCategory,
  1204.             productFamily$productFamily,
  1205.             product$product,
  1206.         );
  1207.         $qb->select('MAX(pv.inputPower)');
  1208.         return $qb->getQuery()->getSingleScalarResult() ?? 0;
  1209.     }
  1210.     public function addMinInputPowerToQueryBuilder(QueryBuilder $qb, ?int $minInputPower): void
  1211.     {
  1212.         if($minInputPower !== null) {
  1213.             $qb->andWhere('pv.inputPower >= :minInputPower')
  1214.                 ->setParameter('minInputPower'$minInputPower);
  1215.         }
  1216.     }
  1217.     public function addMaxInputPowerToQueryBuilder(QueryBuilder $qb, ?int $maxInputPower): void
  1218.     {
  1219.         if($maxInputPower !== null) {
  1220.             $qb->andWhere('pv.inputPower <= :maxInputPower')
  1221.                 ->setParameter('maxInputPower'$maxInputPower);
  1222.         }
  1223.     }
  1224.     // **********************************
  1225.     // Měrný výkon [lm/W]
  1226.     // **********************************
  1227.     public function getMinEfficiency(
  1228.         string $webspace,
  1229.         string $locale,
  1230.         ?ProductCategory $productCategory null,
  1231.         ?ProductFamily $productFamily null,
  1232.         ?Product $product null,
  1233.     ): int
  1234.     {
  1235.         $qb $this->prepareQueryBuilder(
  1236.             webspace$webspace,
  1237.             locale$locale,
  1238.             productCategory$productCategory,
  1239.             productFamily$productFamily,
  1240.             product$product,
  1241.         );
  1242.         $qb->select('MIN(pv.efficiency)');
  1243.         return $qb->getQuery()->getSingleScalarResult() ?? 0;
  1244.     }
  1245.     public function getMaxEfficiency(
  1246.         string $webspace,
  1247.         string $locale,
  1248.         ?ProductCategory $productCategory null,
  1249.         ?ProductFamily $productFamily null,
  1250.         ?Product $product null,
  1251.     ): int
  1252.     {
  1253.         $qb $this->prepareQueryBuilder(
  1254.             webspace$webspace,
  1255.             locale$locale,
  1256.             productCategory$productCategory,
  1257.             productFamily$productFamily,
  1258.             product$product,
  1259.         );
  1260.         $qb->select('MAX(pv.efficiency)');
  1261.         return $qb->getQuery()->getSingleScalarResult() ?? 0;
  1262.     }
  1263.     public function addMinEfficiencyToQueryBuilder(QueryBuilder $qb, ?int $minEfficiency): void
  1264.     {
  1265.         if($minEfficiency !== null) {
  1266.             $qb->andWhere('pv.efficiency >= :minEfficiency')
  1267.                 ->setParameter('minEfficiency'$minEfficiency);
  1268.         }
  1269.     }
  1270.     public function addMaxEfficiencyToQueryBuilder(QueryBuilder $qb, ?int $maxEfficiency): void
  1271.     {
  1272.         if($maxEfficiency !== null) {
  1273.             $qb->andWhere('pv.efficiency <= :maxEfficiency')
  1274.                 ->setParameter('maxEfficiency'$maxEfficiency);
  1275.         }
  1276.     }
  1277.     // **********************************
  1278.     // Elektrická třída ochrany
  1279.     // **********************************
  1280.     public function getAllElProtects(string $webspacestring $locale): array
  1281.     {
  1282.         $qb $this->prepareQueryBuilder($webspace$locale)
  1283.             ->andWhere('pv.protectClassEl <> \'\'')
  1284.             ->select('pv.protectClassEl')
  1285.             ->distinct();
  1286.         $results $qb->getQuery()->getSingleColumnResult();
  1287.         $elProtects = [];
  1288.         foreach ($results as $result) {
  1289.             $items array_map('trim'explode(','$result));
  1290.             $elProtects array_merge($elProtects$items);
  1291.         }
  1292.         $elProtects uString::asort($elProtects);
  1293.         return array_unique($elProtects);
  1294.     }
  1295.     public function addElProtectsToQueryBuilder(QueryBuilder $qb, ?array $elProtects): void
  1296.     {
  1297.         if($elProtects !== null) {
  1298.             $this->andWhereInIn($qb'pv.protectClassEl'$elProtects);
  1299.         }
  1300.     }
  1301.     // **********************************
  1302.     // Metoda napájení
  1303.     // **********************************
  1304.     public function getAllPowerMethods(string $webspacestring $locale): array
  1305.     {
  1306.         $qb $this->prepareQueryBuilder($webspace$locale)
  1307.             ->andWhere('pv.supplyVoltage <> \'\'')
  1308.             ->select('pv.supplyVoltage')
  1309.             ->orderBy('pv.supplyVoltage''ASC')
  1310.             ->distinct();
  1311.         return $qb->getQuery()->getSingleColumnResult();
  1312.     }
  1313.     public function addPowerMethodsToQueryBuilder(QueryBuilder $qb, ?array $powerMethods): void
  1314.     {
  1315.         if($powerMethods !== null) {
  1316.             $qb->andWhere($qb->expr()->in('pv.supplyVoltage'':powerMethods'))
  1317.                 ->setParameter('powerMethods'$powerMethods);
  1318.         }
  1319.     }
  1320.     // **********************************
  1321.     // Světelný zdroj
  1322.     // **********************************
  1323.     public function getAllResourceTypes(string $webspacestring $locale): array
  1324.     {
  1325.         $qb $this->prepareQueryBuilder($webspace$locale)
  1326.             ->andWhere('pv.resourceType <> \'\'')
  1327.             ->select('pv.resourceType')
  1328.             ->distinct();
  1329.         $results $qb->getQuery()->getSingleColumnResult();
  1330.         $resourceTypes = [];
  1331.         foreach ($results as $result) {
  1332.             $items array_map('trim'explode(','$result));
  1333.             $resourceTypes array_merge($resourceTypes$items);
  1334.         }
  1335.         $resourceTypes uString::asort($resourceTypes);
  1336.         return array_unique($resourceTypes);
  1337.     }
  1338.     public function addResourceTypesToQueryBuilder(QueryBuilder $qb, ?array $resourceTypes): void
  1339.     {
  1340.         if($resourceTypes !== null) {
  1341.             $this->andWhereInIn($qb'pv.resourceType'$resourceTypes);
  1342.         }
  1343.     }
  1344.     
  1345. //    public function getAllLightSources(string $webspace, string $locale): array
  1346. //    {
  1347. //        $qb = $this->prepareQueryBuilder($webspace, $locale)
  1348. //            ->andWhere('pv.luminousFluxSupply <> \'\'')
  1349. //            ->select('pv.luminousFluxSupply')
  1350. //            ->distinct();
  1351. //
  1352. //        $results = $qb->getQuery()->getSingleColumnResult();
  1353. //
  1354. //        $lightSources = [];
  1355. //        foreach ($results as $result) {
  1356. //            $items = array_map('trim', explode(',', $result));
  1357. //            $lightSources = array_merge($lightSources, $items);
  1358. //        }
  1359. //        $lightSources = uString::asort($lightSources);
  1360. //
  1361. //        return array_unique($lightSources);
  1362. //    }
  1363. //
  1364. //    public function addLightSourcesToQueryBuilder(QueryBuilder $qb, ?array $lightSources): void
  1365. //    {
  1366. //        if($lightSources !== null) {
  1367. //            $this->andWhereInIn($qb, 'pv.luminousFluxSupply', $lightSources);
  1368. //        }
  1369. //    }
  1370.     // **********************************
  1371.     // Stav produktu
  1372.     // **********************************
  1373.     public function getAllStatuses(string $webspacestring $locale): array
  1374.     {
  1375.         $qb $this->prepareQueryBuilder($webspace$locale)
  1376.             ->andWhere('pv.statusNew <> \'\'')
  1377.             ->select('pv.statusNew')
  1378.             ->distinct();
  1379.         $results $qb->getQuery()->getSingleColumnResult();
  1380.         $statuses = [];
  1381.         foreach ($results as $result) {
  1382.             $items array_map('trim'explode(','$result));
  1383.             $statuses array_merge($statuses$items);
  1384.         }
  1385.         $statuses uString::asort($statuses);
  1386.         return array_unique($statuses);
  1387.     }
  1388.     public function addStatusesToQueryBuilder(QueryBuilder $qb, ?array $statuses): void
  1389.     {
  1390.         if($statuses !== null) {
  1391.             $this->andWhereInIn($qb'pv.statusNew'$statuses);
  1392.         }
  1393.     }
  1394.     // **********************************
  1395.     // Mechanická odolnost
  1396.     // **********************************
  1397.     public function getAllMechanicalDurabilities(string $webspacestring $locale): array
  1398.     {
  1399.         $qb $this->prepareQueryBuilder($webspace$locale)
  1400.             ->andWhere('pv.mechanicalDurability <> \'\'')
  1401.             ->select('pv.mechanicalDurability')
  1402.             ->distinct();
  1403.         $results $qb->getQuery()->getSingleColumnResult();
  1404.         $mechanicalDurabilities = [];
  1405.         foreach ($results as $result) {
  1406.             $items array_map('trim'explode(','$result));
  1407.             $mechanicalDurabilities array_merge($mechanicalDurabilities$items);
  1408.         }
  1409.         $mechanicalDurabilities uString::asort($mechanicalDurabilities);
  1410.         return array_unique($mechanicalDurabilities);
  1411.     }
  1412.     public function addMechanicalDurabilitiesToQueryBuilder(QueryBuilder $qb, ?array $mechanicalDurabilities): void
  1413.     {
  1414.         if($mechanicalDurabilities !== null) {
  1415.             $this->andWhereInIn($qb'pv.mechanicalDurability'$mechanicalDurabilities);
  1416.         }
  1417.     }
  1418.     // **********************************
  1419.     // Typ difúzoru
  1420.     // **********************************
  1421.     public function getAllDispersions(string $webspacestring $locale): array
  1422.     {
  1423.         $qb $this->prepareQueryBuilder($webspace$locale)
  1424.             ->andWhere('pv.dispersion <> \'\'')
  1425.             ->select('pv.dispersion')
  1426.             ->distinct();
  1427.         $results $qb->getQuery()->getSingleColumnResult();
  1428.         $dispersions = [];
  1429.         foreach ($results as $result) {
  1430.             $items array_map('trim'explode(','$result));
  1431.             $dispersions array_merge($dispersions$items);
  1432.         }
  1433.         $dispersions uString::asort($dispersions);
  1434.         return array_unique($dispersions);
  1435.     }
  1436.     public function addDispersionsToQueryBuilder(QueryBuilder $qb, ?array $dispersions): void
  1437.     {
  1438.         if($dispersions !== null) {
  1439.             $this->andWhereInIn($qb'pv.dispersion'$dispersions);
  1440.         }
  1441.     }
  1442.     // **********************************
  1443.     // Předřadník
  1444.     // **********************************
  1445.     public function getAllDrivers(string $webspacestring $locale): array
  1446.     {
  1447.         $qb $this->prepareQueryBuilder($webspace$locale)
  1448.             ->andWhere('pv.driver <> \'\'')
  1449.             ->select('pv.driver')
  1450.             ->distinct();
  1451.         $results $qb->getQuery()->getSingleColumnResult();
  1452.         $drivers = [];
  1453.         foreach ($results as $result) {
  1454.             $items array_map('trim'explode(','$result));
  1455.             $drivers array_merge($drivers$items);
  1456.         }
  1457.         $drivers uString::asort($drivers);
  1458.         return array_unique($drivers);
  1459.     }
  1460.     public function addDriversToQueryBuilder(QueryBuilder $qb, ?array $drivers): void
  1461.     {
  1462.         if($drivers !== null) {
  1463.             $this->andWhereInIn($qb'pv.driver'$drivers);
  1464.         }
  1465.     }
  1466.     // **********************************
  1467.     // Doplňující výbava
  1468.     // **********************************
  1469.     public function getAllAccessories(string $webspacestring $locale): array
  1470.     {
  1471.         $qb $this->prepareQueryBuilder($webspace$locale)
  1472.             ->andWhere('pv.supplements <> \'\'')
  1473.             ->select('pv.supplements')
  1474.             ->distinct();
  1475.         $results $qb->getQuery()->getSingleColumnResult();
  1476.         $accessories = [];
  1477.         foreach ($results as $result) {
  1478.             $items array_map('trim'explode(','$result));
  1479.             $accessories array_merge($accessories$items);
  1480.         }
  1481.         $accessories uString::asort($accessories);
  1482.         return array_unique($accessories);
  1483.     }
  1484.     public function getTitlesByAccessoryCodes(string $webspacestring $locale, array $accessoryIds): array
  1485.     {
  1486.         $qb $this->prepareQueryBuilder($webspace$locale)
  1487.             ->select('pv.productCode, pv.title')
  1488.             ->andWhere('pv.productCode IN (:codes)')
  1489.             ->setParameter('codes'$accessoryIds)
  1490.             ->distinct();
  1491.         $results $qb->getQuery()->getResult();
  1492.         $titles = [];
  1493.         foreach ($results as $result) {
  1494.             $titles[$result['productCode']] = $result['title'];
  1495.         }
  1496.         return $titles;
  1497.     }
  1498.     public function addAccessoriesToQueryBuilder(QueryBuilder $qb, ?array $accessories): void
  1499.     {
  1500.         if($accessories !== null) {
  1501.             $this->andWhereInIn($qb'pv.supplements'$accessories);
  1502.         }
  1503.     }
  1504.     // **********************************
  1505. }