mirror of
https://gitlab.com/Chill-Projet/chill-bundles.git
synced 2025-08-21 07:03:49 +00:00
try to fix some things
This commit is contained in:
@@ -15,6 +15,8 @@ use Chill\PersonBundle\Entity\Person;
|
||||
use Chill\PersonBundle\Entity\Person\ResidentialAddress;
|
||||
use DateTimeImmutable;
|
||||
use Doctrine\Bundle\DoctrineBundle\Repository\ServiceEntityRepository;
|
||||
use Doctrine\DBAL\Types\Types;
|
||||
use Doctrine\ORM\QueryBuilder;
|
||||
use Doctrine\Persistence\ManagerRegistry;
|
||||
|
||||
/**
|
||||
@@ -30,18 +32,37 @@ class ResidentialAddressRepository extends ServiceEntityRepository
|
||||
parent::__construct($registry, ResidentialAddress::class);
|
||||
}
|
||||
|
||||
public function findCurrentResidentialAddressByPerson(Person $person, ?DateTimeImmutable $at = null): ?ResidentialAddress
|
||||
/**
|
||||
* @param Person $person
|
||||
* @param DateTimeImmutable|null $at
|
||||
* @return array|ResidentialAddress[]|null
|
||||
*/
|
||||
public function findCurrentResidentialAddressByPerson(Person $person, ?DateTimeImmutable $at = null): array
|
||||
{
|
||||
return $this->buildQueryFindCurrentResidentialAddresses($person, $at)
|
||||
->select('ra')
|
||||
->getQuery()
|
||||
->getResult();
|
||||
}
|
||||
|
||||
public function buildQueryFindCurrentResidentialAddresses(Person $person, ?DateTimeImmutable $at = null): QueryBuilder
|
||||
{
|
||||
$addresses = $this->findBy(['person' => $person], ['startDate' => 'DESC']);
|
||||
$date = null === $at ? new DateTimeImmutable('today') : $at;
|
||||
$qb = $this->createQueryBuilder('ra');
|
||||
|
||||
foreach ($addresses as $a) {
|
||||
if ($a->getStartDate() < $date && $a->getEndDate() > $date) {
|
||||
return $a;
|
||||
}
|
||||
}
|
||||
$dateFilter = $qb->expr()->andX(
|
||||
$qb->expr()->lte('ra.startDate', ':dateIn'),
|
||||
$qb->expr()->orX(
|
||||
$qb->expr()->isNull('ra.endDate'),
|
||||
$qb->expr()->gte('ra.endDate', ':dateIn')
|
||||
)
|
||||
);
|
||||
|
||||
return null;
|
||||
$qb
|
||||
->where($dateFilter)
|
||||
->setParameter('dateIn', $date, Types::DATE_IMMUTABLE);
|
||||
|
||||
return $qb;
|
||||
}
|
||||
|
||||
// /**
|
||||
|
Reference in New Issue
Block a user