mirror of
https://gitlab.com/Chill-Projet/chill-bundles.git
synced 2025-06-12 13:24:25 +00:00
first indicator for calendar exports
This commit is contained in:
parent
5060906591
commit
3c5d533c58
@ -32,6 +32,7 @@ class ChillCalendarExtension extends Extension implements PrependExtensionInterf
|
|||||||
|
|
||||||
$loader = new Loader\YamlFileLoader($container, new FileLocator(__DIR__ . '/../Resources/config'));
|
$loader = new Loader\YamlFileLoader($container, new FileLocator(__DIR__ . '/../Resources/config'));
|
||||||
$loader->load('services.yml');
|
$loader->load('services.yml');
|
||||||
|
$loader->load('services/exports.yaml');
|
||||||
$loader->load('services/controller.yml');
|
$loader->load('services/controller.yml');
|
||||||
$loader->load('services/fixtures.yml');
|
$loader->load('services/fixtures.yml');
|
||||||
$loader->load('services/form.yml');
|
$loader->load('services/form.yml');
|
||||||
|
20
src/Bundle/ChillCalendarBundle/Export/Declarations.php
Normal file
20
src/Bundle/ChillCalendarBundle/Export/Declarations.php
Normal file
@ -0,0 +1,20 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Chill is a software for social workers
|
||||||
|
*
|
||||||
|
* For the full copyright and license information, please view
|
||||||
|
* the LICENSE file that was distributed with this source code.
|
||||||
|
*/
|
||||||
|
|
||||||
|
declare(strict_types=1);
|
||||||
|
|
||||||
|
namespace Chill\CalendarBundle\Export;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* This class declare constants used for the export framework.
|
||||||
|
*/
|
||||||
|
abstract class Declarations
|
||||||
|
{
|
||||||
|
public const CALENDAR_TYPE = 'calendar';
|
||||||
|
}
|
@ -0,0 +1,111 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace Chill\CalendarBundle\Export\Export;
|
||||||
|
|
||||||
|
use Chill\CalendarBundle\Repository\CalendarRepository;
|
||||||
|
use Chill\MainBundle\Export\ExportInterface;
|
||||||
|
use Chill\MainBundle\Export\FormatterInterface;
|
||||||
|
use Chill\MainBundle\Export\GroupedExportInterface;
|
||||||
|
use Chill\CalendarBundle\Export\Declarations;
|
||||||
|
use Chill\PersonBundle\Security\Authorization\PersonVoter;
|
||||||
|
use Doctrine\ORM\AbstractQuery;
|
||||||
|
use Doctrine\ORM\QueryBuilder;
|
||||||
|
use Symfony\Component\Form\FormBuilderInterface;
|
||||||
|
use Symfony\Component\Process\Exception\LogicException;
|
||||||
|
use Symfony\Component\Security\Core\Role\Role;
|
||||||
|
|
||||||
|
class CountAppointments implements ExportInterface, GroupedExportInterface
|
||||||
|
{
|
||||||
|
|
||||||
|
private CalendarRepository $calendarRepository;
|
||||||
|
|
||||||
|
public function __construct(CalendarRepository $calendarRepository)
|
||||||
|
{
|
||||||
|
$this->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';
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -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 }
|
@ -38,3 +38,7 @@ crud:
|
|||||||
add_new: Ajouter un nouveau
|
add_new: Ajouter un nouveau
|
||||||
title_new: Nouveau motif d'annulation
|
title_new: Nouveau motif d'annulation
|
||||||
title_edit: Modifier le motif d'annulation
|
title_edit: Modifier le motif d'annulation
|
||||||
|
|
||||||
|
# exports
|
||||||
|
Exports of calendar: Exports des rendez-vous
|
||||||
|
Count appointments: Nombre des rendez-vous
|
||||||
|
Loading…
x
Reference in New Issue
Block a user