<?php
namespace App\Filtration;
use App\Entity\Product;
use App\Enum\FilterEnum;
use App\Filtration\Trait\FilterTrait;
use App\Repository\ProductVariantRepository;
use Doctrine\ORM\QueryBuilder;
use Symfony\Contracts\Translation\TranslatorInterface;
class ProductVariantsFiltration
{
use FilterTrait;
private QueryBuilder $qb;
public function __construct(
private readonly TranslatorInterface $translator,
private readonly ProductVariantRepository $productVariantRepository,
private readonly string $webspace,
private readonly string $locale,
private readonly ?array $products = null,
private readonly ?array $types = null,
private readonly ?array $fixations = null,
private readonly ?int $minLuminousFlux = null,
private readonly ?int $maxLuminousFlux = null,
private readonly ?array $cris = null,
private readonly ?array $chromaticities = null,
private readonly ?array $dispersionVariants = null,
private readonly ?array $ips = null,
private readonly ?array $radiationDirects = null,
private readonly ?array $shapes = null,
private readonly ?int $minLength = null,
private readonly ?int $maxLength = null,
private readonly ?int $minWidth = null,
private readonly ?int $maxWidth = null,
private readonly ?int $minHeight = null,
private readonly ?int $maxHeight = null,
private readonly ?array $colors = null,
private readonly ?array $usages = null,
private readonly ?array $maxTemperatures = null,
private readonly ?array $minTemperatures = null,
private readonly ?int $minInputPower = null,
private readonly ?int $maxInputPower = null,
private readonly ?int $minEfficiency = null,
private readonly ?int $maxEfficiency = null,
private readonly ?array $elProtects = null,
private readonly ?array $powerMethods = null,
private readonly ?array $resourceTypes = null,
// private readonly ?array $lightSources = null,
private readonly ?array $statuses = null,
private readonly ?array $mechanicalDurabilities = null,
private readonly ?array $dispersions = null,
private readonly ?array $drivers = null,
private readonly ?array $accessories = null,
) {
$this->qb = $this->productVariantRepository->getProductVariantsQueryBuilder(
webspace: $this->webspace,
locale: $this->locale,
products: $this->products,
);
$this->addWhereInCriteria('pv.type', $types);
$this->addWhereInCriteria('pv.fixation', $fixations);
$this->addNumberBetweenCriteria('pv.luminousFlux', $this->minLuminousFlux, $this->maxLuminousFlux);
$this->addWhereInCriteria('pv.cri', $cris);
$this->addWhereInCriteria('pv.chromaticity', $chromaticities);
$this->addWhereInCriteria('pv.dispersionVariant', $dispersionVariants);
$this->addWhereInCriteria('pv.protectClass', $ips);
$this->addWhereInCriteria('pv.radiationDirect', $radiationDirects);
$this->addWhereInCriteria('pv.shape', $shapes);
$this->addNumberBetweenCriteria('pv.dimensionA', $this->minLength, $this->maxLength);
$this->addNumberBetweenCriteria('pv.dimensionB', $this->minWidth, $this->maxWidth);
$this->addNumberBetweenCriteria('pv.dimensionC', $this->minHeight, $this->maxHeight);
$this->addWhereInCriteria('pv.color', $colors);
$this->addWhereInCriteria('pv.variantUse', $usages);
$this->addWhereInCriteria('pv.tempMax', $maxTemperatures);
$this->addWhereInCriteria('pv.tempMin', $minTemperatures);
$this->addNumberBetweenCriteria('pv.inputPower', $this->minInputPower, $this->maxInputPower);
$this->addNumberBetweenCriteria('pv.efficiency', $this->minEfficiency, $this->maxEfficiency);
$this->addWhereInCriteria('pv.elProtect', $elProtects);
$this->addWhereInCriteria('pv.supplyVoltage', $powerMethods);
$this->addWhereInCriteria('pv.resourceType', $resourceTypes);
// $this->addWhereInCriteria('pv.luminousFluxSupply', $lightSources);
$this->addWhereInCriteria('pv.statusNew', $statuses);
$this->addWhereInCriteria('pv.mechanicalDurability', $mechanicalDurabilities);
$this->addWhereInCriteria('pv.dispersion', $dispersions);
$this->addWhereInCriteria('pv.driver', $drivers);
$this->addWhereInCriteria('pv.supplements', $accessories);
}
public function render(
?array $settings = null,
?Product $product = null,
): array
{
$filters = [];
if($settings['product_type_visible'] ?? false) {
$filters[] = $this->renderTypeFilter();
}
if($settings['product_fixation_visible'] ?? false) {
$filters[] = $this->renderFixationFilter();
}
if($settings['product_luminousFlux_visible'] ?? false) {
$filters[] = $this->renderLuminousFluxFilter(product: $product);
}
if($settings['product_cri_visible'] ?? false) {
$filters[] = $this->renderCriFilter();
}
if($settings['product_chromaticity_visible'] ?? false) {
$filters[] = $this->renderChromaticityFilter();
}
if($settings['product_dispersionVariant_visible'] ?? false) {
$filters[] = $this->renderDispersionVariantFilter();
}
if($settings['product_ip_visible'] ?? false) {
$filters[] = $this->renderIPFilter();
}
if($settings['product_radiationDirect_visible'] ?? false) {
$filters[] = $this->renderRadiationDirectFilter();
}
if($settings['product_shape_visible'] ?? false) {
$filters[] = $this->renderShapeFilter();
}
if($settings['product_length_visible'] ?? false) {
$filters[] = $this->renderLengthFilter(product: $product);
}
if($settings['product_width_visible'] ?? false) {
$filters[] = $this->renderWidthFilter(product: $product);
}
if($settings['product_height_visible'] ?? false) {
$filters[] = $this->renderHeightFilter(product: $product);
}
if($settings['product_color_visible'] ?? false) {
$filters[] = $this->renderColorFilter();
}
if($settings['product_usage_visible'] ?? false) {
$filters[] = $this->renderUsageFilter();
}
if($settings['product_maxTemperature_visible'] ?? false) {
$filters[] = $this->renderMaxTemperatureFilter();
}
if($settings['product_minTemperature_visible'] ?? false) {
$filters[] = $this->renderMinTemperatureFilter();
}
if($settings['product_inputPower_visible'] ?? false) {
$filters[] = $this->renderInputPowerFilter(product: $product);
}
if($settings['product_efficiency_visible'] ?? false) {
$filters[] = $this->renderEfficiencyFilter(product: $product);
}
if($settings['product_elProtect_visible'] ?? false) {
$filters[] = $this->renderElProtectFilter();
}
if($settings['product_powerMethod_visible'] ?? false) {
$filters[] = $this->renderPowerMethodFilter();
}
if($settings['product_lightSource_visible'] ?? false) {
$filters[] = $this->renderResourceTypeFilter();
}
// if($settings['product_lightSource_visible'] ?? false) {
// $filters[] = $this->renderLightSourceFilter();
// }
if($settings['product_status_visible'] ?? false) {
$filters[] = $this->renderStatusFilter();
}
if($settings['product_mechanicalDurability_visible'] ?? false) {
$filters[] = $this->renderMechanicalDurabilityFilter();
}
if($settings['product_dispersion_visible'] ?? false) {
$filters[] = $this->renderDispersionFilter();
}
if($settings['product_driver_visible'] ?? false) {
$filters[] = $this->renderDriverFilter();
}
if($settings['product_accessory_visible'] ?? false) {
$filters[] = $this->renderAccessoryFilter();
}
return $filters;
}
}