Refactor form data handling in export filters and aggregators

Improved normalization and denormalization of form data by introducing default values and null handling across various filters and aggregators. Added `ExportDataNormalizerTrait` and repository dependencies where necessary to streamline data processing. This ensures more robust data handling and better default value management.
This commit is contained in:
2025-04-25 18:24:26 +02:00
parent 6d76b94644
commit b6985e0e5f
11 changed files with 100 additions and 32 deletions

View File

@@ -12,17 +12,21 @@ declare(strict_types=1);
namespace Chill\ActivityBundle\Export\Filter\ACPFilters;
use Chill\ActivityBundle\Export\Declarations;
use Chill\MainBundle\Export\ExportDataNormalizerTrait;
use Chill\MainBundle\Export\ExportGenerationContext;
use Chill\MainBundle\Export\FilterInterface;
use Chill\PersonBundle\Entity\SocialWork\SocialAction;
use Chill\PersonBundle\Form\Type\PickSocialActionType;
use Chill\PersonBundle\Repository\SocialWork\SocialActionRepository;
use Chill\PersonBundle\Templating\Entity\SocialActionRender;
use Doctrine\ORM\QueryBuilder;
use Symfony\Component\Form\FormBuilderInterface;
class BySocialActionFilter implements FilterInterface
{
public function __construct(private readonly SocialActionRender $actionRender) {}
use ExportDataNormalizerTrait;
public function __construct(private readonly SocialActionRender $actionRender, private readonly SocialActionRepository $socialActionRepository) {}
public function addRole(): ?string
{
@@ -63,17 +67,19 @@ class BySocialActionFilter implements FilterInterface
public function normalizeFormData(array $formData): array
{
return ['accepted_socialactions' => $formData['accepted_socialactions']];
return ['accepted_socialactions' => $this->normalizeDoctrineEntity($formData['accepted_socialactions'])];
}
public function denormalizeFormData(array $formData, int $fromVersion): array
{
return ['accepted_socialactions' => $formData['accepted_socialactions']];
return ['accepted_socialactions' => $this->denormalizeDoctrineEntity($formData['accepted_socialactions'], $this->socialActionRepository)];
}
public function getFormDefaultData(): array
{
return [];
return [
'accepted_socialactions' => []
];
}
public function describeAction($data, ExportGenerationContext $context): array

View File

@@ -12,9 +12,12 @@ declare(strict_types=1);
namespace Chill\ActivityBundle\Export\Filter;
use Chill\ActivityBundle\Export\Declarations;
use Chill\MainBundle\Export\ExportDataNormalizerTrait;
use Chill\MainBundle\Export\ExportGenerationContext;
use Chill\MainBundle\Export\FilterInterface;
use Chill\MainBundle\Form\Type\PickLocationTypeType;
use Chill\MainBundle\Repository\LocationRepository;
use Chill\MainBundle\Repository\LocationTypeRepository;
use Chill\MainBundle\Templating\TranslatableStringHelper;
use Doctrine\ORM\Query\Expr\Andx;
use Doctrine\ORM\QueryBuilder;
@@ -22,7 +25,9 @@ use Symfony\Component\Form\FormBuilderInterface;
class LocationTypeFilter implements FilterInterface
{
public function __construct(private readonly TranslatableStringHelper $translatableStringHelper) {}
use ExportDataNormalizerTrait;
public function __construct(private readonly TranslatableStringHelper $translatableStringHelper, private LocationTypeRepository $locationTypeRepository) {}
public function addRole(): ?string
{
@@ -68,17 +73,17 @@ class LocationTypeFilter implements FilterInterface
public function normalizeFormData(array $formData): array
{
return ['accepted_locationtype' => $formData['accepted_locationtype']];
return ['accepted_locationtype' => $this->normalizeDoctrineEntity($formData['accepted_locationtype'])];
}
public function denormalizeFormData(array $formData, int $fromVersion): array
{
return ['accepted_locationtype' => $formData['accepted_locationtype']];
return ['accepted_locationtype' => $this->denormalizeDoctrineEntity($formData['accepted_locationtype'], $this->locationTypeRepository)];
}
public function getFormDefaultData(): array
{
return [];
return ['accepted_locationtype' => []];
}
public function describeAction($data, ExportGenerationContext $context): array