From 841eb57144a88426c20c1f5b4c14c5584b3deb33 Mon Sep 17 00:00:00 2001 From: Mathieu Jaumotte Date: Tue, 13 Sep 2022 15:10:12 +0200 Subject: [PATCH] GeographicalUnit Filter: add join clauses --- .../GeographicalUnitStatFilter.php | 18 +++++++++++++- .../services/exports_accompanying_course.yaml | 24 +++++++++---------- 2 files changed, 29 insertions(+), 13 deletions(-) diff --git a/src/Bundle/ChillPersonBundle/Export/Filter/AccompanyingCourseFilters/GeographicalUnitStatFilter.php b/src/Bundle/ChillPersonBundle/Export/Filter/AccompanyingCourseFilters/GeographicalUnitStatFilter.php index 8f6748b70..e29dfd658 100644 --- a/src/Bundle/ChillPersonBundle/Export/Filter/AccompanyingCourseFilters/GeographicalUnitStatFilter.php +++ b/src/Bundle/ChillPersonBundle/Export/Filter/AccompanyingCourseFilters/GeographicalUnitStatFilter.php @@ -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); diff --git a/src/Bundle/ChillPersonBundle/config/services/exports_accompanying_course.yaml b/src/Bundle/ChillPersonBundle/config/services/exports_accompanying_course.yaml index f19db0649..8a8b20cbe 100644 --- a/src/Bundle/ChillPersonBundle/config/services/exports_accompanying_course.yaml +++ b/src/Bundle/ChillPersonBundle/config/services/exports_accompanying_course.yaml @@ -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