diff --git a/src/Bundle/ChillPersonBundle/Export/Declarations.php b/src/Bundle/ChillPersonBundle/Export/Declarations.php index bb892a69c..58a8eec24 100644 --- a/src/Bundle/ChillPersonBundle/Export/Declarations.php +++ b/src/Bundle/ChillPersonBundle/Export/Declarations.php @@ -21,4 +21,6 @@ abstract class Declarations public const PERSON_TYPE = 'person'; public const ACP_TYPE = 'accompanying_period'; + + public const ACP_SHARED = 'accompanying_period_shared'; } diff --git a/src/Bundle/ChillPersonBundle/Export/Export/CountAccompanyingCourse.php b/src/Bundle/ChillPersonBundle/Export/Export/CountAccompanyingCourse.php index b7b57d3cd..6d2c0c6f6 100644 --- a/src/Bundle/ChillPersonBundle/Export/Export/CountAccompanyingCourse.php +++ b/src/Bundle/ChillPersonBundle/Export/Export/CountAccompanyingCourse.php @@ -105,7 +105,7 @@ class CountAccompanyingCourse implements ExportInterface, GroupedExportInterface public function supportsModifiers(): array { - return [Declarations::ACP_TYPE]; + return [Declarations::ACP_TYPE, Declarations::ACP_SHARED]; } public function getGroup(): string diff --git a/src/Bundle/ChillPersonBundle/Export/Filter/ReferrerFilter.php b/src/Bundle/ChillPersonBundle/Export/Filter/ReferrerFilter.php new file mode 100644 index 000000000..22515d13e --- /dev/null +++ b/src/Bundle/ChillPersonBundle/Export/Filter/ReferrerFilter.php @@ -0,0 +1,161 @@ +userRender = $userRender; + } + + /** + * @inheritDoc + */ + public function buildForm(FormBuilderInterface $builder) + { + $builder->add('accepted_referrers', EntityType::class, [ + 'class' => User::class, + 'choice_label' => function (User $u) { + return $this->userRender->renderString($u, []); + }, + 'multiple' => true, + 'expanded' => true + ]); + /* + $builder->add('referrers', EntityType::class, [ + 'class' => User::class, + 'choice_label' => function (User $u) { + return $this->userRender->renderString($u, []); + }, + 'multiple' => true, + 'expanded' => true + ]); + */ + + } + + /** + * @inheritDoc + */ + public function getTitle(): string + { + return 'Filtered by referrers'; + } + + /** + * @inheritDoc + */ + public function describeAction($data, $format = 'string') + { + $users = []; + + foreach ($data['accepted_referrers'] as $r) { + $users[] = $r; + } + + return [ + 'Filtered by referrer: only %referrers%', [ + '%referrers' => implode(", ou ", $users) + ]]; + /* + $referrers = []; + + foreach ($data['referrers'] as $r) { + $referrers[] = $this->userRender->renderString($r, []); + } + + return ['Filtered by referrers: only %referrers%', [ + '%referrers%' => implode(', ou ', $referrers) + ]]; + */ + } + + /** + * @inheritDoc + */ + public function addRole() + { + return null; + } + + /** + * @inheritDoc + */ + public function alterQuery(QueryBuilder $qb, $data) + { + + $where = $qb->getDQLPart('where'); + + $from_alias = $this->getEntityFromQB($qb); + + // Use querybuilder from alias to find which export context (indicator) + switch ($from_alias) { + case 'acp': + $clause = $qb->expr()->in('acp.user', ':referrers'); + break; + + case 'acpw': + $qb->join('acpw.referrers', 'r'); + $clause = $qb->expr()->in('r', ':referrers'); + break; + + default: + throw new \Exception("Referrer filter doesn't apply on that entity"); + } + + if ($where instanceof Andx) { + $where->add($clause); + } else { + $where = $qb->expr()->andX($clause); + } + + $qb->add('where', $where); + $qb->setParameter('referrers', $data['accepted_referrers']); + + /* + $qb->join('acpw.referrers', 'r'); + + $where = $qb->getDQLPart('where'); + $clause = $qb->expr()->in('r', ':referrers'); + + if ($where instanceof Andx) { + $where->add($clause); + } else { + $where = $qb->expr()->andX($clause); + } + + $qb->add('where', $where); + $qb->setParameter('referrers', $data['referrers']); + */ + } + + private function getEntityFromQB(QueryBuilder $qb): string + { + /** @var From $from */ + $from = $qb->getDQLPart('from'); + + return $from[0]->getAlias(); + } + + /** + * @inheritDoc + */ + public function applyOn() + { + return Declarations::ACP_SHARED; + } +} \ 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 72fa1ad80..4c4bca27d 100644 --- a/src/Bundle/ChillPersonBundle/config/services/exports_accompanying_period.yaml +++ b/src/Bundle/ChillPersonBundle/config/services/exports_accompanying_period.yaml @@ -95,4 +95,11 @@ services: tags: - { name: chill.export_filter, alias: accompanyingcourse_intensity_filter } + chill.person.export.filter_referrer: + class: Chill\PersonBundle\Export\Filter\ReferrerFilter + autowire: true + autoconfigure: true + tags: + - { name: chill.export_filter, alias: accompanyingcourse_referrer_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 4c5ca1dcf..a8d57227f 100644 --- a/src/Bundle/ChillPersonBundle/translations/messages.fr.yml +++ b/src/Bundle/ChillPersonBundle/translations/messages.fr.yml @@ -416,6 +416,10 @@ is occasional: le parcours est ponctuel is regular: le parcours est régulier "Filtered by intensity: only %intensity%": "Filtré par intensité: uniquement si %intensity%" +Filtered by referrers: Filtrer par référent +Accepted referrers: Référents +"Filtered by referrer: only %referrers%": "Filtré par référent: uniquement %referrers%" +