adaptations after having merged ticket-app-master

This commit is contained in:
2025-12-22 17:23:50 +01:00
parent 43d6a86627
commit 35d91762d3
42 changed files with 194 additions and 157 deletions

View File

@@ -18,6 +18,7 @@ use Chill\PersonBundle\Entity\Person;
use Chill\PersonBundle\Entity\PersonAltName;
use Chill\PersonBundle\Repository\ResidentialAddressRepository;
use Doctrine\Common\Collections\Collection;
use Symfony\Component\Serializer\Exception\UnexpectedValueException;
use Symfony\Component\Serializer\Normalizer\AbstractNormalizer;
use Symfony\Component\Serializer\Normalizer\NormalizerAwareInterface;
use Symfony\Component\Serializer\Normalizer\NormalizerAwareTrait;
@@ -38,50 +39,54 @@ class PersonJsonNormalizer implements NormalizerAwareInterface, NormalizerInterf
private readonly \Chill\PersonBundle\PersonIdentifier\Rendering\PersonIdRenderingInterface $personIdRendering,
) {}
/**
* @param Person $person
* @param string|null $format
*/
public function normalize($person, $format = null, array $context = [])
public function normalize($data, $format = null, array $context = []): array
{
if (!$data instanceof Person) {
throw new UnexpectedValueException(sprintf('Expected %s, got %s', Person::class, is_object($data) ? get_class($data) : gettype($data)));
}
$groups = $context[AbstractNormalizer::GROUPS] ?? [];
if (\is_string($groups)) {
$groups = [$groups];
}
$household = $person->getCurrentHousehold();
$currentResidentialAddresses = $this->residentialAddressRepository->findCurrentResidentialAddressByPerson($person);
$household = $data->getCurrentHousehold();
$currentResidentialAddresses = $this->residentialAddressRepository->findCurrentResidentialAddressByPerson($data);
$data = [
$normalizedData = [
'type' => 'person',
'id' => $person->getId(),
'text' => $this->render->renderString($person, ['addAge' => false]),
'textAge' => $this->render->renderString($person, ['addAge' => true]),
'firstName' => $person->getFirstName(),
'lastName' => $person->getLastName(),
'current_household_address' => $this->normalizer->normalize($person->getCurrentHouseholdAddress(), $format, $context),
'birthdate' => $this->normalizer->normalize($person->getBirthdate(), $format, $context),
'deathdate' => $this->normalizer->normalize($person->getDeathdate(), $format, $context),
'age' => $this->normalizer->normalize($person->getAge(), $format, $context),
'phonenumber' => $this->normalizer->normalize($person->getPhonenumber(), $format, $context),
'mobilenumber' => $this->normalizer->normalize($person->getMobilenumber(), $format, $context),
'email' => $person->getEmail(),
'gender' => $this->normalizer->normalize($person->getGender(), $format, $context),
'civility' => $this->normalizer->normalize($person->getCivility(), $format, $context),
'personId' => $this->personIdRendering->renderPersonId($person),
'identifiers' => $this->normalizer->normalize($person->getIdentifiers(), $format, $context),
'id' => $data->getId(),
'text' => $this->render->renderString($data, ['addAge' => false]),
'textAge' => $this->render->renderString($data, ['addAge' => true]),
'firstName' => $data->getFirstName(),
'lastName' => $data->getLastName(),
'current_household_address' => $this->normalizer->normalize($data->getCurrentHouseholdAddress(), $format, $context),
'birthdate' => $this->normalizer->normalize($data->getBirthdate(), $format, $context),
'deathdate' => $this->normalizer->normalize($data->getDeathdate(), $format, $context),
'age' => $this->normalizer->normalize($data->getAge(), $format, $context),
'phonenumber' => $this->normalizer->normalize($data->getPhonenumber(), $format, $context),
'mobilenumber' => $this->normalizer->normalize($data->getMobilenumber(), $format, $context),
'email' => $data->getEmail(),
'gender' => $this->normalizer->normalize($data->getGender(), $format, $context),
'civility' => $this->normalizer->normalize($data->getCivility(), $format, $context),
'personId' => $this->personIdRendering->renderPersonId($data),
'identifiers' => $this->normalizer->normalize($data->getIdentifiers(), $format, $context),
];
if (\in_array('minimal', $groups, true) && 1 === \count($groups)) {
return $data;
return $normalizedData;
}
return [...$data, 'centers' => $this->normalizer->normalize($this->centerResolverManager->resolveCenters($person), $format, $context), 'altNames' => $this->normalizeAltNames($person->getAltNames()), 'current_household_id' => $household ? $this->normalizer->normalize($household->getId(), $format, $context) : null, 'current_residential_addresses' => $currentResidentialAddresses ?
$this->normalizer->normalize($currentResidentialAddresses, $format, $context) :
null];
return [
...$normalizedData,
'centers' => $this->normalizer->normalize($this->centerResolverManager->resolveCenters($data), $format, $context),
'altNames' => $this->normalizeAltNames($data->getAltNames()),
'current_household_id' => $household ? $this->normalizer->normalize($household->getId(), $format, $context) : null,
'current_residential_addresses' => $currentResidentialAddresses ? $this->normalizer->normalize($currentResidentialAddresses, $format, $context) : null,
];
}
public function supportsNormalization($data, $format = null): bool
public function supportsNormalization($data, $format = null, array $context = []): bool
{
return $data instanceof Person && 'json' === $format;
}
@@ -91,7 +96,7 @@ class PersonJsonNormalizer implements NormalizerAwareInterface, NormalizerInterf
*
* @return array<array-key, array<string, string>>
*/
protected function normalizeAltNames(Collection $altNames): array
private function normalizeAltNames(Collection $altNames): array
{
return $altNames
->map(
@@ -105,6 +110,6 @@ class PersonJsonNormalizer implements NormalizerAwareInterface, NormalizerInterf
public function getSupportedTypes(?string $format): array
{
return 'json' === $format ? [Person::class => true] : [];
return 'json' === $format ? [Person::class => false] : [];
}
}