mirror of
https://gitlab.com/Chill-Projet/chill-bundles.git
synced 2025-08-20 22:53:49 +00:00
exports: DurationAggregator: test qb addSelect for compute date interval
This commit is contained in:
@@ -3,8 +3,12 @@
|
||||
namespace Chill\PersonBundle\Export\Aggregator\AccompanyingCourseAggregators;
|
||||
|
||||
use Chill\MainBundle\Export\AggregatorInterface;
|
||||
use Chill\PersonBundle\Entity\AccompanyingPeriod;
|
||||
use Chill\PersonBundle\Export\Declarations;
|
||||
use Doctrine\ORM\EntityRepository;
|
||||
use Doctrine\ORM\QueryBuilder;
|
||||
use Symfony\Bridge\Doctrine\Form\Type\EntityType;
|
||||
use Symfony\Component\Form\Extension\Core\Type\ChoiceType;
|
||||
use Symfony\Component\Form\FormBuilderInterface;
|
||||
|
||||
/**
|
||||
@@ -24,16 +28,17 @@ class DurationAggregator implements AggregatorInterface
|
||||
*/
|
||||
public function getLabels($key, array $values, $data)
|
||||
{
|
||||
return function ($value): string {
|
||||
switch ($value) {
|
||||
dump($key, $values, $data);
|
||||
|
||||
case '_header':
|
||||
return 'Duration';
|
||||
|
||||
|
||||
default:
|
||||
throw new \LogicException(sprintf('The value %s is not valid', $value));
|
||||
return function ($value) use ($data): string {
|
||||
if ($value === '_header') {
|
||||
return 'Duration';
|
||||
}
|
||||
if ($value === null) {
|
||||
return 'current'; // when closingDate is null
|
||||
}
|
||||
return $value;
|
||||
//sprintf("%02d", $value) . ' days';
|
||||
};
|
||||
}
|
||||
|
||||
@@ -75,7 +80,37 @@ class DurationAggregator implements AggregatorInterface
|
||||
public function alterQuery(QueryBuilder $qb, $data)
|
||||
{
|
||||
$qb
|
||||
// OUI
|
||||
->addSelect('(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("DATE_SUB(acp.openingDate, 6, 'day') 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
|
||||
')
|
||||
*/
|
||||
;
|
||||
|
||||
$groupBy = $qb->getDQLPart('groupBy');
|
||||
|
Reference in New Issue
Block a user