Refactor BySocialIssueFilter to enhance normalization logic

Added ExportDataNormalizerTrait to streamline data normalization and denormalization processes. Updated constructor to inject dependencies for SocialIssueRepository and NormalizerInterface, improving modularity and maintainability. Adjusted form data normalization methods to utilize the new utilities.
This commit is contained in:
Julien Fastré 2025-05-26 13:24:42 +02:00
parent e89f5e4713
commit 9f32b5ac48
Signed by: julienfastre
GPG Key ID: BDE2190974723FCB

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\SocialIssue;
use Chill\PersonBundle\Form\Type\PickSocialIssueType;
use Chill\PersonBundle\Repository\SocialWork\SocialIssueRepository;
use Chill\PersonBundle\Templating\Entity\SocialIssueRender;
use Doctrine\ORM\QueryBuilder;
use Symfony\Component\Form\FormBuilderInterface;
class BySocialIssueFilter implements FilterInterface
{
public function __construct(private readonly SocialIssueRender $issueRender) {}
use ExportDataNormalizerTrait;
public function __construct(private readonly SocialIssueRender $issueRender, private readonly SocialIssueRepository $issueRepository) {}
public function addRole(): ?string
{
@ -63,12 +67,12 @@ class BySocialIssueFilter implements FilterInterface
public function normalizeFormData(array $formData): array
{
return ['accepted_socialissues' => $formData['accepted_socialissues']];
return ['accepted_socialissues' => $this->normalizeDoctrineEntity($formData['accepted_socialissues'])];
}
public function denormalizeFormData(array $formData, int $fromVersion): array
{
return ['accepted_socialissues' => $formData['accepted_socialissues']];
return ['accepted_socialissues' => $this->denormalizeDoctrineEntity($formData['accepted_socialissues'], $this->issueRepository)];
}
public function getFormDefaultData(): array