exports: ResidentialAddressAt ThirdParty/User Filter, improve query (issue637 et issue638)

This commit is contained in:
Mathieu Jaumotte 2022-09-26 18:52:00 +02:00
parent 78e00b8eba
commit 9f2ecff63e
2 changed files with 26 additions and 4 deletions

View File

@ -56,10 +56,17 @@ class ResidentialAddressAtThirdpartyFilter implements FilterInterface
}
$where = $qb->getDQLPart('where');
$clause = $qb->expr()->andX(
$qb->expr()->isNotNull('resaddr.hostThirdParty'),
$qb->expr()->between(':date', 'resaddr.startDate', 'resaddr.endDate'),
$qb->expr()->in('tpartycat.id', ':type')
$qb->expr()->in('tpartycat.id', ':type'),
$qb->expr()->orX(
$qb->expr()->between(':date', 'resaddr.startDate', 'resaddr.endDate'),
$qb->expr()->andX(
$qb->expr()->lte('resaddr.startDate', ':date'),
$qb->expr()->isNull('resaddr.endDate')
)
)
);
if ($where instanceof Expr\Andx) {

View File

@ -12,6 +12,7 @@ declare(strict_types=1);
namespace Chill\PersonBundle\Export\Filter\PersonFilters;
use Chill\MainBundle\Export\FilterInterface;
use Chill\MainBundle\Form\Type\ChillDateType;
use Chill\PersonBundle\Entity\Person\ResidentialAddress;
use Chill\PersonBundle\Export\Declarations;
use Doctrine\ORM\Query\Expr;
@ -36,7 +37,17 @@ class ResidentialAddressAtUserFilter implements FilterInterface
}
$where = $qb->getDQLPart('where');
$clause = $qb->expr()->isNotNull('resaddr.hostPerson');
$clause = $qb->expr()->andX(
$qb->expr()->isNotNull('resaddr.hostPerson'),
$qb->expr()->orX(
$qb->expr()->between(':date', 'resaddr.startDate', 'resaddr.endDate'),
$qb->expr()->andX(
$qb->expr()->lte('resaddr.startDate', ':date'),
$qb->expr()->isNull('resaddr.endDate')
)
)
);
if ($where instanceof Andx) {
$where->add($clause);
@ -44,6 +55,7 @@ class ResidentialAddressAtUserFilter implements FilterInterface
$where = $qb->expr()->andX($clause);
}
$qb->setParameter('date', $data['date_calc']);
$qb->add('where', $where);
}
@ -54,7 +66,10 @@ class ResidentialAddressAtUserFilter implements FilterInterface
public function buildForm(\Symfony\Component\Form\FormBuilderInterface $builder)
{
// No form needed unless validity date should be added ( not specified in doc as a parameter ).
$builder->add('date_calc', ChillDateType::class, [
'label' => 'Date during which residential address was valid',
'data' => new \DateTime('now'),
]);
}
public function describeAction($data, $format = 'string')