Merge branch 'bugfix/person-json-normalization-circular-reference' into 'master'

fix circular reference in center normalization

See merge request Chill-Projet/chill-bundles!229
This commit is contained in:
Julien Fastré 2021-11-22 12:02:23 +00:00
commit 99d412adc9
3 changed files with 13 additions and 16 deletions

View File

@ -28,6 +28,7 @@ and this project adheres to
* [person] create an accompanying course: add client-side validation if no origin (https://gitlab.com/champs-libres/departement-de-la-vendee/accent-suivi-developpement/-/issues/210)
* [person] fix bounds for computing current person address: the new address appears immediatly
* [docgen] create a normalizer and serializer for normalization on doc format
* [person normalization] the key center is now "centers" and is an array. Empty array if no center
## Test releases

View File

@ -96,14 +96,9 @@
<p class="chill-no-data-statement">{{ $t('renderbox.no_data') }}</p>
</li>
<li v-if="person.center && options.addCenter">
<li v-if="person.centers !== undefined && person.centers.length > 0 && options.addCenter">
<i class="fa fa-li fa-long-arrow-right"></i>
<template v-if="person.center.type !== undefined">
{{ person.center.name }}
</template>
<template v-else>
<template v-for="c in person.center">{{ c.name }}</template>
</template>
<template v-for="c in person.centers">{{ c.name }}</template>
</li>
<li v-else-if="options.addNoData">
<i class="fa fa-li fa-long-arrow-right"></i>

View File

@ -20,6 +20,7 @@ namespace Chill\PersonBundle\Serializer\Normalizer;
use Chill\MainBundle\Entity\Center;
use Chill\MainBundle\Security\Resolver\CenterResolverDispatcher;
use Chill\MainBundle\Security\Resolver\CenterResolverManagerInterface;
use Chill\PersonBundle\Entity\Household\Household;
use Chill\PersonBundle\Entity\Person;
use Symfony\Component\Serializer\Normalizer\DenormalizerAwareInterface;
@ -49,7 +50,7 @@ class PersonJsonNormalizer implements
private PersonRepository $repository;
private CenterResolverDispatcher $centerResolverDispatcher;
private CenterResolverManagerInterface $centerResolverManager;
use NormalizerAwareTrait;
@ -60,11 +61,11 @@ class PersonJsonNormalizer implements
public function __construct(
ChillEntityRenderExtension $render,
PersonRepository $repository,
CenterResolverDispatcher $centerResolverDispatcher
CenterResolverManagerInterface $centerResolverManager
) {
$this->render = $render;
$this->repository = $repository;
$this->centerResolverDispatcher = $centerResolverDispatcher;
$this->centerResolverManager = $centerResolverManager;
}
public function normalize($person, string $format = null, array $context = [])
@ -79,15 +80,15 @@ class PersonJsonNormalizer implements
'text' => $this->render->renderString($person),
'firstName' => $person->getFirstName(),
'lastName' => $person->getLastName(),
'birthdate' => $this->normalizer->normalize($person->getBirthdate()),
'deathdate' => $this->normalizer->normalize($person->getDeathdate()),
'center' => $this->normalizer->normalize($this->centerResolverDispatcher->resolveCenter($person)),
'birthdate' => $this->normalizer->normalize($person->getBirthdate(), $format, $context),
'deathdate' => $this->normalizer->normalize($person->getDeathdate(), $format, $context),
'centers' => $this->normalizer->normalize($this->centerResolverManager->resolveCenters($person), $format, $context),
'phonenumber' => $person->getPhonenumber(),
'mobilenumber' => $person->getMobilenumber(),
'altNames' => $this->normalizeAltNames($person->getAltNames()),
'gender' => $person->getGender(),
'current_household_address' => $this->normalizer->normalize($person->getCurrentHouseholdAddress()),
'current_household_id' => $household ? $this->normalizer->normalize($household->getId()) : null,
'current_household_address' => $this->normalizer->normalize($person->getCurrentHouseholdAddress(), $format, $context),
'current_household_id' => $household ? $this->normalizer->normalize($household->getId(), $format, $context) : null,
];
}