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] 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 * [person] fix bounds for computing current person address: the new address appears immediatly
* [docgen] create a normalizer and serializer for normalization on doc format * [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 ## Test releases

View File

@ -96,14 +96,9 @@
<p class="chill-no-data-statement">{{ $t('renderbox.no_data') }}</p> <p class="chill-no-data-statement">{{ $t('renderbox.no_data') }}</p>
</li> </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> <i class="fa fa-li fa-long-arrow-right"></i>
<template v-if="person.center.type !== undefined"> <template v-for="c in person.centers">{{ c.name }}</template>
{{ person.center.name }}
</template>
<template v-else>
<template v-for="c in person.center">{{ c.name }}</template>
</template>
</li> </li>
<li v-else-if="options.addNoData"> <li v-else-if="options.addNoData">
<i class="fa fa-li fa-long-arrow-right"></i> <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\Entity\Center;
use Chill\MainBundle\Security\Resolver\CenterResolverDispatcher; use Chill\MainBundle\Security\Resolver\CenterResolverDispatcher;
use Chill\MainBundle\Security\Resolver\CenterResolverManagerInterface;
use Chill\PersonBundle\Entity\Household\Household; use Chill\PersonBundle\Entity\Household\Household;
use Chill\PersonBundle\Entity\Person; use Chill\PersonBundle\Entity\Person;
use Symfony\Component\Serializer\Normalizer\DenormalizerAwareInterface; use Symfony\Component\Serializer\Normalizer\DenormalizerAwareInterface;
@ -49,7 +50,7 @@ class PersonJsonNormalizer implements
private PersonRepository $repository; private PersonRepository $repository;
private CenterResolverDispatcher $centerResolverDispatcher; private CenterResolverManagerInterface $centerResolverManager;
use NormalizerAwareTrait; use NormalizerAwareTrait;
@ -60,11 +61,11 @@ class PersonJsonNormalizer implements
public function __construct( public function __construct(
ChillEntityRenderExtension $render, ChillEntityRenderExtension $render,
PersonRepository $repository, PersonRepository $repository,
CenterResolverDispatcher $centerResolverDispatcher CenterResolverManagerInterface $centerResolverManager
) { ) {
$this->render = $render; $this->render = $render;
$this->repository = $repository; $this->repository = $repository;
$this->centerResolverDispatcher = $centerResolverDispatcher; $this->centerResolverManager = $centerResolverManager;
} }
public function normalize($person, string $format = null, array $context = []) public function normalize($person, string $format = null, array $context = [])
@ -79,15 +80,15 @@ class PersonJsonNormalizer implements
'text' => $this->render->renderString($person), 'text' => $this->render->renderString($person),
'firstName' => $person->getFirstName(), 'firstName' => $person->getFirstName(),
'lastName' => $person->getLastName(), 'lastName' => $person->getLastName(),
'birthdate' => $this->normalizer->normalize($person->getBirthdate()), 'birthdate' => $this->normalizer->normalize($person->getBirthdate(), $format, $context),
'deathdate' => $this->normalizer->normalize($person->getDeathdate()), 'deathdate' => $this->normalizer->normalize($person->getDeathdate(), $format, $context),
'center' => $this->normalizer->normalize($this->centerResolverDispatcher->resolveCenter($person)), 'centers' => $this->normalizer->normalize($this->centerResolverManager->resolveCenters($person), $format, $context),
'phonenumber' => $person->getPhonenumber(), 'phonenumber' => $person->getPhonenumber(),
'mobilenumber' => $person->getMobilenumber(), 'mobilenumber' => $person->getMobilenumber(),
'altNames' => $this->normalizeAltNames($person->getAltNames()), 'altNames' => $this->normalizeAltNames($person->getAltNames()),
'gender' => $person->getGender(), 'gender' => $person->getGender(),
'current_household_address' => $this->normalizer->normalize($person->getCurrentHouseholdAddress()), 'current_household_address' => $this->normalizer->normalize($person->getCurrentHouseholdAddress(), $format, $context),
'current_household_id' => $household ? $this->normalizer->normalize($household->getId()) : null, 'current_household_id' => $household ? $this->normalizer->normalize($household->getId(), $format, $context) : null,
]; ];
} }