From bc2209319a256b4e30e7d2f77528af229ad33f91 Mon Sep 17 00:00:00 2001 From: Mathieu Jaumotte Date: Mon, 1 Aug 2022 14:32:11 +0200 Subject: [PATCH] export new EvaluationFilter --- .../Export/Filter/EvaluationFilter.php | 105 ++++++++++++++++++ .../services/exports_accompanying_period.yaml | 7 ++ .../translations/messages.fr.yml | 4 + 3 files changed, 116 insertions(+) create mode 100644 src/Bundle/ChillPersonBundle/Export/Filter/EvaluationFilter.php diff --git a/src/Bundle/ChillPersonBundle/Export/Filter/EvaluationFilter.php b/src/Bundle/ChillPersonBundle/Export/Filter/EvaluationFilter.php new file mode 100644 index 000000000..7dd2a683d --- /dev/null +++ b/src/Bundle/ChillPersonBundle/Export/Filter/EvaluationFilter.php @@ -0,0 +1,105 @@ +translatableStringHelper = $translatableStringHelper; + } + + /** + * @inheritDoc + */ + public function buildForm(FormBuilderInterface $builder) + { + $builder->add('accepted_evaluations', EntityType::class, [ + 'class' => Evaluation::class, + 'choice_label' => function (Evaluation $ev) { + return $this->translatableStringHelper->localize($ev->getTitle()); + }, + 'multiple' => true, + 'expanded' => true, + ]); + } + + /** + * @inheritDoc + */ + public function getTitle(): string + { + return 'Filter by evaluation'; + } + + /** + * @inheritDoc + */ + public function describeAction($data, $format = 'string'): array + { + $evaluations = []; + + foreach ($data['accepted_evaluations'] as $ev) { + $evaluations[] = $this->translatableStringHelper->localize($ev->getTitle()); + } + + return ['Filtered by evaluations: only %evals%', [ + '%evals%' => implode(", ou ", $evaluations) + ]]; + } + + /** + * @inheritDoc + */ + public function addRole() + { + return null; + } + + /** + * @inheritDoc + */ + public function alterQuery(QueryBuilder $qb, $data) + { + $qb + ->join('acp.works', 'acpw') + ->join('acpw.accompanyingPeriodWorkEvaluations', 'we') + ->join('we.evaluation', 'ev') + ; + + $where = $qb->getDQLPart('where'); + $clause = $qb->expr()->in('ev.id', ':evaluations'); + + if ($where instanceof Andx) { + $where->add($clause); + } else { + $where = $qb->expr()->andX($clause); + } + + $qb->add('where', $where); + $qb->setParameter('evaluations', $data['accepted_evaluations']); + } + + /** + * @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 0556f051c..9c3e27d58 100644 --- a/src/Bundle/ChillPersonBundle/config/services/exports_accompanying_period.yaml +++ b/src/Bundle/ChillPersonBundle/config/services/exports_accompanying_period.yaml @@ -67,6 +67,13 @@ services: tags: - { name: chill.export_filter, alias: accompanyingcourse_socialaction_filter } + chill.person.export.filter_evaluation: + class: Chill\PersonBundle\Export\Filter\EvaluationFilter + autowire: true + autoconfigure: true + tags: + - { name: chill.export_filter, alias: accompanyingcourse_evaluation_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 7f56b90fa..755797a12 100644 --- a/src/Bundle/ChillPersonBundle/translations/messages.fr.yml +++ b/src/Bundle/ChillPersonBundle/translations/messages.fr.yml @@ -394,6 +394,10 @@ Filter by socialaction: Filtrer par action d'accompagnement Accepted socialactions: Actions d'accompagnement "Filtered by socialactions: only %socialactions%": "Filtré par action d'accompagnement: uniquement %socialactions%" +Filter by evaluation: Filtrer par évaluation +Accepted evaluations: Évaluations +"Filtered by evaluations: only %evals%": "Filtré par évaluation: uniquement %evals%" + Filter by origin: Filtrer par origine du parcours Accepted origins: Origines "Filtered by origins: only %origins%": "Filtré par origine du parcours: uniquement %origins%"