GeographicalUnit Filter: add join clauses

This commit is contained in:
Mathieu Jaumotte 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);

View File

@ -44,12 +44,12 @@ services:
tags:
- { name: chill.export_filter, alias: accompanyingcourse_step_filter }
#chill.person.export.filter_geographicalunitstat:
# class: Chill\PersonBundle\Export\Filter\AccompanyingCourseFilters\GeographicalUnitStatFilter
# autowire: true
# autoconfigure: true
# tags:
# - { name: chill.export_filter, alias: accompanyingcourse_geographicalunitstat_filter }
chill.person.export.filter_geographicalunitstat:
class: Chill\PersonBundle\Export\Filter\AccompanyingCourseFilters\GeographicalUnitStatFilter
autowire: true
autoconfigure: true
tags:
- { name: chill.export_filter, alias: accompanyingcourse_geographicalunitstat_filter }
chill.person.export.filter_socialaction:
class: Chill\PersonBundle\Export\Filter\AccompanyingCourseFilters\SocialActionFilter
@ -171,12 +171,12 @@ services:
tags:
- { name: chill.export_aggregator, alias: accompanyingcourse_step_aggregator }
#chill.person.export.aggregator_geographicalunitstat:
# class: Chill\PersonBundle\Export\Aggregator\AccompanyingCourseAggregators\GeographicalUnitStatAggregator
# autowire: true
# autoconfigure: true
# tags:
# - { name: chill.export_aggregator, alias: accompanyingcourse_geographicalunitstat_aggregator }
chill.person.export.aggregator_geographicalunitstat:
class: Chill\PersonBundle\Export\Aggregator\AccompanyingCourseAggregators\GeographicalUnitStatAggregator
autowire: true
autoconfigure: true
tags:
- { name: chill.export_aggregator, alias: accompanyingcourse_geographicalunitstat_aggregator }
chill.person.export.aggregator_socialaction:
class: Chill\PersonBundle\Export\Aggregator\AccompanyingCourseAggregators\SocialActionAggregator