diff --git a/src/Bundle/ChillCalendarBundle/Export/Export/StatAppointmentDuration.php b/src/Bundle/ChillCalendarBundle/Export/Export/StatAppointmentAvgDuration.php similarity index 96% rename from src/Bundle/ChillCalendarBundle/Export/Export/StatAppointmentDuration.php rename to src/Bundle/ChillCalendarBundle/Export/Export/StatAppointmentAvgDuration.php index c46aaaf0c..854172a2a 100644 --- a/src/Bundle/ChillCalendarBundle/Export/Export/StatAppointmentDuration.php +++ b/src/Bundle/ChillCalendarBundle/Export/Export/StatAppointmentAvgDuration.php @@ -13,7 +13,7 @@ use Doctrine\ORM\QueryBuilder; use Symfony\Component\Form\FormBuilderInterface; use Symfony\Component\Security\Core\Role\Role; -class StatAppointmentDuration implements ExportInterface, GroupedExportInterface +class StatAppointmentAvgDuration implements ExportInterface, GroupedExportInterface { private CalendarRepository $calendarRepository; diff --git a/src/Bundle/ChillCalendarBundle/Export/Export/StatAppointmentSumDuration.php b/src/Bundle/ChillCalendarBundle/Export/Export/StatAppointmentSumDuration.php new file mode 100644 index 000000000..0e362d766 --- /dev/null +++ b/src/Bundle/ChillCalendarBundle/Export/Export/StatAppointmentSumDuration.php @@ -0,0 +1,102 @@ +calendarRepository = $calendarRepository; + } + + public function buildForm(FormBuilderInterface $builder): void + { + // no form needed + } + + public function getTitle(): string + { + return 'Sum of appointment durations'; + } + + public function getAllowedFormattersTypes(): array + { + return [FormatterInterface::TYPE_TABULAR]; + } + + public function getDescription(): string + { + return 'Get the sum of appointment durations 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('SUM(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