From 4794e5e7b5c2f29657f53daafbb529fe309045ae Mon Sep 17 00:00:00 2001 From: Mathieu Jaumotte Date: Mon, 1 Aug 2022 15:45:31 +0200 Subject: [PATCH] export new ActivityTypeFilter --- .../Export/Filter/ActivityTypeFilter.php | 111 ++++++++++++++++++ .../services/exports_accompanying_period.yaml | 7 ++ .../translations/messages.fr.yml | 4 + 3 files changed, 122 insertions(+) create mode 100644 src/Bundle/ChillPersonBundle/Export/Filter/ActivityTypeFilter.php diff --git a/src/Bundle/ChillPersonBundle/Export/Filter/ActivityTypeFilter.php b/src/Bundle/ChillPersonBundle/Export/Filter/ActivityTypeFilter.php new file mode 100644 index 000000000..f019394d4 --- /dev/null +++ b/src/Bundle/ChillPersonBundle/Export/Filter/ActivityTypeFilter.php @@ -0,0 +1,111 @@ +translatableStringHelper = $translatableStringHelper; + } + + /** + * @inheritDoc + */ + public function buildForm(FormBuilderInterface $builder) + { + $builder->add('accepted_activitytypes', EntityType::class, [ + 'class' => ActivityType::class, + 'choice_label' => function (ActivityType $aty) { + return $this->translatableStringHelper->localize($aty->getName()); + }, + 'multiple' => true, + 'expanded' => true + ]); + } + + /** + * @inheritDoc + */ + public function getTitle(): string + { + return 'Filter by activity type'; + } + + /** + * @inheritDoc + */ + public function describeAction($data, $format = 'string'): array + { + $types = []; + + foreach ($data['accepted_activitytypes'] as $aty) { + $types[] = $this->translatableStringHelper->localize($aty->getName()); + } + + return ['Filtered by activity types: only %activitytypes%', [ + '%activitytypes%' => implode(", ou ", $types) + ]]; + } + + /** + * @inheritDoc + */ + public function addRole() + { + return null; + } + + /** + * @inheritDoc + */ + public function alterQuery(QueryBuilder $qb, $data) + { + // One2many between activity and accompanyingperiod is not reversed ! + // we replace indicator 'from' clause by 'act', and put 'acp' in a join + + $qb->resetDQLPart('from'); + $qb->from('ChillActivityBundle:Activity', 'act'); + + $qb + ->join('act.accompanyingPeriod', 'acp') + ->join('act.activityType', 'aty') + ; + + $where = $qb->getDQLPart('where'); + $clause = $qb->expr()->in('aty.id', ':activitytypes'); + + if ($where instanceof Andx) { + $where->add($clause); + } else { + $where = $qb->expr()->andX($clause); + } + + $qb->add('where', $where); + $qb->setParameter('activitytypes', $data['accepted_activitytypes']); + + } + + /** + * @inheritDoc + */ + public function applyOn() + { + 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 9c3e27d58..07f3db1ae 100644 --- a/src/Bundle/ChillPersonBundle/config/services/exports_accompanying_period.yaml +++ b/src/Bundle/ChillPersonBundle/config/services/exports_accompanying_period.yaml @@ -74,6 +74,13 @@ services: tags: - { name: chill.export_filter, alias: accompanyingcourse_evaluation_filter } + chill.person.export.filter_activitytype: + class: Chill\PersonBundle\Export\Filter\ActivityTypeFilter + autowire: true + autoconfigure: true + tags: + - { name: chill.export_filter, alias: accompanyingcourse_activitytype_filter } + chill.person.export.filter_origin: class: Chill\PersonBundle\Export\Filter\OriginFilter autowire: true diff --git a/src/Bundle/ChillPersonBundle/translations/messages.fr.yml b/src/Bundle/ChillPersonBundle/translations/messages.fr.yml index 755797a12..79f280360 100644 --- a/src/Bundle/ChillPersonBundle/translations/messages.fr.yml +++ b/src/Bundle/ChillPersonBundle/translations/messages.fr.yml @@ -398,6 +398,10 @@ Filter by evaluation: Filtrer par évaluation Accepted evaluations: Évaluations "Filtered by evaluations: only %evals%": "Filtré par évaluation: uniquement %evals%" +Filter by activity type: Filtrer par type d'activité +Accepted activitytypes: Types d'activités +"Filtered by activity types: only %activitytypes%": "Filtré par type d'activité: seulement %activitytypes%" + Filter by origin: Filtrer par origine du parcours Accepted origins: Origines "Filtered by origins: only %origins%": "Filtré par origine du parcours: uniquement %origins%"