diff --git a/src/Bundle/ChillPersonBundle/Export/Filter/UserJobFilter.php b/src/Bundle/ChillPersonBundle/Export/Filter/UserJobFilter.php new file mode 100644 index 000000000..32991aad6 --- /dev/null +++ b/src/Bundle/ChillPersonBundle/Export/Filter/UserJobFilter.php @@ -0,0 +1,100 @@ +translator = $translator; + $this->translatableStringHelper = $translatableStringHelper; + } + + public function buildForm(FormBuilderInterface $builder) + { + $builder->add('userjob', EntityType::class, [ + 'class' => UserJob::class, + 'choice_label' => function (UserJob $j) { + return $this->translatableStringHelper->localize( + $j->getLabel() + ); + }, + 'multiple' => true, + 'expanded' => true + ]); + } + + public function describeAction($data, $format = 'string') + { + $userjobs = []; + + foreach ($data['userjob'] as $j) { + $userjobs[] = $this->translatableStringHelper->localize( + $j->getLabel()); + } + + return ['Filtered by the following jobs: only %userjobs%', [ + '%userjobs%' => implode(', ou ', $userjobs) + ]]; + } + + public function addRole() + { + return null; + } + + public function alterQuery(QueryBuilder $qb, $data) + { + $qb->join('acpw.referrers', 'r'); + + $where = $qb->getDQLPart('where'); + $clause = $qb->expr()->eq('r.userJob', ':userjob'); + + if ($where instanceof Andx) { + $where->add($clause); + } else { + $where = $qb->expr()->andX($clause); + } + + $qb->add('where', $where); + $qb->setParameter('userjob', $data['userjob']); + } + + public function applyOn() + { + return Declarations::SOCIAL_WORK_ACTION_TYPE; + } + + + public function getTitle() + { + return 'Filter by job'; + } +} \ No newline at end of file diff --git a/src/Bundle/ChillPersonBundle/Export/Filter/UserScopeFilter.php b/src/Bundle/ChillPersonBundle/Export/Filter/UserScopeFilter.php new file mode 100644 index 000000000..dd16bbf74 --- /dev/null +++ b/src/Bundle/ChillPersonBundle/Export/Filter/UserScopeFilter.php @@ -0,0 +1,99 @@ +translator = $translator; + $this->translatableStringHelper = $translatableStringHelper; + } + + public function buildForm(FormBuilderInterface $builder) + { + $builder->add('scope', EntityType::class, [ + 'class' => Scope::class, + 'choice_label' => function (Scope $s) { + return $this->translatableStringHelper->localize( + $s->getName() + ); + }, + 'multiple' => true, + 'expanded' => true + ]); + } + + public function describeAction($data, $format = 'string') + { + $scopes = []; + + foreach ($data['scope'] as $s) { + $scopes[] = $this->translatableStringHelper->localize( + $s->getName()); + } + + return ['Filtered by the following scopes: only %scope%', [ + '%scope%' => implode(', ou ', $scopes) + ]]; + } + + public function addRole() + { + return null; + } + + public function alterQuery(QueryBuilder $qb, $data) + { + $qb->join('acpw.referrers', 'r'); + + $where = $qb->getDQLPart('where'); + $clause = $qb->expr()->eq('r.mainScope', ':scope'); + + if ($where instanceof Andx) { + $where->add($clause); + } else { + $where = $qb->expr()->andX($clause); + } + + $qb->add('where', $where); + $qb->setParameter('scope', $data['scope']); + } + + public function applyOn() + { + return Declarations::SOCIAL_WORK_ACTION_TYPE; + } + + + public function getTitle() + { + return 'Filter by scope'; + } +} \ No newline at end of file diff --git a/src/Bundle/ChillPersonBundle/config/services/exports_social_actions.yaml b/src/Bundle/ChillPersonBundle/config/services/exports_social_actions.yaml index cdf4f50d4..a6b7963c0 100644 --- a/src/Bundle/ChillPersonBundle/config/services/exports_social_actions.yaml +++ b/src/Bundle/ChillPersonBundle/config/services/exports_social_actions.yaml @@ -7,6 +7,7 @@ services: tags: - { name: chill.export, alias: count_social_work_actions } + ## FILTERS chill.person.export.filter_referrers: class: Chill\PersonBundle\Export\Filter\ReferrerFilter autowire: true @@ -14,9 +15,23 @@ services: tags: - { name: chill.export_filter, alias: social_work_actions_referrer_filter } - chill.person.export.filter_social_work_type: - class: Chill\PersonBundle\Export\Filter\SocialWorkTypeFilter + # chill.person.export.filter_social_work_type: + # class: Chill\PersonBundle\Export\Filter\SocialWorkTypeFilter + # autowire: true + # autoconfigure: true + # tags: + # - { name: chill.export_filter, alias: social_work_type_filter } + + chill.person.export.filter_userscope: + class: Chill\PersonBundle\Export\Filter\UserScopeFilter autowire: true autoconfigure: true tags: - - { name: chill.export_filter, alias: social_work_type_filter } \ No newline at end of file + - { name: chill.export_filter, alias: social_work_actions_userscope_filter } + + chill.person.export.filter_userjob: + class: Chill\PersonBundle\Export\Filter\UserJobFilter + autowire: true + autoconfigure: true + tags: + - { name: chill.export_filter, alias: social_work_actions_userjob_filter } \ No newline at end of file