GeographicalUnit Filter: add join clauses

This commit is contained in:
2022-09-13 15:10:12 +02:00
parent d907357748
commit 841eb57144
2 changed files with 29 additions and 13 deletions

View File

@@ -17,6 +17,7 @@ use Chill\MainBundle\Form\Type\ChillDateType;
use Chill\PersonBundle\Export\Declarations;
use DateTime;
use Doctrine\DBAL\Types\Types;
use Doctrine\ORM\Query\Expr;
use Doctrine\ORM\Query\Expr\Andx;
use Doctrine\ORM\QueryBuilder;
use Symfony\Bridge\Doctrine\Form\Type\EntityType;
@@ -41,8 +42,23 @@ class GeographicalUnitStatFilter implements FilterInterface
public function alterQuery(QueryBuilder $qb, $data)
{
if (!in_array('location', $qb->getAllAliases(), true)) {
$qb->join('acp.administrativeLocation', 'location');
}
if (!in_array('address', $qb->getAllAliases(), true)) {
$qb->join('location.address', 'address');
}
if (!in_array('geounit', $qb->getAllAliases(), true)) {
$qb->join(GeographicalUnit::class, 'geounit', Expr\Join::WITH, 'ST_CONTAINS(address.point, geounit.geom) = TRUE');
}
$where = $qb->getDQLPart('where');
$clause = $qb->expr()->eq(1, 1);
$clause = $qb->expr()->andX(
$qb->expr()->eq($x, ':date'),
$qb->expr()->in($x, ':loctype')
);
if ($where instanceof Andx) {
$where->add($clause);