mirror of
https://gitlab.com/Chill-Projet/chill-bundles.git
synced 2025-06-07 18:44:08 +00:00
transform gender data for saved exports
This commit is contained in:
parent
0d2e0b4e91
commit
566c40dd84
@ -12,6 +12,7 @@ declare(strict_types=1);
|
|||||||
namespace Chill\PersonBundle\Export\Filter\PersonFilters;
|
namespace Chill\PersonBundle\Export\Filter\PersonFilters;
|
||||||
|
|
||||||
use Chill\MainBundle\Entity\Gender;
|
use Chill\MainBundle\Entity\Gender;
|
||||||
|
use Chill\MainBundle\Export\DataTransformerInterface;
|
||||||
use Chill\MainBundle\Export\ExportElementValidatedInterface;
|
use Chill\MainBundle\Export\ExportElementValidatedInterface;
|
||||||
use Chill\MainBundle\Export\FilterInterface;
|
use Chill\MainBundle\Export\FilterInterface;
|
||||||
use Chill\MainBundle\Repository\GenderRepository;
|
use Chill\MainBundle\Repository\GenderRepository;
|
||||||
@ -27,7 +28,8 @@ use Symfony\Contracts\Translation\TranslatorInterface;
|
|||||||
|
|
||||||
class GenderFilter implements
|
class GenderFilter implements
|
||||||
ExportElementValidatedInterface,
|
ExportElementValidatedInterface,
|
||||||
FilterInterface
|
FilterInterface,
|
||||||
|
DataTransformerInterface
|
||||||
{
|
{
|
||||||
// inject gender repository and find the active genders so that you can pass them to the ChoiceType (ordered by ordering)
|
// inject gender repository and find the active genders so that you can pass them to the ChoiceType (ordered by ordering)
|
||||||
public function __construct(private readonly TranslatorInterface $translator, private readonly TranslatableStringHelperInterface $translatableStringHelper, private readonly GenderRepository $genderRepository) {}
|
public function __construct(private readonly TranslatorInterface $translator, private readonly TranslatableStringHelperInterface $translatableStringHelper, private readonly GenderRepository $genderRepository) {}
|
||||||
@ -77,6 +79,26 @@ class GenderFilter implements
|
|||||||
]);
|
]);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function transformData(?array $before): array
|
||||||
|
{
|
||||||
|
$transformedData = $before;
|
||||||
|
|
||||||
|
if (array_key_exists('accepted_genders', $before)) {
|
||||||
|
$genderMapping = [
|
||||||
|
'woman' => 2,
|
||||||
|
'man' => 1,
|
||||||
|
'both' => 3,
|
||||||
|
'unknown' => null,
|
||||||
|
];
|
||||||
|
|
||||||
|
$transformedData['accepted_genders_entity'] = array_map(function ($gender) use ($genderMapping) {
|
||||||
|
return $genderMapping[$gender] ?? null;
|
||||||
|
}, $before['accepted_genders']);
|
||||||
|
}
|
||||||
|
|
||||||
|
return $transformedData;
|
||||||
|
}
|
||||||
|
|
||||||
public function getFormDefaultData(): array
|
public function getFormDefaultData(): array
|
||||||
{
|
{
|
||||||
return [];
|
return [];
|
||||||
|
Loading…
x
Reference in New Issue
Block a user