From dea7982ca882a8ea2106f922212e6fedb31b715a Mon Sep 17 00:00:00 2001 From: Mathieu Jaumotte Date: Mon, 22 Aug 2022 18:48:34 +0200 Subject: [PATCH] exports: add activity linked_to_acp new aggregators (wip) --- .../BySocialActionAggregator.php | 79 +++++++++++++++ .../BySocialIssueAggregator.php | 80 +++++++++++++++ .../ACPAggregators/ByThirdpartyAggregator.php | 79 +++++++++++++++ .../ACPAggregators/ByUserAggregator.php | 79 +++++++++++++++ .../ACPAggregators/DateAggregator.php | 99 +++++++++++++++++++ .../ACPAggregators/LocationTypeAggregator.php | 82 +++++++++++++++ .../ACPAggregators/UserScopeAggregator.php | 86 ++++++++++++++++ .../config/services/export.yaml | 35 +++++++ .../translations/messages.fr.yml | 8 ++ 9 files changed, 627 insertions(+) create mode 100644 src/Bundle/ChillActivityBundle/Export/Aggregator/ACPAggregators/BySocialActionAggregator.php create mode 100644 src/Bundle/ChillActivityBundle/Export/Aggregator/ACPAggregators/BySocialIssueAggregator.php create mode 100644 src/Bundle/ChillActivityBundle/Export/Aggregator/ACPAggregators/ByThirdpartyAggregator.php create mode 100644 src/Bundle/ChillActivityBundle/Export/Aggregator/ACPAggregators/ByUserAggregator.php create mode 100644 src/Bundle/ChillActivityBundle/Export/Aggregator/ACPAggregators/DateAggregator.php create mode 100644 src/Bundle/ChillActivityBundle/Export/Aggregator/ACPAggregators/LocationTypeAggregator.php create mode 100644 src/Bundle/ChillActivityBundle/Export/Aggregator/ACPAggregators/UserScopeAggregator.php diff --git a/src/Bundle/ChillActivityBundle/Export/Aggregator/ACPAggregators/BySocialActionAggregator.php b/src/Bundle/ChillActivityBundle/Export/Aggregator/ACPAggregators/BySocialActionAggregator.php new file mode 100644 index 000000000..a5cbc16f1 --- /dev/null +++ b/src/Bundle/ChillActivityBundle/Export/Aggregator/ACPAggregators/BySocialActionAggregator.php @@ -0,0 +1,79 @@ +actionRender = $actionRender; + $this->actionRepository = $actionRepository; + } + + public function getLabels($key, array $values, $data) + { + return function($value) { + if ('_header' === $value) { + return 'Social action'; + } + + $sa = $this->actionRepository->find($value); + + return $this->actionRender->renderString($sa, []); + }; + } + + public function getQueryKeys($data): array + { + return ['socialaction_aggregator']; + } + + public function buildForm(FormBuilderInterface $builder) + { + // no form + } + + public function getTitle(): string + { + return 'Group activity by linked socialaction'; + } + + public function addRole() + { + return null; + } + + public function alterQuery(QueryBuilder $qb, $data) + { + $qb->addSelect('IDENTITY(activity.socialActions) AS socialaction_aggregator'); + + $groupBy = $qb->getDQLPart('groupBy'); + + if (!empty($groupBy)) { + $qb->addGroupBy('socialaction_aggregator'); + } else { + $qb->groupBy('socialaction_aggregator'); + } + } + + public function applyOn(): string + { + return Declarations::ACTIVITY_ACP; + } +} \ No newline at end of file diff --git a/src/Bundle/ChillActivityBundle/Export/Aggregator/ACPAggregators/BySocialIssueAggregator.php b/src/Bundle/ChillActivityBundle/Export/Aggregator/ACPAggregators/BySocialIssueAggregator.php new file mode 100644 index 000000000..193f93f5c --- /dev/null +++ b/src/Bundle/ChillActivityBundle/Export/Aggregator/ACPAggregators/BySocialIssueAggregator.php @@ -0,0 +1,80 @@ +issueRepository = $issueRepository; + $this->issueRender = $issueRender; + } + + public function getLabels($key, array $values, $data) + { + return function ($value): string { + + if ($value === '_header') { + return 'Social issues'; + } + + $i = $this->issueRepository->find($value); + + return $this->issueRender->renderString($i, []); + }; + } + + public function getQueryKeys($data): array + { + return ['socialissue_aggregator']; + } + + public function buildForm(FormBuilderInterface $builder) + { + // no form + } + + public function getTitle(): string + { + return 'Group activity by linked socialissue'; + } + + public function addRole() + { + return null; + } + + public function alterQuery(QueryBuilder $qb, $data) + { + $qb->addSelect('IDENTITY(activity.socialIssues) AS socialissue_aggregator'); + + $groupBy = $qb->getDQLPart('groupBy'); + + if (!empty($groupBy)) { + $qb->addGroupBy('socialissue_aggregator'); + } else { + $qb->groupBy('socialissue_aggregator'); + } + } + + public function applyOn(): string + { + return Declarations::ACTIVITY_ACP; + } +} \ No newline at end of file diff --git a/src/Bundle/ChillActivityBundle/Export/Aggregator/ACPAggregators/ByThirdpartyAggregator.php b/src/Bundle/ChillActivityBundle/Export/Aggregator/ACPAggregators/ByThirdpartyAggregator.php new file mode 100644 index 000000000..583e3589a --- /dev/null +++ b/src/Bundle/ChillActivityBundle/Export/Aggregator/ACPAggregators/ByThirdpartyAggregator.php @@ -0,0 +1,79 @@ +thirdPartyRepository = $thirdPartyRepository; + $this->thirdPartyRender = $thirdPartyRender; + } + + public function getLabels($key, array $values, $data) + { + return function ($value): string { + if ($value === '_header') { + return 'Thirdparty'; + } + + $tp = $this->thirdPartyRepository->find($value); + + return $this->thirdPartyRender->renderString($tp, []); + }; + } + + public function getQueryKeys($data): array + { + return ['thirdparty_aggregator']; + } + + public function buildForm(FormBuilderInterface $builder) + { + // no form + } + + public function getTitle(): string + { + return 'Group activity by linked thirdparties'; + } + + public function addRole() + { + return null; + } + + public function alterQuery(QueryBuilder $qb, $data) + { + $qb->addSelect('IDENTITY(activity.thirdParties) AS thirdparty_aggregator'); + + $groupBy = $qb->getDQLPart('groupBy'); + + if (!empty($groupBy)) { + $qb->addGroupBy('thirdparty_aggregator'); + } else { + $qb->groupBy('thirdparty_aggregator'); + } + } + + public function applyOn(): string + { + return Declarations::ACTIVITY_ACP; + } +} \ No newline at end of file diff --git a/src/Bundle/ChillActivityBundle/Export/Aggregator/ACPAggregators/ByUserAggregator.php b/src/Bundle/ChillActivityBundle/Export/Aggregator/ACPAggregators/ByUserAggregator.php new file mode 100644 index 000000000..9cd6601c1 --- /dev/null +++ b/src/Bundle/ChillActivityBundle/Export/Aggregator/ACPAggregators/ByUserAggregator.php @@ -0,0 +1,79 @@ +userRepository = $userRepository; + $this->userRender = $userRender; + } + + public function getLabels($key, array $values, $data) + { + return function ($value): string { + if ($value === '_header') { + return 'Accepted users'; + } + + $u = $this->userRepository->find($value); + + return $this->userRender->renderString($u, []); + }; + } + + public function getQueryKeys($data): array + { + return ['users_aggregator']; + } + + public function buildForm(FormBuilderInterface $builder) + { + // no form + } + + public function getTitle(): string + { + return 'Group activity by linked users'; + } + + public function addRole() + { + return null; + } + + public function alterQuery(QueryBuilder $qb, $data) + { + $qb->addSelect('IDENTITY(activity.users) AS users_aggregator'); + + $groupBy = $qb->getDQLPart('groupBy'); + + if (!empty($groupBy)) { + $qb->addGroupBy('users_aggregator'); + } else { + $qb->groupBy('users_aggregator'); + } + } + + public function applyOn(): string + { + return Declarations::ACTIVITY_ACP; + } +} \ No newline at end of file diff --git a/src/Bundle/ChillActivityBundle/Export/Aggregator/ACPAggregators/DateAggregator.php b/src/Bundle/ChillActivityBundle/Export/Aggregator/ACPAggregators/DateAggregator.php new file mode 100644 index 000000000..ef866f4f6 --- /dev/null +++ b/src/Bundle/ChillActivityBundle/Export/Aggregator/ACPAggregators/DateAggregator.php @@ -0,0 +1,99 @@ + 'month', + 'by week' => 'week', // sur base du numéro de la semaine + 'by year' => 'year', + ]; + + private CONST DEFAULT_CHOICE = 'year'; + + private TranslatorInterface $translator; + + public function __construct( + TranslatorInterface $translator + ) { + $this->translator = $translator; + } + + public function getLabels($key, array $values, $data) + { + return function ($value): string { + switch ($value) { + case '_header': + return 'By date'; + + case 'month': + return $this->translator->trans('by month'); + + case 'week': + return $this->translator->trans('by week'); + + case 'year': + return $this->translator->trans('by year'); + + default: + throw new LogicException(sprintf('The value %s is not valid', $value)); + } + }; + } + + public function getQueryKeys($data): array + { + return ['date_aggregator']; + } + + public function buildForm(FormBuilderInterface $builder) + { + $builder->add('by_date', ChoiceType::class, [ + 'choices' => self::CHOICES, + 'multiple' => false, + 'expanded' => true, + 'empty_data' => self::DEFAULT_CHOICE, + 'data' => self::DEFAULT_CHOICE, + ]); + } + + public function getTitle(): string + { + return 'Group activity by date'; + } + + public function addRole() + { + return null; + } + + public function alterQuery(QueryBuilder $qb, $data) + { + $qb->addSelect('activity.date AS date_aggregator'); + + $groupBy = $qb->getDQLPart('groupBy'); + + if (!empty($groupBy)) { + $qb->addGroupBy('date_aggregator'); + } else { + $qb->groupBy('date_aggregator'); + } + } + + public function applyOn(): string + { + return Declarations::ACTIVITY_ACP; + } + +} \ No newline at end of file diff --git a/src/Bundle/ChillActivityBundle/Export/Aggregator/ACPAggregators/LocationTypeAggregator.php b/src/Bundle/ChillActivityBundle/Export/Aggregator/ACPAggregators/LocationTypeAggregator.php new file mode 100644 index 000000000..088ac0e4a --- /dev/null +++ b/src/Bundle/ChillActivityBundle/Export/Aggregator/ACPAggregators/LocationTypeAggregator.php @@ -0,0 +1,82 @@ +locationTypeRepository = $locationTypeRepository; + $this->translatableStringHelper = $translatableStringHelper; + } + + public function getLabels($key, array $values, $data) + { + return function ($value): string { + if ($value === '_header') { + return 'Accepted locationtype'; + } + + $lt = $this->locationTypeRepository->find($value); + + return $this->translatableStringHelper->localize( + $lt->getTitle() + ); + }; + } + + public function getQueryKeys($data): array + { + return ['locationtype_aggregator']; + } + + public function buildForm(FormBuilderInterface $builder) + { + // no form + } + + public function getTitle(): string + { + return 'Group activity by locationtype'; + } + + public function addRole() + { + return null; + } + + public function alterQuery(QueryBuilder $qb, $data) + { + $qb->addSelect('IDENTITY(activity.location) AS locationtype_aggregator'); + + $groupBy = $qb->getDQLPart('groupBy'); + + if (!empty($groupBy)) { + $qb->addGroupBy('locationtype_aggregator'); + } else { + $qb->groupBy('locationtype_aggregator'); + } + } + + public function applyOn(): string + { + return Declarations::ACTIVITY_ACP; + } + +} \ No newline at end of file diff --git a/src/Bundle/ChillActivityBundle/Export/Aggregator/ACPAggregators/UserScopeAggregator.php b/src/Bundle/ChillActivityBundle/Export/Aggregator/ACPAggregators/UserScopeAggregator.php new file mode 100644 index 000000000..4d6cef24a --- /dev/null +++ b/src/Bundle/ChillActivityBundle/Export/Aggregator/ACPAggregators/UserScopeAggregator.php @@ -0,0 +1,86 @@ +scopeRepository = $scopeRepository; + $this->translatableStringHelper = $translatableStringHelper; + } + + public function getLabels($key, array $values, $data) + { + return function ($value): string { + if ($value === '_header') { + return 'Scope'; + } + + $s = $this->scopeRepository->find($value); + + return $this->translatableStringHelper->localize( + $s->getName() + ); + }; + } + + public function getQueryKeys($data): array + { + return ['userscope_aggregator']; + } + + public function buildForm(FormBuilderInterface $builder) + { + // no form + } + + public function getTitle(): string + { + return 'Group activity by userscope'; + } + + public function addRole() + { + return null; + } + + public function alterQuery(QueryBuilder $qb, $data) + { + if (!in_array('user', $qb->getAllAliases())) { + $qb->join('activity.user', 'user'); + } + + $qb->addSelect('IDENTITY(user.mainScope) AS userscope_aggregator'); + + $groupBy = $qb->getDQLPart('groupBy'); + + if (!empty($groupBy)) { + $qb->addGroupBy('userscope_aggregator'); + } else { + $qb->groupBy('userscope_aggregator'); + } + } + + public function applyOn(): string + { + return Declarations::ACTIVITY_ACP; + } + +} \ No newline at end of file diff --git a/src/Bundle/ChillActivityBundle/config/services/export.yaml b/src/Bundle/ChillActivityBundle/config/services/export.yaml index 517e85767..c88046c5f 100644 --- a/src/Bundle/ChillActivityBundle/config/services/export.yaml +++ b/src/Bundle/ChillActivityBundle/config/services/export.yaml @@ -122,3 +122,38 @@ services: class: Chill\ActivityBundle\Export\Aggregator\ActivityUserAggregator tags: - { name: chill.export_aggregator, alias: activity_user_aggregator } + + chill.activity.export.locationtype_aggregator: + class: Chill\ActivityBundle\Export\Aggregator\ACPAggregators\LocationTypeAggregator + tags: + - { name: chill.export_aggregator, alias: activity_locationtype_aggregator } + + chill.activity.export.date_aggregator: + class: Chill\ActivityBundle\Export\Aggregator\ACPAggregators\DateAggregator + tags: + - { name: chill.export_aggregator, alias: activity_date_aggregator } + + chill.activity.export.byuser_aggregator: + class: Chill\ActivityBundle\Export\Aggregator\ACPAggregators\ByUserAggregator + tags: + - { name: chill.export_aggregator, alias: activity_byuser_aggregator } + + chill.activity.export.bythirdparty_aggregator: + class: Chill\ActivityBundle\Export\Aggregator\ACPAggregators\ByThirdpartyAggregator + tags: + - { name: chill.export_aggregator, alias: activity_bythirdparty_aggregator } + + chill.activity.export.bysocialaction_aggregator: + class: Chill\ActivityBundle\Export\Aggregator\ACPAggregators\BySocialActionAggregator + tags: + - { name: chill.export_aggregator, alias: activity_bysocialaction_aggregator } + + chill.activity.export.bysocialissue_aggregator: + class: Chill\ActivityBundle\Export\Aggregator\ACPAggregators\BySocialIssueAggregator + tags: + - { name: chill.export_aggregator, alias: activity_bysocialissue_aggregator } + + chill.activity.export.userscope_aggregator: + class: Chill\ActivityBundle\Export\Aggregator\ACPAggregators\UserScopeAggregator + tags: + - { name: chill.export_aggregator, alias: activity_userscope_aggregator } diff --git a/src/Bundle/ChillActivityBundle/translations/messages.fr.yml b/src/Bundle/ChillActivityBundle/translations/messages.fr.yml index b66c606d5..0bef84ba0 100644 --- a/src/Bundle/ChillActivityBundle/translations/messages.fr.yml +++ b/src/Bundle/ChillActivityBundle/translations/messages.fr.yml @@ -286,6 +286,14 @@ Aggregate by activity user: Grouper les activités par utilisateur Aggregate by activity type: Grouper les activités par type Aggregate by activity reason: Grouper les activités par sujet +Group activity by locationtype: Grouper les activités par type de localisation +Group activity by date: Grouper les activités par date +Group activity by linked users: Grouper les activités par TMS impliqué +Group activity by linked thirdparties: Grouper les activités par tiers impliqué +Group activity by linked socialaction: Grouper les activités par action liée +Group activity by linked socialissue: Grouper les activités par problématique liée +Group activity by userscope: Grouper les activités par service du créateur + Last activities: Les dernières activités See activity in accompanying course context: Voir l'activité dans le contexte du parcours d'accompagnement