exports: cleaning code

This commit is contained in:
Mathieu Jaumotte 2022-09-01 10:11:53 +02:00
parent cae9dddac4
commit 374ad43df6
4 changed files with 15 additions and 62 deletions

View File

@ -96,7 +96,7 @@ class DateAggregator implements AggregatorInterface
$fmt = 'IW'; break;
case 'year':
$fmt = 'YYYY'; $order = 'DESC'; break;
$fmt = 'YYYY'; $order = 'DESC'; break; // order DESC does not works !
default:
throw new RuntimeException(sprintf("The frequency data '%s' is invalid.", $data['frequency']));

View File

@ -12,16 +12,7 @@ use Symfony\Component\Form\Extension\Core\Type\ChoiceType;
use Symfony\Component\Form\FormBuilderInterface;
use Symfony\Contracts\Translation\TranslatorInterface;
/**
* 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
final class DurationAggregator implements AggregatorInterface
{
private TranslatorInterface $translator;
@ -49,7 +40,7 @@ class DurationAggregator implements AggregatorInterface
return $this->translator->trans("duration 0 month");
}
return ''. $value . $this->translator->trans(' months');
return $value . $this->translator->trans(' months');
};
}
@ -90,44 +81,15 @@ class DurationAggregator implements AggregatorInterface
*/
public function alterQuery(QueryBuilder $qb, $data)
{
$qb
// OUI
->addSelect('
(acp.closingDate - acp.openingDate +15) *12/365
AS duration_aggregator'
)
//->addSelect('DATE_DIFF(acp.closingDate, acp.openingDate) AS duration_aggregator')
//->addSelect('EXTRACT(month FROM acp.openingDate) AS duration_aggregator')
//->addSelect("DATE_SUB(acp.openingDate, 6, 'day') AS duration_aggregator")
$qb->addSelect('
(acp.closingDate - acp.openingDate +15) *12/365
AS duration_aggregator'
);
// TODO adapter la fonction extract pour l'utiliser avec des intervals: extract(month from interval)
// et ajouter une fonction custom qui calcule les intervals, comme doctrineum/date-interval
// https://packagist.org/packages/doctrineum/date-interval#3.1.0
// (composer fait un conflit de dépendance)
/*
->addSelect("
EXTRACT(
month FROM
DATE_INTERVAL(acp.closingDate, acp.openingDate)
)
AS duration_aggregator")
*/
// NON
//->addSelect("BETWEEN acp.openingDate AND acp.closingDate AS duration_aggregator")
//->addSelect("EXTRACT(month FROM DATE_SUB(acp.openingDate, 6, 'day')) AS duration_aggregator")
//->addSelect('EXTRACT(month FROM DATE_DIFF(acp.closingDate, acp.openingDate)) AS duration_aggregator')
/*
->addSelect('
( CASE
WHEN EXTRACT(day FROM DATE_DIFF(acp.closingDate, acp.openingDate)) > 15
THEN EXTRACT(month FROM DATE_DIFF(acp.closingDate, acp.openingDate)) +1
ELSE EXTRACT(month FROM DATE_DIFF(acp.closingDate, acp.openingDate))
END ) AS duration_aggregator
')
*/
;
// TODO Pour avoir un interval plus précis (nécessaire ?):
// adapter la fonction extract pour pouvoir l'utiliser avec des intervals: extract(month from interval)
// et ajouter une fonction custom qui calcule plus précisément les intervals, comme doctrineum/date-interval
// https://packagist.org/packages/doctrineum/date-interval#3.1.0 (mais composer fait un conflit de dépendance)
$groupBy = $qb->getDQLPart('groupBy');

View File

@ -8,14 +8,7 @@ use Doctrine\ORM\QueryBuilder;
use Symfony\Component\Form\FormBuilderInterface;
use Symfony\Contracts\Translation\TranslatorInterface;
/**
* les regroupements suivants seront effecturés:
* - le demandeur est un usager concerné
* - le demander est un usager, mais non concerné
* - le demandeur est un tiers
* - le parcours ne comporte pas de demandeur
*/
class RequestorAggregator implements AggregatorInterface
final class RequestorAggregator implements AggregatorInterface
{
private TranslatorInterface $translator;
@ -43,9 +36,7 @@ class RequestorAggregator implements AggregatorInterface
*/
public function getQueryKeys($data): array
{
return [
'requestor_aggregator'
];
return ['requestor_aggregator'];
}
/**
@ -107,7 +98,7 @@ class RequestorAggregator implements AggregatorInterface
$qb->groupBy('requestor_aggregator');
}
// TODO 'order by' ne fonctionne pas, l'ordre n'est pas terrible
// TODO 'order by' does not works !
}
/**

View File

@ -11,7 +11,7 @@ use Symfony\Component\Form\Extension\Core\Type\ChoiceType;
use Symfony\Component\Form\FormBuilderInterface;
use Symfony\Contracts\Translation\TranslatorInterface;
class RequestorFilter implements FilterInterface
final class RequestorFilter implements FilterInterface
{
private const REQUESTOR_CHOICES = [