From 9da410afb8349c299f10225e9b5328af8fa48d1e Mon Sep 17 00:00:00 2001 From: Julie Lenaerts Date: Wed, 21 Sep 2022 13:31:24 +0200 Subject: [PATCH] urgency and calendarrange exports --- .../Export/Aggregator/UrgencyAggregator.php | 91 +++++++++++++++ .../Export/Filter/CalendarRangeFilter.php | 104 ++++++++++++++++++ .../Resources/config/services/exports.yaml | 14 +++ .../translations/messages.fr.yml | 10 ++ 4 files changed, 219 insertions(+) create mode 100644 src/Bundle/ChillCalendarBundle/Export/Aggregator/UrgencyAggregator.php create mode 100644 src/Bundle/ChillCalendarBundle/Export/Filter/CalendarRangeFilter.php diff --git a/src/Bundle/ChillCalendarBundle/Export/Aggregator/UrgencyAggregator.php b/src/Bundle/ChillCalendarBundle/Export/Aggregator/UrgencyAggregator.php new file mode 100644 index 000000000..ad19ee7e1 --- /dev/null +++ b/src/Bundle/ChillCalendarBundle/Export/Aggregator/UrgencyAggregator.php @@ -0,0 +1,91 @@ +translator = $translator; + } + + public function addRole(): ?string + { + return null; + } + + public function alterQuery(QueryBuilder $qb, $data) + { + $qb->addSelect('cal.urgent AS urgency_aggregator'); + + $groupBy = $qb->getDQLPart('groupBy'); + + if (!empty($groupBy)) { + $qb->addGroupBy('urgency_aggregator'); + } else { + $qb->groupBy('urgency_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 'Urgency'; + } + + switch ($value) { + case true: + return $this->translator->trans('is urgent'); + + case false: + return $this->translator->trans('is not urgent'); + + default: + throw new LogicException(sprintf('The value %s is not valid', $value)); + } + }; + } + + public function getQueryKeys($data): array + { + return ['urgency_aggregator']; + } + + public function getTitle(): string + { + return 'Group calendars by urgency'; + } +} + diff --git a/src/Bundle/ChillCalendarBundle/Export/Filter/CalendarRangeFilter.php b/src/Bundle/ChillCalendarBundle/Export/Filter/CalendarRangeFilter.php new file mode 100644 index 000000000..9900d58de --- /dev/null +++ b/src/Bundle/ChillCalendarBundle/Export/Filter/CalendarRangeFilter.php @@ -0,0 +1,104 @@ + true, + 'Made within a calendar range' => false + ]; + + private const DEFAULT_CHOICE = false; + + private TranslatorInterface $translator; + + public function __construct(TranslatorInterface $translator) + { + $this->translator = $translator; + } + + public function addRole(): ?string + { + return null; + } + + public function alterQuery(QueryBuilder $qb, $data) + { + $where = $qb->getDQLPart('where'); + + dump($data); + + if ($data['hasCalendarRange']) { + $clause = $qb->expr()->isNotNull('cal.calendarRange'); + } else { + $clause = $qb->expr()->isNull('cal.calendarRange'); + } + + + if ($where instanceof Andx) { + $where->add($clause); + } else { + $where = $qb->expr()->andX($clause); + } + + $qb->add('where', $where); + } + + public function applyOn(): string + { + return Declarations::CALENDAR_TYPE; + } + + public function buildForm(FormBuilderInterface $builder) + { + $builder->add('hasCalendarRange', ChoiceType::class, [ + 'choices' => self::CHOICES, + 'label' => 'has calendar range', + 'multiple' => false, + 'expanded' => true, + 'empty_data' => self::DEFAULT_CHOICE, + 'data' => self::DEFAULT_CHOICE, + ]); + } + + public function describeAction($data, $format = 'string'): array + { + foreach (self::CHOICES as $k => $v) { + if ($v === $data['hasCalendarRange']) { + $choice = $k; + } else { + $choice = 'Not made within a calendar range'; + } + } + + return [ + 'Filtered by calendar range: only %calendarRange%', [ + '%calendarRange%' => $this->translator->trans($choice), + ], + ]; + } + + public function getTitle(): string + { + return 'Filter by calendar range'; + } +} + diff --git a/src/Bundle/ChillCalendarBundle/Resources/config/services/exports.yaml b/src/Bundle/ChillCalendarBundle/Resources/config/services/exports.yaml index a7508f3b5..3eb4bbfdc 100644 --- a/src/Bundle/ChillCalendarBundle/Resources/config/services/exports.yaml +++ b/src/Bundle/ChillCalendarBundle/Resources/config/services/exports.yaml @@ -52,6 +52,13 @@ services: tags: - { name: chill.export_filter, alias: between_dates_filter } + chill.calendar.export.calendar_range_filter: + class: Chill\CalendarBundle\Export\Filter\CalendarRangeFilter + autowire: true + autoconfigure: true + tags: + - { name: chill.export_filter, alias: calendar_range_filter } + ## Aggregator chill.calendar.export.agent_aggregator: @@ -102,3 +109,10 @@ services: autoconfigure: true tags: - { name: chill.export_aggregator, alias: month_aggregator } + + chill.calendar.export.urgency_aggregator: + class: Chill\CalendarBundle\Export\Aggregator\UrgencyAggregator + autowire: true + autoconfigure: true + tags: + - { name: chill.export_aggregator, alias: urgency_aggregator } diff --git a/src/Bundle/ChillCalendarBundle/translations/messages.fr.yml b/src/Bundle/ChillCalendarBundle/translations/messages.fr.yml index a10b7d43d..a03dd4015 100644 --- a/src/Bundle/ChillCalendarBundle/translations/messages.fr.yml +++ b/src/Bundle/ChillCalendarBundle/translations/messages.fr.yml @@ -89,6 +89,8 @@ Filter calendars by agent scope: Filtrer les rendez-vous par services des agents 'Filtered by agent scope: only %scopes%': 'Filtré par services des agents: uniquement les services %scopes%' Filter calendars between certain dates: Filtrer les rendez-vous par date du rendez-vous 'Filtered by calendars between %dateFrom% and %dateTo%': 'Filtré par rendez-vous entre %dateFrom% et %dateTo%' +'Filtered by calendar range: only %calendarRange%': 'Filtré par rendez-vous par plage de disponibilité: uniquement les %calendarRange%' +Filter by calendar range: Filtrer par rendez-vous dans une plage de disponibilité ou non Group calendars by agent: Grouper les rendez-vous par agent Group calendars by agent job: Grouper les rendez-vous par métier de l'agent @@ -97,8 +99,16 @@ Group calendars by location type: Grouper les rendez-vous par type de localisati Group calendars by location: Grouper les rendez-vous par lieu de rendez-vous Group calendars by cancel reason: Grouper les rendez-vous par motif d'annulation Group calendars by month and year: Grouper les rendez-vous par mois et année +Group calendars by urgency: Grouper les rendez-vous par urgent ou non + Scope: Service Job: Métier Location type: Type de localisation Location: Lieu de rendez-vous by month and year: Par mois et année +is urgent: Urgent +is not urgent: Pas urgent +has calendar range: Dans une plage de disponibilité? +Not made within a calendar range: Rendez-vous dans une plage de disponibilité +Made within a calendar range: Rendez-vous en dehors d'une plage de disponibilité +