From ef5b3b24e4db9ab9e082b12eb660b85352d4e5e8 Mon Sep 17 00:00:00 2001 From: Mathieu Jaumotte Date: Mon, 25 Jul 2022 14:44:03 +0200 Subject: [PATCH] exports: create closingmotive filter --- .../Export/Filter/ClosingMotiveFilter.php | 95 +++++++++++++++++++ .../Export/Filter/SocialIssueFilter.php | 2 +- .../services/exports_accompanying_period.yaml | 7 ++ .../translations/messages.fr.yml | 4 + 4 files changed, 107 insertions(+), 1 deletion(-) create mode 100644 src/Bundle/ChillPersonBundle/Export/Filter/ClosingMotiveFilter.php diff --git a/src/Bundle/ChillPersonBundle/Export/Filter/ClosingMotiveFilter.php b/src/Bundle/ChillPersonBundle/Export/Filter/ClosingMotiveFilter.php new file mode 100644 index 000000000..b4fc3f94d --- /dev/null +++ b/src/Bundle/ChillPersonBundle/Export/Filter/ClosingMotiveFilter.php @@ -0,0 +1,95 @@ +translatableStringHelper = $translatableStringHelper; + } + + /** + * @inheritDoc + */ + public function buildForm(FormBuilderInterface $builder) + { + $builder->add('accepted_closingmotives', EntityType::class, [ + 'class' => ClosingMotive::class, + 'choice_label' => function (ClosingMotive $cm) { + return $this->translatableStringHelper->localize($cm->getName()); + }, + 'multiple' => false, + 'expanded' => false + ]); + } + + /** + * @inheritDoc + */ + public function getTitle(): string + { + return 'Filter by closing motive'; + } + + /** + * @inheritDoc + */ + public function describeAction($data, $format = 'string'): array + { + return [ + 'Filtered by closingmotive: only %closingmotive%', [ + '%closingmotive%' => $this->translatableStringHelper->localize( + $data['accepted_closingmotives']->getName()) + ]]; + } + + /** + * @inheritDoc + */ + public function addRole() + { + return null; + } + + /** + * @inheritDoc + */ + public function alterQuery(QueryBuilder $qb, $data) + { + $where = $qb->getDQLPart('where'); + $clause = $qb->expr()->eq('acp.closingMotive', ':closingmotive'); + + if ($where instanceof Andx) { + $where->add($clause); + } else { + $where = $qb->expr()->andX($clause); + } + + $qb->add('where', $where); + $qb->setParameter('closingmotive', $data['accepted_closingmotives']); + } + + /** + * @inheritDoc + */ + public function applyOn(): string + { + return Declarations::ACP_TYPE; + } +} \ No newline at end of file diff --git a/src/Bundle/ChillPersonBundle/Export/Filter/SocialIssueFilter.php b/src/Bundle/ChillPersonBundle/Export/Filter/SocialIssueFilter.php index 27f01cb86..092982d41 100644 --- a/src/Bundle/ChillPersonBundle/Export/Filter/SocialIssueFilter.php +++ b/src/Bundle/ChillPersonBundle/Export/Filter/SocialIssueFilter.php @@ -82,7 +82,7 @@ class SocialIssueFilter implements FilterInterface return null; } - public function alterQuery(QueryBuilder $qb, $data): QueryBuilder + public function alterQuery(QueryBuilder $qb, $data) { $qb->join('acp.socialIssues', 'si'); diff --git a/src/Bundle/ChillPersonBundle/config/services/exports_accompanying_period.yaml b/src/Bundle/ChillPersonBundle/config/services/exports_accompanying_period.yaml index 36544abde..d34512220 100644 --- a/src/Bundle/ChillPersonBundle/config/services/exports_accompanying_period.yaml +++ b/src/Bundle/ChillPersonBundle/config/services/exports_accompanying_period.yaml @@ -67,4 +67,11 @@ services: tags: - { name: chill.export_filter, alias: accompanyingcourse_origin_filter } + chill.person.export.filter_closingmotive: + class: Chill\PersonBundle\Export\Filter\ClosingMotiveFilter + autowire: true + autoconfigure: true + tags: + - { name: chill.export_filter, alias: accompanyingcourse_closingmotive_filter } + ## Aggregators \ No newline at end of file diff --git a/src/Bundle/ChillPersonBundle/translations/messages.fr.yml b/src/Bundle/ChillPersonBundle/translations/messages.fr.yml index 54fe34d1b..51ca82ce6 100644 --- a/src/Bundle/ChillPersonBundle/translations/messages.fr.yml +++ b/src/Bundle/ChillPersonBundle/translations/messages.fr.yml @@ -394,6 +394,10 @@ Filter by origin: Filtrer par origine du parcours Accepted origins: Origines "Filtered by origins: only %origin%": "Filtré par origine du parcours: uniquement %origin%" +Filter by closing motive: Filtrer par motif de fermeture +Accepted closingmotives: Motifs de clôture +"Filtered by closingmotive: only %closingmotive%": "Filtré par motif de clôture: uniquement %closingmotive%" + ## aggregators Group people by nationality: Aggréger les personnes par nationalités Group by level: Grouper par niveau