mirror of
https://gitlab.com/Chill-Projet/chill-bundles.git
synced 2025-08-20 14:43:49 +00:00
Merge remote-tracking branch 'origin/master' into 232_resources_comment
This commit is contained in:
@@ -12,6 +12,8 @@ declare(strict_types=1);
|
||||
namespace Chill\PersonBundle\Serializer\Normalizer;
|
||||
|
||||
use Chill\DocGeneratorBundle\Serializer\Helper\NormalizeNullValueHelper;
|
||||
use Chill\MainBundle\Entity\Address;
|
||||
use Chill\MainBundle\Entity\Location;
|
||||
use Chill\MainBundle\Entity\Scope;
|
||||
use Chill\MainBundle\Entity\User;
|
||||
use Chill\MainBundle\Security\Resolver\ScopeResolverDispatcher;
|
||||
@@ -65,6 +67,9 @@ class AccompanyingPeriodDocGenNormalizer implements ContextAwareNormalizerInterf
|
||||
'requestorPerson' => Person::class,
|
||||
'requestorThirdParty' => ThirdParty::class,
|
||||
'resources' => Collection::class,
|
||||
'location' => Address::class,
|
||||
'locationPerson' => Person::class,
|
||||
'administrativeLocation' => Location::class,
|
||||
];
|
||||
|
||||
private ClosingMotiveRender $closingMotiveRender;
|
||||
@@ -104,9 +109,11 @@ class AccompanyingPeriodDocGenNormalizer implements ContextAwareNormalizerInterf
|
||||
$scopes = [$scopes];
|
||||
}
|
||||
|
||||
$addressContext = array_merge($context, ['docgen:expects' => Address::class, 'groups' => 'docgen:read']);
|
||||
$dateContext = array_merge($context, ['docgen:expects' => DateTime::class, 'groups' => 'docgen:read']);
|
||||
$userContext = array_merge($context, ['docgen:expects' => User::class, 'groups' => 'docgen:read']);
|
||||
$participationContext = array_merge($context, ['docgen:expects' => AccompanyingPeriodParticipation::class, 'groups' => 'docgen:read']);
|
||||
$administrativeLocationContext = array_merge($context, ['docgen:expects' => Location::class, 'groups' => 'docgen:read']);
|
||||
|
||||
return [
|
||||
'id' => $period->getId(),
|
||||
@@ -147,6 +154,12 @@ class AccompanyingPeriodDocGenNormalizer implements ContextAwareNormalizerInterf
|
||||
}, $scopes)),
|
||||
'hasRequestor' => $period->getRequestor() !== null,
|
||||
'requestorKind' => $period->getRequestorKind(),
|
||||
'hasLocation' => $period->getLocation() !== null,
|
||||
'hasLocationPerson' => $period->getPersonLocation() !== null,
|
||||
'hasAdministrativeLocation' => $period->getAdministrativeLocation() !== null,
|
||||
'locationPerson' => $this->normalizer->normalize($period->getPersonLocation(), $format, array_merge($context, ['docgen:expects' => Person::class])),
|
||||
'location' => $this->normalizer->normalize($period->getLocation(), $format, $addressContext),
|
||||
'administrativeLocation' => $this->normalizer->normalize($period->getAdministrativeLocation(), $format, $administrativeLocationContext),
|
||||
];
|
||||
}
|
||||
|
||||
@@ -162,6 +175,9 @@ class AccompanyingPeriodDocGenNormalizer implements ContextAwareNormalizerInterf
|
||||
'hasRequestorThirdParty' => false,
|
||||
'isClosed' => false,
|
||||
'confidential' => false,
|
||||
'hasLocation' => false,
|
||||
'hasLocationPerson' => false,
|
||||
'hasAdministrativeLocation' => false,
|
||||
]
|
||||
);
|
||||
}
|
||||
|
@@ -151,7 +151,7 @@ class PersonDocGenNormalizer implements
|
||||
$normalizer = new NormalizeNullValueHelper($this->normalizer, 'type', 'person');
|
||||
|
||||
$attributes = [
|
||||
'firstname', 'lastname', 'altNames', 'text',
|
||||
'firstname', 'lastname', 'age', 'altNames', 'text',
|
||||
'civility' => Civility::class,
|
||||
'birthdate' => DateTimeInterface::class,
|
||||
'deathdate' => DateTimeInterface::class,
|
||||
|
@@ -15,10 +15,11 @@ use Chill\MainBundle\Entity\Center;
|
||||
use Chill\MainBundle\Security\Resolver\CenterResolverManagerInterface;
|
||||
use Chill\MainBundle\Templating\Entity\ChillEntityRenderExtension;
|
||||
use Chill\PersonBundle\Entity\Person;
|
||||
use Chill\PersonBundle\Entity\PersonAltName;
|
||||
use Chill\PersonBundle\Repository\PersonRepository;
|
||||
use DateTime;
|
||||
use DateTimeImmutable;
|
||||
use LogicException;
|
||||
use Doctrine\Common\Collections\Collection;
|
||||
use Symfony\Component\Serializer\Exception\UnexpectedValueException;
|
||||
use Symfony\Component\Serializer\Normalizer\DenormalizerAwareInterface;
|
||||
use Symfony\Component\Serializer\Normalizer\DenormalizerAwareTrait;
|
||||
@@ -78,13 +79,24 @@ class PersonJsonNormalizer implements
|
||||
$person = new Person();
|
||||
}
|
||||
|
||||
foreach (['firstName', 'lastName', 'phonenumber', 'mobilenumber', 'gender',
|
||||
'birthdate', 'deathdate', 'center', ]
|
||||
as $item) {
|
||||
if (!array_key_exists($item, $data)) {
|
||||
continue;
|
||||
}
|
||||
$fields = [
|
||||
'firstName',
|
||||
'lastName',
|
||||
'phonenumber',
|
||||
'mobilenumber',
|
||||
'gender',
|
||||
'birthdate',
|
||||
'deathdate',
|
||||
'center',
|
||||
'altNames',
|
||||
];
|
||||
|
||||
$fields = array_filter(
|
||||
$fields,
|
||||
static fn (string $field): bool => array_key_exists($field, $data)
|
||||
);
|
||||
|
||||
foreach ($fields as $item) {
|
||||
switch ($item) {
|
||||
case 'firstName':
|
||||
$person->setFirstName($data[$item]);
|
||||
@@ -131,8 +143,23 @@ class PersonJsonNormalizer implements
|
||||
|
||||
break;
|
||||
|
||||
default:
|
||||
throw new LogicException("item not defined: {$item}");
|
||||
case 'altNames':
|
||||
foreach ($data[$item] as $altName) {
|
||||
$oldAltName = $person
|
||||
->getAltNames()
|
||||
->filter(static fn (PersonAltName $n): bool => $n->getKey() === $altName['key'])->first();
|
||||
|
||||
if (false === $oldAltName) {
|
||||
$newAltName = new PersonAltName();
|
||||
$newAltName->setKey($altName['key']);
|
||||
$newAltName->setLabel($altName['label']);
|
||||
$person->addAltName($newAltName);
|
||||
} else {
|
||||
$oldAltName->setLabel($altName['label']);
|
||||
}
|
||||
}
|
||||
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -175,14 +202,22 @@ class PersonJsonNormalizer implements
|
||||
return $data instanceof Person && 'json' === $format;
|
||||
}
|
||||
|
||||
protected function normalizeAltNames($altNames): array
|
||||
/**
|
||||
* @param Collection<array-key, PersonAltName> $altNames
|
||||
*
|
||||
* @return array<array-key, array<string, string>>
|
||||
*/
|
||||
protected function normalizeAltNames(Collection $altNames): array
|
||||
{
|
||||
$r = [];
|
||||
|
||||
foreach ($altNames as $n) {
|
||||
$r[] = ['key' => $n->getKey(), 'label' => $n->getLabel()];
|
||||
}
|
||||
|
||||
return $r;
|
||||
return $altNames
|
||||
->map(
|
||||
static function (PersonAltName $personAltName): array {
|
||||
return [
|
||||
'key' => $personAltName->getKey(),
|
||||
'label' => $personAltName->getLabel(),
|
||||
];
|
||||
}
|
||||
)
|
||||
->toArray();
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user