exports: DurationAggregator with approximative(*) date interval

(*) for more precise, we need dql interval function
This commit is contained in:
Mathieu Jaumotte 2022-08-25 13:06:10 +02:00
parent e1ec2dc25c
commit f5baa2c152
2 changed files with 25 additions and 7 deletions

View File

@ -10,6 +10,7 @@ use Doctrine\ORM\QueryBuilder;
use Symfony\Bridge\Doctrine\Form\Type\EntityType; use Symfony\Bridge\Doctrine\Form\Type\EntityType;
use Symfony\Component\Form\Extension\Core\Type\ChoiceType; use Symfony\Component\Form\Extension\Core\Type\ChoiceType;
use Symfony\Component\Form\FormBuilderInterface; use Symfony\Component\Form\FormBuilderInterface;
use Symfony\Contracts\Translation\TranslatorInterface;
/** /**
* Les regroupements seront un nombre de mois, arrondi à l'unité la plus proche (donc * Les regroupements seront un nombre de mois, arrondi à l'unité la plus proche (donc
@ -22,23 +23,33 @@ use Symfony\Component\Form\FormBuilderInterface;
*/ */
class DurationAggregator implements AggregatorInterface class DurationAggregator implements AggregatorInterface
{ {
private TranslatorInterface $translator;
public function __construct(TranslatorInterface $translator)
{
$this->translator = $translator;
}
/** /**
* @inheritDoc * @inheritDoc
*/ */
public function getLabels($key, array $values, $data) public function getLabels($key, array $values, $data)
{ {
dump($key, $values, $data);
return function ($value) use ($data): string { return function ($value) use ($data): string {
if ($value === '_header') { if ($value === '_header') {
return 'Duration'; return $this->translator->trans('Rounded month duration');
} }
if ($value === null) { if ($value === null) {
return 'current'; // when closingDate is null return $this->translator->trans('current duration'); // when closingDate is null
} }
return $value;
//sprintf("%02d", $value) . ' days'; if ($value === 0) {
return $this->translator->trans("duration 0 month");
}
return ''. $value . $this->translator->trans(' months');
}; };
} }
@ -81,7 +92,10 @@ class DurationAggregator implements AggregatorInterface
{ {
$qb $qb
// OUI // OUI
->addSelect('(acp.closingDate - acp.openingDate) AS duration_aggregator') ->addSelect('
(acp.closingDate - acp.openingDate +15) *12/365
AS duration_aggregator'
)
//->addSelect('DATE_DIFF(acp.closingDate, acp.openingDate) AS duration_aggregator') //->addSelect('DATE_DIFF(acp.closingDate, acp.openingDate) AS duration_aggregator')
//->addSelect('EXTRACT(month FROM acp.openingDate) AS duration_aggregator') //->addSelect('EXTRACT(month FROM acp.openingDate) AS duration_aggregator')
//->addSelect("DATE_SUB(acp.openingDate, 6, 'day') AS duration_aggregator") //->addSelect("DATE_SUB(acp.openingDate, 6, 'day') AS duration_aggregator")

View File

@ -570,6 +570,10 @@ Group by number of children: Grouper les ménages par nombre d'enfants
## persons aggregators ## persons aggregators
Group by duration: Grouper par durée du parcours Group by duration: Grouper par durée du parcours
Rounded month duration: Durée en mois (arrondie)
current duration: en cours
duration 0 month: 0 mois (<15 jours)
' months': ' mois'
Group people by nationality: Grouper les personnes par nationalités Group people by nationality: Grouper les personnes par nationalités
Group by level: Grouper par niveau Group by level: Grouper par niveau
Group by continents: Grouper par continent Group by continents: Grouper par continent