From e728c00671140d889eca0a3e290a8243d56131e6 Mon Sep 17 00:00:00 2001 From: Mathieu Jaumotte Date: Mon, 25 Jul 2022 16:49:57 +0200 Subject: [PATCH] exports: create intensity filter --- .../Export/Filter/EmergencyFilter.php | 2 - .../Export/Filter/IntensityFilter.php | 85 +++++++++++++++++++ .../services/exports_accompanying_period.yaml | 7 ++ .../translations/messages.fr.yml | 9 ++ 4 files changed, 101 insertions(+), 2 deletions(-) create mode 100644 src/Bundle/ChillPersonBundle/Export/Filter/IntensityFilter.php diff --git a/src/Bundle/ChillPersonBundle/Export/Filter/EmergencyFilter.php b/src/Bundle/ChillPersonBundle/Export/Filter/EmergencyFilter.php index 4e292977a..f09d117f4 100644 --- a/src/Bundle/ChillPersonBundle/Export/Filter/EmergencyFilter.php +++ b/src/Bundle/ChillPersonBundle/Export/Filter/EmergencyFilter.php @@ -44,8 +44,6 @@ class EmergencyFilter implements FilterInterface public function describeAction($data, $format = 'string'): array { - dump($data, self::CHOICES); - foreach (self::CHOICES as $k => $v) { if ($v === $data['accepted_emergencies']) { $choice = $k; diff --git a/src/Bundle/ChillPersonBundle/Export/Filter/IntensityFilter.php b/src/Bundle/ChillPersonBundle/Export/Filter/IntensityFilter.php new file mode 100644 index 000000000..b55e7f399 --- /dev/null +++ b/src/Bundle/ChillPersonBundle/Export/Filter/IntensityFilter.php @@ -0,0 +1,85 @@ + 'occasional', + 'is regular' => 'regular', + ]; + + private CONST DEFAULT_CHOICE = 'occasional'; + + private TranslatorInterface $translator; + + public function __construct(TranslatorInterface $translator) + { + $this->translator = $translator; + } + + public function buildForm(FormBuilderInterface $builder) + { + $builder->add('accepted_intensities', 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 intensity'; + } + + public function describeAction($data, $format = 'string'): array + { + foreach (self::CHOICES as $k => $v) { + if ($v === $data['accepted_intensities']) { + $choice = $k; + } + } + + return [ + 'Filtered by intensity: only %intensity%', [ + '%intensity%' => $this->translator->trans($choice) + ] + ]; + } + + public function addRole() + { + return null; + } + + public function alterQuery(QueryBuilder $qb, $data) + { + $where = $qb->getDQLPart('where'); + $clause = $qb->expr()->eq('acp.intensity', ':intensity'); + + if ($where instanceof Andx) { + $where->add($clause); + } else { + $where = $qb->expr()->andX($clause); + } + + $qb->add('where', $where); + $qb->setParameter('intensity', $data['accepted_intensities']); + } + + 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 ff79a1617..72fa1ad80 100644 --- a/src/Bundle/ChillPersonBundle/config/services/exports_accompanying_period.yaml +++ b/src/Bundle/ChillPersonBundle/config/services/exports_accompanying_period.yaml @@ -88,4 +88,11 @@ services: tags: - { name: chill.export_filter, alias: accompanyingcourse_emergency_filter } + chill.person.export.filter_intensity: + class: Chill\PersonBundle\Export\Filter\IntensityFilter + autowire: true + autoconfigure: true + tags: + - { name: chill.export_filter, alias: accompanyingcourse_intensity_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 1b6f96a9a..288793af0 100644 --- a/src/Bundle/ChillPersonBundle/translations/messages.fr.yml +++ b/src/Bundle/ChillPersonBundle/translations/messages.fr.yml @@ -410,6 +410,15 @@ 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%" +Filter by intensity: Filtrer par intensité +Accepted intensities: '' +is occasional: le parcours est ponctuel +is regular: le parcours est régulier +"Filtered by intensity: only %intensity%": "Filtré par intensité: uniquement si %intensity%" + + + + ## aggregators Group people by nationality: Aggréger les personnes par nationalités Group by level: Grouper par niveau