Merge branch 'master' into notification/completion

This commit is contained in:
2022-01-05 11:15:49 +01:00
45 changed files with 474 additions and 217 deletions

View File

@@ -12,6 +12,7 @@ declare(strict_types=1);
namespace Chill\PersonBundle\Serializer\Normalizer;
use Chill\DocGeneratorBundle\Serializer\Helper\NormalizeNullValueHelper;
use Chill\MainBundle\Entity\Address;
use Chill\MainBundle\Entity\Scope;
use Chill\MainBundle\Entity\User;
use Chill\MainBundle\Security\Resolver\ScopeResolverDispatcher;
@@ -65,6 +66,8 @@ class AccompanyingPeriodDocGenNormalizer implements ContextAwareNormalizerInterf
'requestorPerson' => Person::class,
'requestorThirdParty' => ThirdParty::class,
'resources' => Collection::class,
'location' => Address::class,
'locationPerson' => Person::class,
];
private ClosingMotiveRender $closingMotiveRender;
@@ -104,6 +107,7 @@ 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']);
@@ -147,6 +151,10 @@ class AccompanyingPeriodDocGenNormalizer implements ContextAwareNormalizerInterf
}, $scopes)),
'hasRequestor' => $period->getRequestor() !== null,
'requestorKind' => $period->getRequestorKind(),
'hasLocation' => $period->getLocation() !== null,
'hasLocationPerson' => $period->getPersonLocation() !== null,
'locationPerson' => $this->normalizer->normalize($period->getPersonLocation(), $format, array_merge($context, ['docgen:expects' => Person::class])),
'location' => $this->normalizer->normalize($period->getLocation(), $format, $addressContext),
];
}
@@ -162,6 +170,8 @@ class AccompanyingPeriodDocGenNormalizer implements ContextAwareNormalizerInterf
'hasRequestorThirdParty' => false,
'isClosed' => false,
'confidential' => false,
'hasLocation' => false,
'hasLocationPerson' => false,
]
);
}

View File

@@ -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();
}
}