From 881e608c87fe450e0ad0e6afcb912bfb271383f1 Mon Sep 17 00:00:00 2001 From: Mathieu Jaumotte Date: Mon, 18 Jul 2022 18:45:02 +0200 Subject: [PATCH] exports: add a new user scope filter --- .../ChillPersonBundle/Export/Declarations.php | 2 + .../Export/Export/CountAccompanyingCourse.php | 5 +- .../Export/StatAccompanyingCourseDuration.php | 5 +- .../Export/Export/UserScopeFilter.php | 101 ++++++++++++++++++ .../config/services/exports.yaml | 16 ++- .../translations/messages.fr.yml | 4 + 6 files changed, 125 insertions(+), 8 deletions(-) create mode 100644 src/Bundle/ChillPersonBundle/Export/Export/UserScopeFilter.php diff --git a/src/Bundle/ChillPersonBundle/Export/Declarations.php b/src/Bundle/ChillPersonBundle/Export/Declarations.php index b23325e5e..bb892a69c 100644 --- a/src/Bundle/ChillPersonBundle/Export/Declarations.php +++ b/src/Bundle/ChillPersonBundle/Export/Declarations.php @@ -19,4 +19,6 @@ abstract class Declarations public const PERSON_IMPLIED_IN = 'person_implied_in'; public const PERSON_TYPE = 'person'; + + public const ACP_TYPE = 'accompanying_period'; } diff --git a/src/Bundle/ChillPersonBundle/Export/Export/CountAccompanyingCourse.php b/src/Bundle/ChillPersonBundle/Export/Export/CountAccompanyingCourse.php index 39df61cb8..69ab19a55 100644 --- a/src/Bundle/ChillPersonBundle/Export/Export/CountAccompanyingCourse.php +++ b/src/Bundle/ChillPersonBundle/Export/Export/CountAccompanyingCourse.php @@ -15,6 +15,7 @@ use Chill\MainBundle\Export\ExportInterface; use Chill\MainBundle\Export\FormatterInterface; use Chill\MainBundle\Export\GroupedExportInterface; use Chill\PersonBundle\Entity\AccompanyingPeriod; +use Chill\PersonBundle\Export\Declarations; use Chill\PersonBundle\Security\Authorization\AccompanyingPeriodVoter; use Doctrine\ORM\EntityManagerInterface; use Doctrine\ORM\Query; @@ -82,7 +83,7 @@ class CountAccompanyingCourse implements ExportInterface, GroupedExportInterface public function getType(): string { - return 'accompanying_period'; + return Declarations::ACP_TYPE; } public function initiateQuery(array $requiredModifiers, array $acl, array $data = []): QueryBuilder @@ -107,7 +108,7 @@ class CountAccompanyingCourse implements ExportInterface, GroupedExportInterface public function supportsModifiers(): array { - return []; + return [Declarations::ACP_TYPE]; } public function getGroup(): string diff --git a/src/Bundle/ChillPersonBundle/Export/Export/StatAccompanyingCourseDuration.php b/src/Bundle/ChillPersonBundle/Export/Export/StatAccompanyingCourseDuration.php index 1241c7f88..639fa56a4 100644 --- a/src/Bundle/ChillPersonBundle/Export/Export/StatAccompanyingCourseDuration.php +++ b/src/Bundle/ChillPersonBundle/Export/Export/StatAccompanyingCourseDuration.php @@ -15,6 +15,7 @@ use Chill\MainBundle\Export\ExportInterface; use Chill\MainBundle\Export\FormatterInterface; use Chill\MainBundle\Export\GroupedExportInterface; use Chill\MainBundle\Form\Type\ChillDateType; +use Chill\PersonBundle\Export\Declarations; use Chill\PersonBundle\Repository\AccompanyingPeriodRepository; use Chill\PersonBundle\Security\Authorization\AccompanyingPeriodVoter; use Doctrine\ORM\Query; @@ -109,7 +110,7 @@ class StatAccompanyingCourseDuration implements ExportInterface, GroupedExportIn */ public function getType(): string { - return 'accompanying_course'; + return Declarations::ACP_TYPE; } /** @@ -152,7 +153,7 @@ class StatAccompanyingCourseDuration implements ExportInterface, GroupedExportIn */ public function supportsModifiers(): array { - return []; + return [Declarations::ACP_TYPE]; } public function getGroup(): string diff --git a/src/Bundle/ChillPersonBundle/Export/Export/UserScopeFilter.php b/src/Bundle/ChillPersonBundle/Export/Export/UserScopeFilter.php new file mode 100644 index 000000000..58aaf1b67 --- /dev/null +++ b/src/Bundle/ChillPersonBundle/Export/Export/UserScopeFilter.php @@ -0,0 +1,101 @@ +translator = $translator; + $this->translatableStringHelper = $translatableStringHelper; + } + + public function describeAction($data, $format = 'string') + { + // to complete.. + return ['Filtered by user scopes']; + } + + public function addRole() + { + return null; + } + + public function alterQuery(QueryBuilder $qb, $data) + { + $qb + ->join('acp.user', 'u') + ->join('u.mainScope', 's') + ; + + $where = $qb->getDQLPart('where'); + $clause = $qb->expr()->in('u.mainScope', ':userscope'); + + if ($where instanceof Andx) { + $where->add($clause); + } else { + $where = $qb->expr()->andX($clause); + } + + $qb->add('where', $where); + $qb->setParameter('userscope', $data['accepted_userscope']); + + } + + public function applyOn() + { + return Declarations::ACP_TYPE; + } + + public function buildForm(FormBuilderInterface $builder) + { + $builder + ->add('accepted_userscope', EntityType::class, [ + 'class' => Scope::class, + 'choice_label' => function(Scope $s) { + return $this->translatableStringHelper->localize($s->getName()); + }, + 'multiple' => true, + 'expanded' => true, + ]) + ; + } + + public function getTitle() + { + return 'Filter by user scope'; + } +} \ 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 19ed9174b..dad6cbf05 100644 --- a/src/Bundle/ChillPersonBundle/config/services/exports.yaml +++ b/src/Bundle/ChillPersonBundle/config/services/exports.yaml @@ -26,19 +26,19 @@ services: tags: - { name: chill.export, alias: list_person_duplicate } - chill.person.export.count_accompanying_course: + chill.person.export.count_accompanyingcourse: class: Chill\PersonBundle\Export\Export\CountAccompanyingCourse arguments: - "@doctrine.orm.entity_manager" tags: - - { name: chill.export, alias: count_accompanying_course } + - { name: chill.export, alias: count_accompanyingcourse } - chill.person.export.avg_accompanying_course_duration: + chill.person.export.avg_accompanyingcourse_duration: class: Chill\PersonBundle\Export\Export\StatAccompanyingCourseDuration arguments: - '@Chill\PersonBundle\Repository\AccompanyingPeriodRepository' tags: - - { name: chill.export, alias: avg_accompanying_course_duration } + - { name: chill.export, alias: avg_accompanyingcourse_duration } chill.person.export.filter_gender: class: Chill\PersonBundle\Export\Filter\GenderFilter @@ -58,6 +58,14 @@ services: autoconfigure: true tags: - { name: chill.export_filter, alias: person_nationality_filter } + + chill.person.export.filter_userscope: + class: Chill\PersonBundle\Export\Filter\UserScopeFilter + arguments: + $translator: '@translator' + $translatableStringHelper: '@Chill\MainBundle\Templating\TranslatableStringHelper' + tags: + - { name: chill.export_filter, alias: accompanyingcourse_userscope_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 b2cd212e6..382331503 100644 --- a/src/Bundle/ChillPersonBundle/translations/messages.fr.yml +++ b/src/Bundle/ChillPersonBundle/translations/messages.fr.yml @@ -376,6 +376,10 @@ Having an accompanying period closed after this date: Ayant une période d'accom "Having an accompanying period closed before this date": "Ayant une période d'accompagnement fermée avant cette date" "Filtered by accompanying period: persons having an accompanying period closed between the %date_from% and %date_to%": "Filtrer par période d'accompagnement: ayant une période fermée entre le %date_from% et le %date_to%" +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 + ## aggregators Group people by nationality: Aggréger les personnes par nationalités Group by level: Grouper par niveau