src/Filtration/ProductVariantsFiltration.php line 149

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