src/Filtration/ProductsFiltration.php line 155

Open in your IDE?
  1. <?php
  2. namespace App\Filtration;
  3. use App\Entity\ProductCategory;
  4. use App\Entity\ProductFamily;
  5. use App\Enum\FilterEnum;
  6. use App\Filtration\Trait\FilterTrait;
  7. use App\Repository\ProductRepository;
  8. use App\Repository\ProductVariantRepository;
  9. use Doctrine\ORM\QueryBuilder;
  10. use Symfony\Contracts\Translation\TranslatorInterface;
  11. class ProductsFiltration
  12. {
  13.     use FilterTrait;
  14.     private QueryBuilder $qb;
  15.     public function __construct(
  16.         private readonly TranslatorInterface $translator,
  17.         private readonly ProductRepository $productRepository,
  18.         private readonly ProductVariantRepository $productVariantRepository,
  19.         private readonly string $webspace,
  20.         private readonly string $locale,
  21.         private readonly ?array $categories null,
  22.         private readonly ?array $families null,
  23.         private readonly ?array $types null,
  24.         private readonly ?array $fixations null,
  25.         private readonly ?int   $minLuminousFlux null,
  26.         private readonly ?int   $maxLuminousFlux null,
  27.         private readonly ?array $cris null,
  28.         private readonly ?array $chromaticities null,
  29.         private readonly ?array $dispersionVariants null,
  30.         private readonly ?array $ips null,
  31.         private readonly ?array $radiationDirects null,
  32.         private readonly ?array $shapes null,
  33.         private readonly ?int   $minLength null,
  34.         private readonly ?int   $maxLength null,
  35.         private readonly ?int   $minWidth null,
  36.         private readonly ?int   $maxWidth null,
  37.         private readonly ?int   $minHeight null,
  38.         private readonly ?int   $maxHeight null,
  39.         private readonly ?array $colors null,
  40.         private readonly ?array $usages null,
  41.         private readonly ?array $maxTemperatures null,
  42.         private readonly ?array $minTemperatures null,
  43.         private readonly ?int   $minInputPower null,
  44.         private readonly ?int   $maxInputPower null,
  45.         private readonly ?int   $minEfficiency null,
  46.         private readonly ?int   $maxEfficiency null,
  47.         private readonly ?array $elProtects null,
  48.         private readonly ?array $powerMethods null,
  49.         private readonly ?array $resourceTypes null,
  50. //        private readonly ?array $lightSources = null,
  51.         private readonly ?array $statuses null,
  52.         private readonly ?array $mechanicalDurabilities null,
  53.         private readonly ?array $dispersions null,
  54.         private readonly ?array $drivers null,
  55.         private readonly ?array $accessories null,
  56.     ) {
  57.         $this->qb $this->productRepository->getProductsQueryBuilder(
  58.             webspace$this->webspace,
  59.             locale$this->locale,
  60.             categories$this->categories,
  61.             families$this->families,
  62.         );
  63.         $this->addWhereInCriteria('pv.type'$types);
  64.         $this->addWhereInCriteria('pv.fixation'$fixations);
  65.         $this->addNumberBetweenCriteria('pv.luminousFlux'$this->minLuminousFlux$this->maxLuminousFlux);
  66.         $this->addWhereInCriteria('pv.cri'$cris);
  67.         $this->addWhereInCriteria('pv.chromaticity'$chromaticities);
  68.         $this->addWhereInCriteria('pv.dispersionVariant'$dispersionVariants);
  69.         $this->addWhereInCriteria('pv.protectClass'$ips);
  70.         $this->addWhereInCriteria('pv.radiationDirect'$radiationDirects);
  71.         $this->addWhereInCriteria('pv.shape'$shapes);
  72.         $this->addNumberBetweenCriteria('pv.dimensionA'$this->minLength$this->maxLength);
  73.         $this->addNumberBetweenCriteria('pv.dimensionB'$this->minWidth$this->maxWidth);
  74.         $this->addNumberBetweenCriteria('pv.dimensionC'$this->minHeight$this->maxHeight);
  75.         $this->addWhereInCriteria('pv.color'$colors);
  76.         $this->addWhereInCriteria('pv.variantUse'$usages);
  77.         $this->addWhereInCriteria('pv.tempMax'$maxTemperatures);
  78.         $this->addWhereInCriteria('pv.tempMin'$minTemperatures);
  79.         $this->addNumberBetweenCriteria('pv.inputPower'$this->minInputPower$this->maxInputPower);
  80.         $this->addNumberBetweenCriteria('pv.efficiency'$this->minEfficiency$this->maxEfficiency);
  81.         $this->addWhereInCriteria('pv.elProtect'$elProtects);
  82.         $this->addWhereInCriteria('pv.supplyVoltage'$powerMethods);
  83.         $this->addWhereInCriteria('pv.resourceType'$resourceTypes);
  84. //        $this->addWhereInCriteria('pv.luminousFluxSupply', $lightSources);
  85.         $this->addWhereInCriteria('pv.statusNew'$statuses);
  86.         $this->addWhereInCriteria('pv.mechanicalDurability'$mechanicalDurabilities);
  87.         $this->addWhereInCriteria('pv.dispersion'$dispersions);
  88.         $this->addWhereInCriteria('pv.driver'$drivers);
  89.         $this->addWhereInCriteria('pv.supplements'$accessories);
  90.     }
  91.     public function render(
  92.         ?array $settings null,
  93.         ?ProductCategory $productCategory null,
  94.         ?ProductFamily $productFamily null,
  95.     ): array
  96.     {
  97.         $filters = [];
  98.         if($settings['category_type_visible'] ?? false) {
  99.             $filters[] = $this->renderTypeFilter();
  100.         }
  101.         if($settings['category_fixation_visible'] ?? false) {
  102.             $filters[] = $this->renderFixationFilter();
  103.         }
  104.         if($settings['category_luminousFlux_visible'] ?? false) {
  105.             $filters[] = $this->renderLuminousFluxFilter(productCategory$productCategoryproductFamily$productFamily);
  106.         }
  107.         if($settings['category_cri_visible'] ?? false) {
  108.             $filters[] = $this->renderCriFilter();
  109.         }
  110.         if($settings['category_chromaticity_visible'] ?? false) {
  111.             $filters[] = $this->renderChromaticityFilter();
  112.         }
  113.         if($settings['category_dispersionVariant_visible'] ?? false) {
  114.             $filters[] = $this->renderDispersionVariantFilter();
  115.         }
  116.         if($settings['category_ip_visible'] ?? false) {
  117.             $filters[] = $this->renderIPFilter();
  118.         }
  119.         if($settings['category_radiationDirect_visible'] ?? false) {
  120.             $filters[] = $this->renderRadiationDirectFilter();
  121.         }
  122.         if($settings['category_shape_visible'] ?? false) {
  123.             $filters[] = $this->renderShapeFilter();
  124.         }
  125.         if($settings['category_length_visible'] ?? false) {
  126.             $filters[] = $this->renderLengthFilter(productCategory$productCategoryproductFamily$productFamily);
  127.         }
  128.         if($settings['category_width_visible'] ?? false) {
  129.             $filters[] = $this->renderWidthFilter(productCategory$productCategoryproductFamily$productFamily);
  130.         }
  131.         if($settings['category_height_visible'] ?? false) {
  132.             $filters[] = $this->renderHeightFilter(productCategory$productCategoryproductFamily$productFamily);
  133.         }
  134.         if($settings['category_color_visible'] ?? false) {
  135.             $filters[] = $this->renderColorFilter();
  136.         }
  137.         if($settings['category_usage_visible'] ?? false) {
  138.             $filters[] = $this->renderUsageFilter();
  139.         }
  140.         if($settings['category_maxTemperature_visible'] ?? false) {
  141.             $filters[] = $this->renderMaxTemperatureFilter();
  142.         }
  143.         if($settings['category_minTemperature_visible'] ?? false) {
  144.             $filters[] = $this->renderMinTemperatureFilter();
  145.         }
  146.         if($settings['category_inputPower_visible'] ?? false) {
  147.             $filters[] = $this->renderInputPowerFilter(productCategory$productCategoryproductFamily$productFamily);
  148.         }
  149.         if($settings['category_efficiency_visible'] ?? false) {
  150.             $filters[] = $this->renderEfficiencyFilter(productCategory$productCategoryproductFamily$productFamily);
  151.         }
  152.         if($settings['category_elProtect_visible'] ?? false) {
  153.             $filters[] = $this->renderElProtectFilter();
  154.         }
  155.         if($settings['category_powerMethod_visible'] ?? false) {
  156.             $filters[] = $this->renderPowerMethodFilter();
  157.         }
  158.         if($settings['category_lightSource_visible'] ?? false) {
  159.             $filters[] = $this->renderResourceTypeFilter();
  160.         }
  161. //        if($settings['category_lightSource_visible'] ?? false) {
  162. //            $filters[] = $this->renderLightSourceFilter();
  163. //        }
  164.         if($settings['category_status_visible'] ?? false) {
  165.             $filters[] = $this->renderStatusFilter();
  166.         }
  167.         if($settings['category_mechanicalDurability_visible'] ?? false) {
  168.             $filters[] = $this->renderMechanicalDurabilityFilter();
  169.         }
  170.         if($settings['category_dispersion_visible'] ?? false) {
  171.             $filters[] = $this->renderDispersionFilter();
  172.         }
  173.         if($settings['category_driver_visible'] ?? false) {
  174.             $filters[] = $this->renderDriverFilter();
  175.         }
  176.         if($settings['category_accessory_visible'] ?? false) {
  177.             $filters[] = $this->renderAccessoryFilter();
  178.         }
  179.         return $filters;
  180.     }
  181. }