diff --git a/src/Bundle/ChillMainBundle/Entity/Gender.php b/src/Bundle/ChillMainBundle/Entity/Gender.php index 6a96e864a..68dc994ae 100644 --- a/src/Bundle/ChillMainBundle/Entity/Gender.php +++ b/src/Bundle/ChillMainBundle/Entity/Gender.php @@ -5,6 +5,7 @@ namespace Chill\MainBundle\Entity; use Chill\MainBundle\Repository\GenderRepository; use Doctrine\ORM\Mapping as ORM; use Symfony\Component\Serializer\Annotation as Serializer; +use Symfony\Component\Validator\Constraints as Assert; #[Serializer\DiscriminatorMap(typeProperty: 'type', mapping: ['chill_main_gender' => Gender::class])] #[ORM\Entity(repositoryClass: GenderRepository::class)] diff --git a/src/Bundle/ChillMainBundle/Form/GenderType.php b/src/Bundle/ChillMainBundle/Form/GenderType.php index 76d2a4345..d69673b60 100644 --- a/src/Bundle/ChillMainBundle/Form/GenderType.php +++ b/src/Bundle/ChillMainBundle/Form/GenderType.php @@ -34,7 +34,7 @@ class GenderType extends AbstractType 'multiple' => false, 'mapped' => true, 'choice_label' => fn(GenderIconEnum $enum) => '', - 'choice_value' => fn(?GenderIconEnum $enum) => $enum ? $enum->value : null, + 'choice_value' => fn(?GenderIconEnum $enum) => null !== $enum ? $enum->value : null, 'label' => 'gender.admin.Select Gender Icon', 'label_html' => true, ]) diff --git a/src/Bundle/ChillPersonBundle/Entity/Person.php b/src/Bundle/ChillPersonBundle/Entity/Person.php index aa59948df..968763bff 100644 --- a/src/Bundle/ChillPersonBundle/Entity/Person.php +++ b/src/Bundle/ChillPersonBundle/Entity/Person.php @@ -1014,7 +1014,7 @@ class Person implements HasCenterInterface, TrackCreationInterface, TrackUpdateI * * @deprecated Keep for legacy. Used in Chill 1.5 for feminize before icu translations */ - public function getGenderNumeric() +/* public function getGenderNumeric() { return match ($this->getGender()) { self::FEMALE_GENDER => 1, @@ -1022,7 +1022,7 @@ class Person implements HasCenterInterface, TrackCreationInterface, TrackUpdateI self::BOTH_GENDER => 2, default => -1, }; - } + }*/ public function getHouseholdAddresses(): Collection { diff --git a/src/Bundle/ChillPersonBundle/Export/Aggregator/PersonAggregators/GenderAggregator.php b/src/Bundle/ChillPersonBundle/Export/Aggregator/PersonAggregators/GenderAggregator.php index 0181c6e7b..95a1f3c5a 100644 --- a/src/Bundle/ChillPersonBundle/Export/Aggregator/PersonAggregators/GenderAggregator.php +++ b/src/Bundle/ChillPersonBundle/Export/Aggregator/PersonAggregators/GenderAggregator.php @@ -12,6 +12,8 @@ declare(strict_types=1); namespace Chill\PersonBundle\Export\Aggregator\PersonAggregators; use Chill\MainBundle\Export\AggregatorInterface; +use Chill\MainBundle\Repository\GenderRepository; +use Chill\MainBundle\Templating\TranslatableStringHelperInterface; use Chill\PersonBundle\Entity\Person; use Chill\PersonBundle\Export\Declarations; use Doctrine\ORM\QueryBuilder; @@ -20,7 +22,7 @@ use Symfony\Contracts\Translation\TranslatorInterface; final readonly class GenderAggregator implements AggregatorInterface { - public function __construct(private TranslatorInterface $translator) {} + public function __construct(private TranslatorInterface $translator, private TranslatableStringHelperInterface $translatableStringHelper, GenderRepository $repository) {} public function addRole(): ?string { @@ -48,30 +50,16 @@ final readonly class GenderAggregator implements AggregatorInterface public function getLabels($key, array $values, $data) { - return function ($value) { - switch ($value) { - case Person::FEMALE_GENDER: - return $this->translator->trans('woman'); - - case Person::MALE_GENDER: - return $this->translator->trans('man'); - - case Person::BOTH_GENDER: - return $this->translator->trans('both'); - - case Person::NO_INFORMATION: - return $this->translator->trans('unknown'); - - case null: - case '': - return $this->translator->trans('Not given'); - - case '_header': - return $this->translator->trans('Gender'); - - default: - throw new \LogicException(sprintf('The value %s is not valid', $value)); + return function (int|string|null $value) { + if (null === $value || '' === $value) { + return ''; } + + if ('_header' === $value) { + return $this->translator->trans('Gender'); + } + + return (string) $this->translatableStringHelper->localize($this->repository->find((int) $value)?->getLabel()); }; } diff --git a/src/Bundle/ChillPersonBundle/Export/Filter/PersonFilters/GenderFilter.php b/src/Bundle/ChillPersonBundle/Export/Filter/PersonFilters/GenderFilter.php index 5009e37d0..a45aa37ef 100644 --- a/src/Bundle/ChillPersonBundle/Export/Filter/PersonFilters/GenderFilter.php +++ b/src/Bundle/ChillPersonBundle/Export/Filter/PersonFilters/GenderFilter.php @@ -11,13 +11,18 @@ declare(strict_types=1); namespace Chill\PersonBundle\Export\Filter\PersonFilters; +use Chill\MainBundle\Entity\Gender; +use Chill\MainBundle\Entity\GenderEnum; use Chill\MainBundle\Export\ExportElementValidatedInterface; use Chill\MainBundle\Export\FilterInterface; +use Chill\MainBundle\Templating\TranslatableStringHelperInterface; use Chill\PersonBundle\Entity\Person; use Chill\PersonBundle\Export\Declarations; use Doctrine\ORM\Query\Expr; use Doctrine\ORM\QueryBuilder; +use Symfony\Bridge\Doctrine\Form\Type\EntityType; use Symfony\Component\Form\Extension\Core\Type\ChoiceType; +use Symfony\Component\Form\Extension\Core\Type\EnumType; use Symfony\Component\Form\FormBuilderInterface; use Symfony\Component\Validator\Context\ExecutionContextInterface; use Symfony\Contracts\Translation\TranslatorInterface; @@ -26,14 +31,8 @@ class GenderFilter implements ExportElementValidatedInterface, FilterInterface { - /** - * @var TranslatorInterface - */ - protected $translator; - - public function __construct(TranslatorInterface $translator) + public function __construct(private TranslatorInterface $translator, private TranslatableStringHelperInterface $translatableStringHelper) { - $this->translator = $translator; } public function addRole(): ?string @@ -72,14 +71,9 @@ class GenderFilter implements public function buildForm(FormBuilderInterface $builder) { - $builder->add('accepted_genders', ChoiceType::class, [ - 'choices' => [ - 'Woman' => Person::FEMALE_GENDER, - 'Man' => Person::MALE_GENDER, - 'Both' => Person::BOTH_GENDER, - 'Unknown' => Person::NO_INFORMATION, - 'Not given' => 'null', - ], + $builder->add('accepted_genders', EntityType::class, [ + 'class' => Gender::class, + 'choice_label' => fn(Gender $g) => $this->translatableStringHelper->localize($g->getLabel()), 'multiple' => true, 'expanded' => true, ]); @@ -98,7 +92,7 @@ class GenderFilter implements if ('null' === $g) { $genders[] = $this->translator->trans('Not given'); } else { - $genders[] = $this->translator->trans($g); + $genders[] = $this->translatableStringHelper($g->getLabel()); } } diff --git a/src/Bundle/ChillPersonBundle/Search/PersonSearch.php b/src/Bundle/ChillPersonBundle/Search/PersonSearch.php index 9ca72ecac..4d710d8a7 100644 --- a/src/Bundle/ChillPersonBundle/Search/PersonSearch.php +++ b/src/Bundle/ChillPersonBundle/Search/PersonSearch.php @@ -11,6 +11,7 @@ declare(strict_types=1); namespace Chill\PersonBundle\Search; +use Chill\MainBundle\Form\GenderType; use Chill\MainBundle\Form\Type\ChillDateType; use Chill\MainBundle\Form\Type\ChillPhoneNumberType; use Chill\MainBundle\Pagination\PaginatorFactory; @@ -21,7 +22,6 @@ use Chill\MainBundle\Search\SearchInterface; use Chill\MainBundle\Search\Utils\ExtractDateFromPattern; use Chill\MainBundle\Search\Utils\ExtractPhonenumberFromPattern; use Chill\PersonBundle\Entity\Person; -use Chill\PersonBundle\Form\Type\GenderType; use Chill\PersonBundle\Repository\PersonACLAwareRepositoryInterface; use libphonenumber\PhoneNumber; use Symfony\Component\Form\Extension\Core\Type\TextType; diff --git a/src/Bundle/ChillPersonBundle/Serializer/Normalizer/PersonDocGenNormalizer.php b/src/Bundle/ChillPersonBundle/Serializer/Normalizer/PersonDocGenNormalizer.php index c8f9cf455..17549550f 100644 --- a/src/Bundle/ChillPersonBundle/Serializer/Normalizer/PersonDocGenNormalizer.php +++ b/src/Bundle/ChillPersonBundle/Serializer/Normalizer/PersonDocGenNormalizer.php @@ -94,7 +94,7 @@ class PersonDocGenNormalizer implements 'age' => (int) $person->getAge(), 'birthdate' => $this->normalizer->normalize($person->getBirthdate(), $format, $dateContext), 'deathdate' => $this->normalizer->normalize($person->getDeathdate(), $format, $dateContext), - 'gender' => $this->translator->trans($person->getGender()), + 'gender' => $this$this->translator->trans($person->getGender()), 'maritalStatus' => null !== ($ms = $person->getMaritalStatus()) ? $this->translatableStringHelper->localize($ms->getName()) : '', 'maritalStatusDate' => $this->normalizer->normalize($person->getMaritalStatusDate(), $format, $dateContext), 'maritalStatusComment' => $this->normalizer->normalize($person->getMaritalStatusComment(), $format, $dateContext),