exports: add new duration aggregator (wip)

This commit is contained in:
Mathieu Jaumotte 2022-08-09 14:30:34 +02:00
parent 7173e4be4a
commit 2c151c2ec9
3 changed files with 107 additions and 0 deletions

View File

@ -0,0 +1,99 @@
<?php
namespace Chill\PersonBundle\Export\Aggregator\AccompanyingCourseAggregators;
use Chill\MainBundle\Export\AggregatorInterface;
use Chill\PersonBundle\Export\Declarations;
use Doctrine\ORM\QueryBuilder;
use Symfony\Component\Form\FormBuilderInterface;
/**
* Les regroupements seront un nombre de mois, arrondi à l'unité la plus proche (donc
* - au dela de 15 jours => 1 mois,
* - jusqu'à 45 jours => 1 mois,
* 15 | 45 | 75
* --+----o----+----o----+----
* | 30 | 60 |
* etc.)
*/
class DurationAggregator implements AggregatorInterface
{
/**
* @inheritDoc
*/
public function getLabels($key, array $values, $data)
{
return function ($value): string {
switch ($value) {
case '_header':
return 'Duration';
default:
throw new \LogicException(sprintf('The value %s is not valid', $value));
}
};
}
/**
* @inheritDoc
*/
public function getQueryKeys($data): array
{
return ['duration_aggregator'];
}
/**
* @inheritDoc
*/
public function buildForm(FormBuilderInterface $builder)
{
// no form
}
/**
* @inheritDoc
*/
public function getTitle(): string
{
return 'Group by duration';
}
/**
* @inheritDoc
*/
public function addRole()
{
return null;
}
/**
* @inheritDoc
*/
public function alterQuery(QueryBuilder $qb, $data)
{
$qb
->addSelect('(acp.closingDate - acp.openingDate) AS duration_aggregator')
;
$groupBy = $qb->getDQLPart('groupBy');
if (!empty($groupBy)) {
$qb->addGroupBy('duration_aggregator');
} else {
$qb->groupBy('duration_aggregator');
}
$qb->orderBy('duration_aggregator');
}
/**
* @inheritDoc
*/
public function applyOn(): string
{
return Declarations::ACP_TYPE;
}
}

View File

@ -241,3 +241,10 @@ services:
tags:
- { name: chill.export_aggregator, alias: accompanyingcourse_referrer_aggregator }
chill.person.export.aggregator_duration:
class: Chill\PersonBundle\Export\Aggregator\AccompanyingCourseAggregators\DurationAggregator
autowire: true
autoconfigure: true
tags:
- { name: chill.export_aggregator, alias: accompanyingcourse_duration_aggregator }

View File

@ -569,6 +569,7 @@ Group by composition: Grouper les ménages par composition familiale
Group by number of children: Grouper les ménages par nombre d'enfants
## persons aggregators
Group by duration: Grouper par durée du parcours
Group people by nationality: Grouper les personnes par nationalités
Group by level: Grouper par niveau
Group by continents: Grouper par continent