mirror of
https://gitlab.com/Chill-Projet/chill-bundles.git
synced 2025-08-20 22:53:49 +00:00
person: add current residential address in normalizer
This commit is contained in:
@@ -11,10 +11,14 @@ declare(strict_types=1);
|
||||
|
||||
namespace Chill\PersonBundle\Repository;
|
||||
|
||||
use Chill\PersonBundle\Entity\Person;
|
||||
use Chill\PersonBundle\Entity\Person\ResidentialAddress;
|
||||
use DateTimeImmutable;
|
||||
use Doctrine\Bundle\DoctrineBundle\Repository\ServiceEntityRepository;
|
||||
use Doctrine\Persistence\ManagerRegistry;
|
||||
|
||||
use function Symfony\Component\DependencyInjection\Loader\Configurator\ref;
|
||||
|
||||
/**
|
||||
* @method ResidentialAddress|null find($id, $lockMode = null, $lockVersion = null)
|
||||
* @method ResidentialAddress|null findOneBy(array $criteria, array $orderBy = null)
|
||||
@@ -28,6 +32,19 @@ class ResidentialAddressRepository extends ServiceEntityRepository
|
||||
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
|
||||
// */
|
||||
|
Reference in New Issue
Block a user