diff --git a/src/Bundle/ChillActivityBundle/Export/Filter/LocationFilter.php b/src/Bundle/ChillActivityBundle/Export/Filter/LocationFilter.php index 41e33442d..ba19d7ac7 100644 --- a/src/Bundle/ChillActivityBundle/Export/Filter/LocationFilter.php +++ b/src/Bundle/ChillActivityBundle/Export/Filter/LocationFilter.php @@ -24,9 +24,7 @@ final readonly class LocationFilter implements FilterInterface public function __construct( private LocationRepository $locationRepository, - ) - { - } + ) {} public function addRole(): ?string { diff --git a/src/Bundle/ChillAsideActivityBundle/src/Export/Filter/ByActivityTypeFilter.php b/src/Bundle/ChillAsideActivityBundle/src/Export/Filter/ByActivityTypeFilter.php index cc127d4e1..d08884116 100644 --- a/src/Bundle/ChillAsideActivityBundle/src/Export/Filter/ByActivityTypeFilter.php +++ b/src/Bundle/ChillAsideActivityBundle/src/Export/Filter/ByActivityTypeFilter.php @@ -27,9 +27,10 @@ class ByActivityTypeFilter implements FilterInterface use \Chill\MainBundle\Export\ExportDataNormalizerTrait; public function __construct( - private readonly CategoryRender $categoryRender, + private readonly CategoryRender $categoryRender, private readonly TranslatableStringHelperInterface $translatableStringHelper, - private readonly AsideActivityCategoryRepository $asideActivityTypeRepository, private readonly AsideActivityCategoryRepository $asideActivityCategoryRepository, + private readonly AsideActivityCategoryRepository $asideActivityTypeRepository, + private readonly AsideActivityCategoryRepository $asideActivityCategoryRepository, ) {} public function addRole(): ?string diff --git a/src/Bundle/ChillMainBundle/Export/DirectExportInterface.php b/src/Bundle/ChillMainBundle/Export/DirectExportInterface.php index 6521e52d4..0ca0b4a43 100644 --- a/src/Bundle/ChillMainBundle/Export/DirectExportInterface.php +++ b/src/Bundle/ChillMainBundle/Export/DirectExportInterface.php @@ -37,7 +37,7 @@ interface DirectExportInterface extends ExportElementInterface public function denormalizeFormData(array $formData, int $fromVersion): array; - public function getVersion(): int; + public function getNormalizationVersion(): int; /** * get a description, which will be used in UI (and translated). diff --git a/src/Bundle/ChillMainBundle/Export/Formatter/SpreadSheetFormatter.php b/src/Bundle/ChillMainBundle/Export/Formatter/SpreadSheetFormatter.php index 76e17378f..e1c2f067b 100644 --- a/src/Bundle/ChillMainBundle/Export/Formatter/SpreadSheetFormatter.php +++ b/src/Bundle/ChillMainBundle/Export/Formatter/SpreadSheetFormatter.php @@ -155,6 +155,21 @@ class SpreadSheetFormatter implements FormatterInterface } } + public function getNormalizationVersion(): int + { + return 1; + } + + public function normalizeFormData(array $formData): array + { + return $formData; + } + + public function denormalizeFormData(array $formData, int $fromVersion): array + { + return $formData; + } + public function getFormDefaultData(array $aggregatorAliases): array { $data = ['format' => 'xlsx']; diff --git a/src/Bundle/ChillMainBundle/Export/Formatter/SpreadsheetListFormatter.php b/src/Bundle/ChillMainBundle/Export/Formatter/SpreadsheetListFormatter.php index 3c5e90381..fe236a295 100644 --- a/src/Bundle/ChillMainBundle/Export/Formatter/SpreadsheetListFormatter.php +++ b/src/Bundle/ChillMainBundle/Export/Formatter/SpreadsheetListFormatter.php @@ -93,6 +93,21 @@ class SpreadsheetListFormatter implements FormatterInterface ]); } + public function getNormalizationVersion(): int + { + return 1; + } + + public function normalizeFormData(array $formData): array + { + return ['format' => $formData['format'], 'numerotation' => $formData['numerotation']]; + } + + public function denormalizeFormData(array $formData, int $fromVersion): array + { + return ['format' => $formData['format'], 'numerotation' => $formData['numerotation']]; + } + public function getFormDefaultData(array $aggregatorAliases): array { return ['numerotation' => true, 'format' => 'xlsx']; diff --git a/src/Bundle/ChillMainBundle/Repository/GeographicalUnitRepository.php b/src/Bundle/ChillMainBundle/Repository/GeographicalUnitRepository.php index 35ec31ff3..ec24421f8 100644 --- a/src/Bundle/ChillMainBundle/Repository/GeographicalUnitRepository.php +++ b/src/Bundle/ChillMainBundle/Repository/GeographicalUnitRepository.php @@ -13,6 +13,7 @@ namespace Chill\MainBundle\Repository; use Chill\MainBundle\Entity\Address; use Chill\MainBundle\Entity\GeographicalUnit; +use Chill\MainBundle\Entity\GeographicalUnit\SimpleGeographicalUnitDTO; use Doctrine\ORM\EntityManagerInterface; use Doctrine\ORM\EntityRepository; use Doctrine\ORM\Query\Expr\Join; @@ -42,7 +43,7 @@ final readonly class GeographicalUnitRepository implements GeographicalUnitRepos $qb = $this->buildQueryGeographicalUnitContainingAddress($address); return $qb - ->select(sprintf('NEW %s(gu.id, gu.unitName, gu.unitRefId, IDENTITY(gu.layer))', GeographicalUnit\SimpleGeographicalUnitDTO::class)) + ->select(sprintf('NEW %s(gu.id, gu.unitName, gu.unitRefId, IDENTITY(gu.layer))', SimpleGeographicalUnitDTO::class)) ->addOrderBy('IDENTITY(gu.layer)') ->addOrderBy('gu.unitName') ->getQuery() @@ -58,7 +59,7 @@ final readonly class GeographicalUnitRepository implements GeographicalUnitRepos ; return $qb - ->select(sprintf('NEW %s(gu.id, gu.unitName, gu.unitRefId, IDENTITY(gu.layer))', GeographicalUnit\SimpleGeographicalUnitDTO::class)) + ->select(sprintf('NEW %s(gu.id, gu.unitName, gu.unitRefId, IDENTITY(gu.layer))', SimpleGeographicalUnitDTO::class)) ->innerJoin(Address::class, 'address', Join::WITH, 'ST_CONTAINS(gu.geom, address.point) = TRUE') ->where($qb->expr()->eq('address', ':address')) ->setParameter('address', $address) @@ -70,6 +71,19 @@ final readonly class GeographicalUnitRepository implements GeographicalUnitRepos return $this->repository->find($id); } + public function findSimpleGeographicalUnit(int $id): ?SimpleGeographicalUnitDTO + { + $qb = $this->repository + ->createQueryBuilder('gu'); + + return $qb + ->select(sprintf('NEW %s(gu.id, gu.unitName, gu.unitRefId, IDENTITY(gu.layer))', SimpleGeographicalUnitDTO::class)) + ->where('gu.id = :id') + ->setParameter('id', $id) + ->getQuery() + ->getOneOrNullResult(); + } + /** * Will return only partial object, where the @see{GeographicalUnit::geom} property is not loaded. * @@ -79,7 +93,7 @@ final readonly class GeographicalUnitRepository implements GeographicalUnitRepos { return $this->repository ->createQueryBuilder('gu') - ->select(sprintf('NEW %s(gu.id, gu.unitName, gu.unitRefId, IDENTITY(gu.layer))', GeographicalUnit\SimpleGeographicalUnitDTO::class)) + ->select(sprintf('NEW %s(gu.id, gu.unitName, gu.unitRefId, IDENTITY(gu.layer))', SimpleGeographicalUnitDTO::class)) ->addOrderBy('IDENTITY(gu.layer)') ->addOrderBy('gu.unitName') ->getQuery() diff --git a/src/Bundle/ChillMainBundle/Repository/GeographicalUnitRepositoryInterface.php b/src/Bundle/ChillMainBundle/Repository/GeographicalUnitRepositoryInterface.php index b00b0cd98..695474036 100644 --- a/src/Bundle/ChillMainBundle/Repository/GeographicalUnitRepositoryInterface.php +++ b/src/Bundle/ChillMainBundle/Repository/GeographicalUnitRepositoryInterface.php @@ -27,4 +27,6 @@ interface GeographicalUnitRepositoryInterface extends ObjectRepository public function findGeographicalUnitContainingAddress(Address $address, int $offset = 0, int $limit = 50): array; public function countGeographicalUnitContainingAddress(Address $address): int; + + public function findSimpleGeographicalUnit(int $id): ?SimpleGeographicalUnitDTO; } diff --git a/src/Bundle/ChillPersonBundle/Export/Export/CountAccompanyingCourse.php b/src/Bundle/ChillPersonBundle/Export/Export/CountAccompanyingCourse.php index 98f8e56c8..23782c9ee 100644 --- a/src/Bundle/ChillPersonBundle/Export/Export/CountAccompanyingCourse.php +++ b/src/Bundle/ChillPersonBundle/Export/Export/CountAccompanyingCourse.php @@ -60,7 +60,7 @@ class CountAccompanyingCourse implements ExportInterface, GroupedExportInterface return $formData; } - public function denormalizeFormData(array $formData, ExportGenerationContext $context): array + public function denormalizeFormData(array $formData, int $fromVersion): array { return $formData; } diff --git a/src/Bundle/ChillPersonBundle/Export/Export/ListPersonDuplicate.php b/src/Bundle/ChillPersonBundle/Export/Export/ListPersonDuplicate.php index c20294e9b..9ee2bf0e2 100644 --- a/src/Bundle/ChillPersonBundle/Export/Export/ListPersonDuplicate.php +++ b/src/Bundle/ChillPersonBundle/Export/Export/ListPersonDuplicate.php @@ -13,6 +13,7 @@ namespace Chill\PersonBundle\Export\Export; use Chill\MainBundle\Export\DirectExportInterface; use Chill\MainBundle\Export\ExportElementValidatedInterface; +use Chill\MainBundle\Export\FormattedExportGeneration; use Chill\MainBundle\Export\GroupedExportInterface; use Chill\PersonBundle\Security\Authorization\PersonVoter; use Doctrine\ORM\EntityManagerInterface; @@ -21,7 +22,6 @@ use PhpOffice\PhpSpreadsheet\Writer\Xlsx; use Symfony\Component\Form\Extension\Core\Type\NumberType; use Symfony\Component\Form\FormBuilderInterface; use Symfony\Component\HttpFoundation\BinaryFileResponse; -use Symfony\Component\HttpFoundation\Response; use Symfony\Component\HttpFoundation\ResponseHeaderBag; use Symfony\Component\Routing\Generator\UrlGeneratorInterface; use Symfony\Component\Validator\Context\ExecutionContextInterface; @@ -85,7 +85,7 @@ class ListPersonDuplicate implements DirectExportInterface, ExportElementValidat return ['precision' => self::PRECISION_DEFAULT_VALUE]; } - public function generate(array $acl, \Chill\MainBundle\Export\ExportGenerationContext $context, array $data = []): Response + public function generate(array $acl, array $data, \Chill\MainBundle\Export\ExportGenerationContext $context): FormattedExportGeneration { $values = []; $values[] = $this->getHeaders(); diff --git a/src/Bundle/ChillPersonBundle/Export/Filter/AccompanyingCourseFilters/AdministrativeLocationFilter.php b/src/Bundle/ChillPersonBundle/Export/Filter/AccompanyingCourseFilters/AdministrativeLocationFilter.php index 616d5c22e..6c43f25bd 100644 --- a/src/Bundle/ChillPersonBundle/Export/Filter/AccompanyingCourseFilters/AdministrativeLocationFilter.php +++ b/src/Bundle/ChillPersonBundle/Export/Filter/AccompanyingCourseFilters/AdministrativeLocationFilter.php @@ -13,7 +13,6 @@ namespace Chill\PersonBundle\Export\Filter\AccompanyingCourseFilters; use Chill\MainBundle\Export\FilterInterface; use Chill\MainBundle\Form\Type\PickUserLocationType; -use Chill\MainBundle\Repository\LocationRepository; use Chill\MainBundle\Repository\LocationTypeRepository; use Chill\MainBundle\Templating\TranslatableStringHelper; use Chill\PersonBundle\Export\Declarations; diff --git a/src/Bundle/ChillPersonBundle/Export/Filter/AccompanyingCourseFilters/CreatorFilter.php b/src/Bundle/ChillPersonBundle/Export/Filter/AccompanyingCourseFilters/CreatorFilter.php index 3b5934c92..c74f67360 100644 --- a/src/Bundle/ChillPersonBundle/Export/Filter/AccompanyingCourseFilters/CreatorFilter.php +++ b/src/Bundle/ChillPersonBundle/Export/Filter/AccompanyingCourseFilters/CreatorFilter.php @@ -24,10 +24,7 @@ final readonly class CreatorFilter implements FilterInterface { use \Chill\MainBundle\Export\ExportDataNormalizerTrait; - function __construct(private readonly UserRepositoryInterface $userRepository) - { - - } + public function __construct(private readonly UserRepositoryInterface $userRepository) {} public function addRole(): ?string { diff --git a/src/Bundle/ChillPersonBundle/Export/Filter/AccompanyingCourseFilters/GeographicalUnitStatFilter.php b/src/Bundle/ChillPersonBundle/Export/Filter/AccompanyingCourseFilters/GeographicalUnitStatFilter.php index 0d9408ebf..b5ac0bbc9 100644 --- a/src/Bundle/ChillPersonBundle/Export/Filter/AccompanyingCourseFilters/GeographicalUnitStatFilter.php +++ b/src/Bundle/ChillPersonBundle/Export/Filter/AccompanyingCourseFilters/GeographicalUnitStatFilter.php @@ -106,6 +106,32 @@ class GeographicalUnitStatFilter implements FilterInterface ]); } + public function getNormalizationVersion(): int + { + return 1; + } + + public function normalizeFormData(array $formData): array + { + return [ + 'date_calc' => $formData['date_calc']->normalize(), + 'units' => array_map(static fn (SimpleGeographicalUnitDTO $unitDTO) => $unitDTO->id, $formData['units']), + ]; + } + + public function denormalizeFormData(array $formData, int $fromVersion): array + { + $units = array_filter( + array_map( + fn (int $id) => $this->geographicalUnitRepository->findSimpleGeographicalUnit($id), + $formData['units'], + ), + static fn (?SimpleGeographicalUnitDTO $unitDTO) => null !== $unitDTO, + ); + + return ['date_calc' => RollingDate::fromNormalized($formData['date_calc']), 'units' => $units]; + } + public function getFormDefaultData(): array { return ['date_calc' => new RollingDate(RollingDate::T_TODAY)]; diff --git a/src/Bundle/ChillPersonBundle/Export/Filter/AccompanyingCourseFilters/UserJobFilter.php b/src/Bundle/ChillPersonBundle/Export/Filter/AccompanyingCourseFilters/UserJobFilter.php index 3bdf68b19..40b255988 100644 --- a/src/Bundle/ChillPersonBundle/Export/Filter/AccompanyingCourseFilters/UserJobFilter.php +++ b/src/Bundle/ChillPersonBundle/Export/Filter/AccompanyingCourseFilters/UserJobFilter.php @@ -23,7 +23,6 @@ use Chill\MainBundle\Service\RollingDate\RollingDateConverterInterface; use Chill\MainBundle\Templating\TranslatableStringHelper; use Chill\PersonBundle\Entity\AccompanyingPeriod\UserHistory; use Chill\PersonBundle\Export\Declarations; -use Doctrine\Common\Collections\ArrayCollection; use Doctrine\Common\Collections\Collection; use Doctrine\ORM\QueryBuilder; use Symfony\Bridge\Doctrine\Form\Type\EntityType; diff --git a/src/Bundle/ChillPersonBundle/Export/Filter/PersonFilters/GeographicalUnitFilter.php b/src/Bundle/ChillPersonBundle/Export/Filter/PersonFilters/GeographicalUnitFilter.php index e2041c3fa..fc7def8f9 100644 --- a/src/Bundle/ChillPersonBundle/Export/Filter/PersonFilters/GeographicalUnitFilter.php +++ b/src/Bundle/ChillPersonBundle/Export/Filter/PersonFilters/GeographicalUnitFilter.php @@ -25,16 +25,21 @@ use Doctrine\ORM\QueryBuilder; use Symfony\Component\Form\Extension\Core\Type\ChoiceType; use Symfony\Component\Form\FormBuilderInterface; -class GeographicalUnitFilter implements \Chill\MainBundle\Export\FilterInterface +final readonly class GeographicalUnitFilter implements \Chill\MainBundle\Export\FilterInterface { - public function __construct(private readonly GeographicalUnitRepositoryInterface $geographicalUnitRepository, private readonly GeographicalUnitLayerRepositoryInterface $geographicalUnitLayerRepository, private readonly TranslatableStringHelperInterface $translatableStringHelper, private readonly RollingDateConverterInterface $rollingDateConverter) {} + public function __construct( + private GeographicalUnitRepositoryInterface $geographicalUnitRepository, + private GeographicalUnitLayerRepositoryInterface $geographicalUnitLayerRepository, + private TranslatableStringHelperInterface $translatableStringHelper, + private RollingDateConverterInterface $rollingDateConverter, + ) {} public function addRole(): ?string { return null; } - public function alterQuery(QueryBuilder $qb, $data) + public function alterQuery(QueryBuilder $qb, $data, \Chill\MainBundle\Export\ExportGenerationContext $exportGenerationContext) { $subQuery = 'SELECT 1 @@ -88,6 +93,32 @@ class GeographicalUnitFilter implements \Chill\MainBundle\Export\FilterInterface ]); } + public function getNormalizationVersion(): int + { + return 1; + } + + public function normalizeFormData(array $formData): array + { + return [ + 'date_calc' => $formData['date_calc']->normalize(), + 'units' => array_map(static fn (SimpleGeographicalUnitDTO $unitDTO) => $unitDTO->id, $formData['units']), + ]; + } + + public function denormalizeFormData(array $formData, int $fromVersion): array + { + $units = array_filter( + array_map( + fn (int $id) => $this->geographicalUnitRepository->findSimpleGeographicalUnit($id), + $formData['units'], + ), + static fn (?SimpleGeographicalUnitDTO $unitDTO) => null !== $unitDTO, + ); + + return ['date_calc' => RollingDate::fromNormalized($formData['date_calc']), 'units' => $units]; + } + public function getFormDefaultData(): array { return ['date_calc' => new RollingDate(RollingDate::T_TODAY)]; diff --git a/src/Bundle/ChillPersonBundle/Export/Filter/SocialWorkFilters/CreatorFilter.php b/src/Bundle/ChillPersonBundle/Export/Filter/SocialWorkFilters/CreatorFilter.php index 2eb447fca..688195cd5 100644 --- a/src/Bundle/ChillPersonBundle/Export/Filter/SocialWorkFilters/CreatorFilter.php +++ b/src/Bundle/ChillPersonBundle/Export/Filter/SocialWorkFilters/CreatorFilter.php @@ -25,10 +25,7 @@ final readonly class CreatorFilter implements FilterInterface use \Chill\MainBundle\Export\ExportDataNormalizerTrait; private const PREFIX = 'acpw_filter_creator'; - function __construct(private UserRepositoryInterface $userRepository) - { - - } + public function __construct(private UserRepositoryInterface $userRepository) {} public function addRole(): ?string { diff --git a/src/Bundle/ChillPersonBundle/Export/Filter/SocialWorkFilters/ScopeFilter.php b/src/Bundle/ChillPersonBundle/Export/Filter/SocialWorkFilters/ScopeFilter.php index 485bf78bd..6aa4ea097 100644 --- a/src/Bundle/ChillPersonBundle/Export/Filter/SocialWorkFilters/ScopeFilter.php +++ b/src/Bundle/ChillPersonBundle/Export/Filter/SocialWorkFilters/ScopeFilter.php @@ -21,7 +21,6 @@ use Chill\PersonBundle\Export\Declarations; use Doctrine\ORM\QueryBuilder; use Symfony\Bridge\Doctrine\Form\Type\EntityType; use Symfony\Component\Form\FormBuilderInterface; -use Symfony\Contracts\Translation\TranslatorInterface; final readonly class ScopeFilter implements FilterInterface {