mirror of
https://gitlab.com/Chill-Projet/chill-bundles.git
synced 2025-06-13 13:54:23 +00:00
person: add current residential address in normalizer
This commit is contained in:
parent
2926965400
commit
24fc7a216b
@ -11,10 +11,14 @@ declare(strict_types=1);
|
|||||||
|
|
||||||
namespace Chill\PersonBundle\Repository;
|
namespace Chill\PersonBundle\Repository;
|
||||||
|
|
||||||
|
use Chill\PersonBundle\Entity\Person;
|
||||||
use Chill\PersonBundle\Entity\Person\ResidentialAddress;
|
use Chill\PersonBundle\Entity\Person\ResidentialAddress;
|
||||||
|
use DateTimeImmutable;
|
||||||
use Doctrine\Bundle\DoctrineBundle\Repository\ServiceEntityRepository;
|
use Doctrine\Bundle\DoctrineBundle\Repository\ServiceEntityRepository;
|
||||||
use Doctrine\Persistence\ManagerRegistry;
|
use Doctrine\Persistence\ManagerRegistry;
|
||||||
|
|
||||||
|
use function Symfony\Component\DependencyInjection\Loader\Configurator\ref;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @method ResidentialAddress|null find($id, $lockMode = null, $lockVersion = null)
|
* @method ResidentialAddress|null find($id, $lockMode = null, $lockVersion = null)
|
||||||
* @method ResidentialAddress|null findOneBy(array $criteria, array $orderBy = null)
|
* @method ResidentialAddress|null findOneBy(array $criteria, array $orderBy = null)
|
||||||
@ -28,6 +32,19 @@ class ResidentialAddressRepository extends ServiceEntityRepository
|
|||||||
parent::__construct($registry, ResidentialAddress::class);
|
parent::__construct($registry, ResidentialAddress::class);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function findCurrentResidentialAddressByPerson(Person $person, ?DateTimeImmutable $at = null): ?ResidentialAddress
|
||||||
|
{
|
||||||
|
$addresses = $this->findBy(['person' => $person], ['startDate' => 'DESC']);
|
||||||
|
$date = null === $at ? new DateTimeImmutable('today') : $at;
|
||||||
|
|
||||||
|
foreach ($addresses as $a) {
|
||||||
|
if($a->getStartDate() < $date && $a->getEndDate() > $date) {
|
||||||
|
return $a;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
// /**
|
// /**
|
||||||
// * @return ResidentialAddress[] Returns an array of ResidentialAddress objects
|
// * @return ResidentialAddress[] Returns an array of ResidentialAddress objects
|
||||||
// */
|
// */
|
||||||
|
@ -17,6 +17,7 @@ use Chill\MainBundle\Templating\Entity\ChillEntityRenderExtension;
|
|||||||
use Chill\PersonBundle\Entity\Person;
|
use Chill\PersonBundle\Entity\Person;
|
||||||
use Chill\PersonBundle\Entity\PersonAltName;
|
use Chill\PersonBundle\Entity\PersonAltName;
|
||||||
use Chill\PersonBundle\Repository\PersonRepository;
|
use Chill\PersonBundle\Repository\PersonRepository;
|
||||||
|
use Chill\PersonBundle\Repository\ResidentialAddressRepository;
|
||||||
use DateTime;
|
use DateTime;
|
||||||
use DateTimeImmutable;
|
use DateTimeImmutable;
|
||||||
use Doctrine\Common\Collections\Collection;
|
use Doctrine\Common\Collections\Collection;
|
||||||
@ -51,14 +52,18 @@ class PersonJsonNormalizer implements
|
|||||||
|
|
||||||
private PersonRepository $repository;
|
private PersonRepository $repository;
|
||||||
|
|
||||||
|
private ResidentialAddressRepository $residentialAddressRepository;
|
||||||
|
|
||||||
public function __construct(
|
public function __construct(
|
||||||
ChillEntityRenderExtension $render,
|
ChillEntityRenderExtension $render,
|
||||||
PersonRepository $repository,
|
PersonRepository $repository,
|
||||||
CenterResolverManagerInterface $centerResolverManager
|
CenterResolverManagerInterface $centerResolverManager,
|
||||||
|
ResidentialAddressRepository $residentialAddressRepository
|
||||||
) {
|
) {
|
||||||
$this->render = $render;
|
$this->render = $render;
|
||||||
$this->repository = $repository;
|
$this->repository = $repository;
|
||||||
$this->centerResolverManager = $centerResolverManager;
|
$this->centerResolverManager = $centerResolverManager;
|
||||||
|
$this->residentialAddressRepository = $residentialAddressRepository;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function denormalize($data, $type, $format = null, array $context = [])
|
public function denormalize($data, $type, $format = null, array $context = [])
|
||||||
@ -181,6 +186,7 @@ class PersonJsonNormalizer implements
|
|||||||
public function normalize($person, $format = null, array $context = [])
|
public function normalize($person, $format = null, array $context = [])
|
||||||
{
|
{
|
||||||
$household = $person->getCurrentHousehold();
|
$household = $person->getCurrentHousehold();
|
||||||
|
$currentResidentialAddress = $this->residentialAddressRepository->findCurrentResidentialAddressByPerson($person);
|
||||||
|
|
||||||
return [
|
return [
|
||||||
'type' => 'person',
|
'type' => 'person',
|
||||||
@ -200,6 +206,7 @@ class PersonJsonNormalizer implements
|
|||||||
'gender' => $person->getGender(),
|
'gender' => $person->getGender(),
|
||||||
'current_household_address' => $this->normalizer->normalize($person->getCurrentHouseholdAddress(), $format, $context),
|
'current_household_address' => $this->normalizer->normalize($person->getCurrentHouseholdAddress(), $format, $context),
|
||||||
'current_household_id' => $household ? $this->normalizer->normalize($household->getId(), $format, $context) : null,
|
'current_household_id' => $household ? $this->normalizer->normalize($household->getId(), $format, $context) : null,
|
||||||
|
'current_residential_address' => $currentResidentialAddress ? $this->normalizer->normalize($currentResidentialAddress->getAddress()): null
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user