mirror of
https://gitlab.com/Chill-Projet/chill-bundles.git
synced 2025-08-20 22:53:49 +00:00
exports: DurationAggregator with approximative(*) date interval
(*) for more precise, we need dql interval function
This commit is contained in:
@@ -10,6 +10,7 @@ use Doctrine\ORM\QueryBuilder;
|
||||
use Symfony\Bridge\Doctrine\Form\Type\EntityType;
|
||||
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
|
||||
@@ -22,23 +23,33 @@ use Symfony\Component\Form\FormBuilderInterface;
|
||||
*/
|
||||
class DurationAggregator implements AggregatorInterface
|
||||
{
|
||||
private TranslatorInterface $translator;
|
||||
|
||||
public function __construct(TranslatorInterface $translator)
|
||||
{
|
||||
$this->translator = $translator;
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
public function getLabels($key, array $values, $data)
|
||||
{
|
||||
dump($key, $values, $data);
|
||||
|
||||
return function ($value) use ($data): string {
|
||||
|
||||
if ($value === '_header') {
|
||||
return 'Duration';
|
||||
return $this->translator->trans('Rounded month duration');
|
||||
}
|
||||
|
||||
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
|
||||
// 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('EXTRACT(month FROM acp.openingDate) AS duration_aggregator')
|
||||
//->addSelect("DATE_SUB(acp.openingDate, 6, 'day') AS duration_aggregator")
|
||||
|
Reference in New Issue
Block a user