From bb22317eb108380c3af0c25131e2953472c10603 Mon Sep 17 00:00:00 2001 From: Mathieu Jaumotte Date: Wed, 20 Jul 2022 16:38:46 +0200 Subject: [PATCH] exports: add new social issues filter (wip) --- .../Export/Filter/SocialIssueFilter.php | 97 +++++++++++++++++++ .../config/services/exports.yaml | 7 ++ .../translations/messages.fr.yml | 4 + 3 files changed, 108 insertions(+) create mode 100644 src/Bundle/ChillPersonBundle/Export/Filter/SocialIssueFilter.php diff --git a/src/Bundle/ChillPersonBundle/Export/Filter/SocialIssueFilter.php b/src/Bundle/ChillPersonBundle/Export/Filter/SocialIssueFilter.php new file mode 100644 index 000000000..eac3544f8 --- /dev/null +++ b/src/Bundle/ChillPersonBundle/Export/Filter/SocialIssueFilter.php @@ -0,0 +1,97 @@ +translator = $translator; + $this->translatableStringHelper = $translatableStringHelper; + } + + public function buildForm(FormBuilderInterface $builder) + { + $builder->add('accepted_socialissue', EntityType::class, [ + 'class' => SocialIssue::class, + 'choice_label' => function(SocialIssue $s) { + return $this->translatableStringHelper->localize($s->getTitle()); + }, + 'multiple' => true, + 'expanded' => true, + ]); + } + + public function getTitle() + { + return 'Filter by social issue'; + } + + public function describeAction($data, $format = 'string') + { + $issues = []; + + foreach ($data['accepted_socialissue'] as $i) { + if ('null' === $i) { + $issues[] = $this->translator->trans('Not given'); + } else { + $issues[] = $this->translatableStringHelper->localize($i->getTitle()); + } + } + + return [ + 'Filtered by socialissues: only %socialissues%', [ + '%socialissues%' => implode(', ', $issues) + ]]; + } + + public function addRole() + { + return null; + } + + public function alterQuery(QueryBuilder $qb, $data) + { + $qb->join('acp.socialIssues', 's'); + + $where = $qb->getDQLPart('where'); + $clause = $qb->expr()->in('s.id', ':socialissues'); + + if ($where instanceof Andx) { + $where->add($clause); + } else { + $where = $qb->expr()->andX($clause); + } + + $qb->add('where', $where); + $qb->setParameter('socialissues', $data['accepted_socialissue']); + } + + public function applyOn() + { + return Declarations::ACP_TYPE; + } + +} \ No newline at end of file diff --git a/src/Bundle/ChillPersonBundle/config/services/exports.yaml b/src/Bundle/ChillPersonBundle/config/services/exports.yaml index e58ba3ef5..2a02707ed 100644 --- a/src/Bundle/ChillPersonBundle/config/services/exports.yaml +++ b/src/Bundle/ChillPersonBundle/config/services/exports.yaml @@ -73,6 +73,13 @@ services: tags: - { name: chill.export_filter, alias: accompanyingcourse_userjob_filter } + chill.person.export.filter_socialissue: + class: Chill\PersonBundle\Export\Filter\SocialIssueFilter + autowire: true + autoconfigure: true + tags: + - { name: chill.export_filter, alias: accompanyingcourse_socialissue_filter } + chill.person.export.filter_step: class: Chill\PersonBundle\Export\Filter\StepFilter autowire: true diff --git a/src/Bundle/ChillPersonBundle/translations/messages.fr.yml b/src/Bundle/ChillPersonBundle/translations/messages.fr.yml index 42b6e6840..690936ae4 100644 --- a/src/Bundle/ChillPersonBundle/translations/messages.fr.yml +++ b/src/Bundle/ChillPersonBundle/translations/messages.fr.yml @@ -384,6 +384,10 @@ Filter by user job: Filtrer par métier du référent Accepted userjob: Métiers "Filtered by user jobs: only %jobs%": "Filtré par métier du référent: uniquement %jobs%" +Filter by social issue: Filtrer par problématiques sociales +Accepted socialissue: Problématiques sociales +"Filtered by socialissues: only %socialissues%": "Filtré par problématique sociale: uniquement %socialissues%" + Filter by step: Filtrer par statut du parcours Accepted step: Statuts "Filtered by steps: only %step%": "Filtré par statut du parcours: uniquement %step%"