diff --git a/src/Bundle/ChillPersonBundle/Export/Filter/OriginFilter.php b/src/Bundle/ChillPersonBundle/Export/Filter/OriginFilter.php new file mode 100644 index 000000000..01cbdfb89 --- /dev/null +++ b/src/Bundle/ChillPersonBundle/Export/Filter/OriginFilter.php @@ -0,0 +1,95 @@ +translatableStringHelper = $translatableStringHelper; + } + + /** + * @inheritDoc + */ + public function buildForm(FormBuilderInterface $builder) + { + $builder->add('accepted_origins', EntityType::class, [ + 'class' => Origin::class, + 'choice_label' => function (Origin $o) { + return $this->translatableStringHelper->localize($o->getLabel()); + }, + 'multiple' => false, + 'expanded' => true + ]); + } + + /** + * @inheritDoc + */ + public function getTitle(): string + { + return 'Filter by origin'; + } + + /** + * @inheritDoc + */ + public function describeAction($data, $format = 'string'): array + { + return ['Filtered by origins: only %origin%', [ + '%origin%' => $this->translatableStringHelper->localize( + $data['accepted_origins']->getLabel()) + ]]; + } + + /** + * @inheritDoc + */ + public function addRole() + { + return null; + } + + /** + * @inheritDoc + */ + public function alterQuery(QueryBuilder $qb, $data) + { + $where = $qb->getDQLPart('where'); + $clause = $qb->expr()->eq('acp.origin', ':origin'); + + if ($where instanceof Andx) { + $where->add($clause); + } else { + $where = $qb->expr()->andX($clause); + } + + $qb->add('where', $where); + $qb->setParameter('origin', $data['accepted_origins']); + } + + /** + * @inheritDoc + */ + public function applyOn(): string + { + return Declarations::ACP_TYPE; + } +} \ No newline at end of file diff --git a/src/Bundle/ChillPersonBundle/config/services/exports.yaml b/src/Bundle/ChillPersonBundle/config/services/exports.yaml index 2a02707ed..093b7315b 100644 --- a/src/Bundle/ChillPersonBundle/config/services/exports.yaml +++ b/src/Bundle/ChillPersonBundle/config/services/exports.yaml @@ -86,6 +86,13 @@ services: autoconfigure: true tags: - { name: chill.export_filter, alias: accompanyingcourse_step_filter } + + chill.person.export.filter_origin: + class: Chill\PersonBundle\Export\Filter\OriginFilter + autowire: true + autoconfigure: true + tags: + - { name: chill.export_filter, alias: accompanyingcourse_origin_filter } chill.person.export.aggregator_nationality: class: Chill\PersonBundle\Export\Aggregator\NationalityAggregator diff --git a/src/Bundle/ChillPersonBundle/translations/messages.fr.yml b/src/Bundle/ChillPersonBundle/translations/messages.fr.yml index 8e532dd35..54fe34d1b 100644 --- a/src/Bundle/ChillPersonBundle/translations/messages.fr.yml +++ b/src/Bundle/ChillPersonBundle/translations/messages.fr.yml @@ -390,6 +390,10 @@ Filter by step: Filtrer par statut du parcours Accepted steps: Statuts "Filtered by steps: only %step%": "Filtré par statut du parcours: uniquement %step%" +Filter by origin: Filtrer par origine du parcours +Accepted origins: Origines +"Filtered by origins: only %origin%": "Filtré par origine du parcours: uniquement %origin%" + ## aggregators Group people by nationality: Aggréger les personnes par nationalités Group by level: Grouper par niveau