mirror of
https://gitlab.com/Chill-Projet/chill-bundles.git
synced 2025-06-07 18:44:08 +00:00
add average duration indicator calendar
This commit is contained in:
parent
3c5d533c58
commit
dfbaaef778
@ -0,0 +1,103 @@
|
||||
<?php
|
||||
|
||||
namespace Chill\CalendarBundle\Export\Export;
|
||||
|
||||
use Chill\CalendarBundle\Export\Declarations;
|
||||
use Chill\CalendarBundle\Repository\CalendarRepository;
|
||||
use Chill\MainBundle\Export\ExportInterface;
|
||||
use Chill\MainBundle\Export\FormatterInterface;
|
||||
use Chill\MainBundle\Export\GroupedExportInterface;
|
||||
use Chill\PersonBundle\Security\Authorization\AccompanyingPeriodVoter;
|
||||
use Doctrine\ORM\Query;
|
||||
use Doctrine\ORM\QueryBuilder;
|
||||
use Symfony\Component\Form\FormBuilderInterface;
|
||||
use Symfony\Component\Security\Core\Role\Role;
|
||||
|
||||
class StatAppointmentDuration implements ExportInterface, GroupedExportInterface
|
||||
{
|
||||
|
||||
private CalendarRepository $calendarRepository;
|
||||
|
||||
public function __construct(
|
||||
CalendarRepository $calendarRepository
|
||||
) {
|
||||
$this->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';
|
||||
}
|
||||
|
||||
}
|
@ -6,4 +6,11 @@ services:
|
||||
autowire: true
|
||||
autoconfigure: true
|
||||
tags:
|
||||
- { name: chill.export, alias: count_appointments }
|
||||
- { 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 }
|
@ -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
|
||||
|
Loading…
x
Reference in New Issue
Block a user