Merge remote-tracking branch 'origin/136-add-search-endpoint' into 139_demandeur

This commit is contained in:
2021-05-07 19:27:19 +02:00
19 changed files with 395 additions and 27 deletions

View File

@@ -25,7 +25,7 @@ use Symfony\Component\Serializer\Normalizer\NormalizerAwareInterface;
use Chill\PersonBundle\Repository\PersonRepository;
use Symfony\Component\Serializer\Exception\RuntimeException;
use Symfony\Component\Serializer\Exception\UnexpectedValueException;
use Chill\MainBundle\Templating\Entity\ChillEntityRenderExtension;
/**
* Serialize a Person entity
@@ -41,25 +41,45 @@ class PersonNormalizer implements
protected PersonRepository $repository;
private ChillEntityRenderExtension $render;
public const GET_PERSON = 'get_person';
public function __construct(PersonRepository $repository)
public function __construct(PersonRepository $repository, ChillEntityRenderExtension $render)
{
$this->repository = $repository;
$this->render = $render;
}
public function normalize($person, string $format = null, array $context = array())
{
/** @var Person $person */
return [
'id' => $person->getId(),
'type' => 'person',
'person_id' => $person->getId(),
'text' => $this->render->renderString($person),
'firstName' => $person->getFirstName(),
'lastName' => $person->getLastName(),
'birthdate' => $this->normalizer->normalize($person->getBirthdate()),
'center' => $this->normalizer->normalize($person->getCenter())
'center' => $this->normalizer->normalize($person->getCenter()),
'phonenumber' => $person->getPhonenumber(),
'mobilenumber' => $person->getMobilenumber(),
'altNames' => $this->normalizeAltNames($person->getAltNames())
];
}
protected function normalizeAltNames($altNames): array
{
$r = [];
foreach ($altNames as $n) {
$r[] = [ 'key' => $n->getKey(), 'label' => $n->getLabel() ];
}
return $r;
}
public function denormalize($data, string $type, string $format = null, array $context = []): Person
{
if ($context[self::GET_PERSON] ?? true) {

View File

@@ -3,6 +3,7 @@ services:
Chill\PersonBundle\Serializer\Normalizer\PersonNormalizer:
arguments:
$repository: '@Chill\PersonBundle\Repository\PersonRepository'
$render: '@Chill\MainBundle\Templating\Entity\ChillEntityRenderExtension'
tags:
- { name: 'serializer.normalizer', priority: 64 }