diff --git a/src/Bundle/ChillCalendarBundle/Export/Aggregator/CancelReasonAggregator.php b/src/Bundle/ChillCalendarBundle/Export/Aggregator/CancelReasonAggregator.php new file mode 100644 index 000000000..f63be8b5d --- /dev/null +++ b/src/Bundle/ChillCalendarBundle/Export/Aggregator/CancelReasonAggregator.php @@ -0,0 +1,80 @@ +cancelReasonRepository = $cancelReasonRepository; + $this->translatableStringHelper = $translatableStringHelper; + } + + public function getLabels($key, array $values, $data): \Closure + { + return function($value): string { + if ($value === '_header') { + return 'Cancel reason'; + } + + $j = $this->cancelReasonRepository->find($value); + + return $this->translatableStringHelper->localize( + $j->getName() + ); + }; + } + + public function getQueryKeys($data): array + { + return ['cancel_reason_aggregator']; + } + + public function buildForm(FormBuilderInterface $builder) + { + // no form + } + + public function getTitle(): string + { + return 'Group by cancel reason'; + } + + public function addRole() + { + return null; + } + + public function alterQuery(QueryBuilder $qb, $data) + { + $qb->join('cal.cancelReason', 'cr'); + + $qb->addSelect('IDENTITY(cal.cancelReason) as cancel_reason_aggregator'); + + $groupBy = $qb->getDQLPart('groupBy'); + + if (!empty($groupBy)) { + $qb->addGroupBy('cancel_reason_aggregator'); + } else { + $qb->groupBy('cancel_reason_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 index b24120c15..fa83d8398 100644 --- a/src/Bundle/ChillCalendarBundle/Export/Aggregator/MonthYearAggregator.php +++ b/src/Bundle/ChillCalendarBundle/Export/Aggregator/MonthYearAggregator.php @@ -14,12 +14,20 @@ class MonthYearAggregator implements AggregatorInterface public function getQueryKeys($data): array { - return ['monty_year_aggregator']; + return ['month_year_aggregator']; } public function getLabels($key, array $values, $data): Closure { + dump($values); + + $labels = []; + + return static function (string $value) use ($labels): string { + return $labels[$value]; + }; + } public function buildForm(FormBuilderInterface $builder) @@ -39,11 +47,21 @@ class MonthYearAggregator implements AggregatorInterface public function alterQuery(QueryBuilder $qb, $data) { - // TODO: Implement alterQuery() method. + $qb->addSelect('MONTH(:startDate), YEAR(:startDate) as month_year_aggregator'); +// $qb->addSelect('YEAR(cal.startDate) as year_aggregator'); + + $qb->setParameter('startDate', 'cal.startDate'); + $groupBy = $qb->getDQLPart('groupBy'); + + if (!empty($groupBy)) { + $qb->addGroupBy('month_year_aggregator'); + } else { + $qb->groupBy('month_year_aggregator'); + } } public function applyOn(): string { - return [ Declarations::CALENDAR_TYPE ]; + 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 e86194ea6..0f9ed1a49 100644 --- a/src/Bundle/ChillCalendarBundle/Resources/config/services/exports.yaml +++ b/src/Bundle/ChillCalendarBundle/Resources/config/services/exports.yaml @@ -87,4 +87,18 @@ services: autowire: true autoconfigure: true tags: - - { name: chill.export_aggregator, alias: location_aggregator } \ No newline at end of file + - { name: chill.export_aggregator, alias: location_aggregator } + + chill.calendar.export.cancel_reason_aggregator: + class: Chill\CalendarBundle\Export\Aggregator\CancelReasonAggregator + autowire: true + autoconfigure: true + tags: + - { name: chill.export_aggregator, alias: cancel_reason_aggregator } + + chill.calendar.export.month_year_aggregator: + class: Chill\CalendarBundle\Export\Aggregator\MonthYearAggregator + autowire: true + autoconfigure: true + tags: + - { name: chill.export_aggregator, alias: month_year_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 b0add946d..320be80f5 100644 --- a/src/Bundle/ChillCalendarBundle/translations/messages.fr.yml +++ b/src/Bundle/ChillCalendarBundle/translations/messages.fr.yml @@ -63,7 +63,9 @@ 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 +Group by cancel reason: Grouper par motif d'annulation +Group by month and year: Grouper par mois et année Scope: Service Job: Métier Location type: Type de localisation -Location: Lieu de rendez-vous \ No newline at end of file +Location: Lieu de rendez-vous