mirror of
https://gitlab.com/Chill-Projet/chill-bundles.git
synced 2025-08-20 14:43:49 +00:00
Merge branch '111_exports' into social_action_exports
This commit is contained in:
@@ -0,0 +1,148 @@
|
||||
<?php
|
||||
|
||||
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;
|
||||
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
|
||||
{
|
||||
private TranslatorInterface $translator;
|
||||
|
||||
public function __construct(TranslatorInterface $translator)
|
||||
{
|
||||
$this->translator = $translator;
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
public function getLabels($key, array $values, $data)
|
||||
{
|
||||
return function ($value) use ($data): string {
|
||||
|
||||
if ($value === '_header') {
|
||||
return $this->translator->trans('Rounded month duration');
|
||||
}
|
||||
|
||||
if ($value === null) {
|
||||
return $this->translator->trans('current duration'); // when closingDate is null
|
||||
}
|
||||
|
||||
if ($value === 0) {
|
||||
return $this->translator->trans("duration 0 month");
|
||||
}
|
||||
|
||||
return ''. $value . $this->translator->trans(' months');
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* @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
|
||||
// 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")
|
||||
|
||||
// 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');
|
||||
|
||||
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;
|
||||
}
|
||||
}
|
@@ -2,13 +2,14 @@
|
||||
|
||||
namespace Chill\PersonBundle\Export\Filter\AccompanyingCourseFilters;
|
||||
|
||||
use Chill\MainBundle\Entity\GeographicalUnit;
|
||||
use Chill\MainBundle\Export\FilterInterface;
|
||||
use Chill\MainBundle\Form\Type\ChillDateType;
|
||||
use Chill\PersonBundle\Export\Declarations;
|
||||
use Doctrine\DBAL\Types\Types;
|
||||
use Doctrine\ORM\Query\Expr\Andx;
|
||||
use Doctrine\ORM\QueryBuilder;
|
||||
use Symfony\Component\Form\Extension\Core\Type\ChoiceType;
|
||||
use Symfony\Bridge\Doctrine\Form\Type\EntityType;
|
||||
use Symfony\Component\Form\FormBuilderInterface;
|
||||
|
||||
/**
|
||||
@@ -23,12 +24,6 @@ use Symfony\Component\Form\FormBuilderInterface;
|
||||
*/
|
||||
class GeographicalUnitStatFilter implements FilterInterface
|
||||
{
|
||||
|
||||
private const LOCTYPE = [
|
||||
'center' => 'center',
|
||||
// TODO not yet implemented: https://gitlab.com/champs-libres/departement-de-la-vendee/chill/-/issues/626
|
||||
];
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
@@ -38,9 +33,12 @@ class GeographicalUnitStatFilter implements FilterInterface
|
||||
->add('date', ChillDateType::class, [
|
||||
'data' => new \DateTime(),
|
||||
])
|
||||
->add('accepted_loctype', ChoiceType::class, [
|
||||
'choices' => self::LOCTYPE,
|
||||
'multiple' => false,
|
||||
->add('accepted_loctype', EntityType::class, [
|
||||
'class' => GeographicalUnit::class,
|
||||
'choice_label' => function (GeographicalUnit $u) {
|
||||
return $u->getUnitName();
|
||||
},
|
||||
'multiple' => true,
|
||||
'expanded' => true,
|
||||
])
|
||||
;
|
||||
|
Reference in New Issue
Block a user