From 2413c986edc3c286a5dbd97fc60ba39e21a724bd Mon Sep 17 00:00:00 2001 From: Mathieu Jaumotte Date: Wed, 3 Aug 2022 13:34:06 +0200 Subject: [PATCH] exports: add a new GeographicUnitStat Filter (wip) --- .../Filter/GeographicalUnitStatFilter.php | 101 ++++++++++++++++++ .../services/exports_accompanying_period.yaml | 7 ++ 2 files changed, 108 insertions(+) create mode 100644 src/Bundle/ChillPersonBundle/Export/Filter/GeographicalUnitStatFilter.php diff --git a/src/Bundle/ChillPersonBundle/Export/Filter/GeographicalUnitStatFilter.php b/src/Bundle/ChillPersonBundle/Export/Filter/GeographicalUnitStatFilter.php new file mode 100644 index 000000000..0375846e6 --- /dev/null +++ b/src/Bundle/ChillPersonBundle/Export/Filter/GeographicalUnitStatFilter.php @@ -0,0 +1,101 @@ + 'territoire', + // TODO not yet implemented: https://gitlab.com/champs-libres/departement-de-la-vendee/chill/-/issues/626 + ]; + + /** + * @inheritDoc + */ + public function buildForm(FormBuilderInterface $builder) + { + $builder + ->add('date', ChillDateType::class, [ + 'data' => new \DateTime(), + ]) + ->add('accepted_loctype', ChoiceType::class, [ + 'choices' => self::LOCTYPE, + 'multiple' => false, + 'expanded' => true, + ]) + ; + } + + /** + * @inheritDoc + */ + public function getTitle(): string + { + return 'Filter by geographic unit'; + } + + /** + * @inheritDoc + */ + public function describeAction($data, $format = 'string'): array + { + return ['Filtered by geographic unit: only %date%', [ + '%date%' => $data['date']->format('d-m-Y'), + ]]; + } + + /** + * @inheritDoc + */ + public function addRole() + { + return null; + } + + /** + * @inheritDoc + */ + public function alterQuery(QueryBuilder $qb, $data) + { + $where = $qb->getDQLPart('where'); + $clause = $qb->expr()->eq(1, 1); + + if ($where instanceof Andx) { + $where->add($clause); + } else { + $where = $qb->expr()->andX($clause); + } + + $qb->add('where', $where); + $qb->setParameter('date', $data['date'], Types::DATE_MUTABLE); + $qb->setParameter('loctype', $data['accepted_loctype']); + } + + /** + * @inheritDoc + */ + public function applyOn(): string + { + return Declarations::ACP_TYPE; + } +} \ No newline at end of file diff --git a/src/Bundle/ChillPersonBundle/config/services/exports_accompanying_period.yaml b/src/Bundle/ChillPersonBundle/config/services/exports_accompanying_period.yaml index b715605af..7ab97f20f 100644 --- a/src/Bundle/ChillPersonBundle/config/services/exports_accompanying_period.yaml +++ b/src/Bundle/ChillPersonBundle/config/services/exports_accompanying_period.yaml @@ -60,6 +60,13 @@ services: tags: - { name: chill.export_filter, alias: accompanyingcourse_step_filter } + chill.person.export.filter_geographicalunitstat: + class: Chill\PersonBundle\Export\Filter\GeographicalUnitStatFilter + autowire: true + autoconfigure: true + tags: + - { name: chill.export_filter, alias: accompanyingcourse_geographicalunitstat_filter } + chill.person.export.filter_socialaction: class: Chill\PersonBundle\Export\Filter\SocialActionFilter autowire: true