mirror of
https://gitlab.com/Chill-Projet/chill-bundles.git
synced 2025-09-05 06:14:59 +00:00
Compute allowed centers and regroupment at the time of generating the export
This commit is contained in:
@@ -12,19 +12,22 @@ declare(strict_types=1);
|
||||
namespace Chill\MainBundle\Export;
|
||||
|
||||
use Chill\MainBundle\Entity\Center;
|
||||
use Chill\MainBundle\Entity\Regroupment;
|
||||
use Chill\MainBundle\Form\Type\Export\AggregatorType;
|
||||
use Chill\MainBundle\Form\Type\Export\ExportType;
|
||||
use Chill\MainBundle\Form\Type\Export\FilterType;
|
||||
use Chill\MainBundle\Repository\CenterRepositoryInterface;
|
||||
use Chill\MainBundle\Repository\RegroupmentRepository;
|
||||
|
||||
/**
|
||||
* @phpstan-type NormalizedData array{centers: list<int>, export: array{form: array<string, mixed>, version: int}, filters: array<string, array{enabled: boolean, form: array<string, mixed>, version: int}>, aggregators: array<string, array{enabled: boolean, form: array<string, mixed>, version: int}>, pick_formatter: string, formatter: array{form: array<string, mixed>, version: int}}
|
||||
* @phpstan-type NormalizedData array{centers: array{centers: list<int>, regroupments: list<int>}, export: array{form: array<string, mixed>, version: int}, filters: array<string, array{enabled: boolean, form: array<string, mixed>, version: int}>, aggregators: array<string, array{enabled: boolean, form: array<string, mixed>, version: int}>, pick_formatter: string, formatter: array{form: array<string, mixed>, version: int}}
|
||||
*/
|
||||
class ExportConfigNormalizer
|
||||
{
|
||||
public function __construct(
|
||||
private readonly ExportManager $exportManager,
|
||||
private readonly CenterRepositoryInterface $centerRepository,
|
||||
private readonly RegroupmentRepository $regroupmentRepository,
|
||||
) {}
|
||||
|
||||
/**
|
||||
@@ -42,10 +45,10 @@ class ExportConfigNormalizer
|
||||
],
|
||||
];
|
||||
|
||||
$serialized['centers'] = array_values(
|
||||
array_map(static fn (Center $center) => $center->getId(), $formData['centers'])
|
||||
);
|
||||
|
||||
$serialized['centers'] = [
|
||||
'centers' => array_values(array_map(static fn (Center $center) => $center->getId(), $formData['centers']['centers'] ?? [])),
|
||||
'regroupments' => array_values(array_map(static fn (Regroupment $group) => $group->getId(), $formData['centers']['regroupments'] ?? [])),
|
||||
];
|
||||
|
||||
$filtersSerialized = [];
|
||||
foreach ($formData[ExportType::FILTER_KEY] as $alias => $filterData) {
|
||||
@@ -116,7 +119,10 @@ class ExportConfigNormalizer
|
||||
'aggregators' => $aggregatorsConfig,
|
||||
'pick_formatter' => $serializedData['pick_formatter'],
|
||||
'formatter' => $formater->denormalizeFormData($serializedData['formatter']['form'], $serializedData['formatter']['version']),
|
||||
'centers' => array_filter(array_map(fn (int $id) => $this->centerRepository->find($id), $serializedData['centers']), fn ($item) => null !== $item),
|
||||
'centers' => [
|
||||
'centers' => array_values(array_filter(array_map(fn (int $id) => $this->centerRepository->find($id), $serializedData['centers']['centers']), fn ($item) => null !== $item)),
|
||||
'regroupments' => array_values(array_filter(array_map(fn (int $id) => $this->regroupmentRepository->find($id), $serializedData['centers']['regroupments']), fn ($item) => null !== $item)),
|
||||
],
|
||||
];
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user