From 3c5d533c580b4ff0784d8b47971ce0805832a0d2 Mon Sep 17 00:00:00 2001 From: Julie Lenaerts Date: Wed, 17 Aug 2022 16:04:46 +0200 Subject: [PATCH] first indicator for calendar exports --- .../ChillCalendarExtension.php | 1 + .../Export/Declarations.php | 20 ++++ .../Export/Export/CountAppointments.php | 111 ++++++++++++++++++ .../Resources/config/services/exports.yaml | 9 ++ .../translations/messages.fr.yml | 4 + 5 files changed, 145 insertions(+) create mode 100644 src/Bundle/ChillCalendarBundle/Export/Declarations.php create mode 100644 src/Bundle/ChillCalendarBundle/Export/Export/CountAppointments.php create mode 100644 src/Bundle/ChillCalendarBundle/Resources/config/services/exports.yaml diff --git a/src/Bundle/ChillCalendarBundle/DependencyInjection/ChillCalendarExtension.php b/src/Bundle/ChillCalendarBundle/DependencyInjection/ChillCalendarExtension.php index 165365597..e33e6c3c3 100644 --- a/src/Bundle/ChillCalendarBundle/DependencyInjection/ChillCalendarExtension.php +++ b/src/Bundle/ChillCalendarBundle/DependencyInjection/ChillCalendarExtension.php @@ -32,6 +32,7 @@ class ChillCalendarExtension extends Extension implements PrependExtensionInterf $loader = new Loader\YamlFileLoader($container, new FileLocator(__DIR__ . '/../Resources/config')); $loader->load('services.yml'); + $loader->load('services/exports.yaml'); $loader->load('services/controller.yml'); $loader->load('services/fixtures.yml'); $loader->load('services/form.yml'); diff --git a/src/Bundle/ChillCalendarBundle/Export/Declarations.php b/src/Bundle/ChillCalendarBundle/Export/Declarations.php new file mode 100644 index 000000000..616d70a1a --- /dev/null +++ b/src/Bundle/ChillCalendarBundle/Export/Declarations.php @@ -0,0 +1,20 @@ +calendarRepository = $calendarRepository; + } + + public function buildForm(FormBuilderInterface $builder) + { + // No form necessary + } + + public function getAllowedFormattersTypes(): array + { + return [FormatterInterface::TYPE_TABULAR]; + } + + public function getDescription(): string + { + return 'Count appointments by various parameters.'; + } + + public function getLabels($key, array $values, $data): \Closure + { + 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(AbstractQuery::HYDRATE_SCALAR); + } + + public function getTitle(): string + { + return 'Count appointments'; + } + + public function getType(): string + { + return Declarations::CALENDAR_TYPE; + } + + /** + * Initiate the query. + */ + public function initiateQuery(array $requiredModifiers, array $acl, array $data = []): QueryBuilder + { + $centers = array_map(static function ($el) { + return $el['center']; + }, $acl); + + $qb = $this->calendarRepository->createQueryBuilder('appointment'); + + $qb->select('COUNT(appointment.id) AS export_result'); + + return $qb; + } + + public function requiredRole(): Role + { + + // which role should we give here? + return new Role(PersonVoter::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 new file mode 100644 index 000000000..ee8f444a5 --- /dev/null +++ b/src/Bundle/ChillCalendarBundle/Resources/config/services/exports.yaml @@ -0,0 +1,9 @@ +services: + + ## Indicators + chill.calendar.export.count_appointments: + class: Chill\CalendarBundle\Export\Export\CountAppointments + autowire: true + autoconfigure: true + tags: + - { name: chill.export, alias: count_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 da244fd13..5d32bc5d1 100644 --- a/src/Bundle/ChillCalendarBundle/translations/messages.fr.yml +++ b/src/Bundle/ChillCalendarBundle/translations/messages.fr.yml @@ -38,3 +38,7 @@ crud: add_new: Ajouter un nouveau title_new: Nouveau motif d'annulation title_edit: Modifier le motif d'annulation + +# exports +Exports of calendar: Exports des rendez-vous +Count appointments: Nombre des rendez-vous