From 3eb07121cec3cd388b6acf3a278b7fd6c2e5ea0b Mon Sep 17 00:00:00 2001 From: Julie Lenaerts Date: Thu, 18 Aug 2022 10:56:47 +0200 Subject: [PATCH] filters added --- .../Export/Filter/AgentFilter.php | 79 +++++++++++++++ .../Export/Filter/BetweenDatesFilter.php | 70 +++++++++++++ .../Export/Filter/JobFilter.php | 99 +++++++++++++++++++ .../Export/Filter/ScopeFilter.php | 99 +++++++++++++++++++ .../Resources/config/services/exports.yaml | 41 +++++++- .../translations/messages.fr.yml | 13 +++ 6 files changed, 399 insertions(+), 2 deletions(-) create mode 100644 src/Bundle/ChillCalendarBundle/Export/Filter/AgentFilter.php create mode 100644 src/Bundle/ChillCalendarBundle/Export/Filter/BetweenDatesFilter.php create mode 100644 src/Bundle/ChillCalendarBundle/Export/Filter/JobFilter.php create mode 100644 src/Bundle/ChillCalendarBundle/Export/Filter/ScopeFilter.php diff --git a/src/Bundle/ChillCalendarBundle/Export/Filter/AgentFilter.php b/src/Bundle/ChillCalendarBundle/Export/Filter/AgentFilter.php new file mode 100644 index 000000000..5c16d0728 --- /dev/null +++ b/src/Bundle/ChillCalendarBundle/Export/Filter/AgentFilter.php @@ -0,0 +1,79 @@ +userRender = $userRender; + } + + public function buildForm(FormBuilderInterface $builder) + { + $builder->add('accepted_agents', EntityType::class, [ + 'class' => User::class, + 'choice_label' => function (User $u) { + return $this->userRender->renderString($u, []); + }, + 'multiple' => true, + 'expanded' => true + ]); + + } + + public function getTitle(): string + { + return 'Filter by agent'; + } + + public function describeAction($data, $format = 'string'): array + { + $users = []; + + foreach ($data['accepted_agents'] as $r) { + $users[] = $r; + } + + return [ + 'Filtered by agent: only %agents%', [ + '%agents' => implode(", ou ", $users) + ]]; + } + + public function addRole() + { + return null; + } + + public function alterQuery(QueryBuilder $qb, $data) + { + $where = $qb->getDQLPart('where'); + $clause = $qb->expr()->in('cal.user', ':agents'); + + if ($where instanceof Andx) { + $where->add($clause); + } else { + $where = $qb->expr()->andX($clause); + } + + $qb->add('where', $where); + $qb->setParameter('agents', $data['accepted_agents']); + } + + public function applyOn(): string + { + return Declarations::CALENDAR_TYPE; + } +} \ No newline at end of file diff --git a/src/Bundle/ChillCalendarBundle/Export/Filter/BetweenDatesFilter.php b/src/Bundle/ChillCalendarBundle/Export/Filter/BetweenDatesFilter.php new file mode 100644 index 000000000..a23c76d98 --- /dev/null +++ b/src/Bundle/ChillCalendarBundle/Export/Filter/BetweenDatesFilter.php @@ -0,0 +1,70 @@ +add('date_from', ChillDateType::class, [ + 'data' => new \DateTime(), + ]) + ->add('date_to', ChillDateType::class, [ + 'data' => new \DateTime(), + ]) + ; + } + + public function getTitle(): string + { + return 'Filter by appointments between certain dates'; + } + + public function describeAction($data, $format = 'string'): array + { + return ['Filtered by appointments between %dateFrom% and %dateTo%', [ + '%dateFrom%' => $data['date_from']->format('d-m-Y'), + '%dateTo%' => $data['date_to']->format('d-m-Y'), + ]]; + } + + public function addRole() + { + return null; + } + + public function alterQuery(QueryBuilder $qb, $data) + { + $where = $qb->getDQLPart('where'); + + $clause = $qb->expr()->andX( + $qb->expr()->gte('cal.startDate', ':dateFrom'), + $qb->expr()->lte('cal.endDate', ':dateTo') + ); + + if ($where instanceof Andx) { + $where->add($clause); + } else { + $where = $qb->expr()->andX($clause); + } + + $qb->add('where', $where); + $qb->setParameter('dateFrom', $data['date_from']); + // modify dateTo so that entire day is also taken into account up until the beginning of the next day. + $qb->setParameter('dateTo', $data['date_to']->modify('+1 day')); + } + + public function applyOn(): string + { + return Declarations::CALENDAR_TYPE; + } +} \ No newline at end of file diff --git a/src/Bundle/ChillCalendarBundle/Export/Filter/JobFilter.php b/src/Bundle/ChillCalendarBundle/Export/Filter/JobFilter.php new file mode 100644 index 000000000..42e03e239 --- /dev/null +++ b/src/Bundle/ChillCalendarBundle/Export/Filter/JobFilter.php @@ -0,0 +1,99 @@ +translator = $translator; + $this->translatableStringHelper = $translatableStringHelper; + } + + public function buildForm(FormBuilderInterface $builder) + { + $builder->add('job', EntityType::class, [ + 'class' => UserJob::class, + 'choice_label' => function (UserJob $j) { + return $this->translatableStringHelper->localize( + $j->getLabel() + ); + }, + 'multiple' => true, + 'expanded' => true + ]); + } + + public function describeAction($data, $format = 'string'): array + { + $userJobs = []; + + foreach ($data['job'] as $j) { + $userJobs[] = $this->translatableStringHelper->localize( + $j->getLabel()); + } + + return ['Filtered by agent job: only %jobs%', [ + '%jobs%' => implode(', ou ', $userJobs) + ]]; + } + + public function addRole() + { + return null; + } + + public function alterQuery(QueryBuilder $qb, $data) + { + $qb->join('cal.user', 'u'); + + $where = $qb->getDQLPart('where'); + $clause = $qb->expr()->in('u.userJob', ':job'); + + if ($where instanceof Andx) { + $where->add($clause); + } else { + $where = $qb->expr()->andX($clause); + } + + $qb->add('where', $where); + $qb->setParameter('job', $data['job']); + } + + public function applyOn(): string + { + return Declarations::CALENDAR_TYPE; + } + + + public function getTitle(): string + { + return 'Filter by agent job'; + } +} diff --git a/src/Bundle/ChillCalendarBundle/Export/Filter/ScopeFilter.php b/src/Bundle/ChillCalendarBundle/Export/Filter/ScopeFilter.php new file mode 100644 index 000000000..c3fc7b1e4 --- /dev/null +++ b/src/Bundle/ChillCalendarBundle/Export/Filter/ScopeFilter.php @@ -0,0 +1,99 @@ +translator = $translator; + $this->translatableStringHelper = $translatableStringHelper; + } + + public function buildForm(FormBuilderInterface $builder) + { + $builder->add('scope', EntityType::class, [ + 'class' => Scope::class, + 'choice_label' => function (Scope $s) { + return $this->translatableStringHelper->localize( + $s->getName() + ); + }, + 'multiple' => true, + 'expanded' => true + ]); + } + + public function describeAction($data, $format = 'string') + { + $scopes = []; + + foreach ($data['scope'] as $s) { + $scopes[] = $this->translatableStringHelper->localize( + $s->getName()); + } + + return ['Filtered by agent scope: only %scopes%', [ + '%scopes%' => implode(', ou ', $scopes) + ]]; + } + + public function addRole() + { + return null; + } + + public function alterQuery(QueryBuilder $qb, $data) + { + $qb->join('cal.user', 'u'); + + $where = $qb->getDQLPart('where'); + $clause = $qb->expr()->in('u.mainScope', ':scope'); + + if ($where instanceof Andx) { + $where->add($clause); + } else { + $where = $qb->expr()->andX($clause); + } + + $qb->add('where', $where); + $qb->setParameter('scope', $data['scope']); + } + + public function applyOn() + { + return Declarations::CALENDAR_TYPE; + } + + + public function getTitle() + { + return 'Filter by agent scope'; + } +} \ 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 ef0b43089..834cdfa78 100644 --- a/src/Bundle/ChillCalendarBundle/Resources/config/services/exports.yaml +++ b/src/Bundle/ChillCalendarBundle/Resources/config/services/exports.yaml @@ -9,8 +9,45 @@ services: - { name: chill.export, alias: count_appointments } chill.calendar.export.average_duration_appointments: - class: Chill\CalendarBundle\Export\Export\StatAppointmentDuration + class: Chill\CalendarBundle\Export\Export\StatAppointmentAvgDuration autowire: true autoconfigure: true tags: - - { name: chill.export, alias: average_duration_appointments } \ No newline at end of file + - { name: chill.export, alias: average_duration_appointments } + + chill.calendar.export.sum_duration_appointments: + class: Chill\CalendarBundle\Export\Export\StatAppointmentSumDuration + autowire: true + autoconfigure: true + tags: + - { name: chill.export, alias: sum_duration_appointments } + + ## Filters + + chill.calendar.export.agent_filter: + class: Chill\CalendarBundle\Export\Filter\AgentFilter + autowire: true + autoconfigure: true + tags: + - { name: chill.export_filter, alias: agent_filter } + + chill.calendar.export.job_filter: + class: Chill\CalendarBundle\Export\Filter\JobFilter + autowire: true + autoconfigure: true + tags: + - { name: chill.export_filter, alias: job_filter } + + chill.calendar.export.scope_filter: + class: Chill\CalendarBundle\Export\Filter\ScopeFilter + autowire: true + autoconfigure: true + tags: + - { name: chill.export_filter, alias: scope_filter } + + chill.calendar.export.between_dates_filter: + class: Chill\CalendarBundle\Export\Filter\BetweenDatesFilter + autowire: true + autoconfigure: true + tags: + - { name: chill.export_filter, alias: between_dates_filter } \ 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 353b2e851..a1c848ad7 100644 --- a/src/Bundle/ChillCalendarBundle/translations/messages.fr.yml +++ b/src/Bundle/ChillCalendarBundle/translations/messages.fr.yml @@ -42,5 +42,18 @@ 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 + +Sum of appointment durations: Somme des durées des rendez-vous +Get the sum of appointment durations according to various filters: Calculer la somme des durées des rendez-vous + +'Filtered by agent: only %agents%': "Filtré par agents: uniquement %agents%" +Filter by agent: Filtrer par agents +Filter by agent job: Filtrer par métiers des agents +'Filtered by agent job: only %jobs%': 'Filtré par métiers des agents: uniquement les %jobs%' +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%'