From b05ed86d1e04bb12bbb8a0c9fbe46cc93e575f69 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Julien=20Fastr=C3=A9?= Date: Mon, 20 Nov 2023 18:06:55 +0100 Subject: [PATCH 1/3] DX: Fix aggregator: "group activity by type" --- .changes/unreleased/Fixed-20231120-174603.yaml | 5 +++++ .../Export/Aggregator/ActivityTypeAggregator.php | 9 ++------- 2 files changed, 7 insertions(+), 7 deletions(-) create mode 100644 .changes/unreleased/Fixed-20231120-174603.yaml diff --git a/.changes/unreleased/Fixed-20231120-174603.yaml b/.changes/unreleased/Fixed-20231120-174603.yaml new file mode 100644 index 000000000..0d8b80652 --- /dev/null +++ b/.changes/unreleased/Fixed-20231120-174603.yaml @@ -0,0 +1,5 @@ +kind: Fixed +body: 'Export: fix loading of "Group activity by type"' +time: 2023-11-20T17:46:03.999758401+01:00 +custom: + Issue: "211" diff --git a/src/Bundle/ChillActivityBundle/Export/Aggregator/ActivityTypeAggregator.php b/src/Bundle/ChillActivityBundle/Export/Aggregator/ActivityTypeAggregator.php index fa658635b..2c7891dd6 100644 --- a/src/Bundle/ChillActivityBundle/Export/Aggregator/ActivityTypeAggregator.php +++ b/src/Bundle/ChillActivityBundle/Export/Aggregator/ActivityTypeAggregator.php @@ -56,20 +56,15 @@ class ActivityTypeAggregator implements AggregatorInterface public function getLabels($key, array $values, $data): \Closure { - // for performance reason, we load data from db only once - $this->activityTypeRepository->findBy(['id' => $values]); - - return function ($value): string { + return function (null|int|string $value): string { if ('_header' === $value) { return 'Activity type'; } - if (null === $value || '' === $value) { + if (null === $value || '' === $value || null === $t = $this->activityTypeRepository->find($value)) { return ''; } - $t = $this->activityTypeRepository->find($value); - return $this->translatableStringHelper->localize($t->getName()); }; } From 2883e085edad1be325e31106eb44f61022e3d588 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Julien=20Fastr=C3=A9?= Date: Mon, 20 Nov 2023 18:07:06 +0100 Subject: [PATCH 2/3] DX: Fix aggregator: "group activity by reason" --- .changes/unreleased/Fixed-20231120-174952.yaml | 5 +++++ .../PersonAggregators/ActivityReasonAggregator.php | 6 ------ 2 files changed, 5 insertions(+), 6 deletions(-) create mode 100644 .changes/unreleased/Fixed-20231120-174952.yaml diff --git a/.changes/unreleased/Fixed-20231120-174952.yaml b/.changes/unreleased/Fixed-20231120-174952.yaml new file mode 100644 index 000000000..a10817f0f --- /dev/null +++ b/.changes/unreleased/Fixed-20231120-174952.yaml @@ -0,0 +1,5 @@ +kind: Fixed +body: 'Export: fix loading of "group activity by reasons"' +time: 2023-11-20T17:49:52.416508936+01:00 +custom: + Issue: "190" diff --git a/src/Bundle/ChillActivityBundle/Export/Aggregator/PersonAggregators/ActivityReasonAggregator.php b/src/Bundle/ChillActivityBundle/Export/Aggregator/PersonAggregators/ActivityReasonAggregator.php index 4b1f4894e..f0364bf8e 100644 --- a/src/Bundle/ChillActivityBundle/Export/Aggregator/PersonAggregators/ActivityReasonAggregator.php +++ b/src/Bundle/ChillActivityBundle/Export/Aggregator/PersonAggregators/ActivityReasonAggregator.php @@ -99,12 +99,6 @@ class ActivityReasonAggregator implements AggregatorInterface, ExportElementVali public function getLabels($key, array $values, $data) { - match ($data['level']) { - 'reasons' => $this->activityReasonRepository->findBy(['id' => $values]), - 'categories' => $this->activityReasonCategoryRepository->findBy(['id' => $values]), - default => throw new \RuntimeException(sprintf("The level data '%s' is invalid.", $data['level'])), - }; - return function ($value) use ($data) { if ('_header' === $value) { return 'reasons' === $data['level'] ? 'Group by reasons' : 'Group by categories of reason'; From d0bceb59dcc116cabbec9564343837a6e2048daa Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Julien=20Fastr=C3=A9?= Date: Mon, 20 Nov 2023 18:15:53 +0100 Subject: [PATCH 3/3] Export: fix usage of some Collection returned instead of array in export filters --- .changes/unreleased/Fixed-20231120-181130.yaml | 5 +++++ .../HouseholdAggregators/ChildrenNumberAggregator.php | 4 ++-- .../Filter/AccompanyingCourseFilters/CreatorFilter.php | 9 ++++++++- .../GeographicalUnitStatFilter.php | 6 +++++- .../HandlingThirdPartyFilter.php | 6 +++++- .../JobWorkingOnCourseFilter.php | 3 ++- .../ScopeWorkingOnCourseFilter.php | 3 ++- .../AccompanyingCourseFilters/StepFilterBetweenDates.php | 6 +++++- .../AccompanyingCourseFilters/StepFilterOnDate.php | 6 +++++- .../UserWorkingOnCourseFilter.php | 3 ++- .../PersonFilters/ByHouseholdCompositionFilter.php | 3 ++- .../Filter/PersonFilters/GeographicalUnitFilter.php | 3 ++- .../Export/Filter/SocialWorkFilters/CreatorFilter.php | 9 ++++++++- 13 files changed, 53 insertions(+), 13 deletions(-) create mode 100644 .changes/unreleased/Fixed-20231120-181130.yaml diff --git a/.changes/unreleased/Fixed-20231120-181130.yaml b/.changes/unreleased/Fixed-20231120-181130.yaml new file mode 100644 index 000000000..2d79fecbc --- /dev/null +++ b/.changes/unreleased/Fixed-20231120-181130.yaml @@ -0,0 +1,5 @@ +kind: Fixed +body: 'Export: fix usage of some Collection returned instead of array in export filters' +time: 2023-11-20T18:11:30.290242917+01:00 +custom: + Issue: "213" diff --git a/src/Bundle/ChillPersonBundle/Export/Aggregator/HouseholdAggregators/ChildrenNumberAggregator.php b/src/Bundle/ChillPersonBundle/Export/Aggregator/HouseholdAggregators/ChildrenNumberAggregator.php index cea3de7dd..e013c2f0f 100644 --- a/src/Bundle/ChillPersonBundle/Export/Aggregator/HouseholdAggregators/ChildrenNumberAggregator.php +++ b/src/Bundle/ChillPersonBundle/Export/Aggregator/HouseholdAggregators/ChildrenNumberAggregator.php @@ -70,7 +70,7 @@ class ChildrenNumberAggregator implements AggregatorInterface public function getLabels($key, array $values, $data) { - return static function ($value): string { + return static function (int|string|null $value): string { if ('_header' === $value) { return 'Number of children'; } @@ -79,7 +79,7 @@ class ChildrenNumberAggregator implements AggregatorInterface return ''; } - return $value; + return (string) $value; }; } diff --git a/src/Bundle/ChillPersonBundle/Export/Filter/AccompanyingCourseFilters/CreatorFilter.php b/src/Bundle/ChillPersonBundle/Export/Filter/AccompanyingCourseFilters/CreatorFilter.php index a73f82f69..4fa2c2d1d 100644 --- a/src/Bundle/ChillPersonBundle/Export/Filter/AccompanyingCourseFilters/CreatorFilter.php +++ b/src/Bundle/ChillPersonBundle/Export/Filter/AccompanyingCourseFilters/CreatorFilter.php @@ -15,6 +15,7 @@ use Chill\MainBundle\Entity\User; use Chill\MainBundle\Export\FilterInterface; use Chill\MainBundle\Form\Type\PickUserDynamicType; use Chill\PersonBundle\Export\Declarations; +use Doctrine\Common\Collections\Collection; use Doctrine\ORM\QueryBuilder; use Symfony\Component\Form\FormBuilderInterface; @@ -59,7 +60,13 @@ class CreatorFilter implements FilterInterface { return [ 'Filtered by creator: only %creators%', [ - '%creators%' => implode(', ', array_map(static fn (User $u) => $u->getLabel(), $data['accepted_creators'])), + '%creators%' => implode( + ', ', + array_map( + static fn (User $u) => $u->getLabel(), + $data['accepted_creators'] instanceof Collection ? $data['accepted_creators']->toArray() : $data['accepted_creators'] + ) + ), ], ]; } diff --git a/src/Bundle/ChillPersonBundle/Export/Filter/AccompanyingCourseFilters/GeographicalUnitStatFilter.php b/src/Bundle/ChillPersonBundle/Export/Filter/AccompanyingCourseFilters/GeographicalUnitStatFilter.php index 695831f9c..3b1183c99 100644 --- a/src/Bundle/ChillPersonBundle/Export/Filter/AccompanyingCourseFilters/GeographicalUnitStatFilter.php +++ b/src/Bundle/ChillPersonBundle/Export/Filter/AccompanyingCourseFilters/GeographicalUnitStatFilter.php @@ -23,6 +23,7 @@ use Chill\MainBundle\Templating\TranslatableStringHelperInterface; use Chill\PersonBundle\Entity\AccompanyingPeriod; use Chill\PersonBundle\Entity\Household\PersonHouseholdAddress; use Chill\PersonBundle\Export\Declarations; +use Doctrine\Common\Collections\Collection; use Doctrine\ORM\QueryBuilder; use Symfony\Component\Form\Extension\Core\Type\ChoiceType; use Symfony\Component\Form\FormBuilderInterface; @@ -68,7 +69,10 @@ class GeographicalUnitStatFilter implements FilterInterface 'acp_geog_filter_date', $this->rollingDateConverter->convert($data['date_calc']) ) - ->setParameter('acp_geog_filter_units', array_map(static fn (SimpleGeographicalUnitDTO $unitDTO) => $unitDTO->id, $data['units'])); + ->setParameter('acp_geog_filter_units', array_map( + static fn (SimpleGeographicalUnitDTO $unitDTO) => $unitDTO->id, + $data['units'] instanceof Collection ? $data['units']->toArray() : $data['units'] + )); } public function applyOn(): string diff --git a/src/Bundle/ChillPersonBundle/Export/Filter/AccompanyingCourseFilters/HandlingThirdPartyFilter.php b/src/Bundle/ChillPersonBundle/Export/Filter/AccompanyingCourseFilters/HandlingThirdPartyFilter.php index 80bc7b04a..8a9f734aa 100644 --- a/src/Bundle/ChillPersonBundle/Export/Filter/AccompanyingCourseFilters/HandlingThirdPartyFilter.php +++ b/src/Bundle/ChillPersonBundle/Export/Filter/AccompanyingCourseFilters/HandlingThirdPartyFilter.php @@ -16,6 +16,7 @@ use Chill\PersonBundle\Export\Declarations; use Chill\ThirdPartyBundle\Entity\ThirdParty; use Chill\ThirdPartyBundle\Form\Type\PickThirdpartyDynamicType; use Chill\ThirdPartyBundle\Templating\Entity\ThirdPartyRender; +use Doctrine\Common\Collections\Collection; use Doctrine\ORM\QueryBuilder; use Symfony\Component\Form\FormBuilderInterface; @@ -52,7 +53,10 @@ final readonly class HandlingThirdPartyFilter implements FilterInterface [ '%3parties%' => implode( ', ', - array_map(fn (ThirdParty $thirdParty) => $this->thirdPartyRender->renderString($thirdParty, []), $data['handling_3parties']) + array_map( + fn (ThirdParty $thirdParty) => $this->thirdPartyRender->renderString($thirdParty, []), + $data['handling_3parties'] instanceof Collection ? $data['handling_3parties']->toArray() : $data['handling_3parties'] + ) ), ], ]; diff --git a/src/Bundle/ChillPersonBundle/Export/Filter/AccompanyingCourseFilters/JobWorkingOnCourseFilter.php b/src/Bundle/ChillPersonBundle/Export/Filter/AccompanyingCourseFilters/JobWorkingOnCourseFilter.php index 5f0cf373b..099320c95 100644 --- a/src/Bundle/ChillPersonBundle/Export/Filter/AccompanyingCourseFilters/JobWorkingOnCourseFilter.php +++ b/src/Bundle/ChillPersonBundle/Export/Filter/AccompanyingCourseFilters/JobWorkingOnCourseFilter.php @@ -21,6 +21,7 @@ use Chill\MainBundle\Service\RollingDate\RollingDateConverterInterface; use Chill\MainBundle\Templating\TranslatableStringHelperInterface; use Chill\PersonBundle\Entity\AccompanyingPeriod\AccompanyingPeriodInfo; use Chill\PersonBundle\Export\Declarations; +use Doctrine\Common\Collections\Collection; use Doctrine\ORM\QueryBuilder; use Symfony\Bridge\Doctrine\Form\Type\EntityType; use Symfony\Component\Form\FormBuilderInterface; @@ -115,7 +116,7 @@ readonly class JobWorkingOnCourseFilter implements FilterInterface ', ', array_map( fn (UserJob $userJob) => $this->translatableStringHelper->localize($userJob->getLabel()), - $data['jobs'] + $data['jobs'] instanceof Collection ? $data['jobs']->toArray() : $data['jobs'] ) ), '%start_date%' => $this->rollingDateConverter->convert($data['start_date'])?->format('d-m-Y'), diff --git a/src/Bundle/ChillPersonBundle/Export/Filter/AccompanyingCourseFilters/ScopeWorkingOnCourseFilter.php b/src/Bundle/ChillPersonBundle/Export/Filter/AccompanyingCourseFilters/ScopeWorkingOnCourseFilter.php index 36ec27357..403ddd0b5 100644 --- a/src/Bundle/ChillPersonBundle/Export/Filter/AccompanyingCourseFilters/ScopeWorkingOnCourseFilter.php +++ b/src/Bundle/ChillPersonBundle/Export/Filter/AccompanyingCourseFilters/ScopeWorkingOnCourseFilter.php @@ -21,6 +21,7 @@ use Chill\MainBundle\Service\RollingDate\RollingDateConverterInterface; use Chill\MainBundle\Templating\TranslatableStringHelperInterface; use Chill\PersonBundle\Entity\AccompanyingPeriod\AccompanyingPeriodInfo; use Chill\PersonBundle\Export\Declarations; +use Doctrine\Common\Collections\Collection; use Doctrine\ORM\QueryBuilder; use Symfony\Bridge\Doctrine\Form\Type\EntityType; use Symfony\Component\Form\FormBuilderInterface; @@ -110,7 +111,7 @@ readonly class ScopeWorkingOnCourseFilter implements FilterInterface ', ', array_map( fn (Scope $scope) => $this->translatableStringHelper->localize($scope->getName()), - $data['scopes'] + $data['scopes'] instanceof Collection ? $data['scopes']->toArray() : $data['scopes'] ) ), '%start_date%' => $this->rollingDateConverter->convert($data['start_date'])?->format('d-m-Y'), diff --git a/src/Bundle/ChillPersonBundle/Export/Filter/AccompanyingCourseFilters/StepFilterBetweenDates.php b/src/Bundle/ChillPersonBundle/Export/Filter/AccompanyingCourseFilters/StepFilterBetweenDates.php index 9d49f820b..dfd627eda 100644 --- a/src/Bundle/ChillPersonBundle/Export/Filter/AccompanyingCourseFilters/StepFilterBetweenDates.php +++ b/src/Bundle/ChillPersonBundle/Export/Filter/AccompanyingCourseFilters/StepFilterBetweenDates.php @@ -17,6 +17,7 @@ use Chill\MainBundle\Service\RollingDate\RollingDate; use Chill\MainBundle\Service\RollingDate\RollingDateConverterInterface; use Chill\PersonBundle\Entity\AccompanyingPeriod; use Chill\PersonBundle\Export\Declarations; +use Doctrine\Common\Collections\Collection; use Doctrine\ORM\QueryBuilder; use Symfony\Component\Form\Extension\Core\Type\ChoiceType; use Symfony\Component\Form\FormBuilderInterface; @@ -98,7 +99,10 @@ class StepFilterBetweenDates implements FilterInterface public function describeAction($data, $format = 'string') { - $steps = array_map(fn (string $step) => $this->translator->trans(array_flip(self::STEPS)[$step]), $data['accepted_steps_multi']); + $steps = array_map( + fn (string $step) => $this->translator->trans(array_flip(self::STEPS)[$step]), + $data['accepted_steps_multi'] instanceof Collection ? $data['accepted_steps_multi']->toArray() : $data['accepted_steps_multi'] + ); return ['export.filter.course.by_step.Filtered by steps: only %step% and between %date_from% and %date_to%', [ '%step%' => implode(', ', $steps), diff --git a/src/Bundle/ChillPersonBundle/Export/Filter/AccompanyingCourseFilters/StepFilterOnDate.php b/src/Bundle/ChillPersonBundle/Export/Filter/AccompanyingCourseFilters/StepFilterOnDate.php index 66355e44d..8b36b1b5b 100644 --- a/src/Bundle/ChillPersonBundle/Export/Filter/AccompanyingCourseFilters/StepFilterOnDate.php +++ b/src/Bundle/ChillPersonBundle/Export/Filter/AccompanyingCourseFilters/StepFilterOnDate.php @@ -17,6 +17,7 @@ use Chill\MainBundle\Service\RollingDate\RollingDate; use Chill\MainBundle\Service\RollingDate\RollingDateConverterInterface; use Chill\PersonBundle\Entity\AccompanyingPeriod; use Chill\PersonBundle\Export\Declarations; +use Doctrine\Common\Collections\Collection; use Doctrine\ORM\QueryBuilder; use Symfony\Component\Form\Extension\Core\Type\ChoiceType; use Symfony\Component\Form\FormBuilderInterface; @@ -101,7 +102,10 @@ class StepFilterOnDate implements FilterInterface public function describeAction($data, $format = 'string') { - $steps = array_map(fn (string $step) => $this->translator->trans(array_flip(self::STEPS)[$step]), $data['accepted_steps_multi']); + $steps = array_map( + fn (string $step) => $this->translator->trans(array_flip(self::STEPS)[$step]), + $data['accepted_steps_multi'] instanceof Collection ? $data['accepted_steps_multi']->toArray() : $data['accepted_steps_multi'] + ); return ['Filtered by steps: only %step%', [ '%step%' => implode(', ', $steps), diff --git a/src/Bundle/ChillPersonBundle/Export/Filter/AccompanyingCourseFilters/UserWorkingOnCourseFilter.php b/src/Bundle/ChillPersonBundle/Export/Filter/AccompanyingCourseFilters/UserWorkingOnCourseFilter.php index 42bb7dea3..85d5db9d6 100644 --- a/src/Bundle/ChillPersonBundle/Export/Filter/AccompanyingCourseFilters/UserWorkingOnCourseFilter.php +++ b/src/Bundle/ChillPersonBundle/Export/Filter/AccompanyingCourseFilters/UserWorkingOnCourseFilter.php @@ -20,6 +20,7 @@ use Chill\MainBundle\Service\RollingDate\RollingDateConverterInterface; use Chill\MainBundle\Templating\Entity\UserRender; use Chill\PersonBundle\Entity\AccompanyingPeriod; use Chill\PersonBundle\Export\Declarations; +use Doctrine\Common\Collections\Collection; use Doctrine\ORM\QueryBuilder; use Symfony\Component\Form\FormBuilderInterface; @@ -72,7 +73,7 @@ final readonly class UserWorkingOnCourseFilter implements FilterInterface ', ', array_map( fn (User $u) => $this->userRender->renderString($u, []), - $data['users'] + $data['users'] instanceof Collection ? $data['users']->toArray() : $data['users'] ) ), '%start_date%' => $this->rollingDateConverter->convert($data['start_date'])?->format('d-m-Y'), diff --git a/src/Bundle/ChillPersonBundle/Export/Filter/PersonFilters/ByHouseholdCompositionFilter.php b/src/Bundle/ChillPersonBundle/Export/Filter/PersonFilters/ByHouseholdCompositionFilter.php index fdd799ab9..e873a6598 100644 --- a/src/Bundle/ChillPersonBundle/Export/Filter/PersonFilters/ByHouseholdCompositionFilter.php +++ b/src/Bundle/ChillPersonBundle/Export/Filter/PersonFilters/ByHouseholdCompositionFilter.php @@ -21,6 +21,7 @@ use Chill\PersonBundle\Entity\Household\HouseholdCompositionType; use Chill\PersonBundle\Entity\Household\HouseholdMember; use Chill\PersonBundle\Export\Declarations; use Chill\PersonBundle\Repository\Household\HouseholdCompositionTypeRepositoryInterface; +use Doctrine\Common\Collections\Collection; use Doctrine\DBAL\Types\Types; use Doctrine\ORM\QueryBuilder; use Symfony\Bridge\Doctrine\Form\Type\EntityType; @@ -84,7 +85,7 @@ class ByHouseholdCompositionFilter implements FilterInterface { $compos = array_map( fn (HouseholdCompositionType $compositionType) => $this->translatableStringHelper->localize($compositionType->getLabel()), - $data['compositions']->toArray() + $data['compositions'] instanceof Collection ? $data['compositions']->toArray() : $data['compositions'] ); return ['export.filter.person.by_composition.Filtered by composition at %date%: only %compositions%', [ diff --git a/src/Bundle/ChillPersonBundle/Export/Filter/PersonFilters/GeographicalUnitFilter.php b/src/Bundle/ChillPersonBundle/Export/Filter/PersonFilters/GeographicalUnitFilter.php index d54842b47..e2041c3fa 100644 --- a/src/Bundle/ChillPersonBundle/Export/Filter/PersonFilters/GeographicalUnitFilter.php +++ b/src/Bundle/ChillPersonBundle/Export/Filter/PersonFilters/GeographicalUnitFilter.php @@ -20,6 +20,7 @@ use Chill\MainBundle\Service\RollingDate\RollingDateConverterInterface; use Chill\MainBundle\Templating\TranslatableStringHelperInterface; use Chill\PersonBundle\Entity\Household\PersonHouseholdAddress; use Chill\PersonBundle\Export\Declarations; +use Doctrine\Common\Collections\Collection; use Doctrine\ORM\QueryBuilder; use Symfony\Component\Form\Extension\Core\Type\ChoiceType; use Symfony\Component\Form\FormBuilderInterface; @@ -102,7 +103,7 @@ class GeographicalUnitFilter implements \Chill\MainBundle\Export\FilterInterface ', ', array_map( fn (SimpleGeographicalUnitDTO $item) => $this->translatableStringHelper->localize($this->geographicalUnitLayerRepository->find($item->layerId)->getName()).' > '.$item->unitName, - $data['units'] + $data['units'] instanceof Collection ? $data['units']->toArray() : $data['units'] ) ), ], diff --git a/src/Bundle/ChillPersonBundle/Export/Filter/SocialWorkFilters/CreatorFilter.php b/src/Bundle/ChillPersonBundle/Export/Filter/SocialWorkFilters/CreatorFilter.php index 100bcfdc4..c990e658e 100644 --- a/src/Bundle/ChillPersonBundle/Export/Filter/SocialWorkFilters/CreatorFilter.php +++ b/src/Bundle/ChillPersonBundle/Export/Filter/SocialWorkFilters/CreatorFilter.php @@ -15,6 +15,7 @@ use Chill\MainBundle\Entity\User; use Chill\MainBundle\Export\FilterInterface; use Chill\MainBundle\Form\Type\PickUserDynamicType; use Chill\PersonBundle\Export\Declarations; +use Doctrine\Common\Collections\Collection; use Doctrine\ORM\QueryBuilder; use Symfony\Component\Form\FormBuilderInterface; @@ -55,7 +56,13 @@ class CreatorFilter implements FilterInterface { return [ 'export.filter.work.by_creator.Filtered by creator: only %creators%', [ - '%creators%' => implode(', ', array_map(static fn (User $u) => $u->getLabel(), $data['creators'])), + '%creators%' => implode( + ', ', + array_map( + static fn (User $u) => $u->getLabel(), + $data['creators'] instanceof Collection ? $data['creators']->toArray() : $data['creators'] + ) + ), ], ]; }