From 6e439adce251b87cd3e2a2cf60454c528b9c6d09 Mon Sep 17 00:00:00 2001 From: Mathieu Jaumotte Date: Mon, 1 Aug 2022 16:50:02 +0200 Subject: [PATCH] export new administrative location filter --- .../Filter/AdministrativeLocationFilter.php | 99 +++++++++++++++++++ .../services/exports_accompanying_period.yaml | 7 ++ .../translations/messages.fr.yml | 4 + 3 files changed, 110 insertions(+) create mode 100644 src/Bundle/ChillPersonBundle/Export/Filter/AdministrativeLocationFilter.php diff --git a/src/Bundle/ChillPersonBundle/Export/Filter/AdministrativeLocationFilter.php b/src/Bundle/ChillPersonBundle/Export/Filter/AdministrativeLocationFilter.php new file mode 100644 index 000000000..b52a2abe1 --- /dev/null +++ b/src/Bundle/ChillPersonBundle/Export/Filter/AdministrativeLocationFilter.php @@ -0,0 +1,99 @@ +translatableStringHelper = $translatableStringHelper; + } + + /** + * @inheritDoc + */ + public function buildForm(FormBuilderInterface $builder) + { + $builder->add('accepted_locations', EntityType::class, [ + 'class' => Location::class, + 'choice_label' => function (Location $l) { + return $l->getName() .' ('. $this->translatableStringHelper->localize($l->getLocationType()->getTitle()) . ')'; + }, + 'multiple' => true, + 'expanded' => true, + ]); + } + + /** + * @inheritDoc + */ + public function getTitle(): string + { + return 'Filter by administrative location'; + } + + /** + * @inheritDoc + */ + public function describeAction($data, $format = 'string'): array + { + $locations = []; + + foreach ($data['accepted_locations'] as $l) { + $locations[] = $l->getName(); + } + + return ['Filtered by administratives locations: only %locations%', [ + '%locations%' => implode(", ou ", $locations) + ]]; + } + + /** + * @inheritDoc + */ + public function addRole() + { + return null; + } + + /** + * @inheritDoc + */ + public function alterQuery(QueryBuilder $qb, $data) + { + $where = $qb->getDQLPart('where'); + $clause = $qb->expr()->in('acp.administrativeLocation', ':locations'); + + if ($where instanceof Andx) { + $where->add($clause); + } else { + $where = $qb->expr()->andX($clause); + } + + $qb->add('where', $where); + $qb->setParameter('locations', $data['accepted_locations']); + } + + /** + * @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 07f3db1ae..671309ae8 100644 --- a/src/Bundle/ChillPersonBundle/config/services/exports_accompanying_period.yaml +++ b/src/Bundle/ChillPersonBundle/config/services/exports_accompanying_period.yaml @@ -95,6 +95,13 @@ services: tags: - { name: chill.export_filter, alias: accompanyingcourse_closingmotive_filter } + chill.person.export.filter_administrative_location: + class: Chill\PersonBundle\Export\Filter\AdministrativeLocationFilter + autowire: true + autoconfigure: true + tags: + - { name: chill.export_filter, alias: accompanyingcourse_administrative_location_filter } + chill.person.export.filter_confidential: class: Chill\PersonBundle\Export\Filter\ConfidentialFilter autowire: true diff --git a/src/Bundle/ChillPersonBundle/translations/messages.fr.yml b/src/Bundle/ChillPersonBundle/translations/messages.fr.yml index 79f280360..a524228fc 100644 --- a/src/Bundle/ChillPersonBundle/translations/messages.fr.yml +++ b/src/Bundle/ChillPersonBundle/translations/messages.fr.yml @@ -410,6 +410,10 @@ Filter by closing motive: Filtrer par motif de fermeture Accepted closingmotives: Motifs de clôture "Filtered by closingmotive: only %closingmotives%": "Filtré par motif de clôture: uniquement %closingmotives%" +Filter by administrative location: Filtrer par localisation administrative +Accepted locations: Localisations administratives +"Filtered by administratives locations: only %locations%": "Filtré par localisation administrative: uniquement %locations%" + Filter by confidential: Filtrer par confidentialité Accepted confidentials: '' is confidential: le parcours est confidentiel