mirror of
https://gitlab.com/Chill-Projet/chill-bundles.git
synced 2025-08-27 18:13:48 +00:00
Refactor aggregator and filter retrieval into a new class
Moved aggregator and filter retrieval logic from ExportGenerator to the newly introduced ExportConfigProcessor class. This improves separation of concerns, simplifies ExportGenerator, and enhances code maintainability and readability. Updated related tests accordingly.
This commit is contained in:
@@ -33,6 +33,7 @@ final readonly class ExportGenerator
|
||||
private LoggerInterface $logger,
|
||||
private AuthorizationHelperInterface $authorizationHelper,
|
||||
private CenterRegroupementResolver $centerRegroupementResolver,
|
||||
private ExportConfigProcessor $exportConfigProcessor,
|
||||
) {}
|
||||
|
||||
public function generate(string $exportAlias, array $configuration, ?User $byUser = null): FormattedExportGeneration
|
||||
@@ -94,10 +95,10 @@ final readonly class ExportGenerator
|
||||
$aggregatorsData = [];
|
||||
|
||||
if ($query instanceof QueryBuilder) {
|
||||
foreach ($this->retrieveUsedAggregators($data[ExportType::AGGREGATOR_KEY]) as $alias => $aggregator) {
|
||||
foreach ($this->exportConfigProcessor->retrieveUsedAggregators($data[ExportType::AGGREGATOR_KEY]) as $alias => $aggregator) {
|
||||
$aggregatorsData[$alias] = $data[ExportType::AGGREGATOR_KEY][$alias]['form'];
|
||||
}
|
||||
foreach ($this->retrieveUsedFilters($data[ExportType::FILTER_KEY]) as $alias => $filter) {
|
||||
foreach ($this->exportConfigProcessor->retrieveUsedFilters($data[ExportType::FILTER_KEY]) as $alias => $filter) {
|
||||
$filtersData[$alias] = $data[ExportType::FILTER_KEY][$alias]['form'];
|
||||
}
|
||||
}
|
||||
@@ -184,7 +185,7 @@ final readonly class ExportGenerator
|
||||
|
||||
$usedTypes = [];
|
||||
|
||||
foreach ($this->retrieveUsedFilters($data) as $filter) {
|
||||
foreach ($this->exportConfigProcessor->retrieveUsedFilters($data) as $filter) {
|
||||
if (!\in_array($filter->applyOn(), $usedTypes, true)) {
|
||||
$usedTypes[] = $filter->applyOn();
|
||||
}
|
||||
@@ -204,7 +205,7 @@ final readonly class ExportGenerator
|
||||
|
||||
$usedTypes = [];
|
||||
|
||||
foreach ($this->retrieveUsedAggregators($data) as $alias => $aggregator) {
|
||||
foreach ($this->exportConfigProcessor->retrieveUsedAggregators($data) as $alias => $aggregator) {
|
||||
if (!\in_array($aggregator->applyOn(), $usedTypes, true)) {
|
||||
$usedTypes[] = $aggregator->applyOn();
|
||||
}
|
||||
@@ -213,38 +214,6 @@ final readonly class ExportGenerator
|
||||
return $usedTypes;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return iterable<string, AggregatorInterface>
|
||||
*/
|
||||
private function retrieveUsedAggregators(mixed $data): iterable
|
||||
{
|
||||
if (null === $data) {
|
||||
return [];
|
||||
}
|
||||
|
||||
foreach ($data as $alias => $aggregatorData) {
|
||||
if ($this->exportManager->hasAggregator($alias) && true === $aggregatorData['enabled']) {
|
||||
yield $alias => $this->exportManager->getAggregator($alias);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @return iterable<string, FilterInterface>
|
||||
*/
|
||||
private function retrieveUsedFilters(mixed $data): iterable
|
||||
{
|
||||
if (null === $data) {
|
||||
return [];
|
||||
}
|
||||
|
||||
foreach ($data as $alias => $filterData) {
|
||||
if ($this->exportManager->hasFilter($alias) && true === $filterData['enabled']) {
|
||||
yield $alias => $this->exportManager->getFilter($alias);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Alter the query with selected aggregators.
|
||||
*/
|
||||
@@ -253,7 +222,7 @@ final readonly class ExportGenerator
|
||||
array $data,
|
||||
ExportGenerationContext $context,
|
||||
): void {
|
||||
foreach ($this->retrieveUsedAggregators($data) as $alias => $aggregator) {
|
||||
foreach ($this->exportConfigProcessor->retrieveUsedAggregators($data) as $alias => $aggregator) {
|
||||
$formData = $data[$alias];
|
||||
$aggregator->alterQuery($qb, $formData['form'], $context);
|
||||
}
|
||||
@@ -267,7 +236,7 @@ final readonly class ExportGenerator
|
||||
mixed $data,
|
||||
ExportGenerationContext $context,
|
||||
): void {
|
||||
foreach ($this->retrieveUsedFilters($data) as $alias => $filter) {
|
||||
foreach ($this->exportConfigProcessor->retrieveUsedFilters($data) as $alias => $filter) {
|
||||
$formData = $data[$alias];
|
||||
|
||||
$filter->alterQuery($qb, $formData['form'], $context);
|
||||
|
Reference in New Issue
Block a user