mirror of
				https://gitlab.com/Chill-Projet/chill-bundles.git
				synced 2025-11-04 03:08:25 +00:00 
			
		
		
		
	Normalize genderEntity for document generation
This commit is contained in:
		@@ -21,13 +21,13 @@ use Symfony\Component\Validator\Constraints as Assert;
 | 
			
		||||
#[ORM\Table(name: 'chill_main_gender')]
 | 
			
		||||
class Gender
 | 
			
		||||
{
 | 
			
		||||
    #[Serializer\Groups(['read'])]
 | 
			
		||||
    #[Serializer\Groups(['read', 'docgen:read'])]
 | 
			
		||||
    #[ORM\Id]
 | 
			
		||||
    #[ORM\GeneratedValue]
 | 
			
		||||
    #[ORM\Column(type: \Doctrine\DBAL\Types\Types::INTEGER)]
 | 
			
		||||
    private ?int $id = null;
 | 
			
		||||
 | 
			
		||||
    #[Serializer\Groups(['read'])]
 | 
			
		||||
    #[Serializer\Groups(['read', 'docgen:read'])]
 | 
			
		||||
    #[ORM\Column(type: \Doctrine\DBAL\Types\Types::JSON)]
 | 
			
		||||
    private array $label = [];
 | 
			
		||||
 | 
			
		||||
@@ -36,7 +36,7 @@ class Gender
 | 
			
		||||
    private bool $active = true;
 | 
			
		||||
 | 
			
		||||
    #[Assert\NotNull(message: 'You must choose a gender translation')]
 | 
			
		||||
    #[Serializer\Groups(['read'])]
 | 
			
		||||
    #[Serializer\Groups(['read', 'docgen:read'])]
 | 
			
		||||
    #[ORM\Column(type: \Doctrine\DBAL\Types\Types::STRING, enumType: GenderEnum::class)]
 | 
			
		||||
    private GenderEnum $genderTranslation;
 | 
			
		||||
 | 
			
		||||
 
 | 
			
		||||
@@ -0,0 +1,39 @@
 | 
			
		||||
<?php
 | 
			
		||||
 | 
			
		||||
declare(strict_types=1);
 | 
			
		||||
 | 
			
		||||
/*
 | 
			
		||||
 * Chill is a software for social workers
 | 
			
		||||
 *
 | 
			
		||||
 * For the full copyright and license information, please view
 | 
			
		||||
 * the LICENSE file that was distributed with this source code.
 | 
			
		||||
 */
 | 
			
		||||
 | 
			
		||||
namespace Chill\PersonBundle\Serializer\Normalizer;
 | 
			
		||||
 | 
			
		||||
use Chill\MainBundle\Entity\Gender;
 | 
			
		||||
use Chill\MainBundle\Templating\TranslatableStringHelper;
 | 
			
		||||
use Symfony\Component\Serializer\Normalizer\ContextAwareNormalizerInterface;
 | 
			
		||||
use Symfony\Component\Serializer\Normalizer\NormalizerAwareInterface;
 | 
			
		||||
use Symfony\Component\Serializer\Normalizer\NormalizerAwareTrait;
 | 
			
		||||
 | 
			
		||||
class GenderDocGenNormalizer implements ContextAwareNormalizerInterface, NormalizerAwareInterface
 | 
			
		||||
{
 | 
			
		||||
    use NormalizerAwareTrait;
 | 
			
		||||
 | 
			
		||||
    public function __construct(private readonly TranslatableStringHelper $translatableStringHelper) {}
 | 
			
		||||
 | 
			
		||||
    public function supportsNormalization($data, ?string $format = null, array $context = [])
 | 
			
		||||
    {
 | 
			
		||||
        return $data instanceof Gender;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public function normalize($gender, ?string $format = null, array $context = [])
 | 
			
		||||
    {
 | 
			
		||||
        return [
 | 
			
		||||
            'id' => $gender->getId(),
 | 
			
		||||
            'label' => $this->translatableStringHelper->localize($gender->getLabel()),
 | 
			
		||||
            'genderTranslation' => $gender->getGenderTranslation(),
 | 
			
		||||
        ];
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
@@ -95,7 +95,8 @@ 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->normalizer->normalize($person->getGender(), $format, $genderContext),
 | 
			
		||||
            'gender' => $this->translatableStringHelper->localize($person->getGender()->getLabel()),
 | 
			
		||||
            'genderEntity' => $this->normalizer->normalize($person->getGender(), $format, $genderContext),
 | 
			
		||||
            '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),
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user