From 03d098e5e1407095c3384a32062bea85490f29b0 Mon Sep 17 00:00:00 2001 From: Julie Lenaerts Date: Thu, 18 Aug 2022 12:15:30 +0200 Subject: [PATCH] aggregators added - monthYearAggregator not finished --- .../Export/Aggregator/AgentAggregator.php | 79 ++++++++++++++++++ .../Export/Aggregator/JobAggregator.php | 80 ++++++++++++++++++ .../Export/Aggregator/LocationAggregator.php | 75 +++++++++++++++++ .../Aggregator/LocationTypeAggregator.php | 81 +++++++++++++++++++ .../Export/Aggregator/MonthYearAggregator.php | 49 +++++++++++ .../Export/Aggregator/ScopeAggregator.php | 80 ++++++++++++++++++ .../Resources/config/services/exports.yaml | 39 ++++++++- .../translations/messages.fr.yml | 10 +++ 8 files changed, 492 insertions(+), 1 deletion(-) create mode 100644 src/Bundle/ChillCalendarBundle/Export/Aggregator/AgentAggregator.php create mode 100644 src/Bundle/ChillCalendarBundle/Export/Aggregator/JobAggregator.php create mode 100644 src/Bundle/ChillCalendarBundle/Export/Aggregator/LocationAggregator.php create mode 100644 src/Bundle/ChillCalendarBundle/Export/Aggregator/LocationTypeAggregator.php create mode 100644 src/Bundle/ChillCalendarBundle/Export/Aggregator/MonthYearAggregator.php create mode 100644 src/Bundle/ChillCalendarBundle/Export/Aggregator/ScopeAggregator.php diff --git a/src/Bundle/ChillCalendarBundle/Export/Aggregator/AgentAggregator.php b/src/Bundle/ChillCalendarBundle/Export/Aggregator/AgentAggregator.php new file mode 100644 index 000000000..ed7c265ff --- /dev/null +++ b/src/Bundle/ChillCalendarBundle/Export/Aggregator/AgentAggregator.php @@ -0,0 +1,79 @@ +userRepository = $userRepository; + $this->userRender = $userRender; + } + + public function addRole() + { + return null; + } + + public function alterQuery(QueryBuilder $qb, $data) + { + $qb->join('cal.user', 'u'); + + $qb->addSelect('u.id AS agent_aggregator'); + + $groupBy = $qb->getDQLPart('groupBy'); + + if (!empty($groupBy)) { + $qb->addGroupBy('agent_aggregator'); + } else { + $qb->groupBy('agent_aggregator'); + } + + } + + public function applyOn(): string + { + return Declarations::CALENDAR_TYPE; + } + + public function buildForm(FormBuilderInterface $builder) + { + // no form + } + + public function getLabels($key, array $values, $data): \Closure + { + return function ($value): string { + if ('_header' === $value) { + return 'Agent'; + } + + $r = $this->userRepository->find($value); + + return $this->userRender->renderString($r, []); + }; + } + + public function getQueryKeys($data): array + { + return ['agent_aggregator']; + } + + public function getTitle(): string + { + return 'Group by agent'; + } +} \ No newline at end of file diff --git a/src/Bundle/ChillCalendarBundle/Export/Aggregator/JobAggregator.php b/src/Bundle/ChillCalendarBundle/Export/Aggregator/JobAggregator.php new file mode 100644 index 000000000..b019cc21b --- /dev/null +++ b/src/Bundle/ChillCalendarBundle/Export/Aggregator/JobAggregator.php @@ -0,0 +1,80 @@ +jobRepository = $jobRepository; + $this->translatableStringHelper = $translatableStringHelper; + } + + public function getLabels($key, array $values, $data): \Closure + { + return function($value): string { + if ($value === '_header') { + return 'Job'; + } + + $j = $this->jobRepository->find($value); + + return $this->translatableStringHelper->localize( + $j->getLabel() + ); + }; + } + + public function getQueryKeys($data): array + { + return ['job_aggregator']; + } + + public function buildForm(FormBuilderInterface $builder) + { + // no form + } + + public function getTitle(): string + { + return 'Group by agent job'; + } + + public function addRole() + { + return null; + } + + public function alterQuery(QueryBuilder $qb, $data) + { + $qb->join('cal.user', 'u'); + + $qb->addSelect('IDENTITY(u.userJob) as job_aggregator'); + + $groupBy = $qb->getDQLPart('groupBy'); + + if (!empty($groupBy)) { + $qb->addGroupBy('job_aggregator'); + } else { + $qb->groupBy('job_aggregator'); + } + } + + public function applyOn(): string + { + return Declarations::CALENDAR_TYPE; + } +} \ No newline at end of file diff --git a/src/Bundle/ChillCalendarBundle/Export/Aggregator/LocationAggregator.php b/src/Bundle/ChillCalendarBundle/Export/Aggregator/LocationAggregator.php new file mode 100644 index 000000000..bc921c9c7 --- /dev/null +++ b/src/Bundle/ChillCalendarBundle/Export/Aggregator/LocationAggregator.php @@ -0,0 +1,75 @@ +locationRepository = $locationRepository; + } + + public function getLabels($key, array $values, $data): \Closure + { + return function($value): string { + if ($value === '_header') { + return 'Location'; + } + + $l = $this->locationRepository->find($value); + + return $l->getName(); + + }; + } + + public function getQueryKeys($data): array + { + return ['location_aggregator']; + } + + public function buildForm(FormBuilderInterface $builder) + { + // no form + } + + public function getTitle(): string + { + return 'Group by location'; + } + + public function addRole(): ?Role + { + return null; + } + + public function alterQuery(QueryBuilder $qb, $data) + { + $qb->join('cal.location', 'l'); + $qb->addSelect('IDENTITY(cal.location) as location_aggregator'); + + $groupBy = $qb->getDQLPart('groupBy'); + + if (!empty($groupBy)) { + $qb->addGroupBy('location_aggregator'); + } else { + $qb->groupBy('location_aggregator'); + } + } + + public function applyOn(): string + { + return Declarations::CALENDAR_TYPE; + } + +} \ No newline at end of file diff --git a/src/Bundle/ChillCalendarBundle/Export/Aggregator/LocationTypeAggregator.php b/src/Bundle/ChillCalendarBundle/Export/Aggregator/LocationTypeAggregator.php new file mode 100644 index 000000000..3b3b9105a --- /dev/null +++ b/src/Bundle/ChillCalendarBundle/Export/Aggregator/LocationTypeAggregator.php @@ -0,0 +1,81 @@ +locationTypeRepository = $locationTypeRepository; + $this->translatableStringHelper = $translatableStringHelper; + } + + public function getLabels($key, array $values, $data): \Closure + { + return function($value): string { + if ($value === '_header') { + return 'Location type'; + } + + $j = $this->locationTypeRepository->find($value); + + return $this->translatableStringHelper->localize( + $j->getTitle() + ); + }; + } + + public function getQueryKeys($data): array + { + return ['location_type_aggregator']; + } + + public function buildForm(FormBuilderInterface $builder) + { + // no form + } + + public function getTitle(): string + { + return 'Group by location type'; + } + + public function addRole() + { + return null; + } + + public function alterQuery(QueryBuilder $qb, $data) + { + $qb->join('cal.location', 'l'); + + $qb->addSelect('IDENTITY(l.locationType) as location_type_aggregator'); + + $groupBy = $qb->getDQLPart('groupBy'); + + if (!empty($groupBy)) { + $qb->addGroupBy('location_type_aggregator'); + } else { + $qb->groupBy('location_type_aggregator'); + } + } + + public function applyOn(): string + { + return Declarations::CALENDAR_TYPE; + } + +} \ No newline at end of file diff --git a/src/Bundle/ChillCalendarBundle/Export/Aggregator/MonthYearAggregator.php b/src/Bundle/ChillCalendarBundle/Export/Aggregator/MonthYearAggregator.php new file mode 100644 index 000000000..b24120c15 --- /dev/null +++ b/src/Bundle/ChillCalendarBundle/Export/Aggregator/MonthYearAggregator.php @@ -0,0 +1,49 @@ +scopeRepository = $scopeRepository; + $this->translatableStringHelper = $translatableStringHelper; + } + + public function getLabels($key, array $values, $data): \Closure + { + 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 ['scope_aggregator']; + } + + public function buildForm(FormBuilderInterface $builder) + { + // no form + } + + public function getTitle(): string + { + return 'Group by agent scope'; + } + + public function addRole() + { + return null; + } + + public function alterQuery(QueryBuilder $qb, $data) + { + $qb->join('cal.user', 'u'); + + $qb->addSelect('IDENTITY(u.mainScope) as scope_aggregator'); + + $groupBy = $qb->getDQLPart('groupBy'); + + if (!empty($groupBy)) { + $qb->addGroupBy('scope_aggregator'); + } else { + $qb->groupBy('scope_aggregator'); + } + } + + public function applyOn(): string + { + return Declarations::CALENDAR_TYPE; + } +} \ No newline at end of file diff --git a/src/Bundle/ChillCalendarBundle/Resources/config/services/exports.yaml b/src/Bundle/ChillCalendarBundle/Resources/config/services/exports.yaml index 834cdfa78..e86194ea6 100644 --- a/src/Bundle/ChillCalendarBundle/Resources/config/services/exports.yaml +++ b/src/Bundle/ChillCalendarBundle/Resources/config/services/exports.yaml @@ -50,4 +50,41 @@ services: autowire: true autoconfigure: true tags: - - { name: chill.export_filter, alias: between_dates_filter } \ No newline at end of file + - { name: chill.export_filter, alias: between_dates_filter } + + ## Aggregator + + chill.calendar.export.agent_aggregator: + class: Chill\CalendarBundle\Export\Aggregator\AgentAggregator + autowire: true + autoconfigure: true + tags: + - { name: chill.export_aggregator, alias: agent_aggregator } + + chill.calendar.export.job_aggregator: + class: Chill\CalendarBundle\Export\Aggregator\JobAggregator + autowire: true + autoconfigure: true + tags: + - { name: chill.export_aggregator, alias: job_aggregator } + + chill.calendar.export.scope_aggregator: + class: Chill\CalendarBundle\Export\Aggregator\ScopeAggregator + autowire: true + autoconfigure: true + tags: + - { name: chill.export_aggregator, alias: scope_aggregator } + + chill.calendar.export.location_type_aggregator: + class: Chill\CalendarBundle\Export\Aggregator\LocationTypeAggregator + autowire: true + autoconfigure: true + tags: + - { name: chill.export_aggregator, alias: location_type_aggregator } + + chill.calendar.export.location_aggregator: + class: Chill\CalendarBundle\Export\Aggregator\LocationAggregator + autowire: true + autoconfigure: true + tags: + - { name: chill.export_aggregator, alias: location_aggregator } \ No newline at end of file diff --git a/src/Bundle/ChillCalendarBundle/translations/messages.fr.yml b/src/Bundle/ChillCalendarBundle/translations/messages.fr.yml index a1c848ad7..b0add946d 100644 --- a/src/Bundle/ChillCalendarBundle/translations/messages.fr.yml +++ b/src/Bundle/ChillCalendarBundle/translations/messages.fr.yml @@ -57,3 +57,13 @@ Filter by agent scope: Filtrer par services des agents 'Filtered by agent scope: only %scopes%': 'Filtré par services des agents: uniquement les services %scopes%' Filter by appointments between certain dates: Filtrer par date du rendez-vous 'Filtered by appointments between %dateFrom% and %dateTo%': 'Filtré par rendez-vous entre %dateFrom% et %dateTo%' + +Group by agent: Grouper par agent +Group by agent job: Grouper par métier de l'agent +Group by agent scope: Grouper par service de l'agent +Group by location type: Grouper par type de localisation +Group by location: Grouper par lieu de rendez-vous +Scope: Service +Job: Métier +Location type: Type de localisation +Location: Lieu de rendez-vous \ No newline at end of file