From dfbaaef77871b2dc062cdb30ba327cd4b5e22d81 Mon Sep 17 00:00:00 2001 From: Julie Lenaerts Date: Wed, 17 Aug 2022 17:36:42 +0200 Subject: [PATCH] add average duration indicator calendar --- .../Export/Export/StatAppointmentDuration.php | 103 ++++++++++++++++++ .../Resources/config/services/exports.yaml | 9 +- .../translations/messages.fr.yml | 2 + 3 files changed, 113 insertions(+), 1 deletion(-) create mode 100644 src/Bundle/ChillCalendarBundle/Export/Export/StatAppointmentDuration.php diff --git a/src/Bundle/ChillCalendarBundle/Export/Export/StatAppointmentDuration.php b/src/Bundle/ChillCalendarBundle/Export/Export/StatAppointmentDuration.php new file mode 100644 index 000000000..c46aaaf0c --- /dev/null +++ b/src/Bundle/ChillCalendarBundle/Export/Export/StatAppointmentDuration.php @@ -0,0 +1,103 @@ +calendarRepository = $calendarRepository; + } + + public function buildForm(FormBuilderInterface $builder): void + { + // no form needed + } + + public function getTitle(): string + { + return 'Average appointment duration'; + } + + public function getAllowedFormattersTypes(): array + { + return [FormatterInterface::TYPE_TABULAR]; + } + + public function getDescription(): string + { + return 'Get the average of appointment duration according to various filters'; + } + + public function getLabels($key, array $values, $data) + { + if ('export_result' !== $key) { + throw new \LogicException("the key {$key} is not used by this export"); + } + + $labels = array_combine($values, $values); + $labels['_header'] = $this->getTitle(); + + return static function ($value) use ($labels) { + return $labels[$value]; + }; + } + + public function getQueryKeys($data): array + { + return ['export_result']; + } + + public function getResult($qb, $data) + { + return $qb->getQuery()->getResult(Query::HYDRATE_SCALAR); + } + + public function getType(): string + { + return Declarations::CALENDAR_TYPE; + } + + public function initiateQuery(array $requiredModifiers, array $acl, array $data = []): QueryBuilder + { + $qb = $this->calendarRepository->createQueryBuilder('cal'); + + $qb + ->select('AVG(cal.endDate - cal.startDate) AS export_result'); + + return $qb; + } + + public function requiredRole(): Role + { + return new Role(AccompanyingPeriodVoter::STATS); + } + + public function supportsModifiers(): array + { + return [ + Declarations::CALENDAR_TYPE + ]; + } + + public function getGroup(): string + { + return 'Exports of calendar'; + } + +} \ 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 ee8f444a5..ef0b43089 100644 --- a/src/Bundle/ChillCalendarBundle/Resources/config/services/exports.yaml +++ b/src/Bundle/ChillCalendarBundle/Resources/config/services/exports.yaml @@ -6,4 +6,11 @@ services: autowire: true autoconfigure: true tags: - - { name: chill.export, alias: count_appointments } \ No newline at end of file + - { name: chill.export, alias: count_appointments } + + chill.calendar.export.average_duration_appointments: + class: Chill\CalendarBundle\Export\Export\StatAppointmentDuration + autowire: true + autoconfigure: true + tags: + - { name: chill.export, alias: average_duration_appointments } \ 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 5d32bc5d1..353b2e851 100644 --- a/src/Bundle/ChillCalendarBundle/translations/messages.fr.yml +++ b/src/Bundle/ChillCalendarBundle/translations/messages.fr.yml @@ -42,3 +42,5 @@ crud: # exports Exports of calendar: Exports des rendez-vous Count appointments: Nombre des rendez-vous +Average appointment duration: Moyenne des durées des rendez-vous +Get the average of appointment duration according to various filters: Calculer la moyenne des durées des rendez-vous