From 70f118011b8bd7c9e96a6afebfc87c38fce838e0 Mon Sep 17 00:00:00 2001 From: Mathieu Jaumotte Date: Tue, 19 Jul 2022 15:04:57 +0200 Subject: [PATCH] exports: add a new user job filter --- .../Export/Filter/UserJobFilter.php | 102 ++++++++++++++++++ .../{Export => Filter}/UserScopeFilter.php | 0 .../config/services/exports.yaml | 8 ++ .../translations/messages.fr.yml | 4 + 4 files changed, 114 insertions(+) create mode 100644 src/Bundle/ChillPersonBundle/Export/Filter/UserJobFilter.php rename src/Bundle/ChillPersonBundle/Export/{Export => Filter}/UserScopeFilter.php (100%) diff --git a/src/Bundle/ChillPersonBundle/Export/Filter/UserJobFilter.php b/src/Bundle/ChillPersonBundle/Export/Filter/UserJobFilter.php new file mode 100644 index 000000000..6e2c7d19f --- /dev/null +++ b/src/Bundle/ChillPersonBundle/Export/Filter/UserJobFilter.php @@ -0,0 +1,102 @@ +translator = $translator; + $this->translatableStringHelper = $translatableStringHelper; + } + + public function describeAction($data, $format = 'string') + { + // to complete.. + return ['Filtered by user jobs']; + } + + public function addRole() + { + return null; + } + + public function alterQuery(QueryBuilder $qb, $data) + { + $qb + ->join('acp.user', 'u') + ->join('u.userJob', 'j') + ; + + $where = $qb->getDQLPart('where'); + $clause = $qb->expr()->in('u.userJob', ':userjob'); + + if ($where instanceof Andx) { + $where->add($clause); + } else { + $where = $qb->expr()->andX($clause); + } + + $qb->add('where', $where); + $qb->setParameter('userjob', $data['accepted_userjob']); + + } + + public function applyOn() + { + return Declarations::ACP_TYPE; + } + + public function buildForm(FormBuilderInterface $builder) + { + $builder + ->add('accepted_userjob', EntityType::class, [ + 'class' => UserJob::class, + 'choice_label' => function(UserJob $j) { + return $this->translatableStringHelper->localize($j->getLabel()); + }, + 'multiple' => true, + 'expanded' => true, + ]) + ; + } + + public function getTitle() + { + return 'Filter by user job'; + } +} \ No newline at end of file diff --git a/src/Bundle/ChillPersonBundle/Export/Export/UserScopeFilter.php b/src/Bundle/ChillPersonBundle/Export/Filter/UserScopeFilter.php similarity index 100% rename from src/Bundle/ChillPersonBundle/Export/Export/UserScopeFilter.php rename to src/Bundle/ChillPersonBundle/Export/Filter/UserScopeFilter.php diff --git a/src/Bundle/ChillPersonBundle/config/services/exports.yaml b/src/Bundle/ChillPersonBundle/config/services/exports.yaml index dad6cbf05..4cf752870 100644 --- a/src/Bundle/ChillPersonBundle/config/services/exports.yaml +++ b/src/Bundle/ChillPersonBundle/config/services/exports.yaml @@ -66,6 +66,14 @@ services: $translatableStringHelper: '@Chill\MainBundle\Templating\TranslatableStringHelper' tags: - { name: chill.export_filter, alias: accompanyingcourse_userscope_filter } + + chill.person.export.filter_userjob: + class: Chill\PersonBundle\Export\Filter\UserJobFilter + arguments: + $translator: '@translator' + $translatableStringHelper: '@Chill\MainBundle\Templating\TranslatableStringHelper' + tags: + - { name: chill.export_filter, alias: accompanyingcourse_userjob_filter } chill.person.export.aggregator_nationality: class: Chill\PersonBundle\Export\Aggregator\NationalityAggregator diff --git a/src/Bundle/ChillPersonBundle/translations/messages.fr.yml b/src/Bundle/ChillPersonBundle/translations/messages.fr.yml index 382331503..122571198 100644 --- a/src/Bundle/ChillPersonBundle/translations/messages.fr.yml +++ b/src/Bundle/ChillPersonBundle/translations/messages.fr.yml @@ -380,6 +380,10 @@ Filter by user scope: Filtrer par service du référent Accepted userscope: Services Filtered by user scopes: Filtré par service du référent +Filter by user job: Filtrer par métier du référent +Accepted userjob: Métiers +Filtered by user jobs: Filtré par métier du référent + ## aggregators Group people by nationality: Aggréger les personnes par nationalités Group by level: Grouper par niveau