mirror of
https://gitlab.com/Chill-Projet/chill-bundles.git
synced 2025-08-20 22:53:49 +00:00
Merge remote-tracking branch 'origin/136-add-search-endpoint' into 139_demandeur
This commit is contained in:
@@ -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) {
|
||||
|
@@ -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 }
|
||||
|
||||
|
Reference in New Issue
Block a user