From da224ea4bc7f20e21d003b16cc232997edd277ca Mon Sep 17 00:00:00 2001 From: Mathieu Jaumotte Date: Mon, 25 Jul 2022 16:35:11 +0200 Subject: [PATCH] exports: create emergency filter --- .../Export/Filter/ConfidentialFilter.php | 2 +- .../Export/Filter/EmergencyFilter.php | 87 +++++++++++++++++++ .../services/exports_accompanying_period.yaml | 7 ++ .../translations/messages.fr.yml | 8 +- 4 files changed, 102 insertions(+), 2 deletions(-) create mode 100644 src/Bundle/ChillPersonBundle/Export/Filter/EmergencyFilter.php diff --git a/src/Bundle/ChillPersonBundle/Export/Filter/ConfidentialFilter.php b/src/Bundle/ChillPersonBundle/Export/Filter/ConfidentialFilter.php index f33ce9c1e..7e043c131 100644 --- a/src/Bundle/ChillPersonBundle/Export/Filter/ConfidentialFilter.php +++ b/src/Bundle/ChillPersonBundle/Export/Filter/ConfidentialFilter.php @@ -45,7 +45,7 @@ class ConfidentialFilter implements FilterInterface public function describeAction($data, $format = 'string'): array { dump($data, self::CHOICES); - //$choice = //array_flip(self::CHOICES)[$data['accepted_confidentials']]; + foreach (self::CHOICES as $k => $v) { if ($v === $data['accepted_confidentials']) { $choice = $k; diff --git a/src/Bundle/ChillPersonBundle/Export/Filter/EmergencyFilter.php b/src/Bundle/ChillPersonBundle/Export/Filter/EmergencyFilter.php new file mode 100644 index 000000000..4e292977a --- /dev/null +++ b/src/Bundle/ChillPersonBundle/Export/Filter/EmergencyFilter.php @@ -0,0 +1,87 @@ + false, + 'is emergency' => true, + ]; + + private CONST DEFAULT_CHOICE = false; + + private TranslatorInterface $translator; + + public function __construct(TranslatorInterface $translator) + { + $this->translator = $translator; + } + + public function buildForm(FormBuilderInterface $builder) + { + $builder->add('accepted_emergencies', ChoiceType::class, [ + 'choices' => self::CHOICES, + 'multiple' => false, + 'expanded' => true, + 'empty_data' => self::DEFAULT_CHOICE, + 'data' => self::DEFAULT_CHOICE, + ]); + } + + public function getTitle(): string + { + return 'Filter by emergency'; + } + + public function describeAction($data, $format = 'string'): array + { + dump($data, self::CHOICES); + + foreach (self::CHOICES as $k => $v) { + if ($v === $data['accepted_emergencies']) { + $choice = $k; + } + } + + return [ + 'Filtered by emergency: only %emergency%', [ + '%emergency%' => $this->translator->trans($choice) + ] + ]; + } + + public function addRole() + { + return null; + } + + public function alterQuery(QueryBuilder $qb, $data) + { + $where = $qb->getDQLPart('where'); + $clause = $qb->expr()->eq('acp.emergency', ':emergency'); + + if ($where instanceof Andx) { + $where->add($clause); + } else { + $where = $qb->expr()->andX($clause); + } + + $qb->add('where', $where); + $qb->setParameter('emergency', $data['accepted_emergencies']); + } + + 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 abaeffd8a..ff79a1617 100644 --- a/src/Bundle/ChillPersonBundle/config/services/exports_accompanying_period.yaml +++ b/src/Bundle/ChillPersonBundle/config/services/exports_accompanying_period.yaml @@ -81,4 +81,11 @@ services: tags: - { name: chill.export_filter, alias: accompanyingcourse_confidential_filter } + chill.person.export.filter_emergency: + class: Chill\PersonBundle\Export\Filter\EmergencyFilter + autowire: true + autoconfigure: true + tags: + - { name: chill.export_filter, alias: accompanyingcourse_emergency_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 c755126de..1b6f96a9a 100644 --- a/src/Bundle/ChillPersonBundle/translations/messages.fr.yml +++ b/src/Bundle/ChillPersonBundle/translations/messages.fr.yml @@ -399,11 +399,17 @@ Accepted closingmotives: Motifs de clôture "Filtered by closingmotive: only %closingmotives%": "Filtré par motif de clôture: uniquement %closingmotives%" Filter by confidential: Filtrer par confidentialité -Accepted confidentials: Choix possibles +Accepted confidentials: '' is confidential: le parcours est confidentiel is not confidential: le parcours n'est pas confidentiel "Filtered by confidential: only %confidential%": "Filtré par confidentialité: uniquement si %confidential%" +Filter by emergency: Filtrer par urgence +Accepted emergencies: '' +is emergency: le parcours est urgent +is not emergency: le parcours n'est pas urgent +"Filtered by emergency: only %emergency%": "Filtré par urgence: uniquement si %emergency%" + ## aggregators Group people by nationality: Aggréger les personnes par nationalités Group by level: Grouper par niveau