Merge branch '211-errors-exports' into 'master'

Resolve multiple errors in filters and aggregators

Closes #213 and #211

See merge request Chill-Projet/chill-bundles!617
This commit is contained in:
Julien Fastré 2023-11-21 12:53:27 +00:00
commit 7132dfa3f6
17 changed files with 65 additions and 26 deletions

View File

@ -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"

View File

@ -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"

View File

@ -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"

View File

@ -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());
};
}

View File

@ -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';

View File

@ -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;
};
}

View File

@ -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']
)
),
], ];
}

View File

@ -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

View File

@ -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']
)
),
],
];

View File

@ -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'),

View File

@ -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'),

View File

@ -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),

View File

@ -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),

View File

@ -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'),

View File

@ -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%', [

View File

@ -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']
)
),
],

View File

@ -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']
)
),
],
];
}