mirror of
https://gitlab.com/Chill-Projet/chill-bundles.git
synced 2025-07-01 22:46:13 +00:00
exports: add on_date parameter on Composition Filter/Aggregator
This commit is contained in:
parent
c693dfde66
commit
bc5d610f80
@ -3,9 +3,12 @@
|
||||
namespace Chill\PersonBundle\Export\Aggregator\HouseholdAggregators;
|
||||
|
||||
use Chill\MainBundle\Export\AggregatorInterface;
|
||||
use Chill\MainBundle\Form\Type\ChillDateType;
|
||||
use Chill\MainBundle\Templating\TranslatableStringHelper;
|
||||
use Chill\PersonBundle\Export\Declarations;
|
||||
use Chill\PersonBundle\Repository\Household\HouseholdCompositionTypeRepository;
|
||||
use Doctrine\DBAL\Types\Types;
|
||||
use Doctrine\ORM\Query\Expr\Andx;
|
||||
use Doctrine\ORM\QueryBuilder;
|
||||
use Symfony\Component\Form\FormBuilderInterface;
|
||||
|
||||
@ -54,7 +57,9 @@ class CompositionAggregator implements AggregatorInterface
|
||||
*/
|
||||
public function buildForm(FormBuilderInterface $builder)
|
||||
{
|
||||
// TODO: Implement buildForm() method.
|
||||
$builder->add('on_date', ChillDateType::class, [
|
||||
'data' => new \DateTime('now'),
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -87,6 +92,26 @@ class CompositionAggregator implements AggregatorInterface
|
||||
} else {
|
||||
$qb->groupBy('composition_aggregator');
|
||||
}
|
||||
|
||||
// add date in where clause
|
||||
$where = $qb->getDQLPart('where');
|
||||
|
||||
$clause = $qb->expr()->andX(
|
||||
$qb->expr()->lte('composition.startDate', ':ondate'),
|
||||
$qb->expr()->orX(
|
||||
$qb->expr()->gt('composition.endDate', ':ondate'),
|
||||
$qb->expr()->isNull('composition.endDate')
|
||||
)
|
||||
);
|
||||
|
||||
if ($where instanceof Andx) {
|
||||
$where->add($clause);
|
||||
} else {
|
||||
$where = $qb->expr()->andX($clause);
|
||||
}
|
||||
|
||||
$qb->add('where', $where);
|
||||
$qb->setParameter('ondate', $data['on_date'], Types::DATE_MUTABLE);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -3,9 +3,11 @@
|
||||
namespace Chill\PersonBundle\Export\Filter\HouseholdFilters;
|
||||
|
||||
use Chill\MainBundle\Export\FilterInterface;
|
||||
use Chill\MainBundle\Form\Type\ChillDateType;
|
||||
use Chill\MainBundle\Templating\TranslatableStringHelper;
|
||||
use Chill\PersonBundle\Entity\Household\HouseholdCompositionType;
|
||||
use Chill\PersonBundle\Export\Declarations;
|
||||
use Doctrine\DBAL\Types\Types;
|
||||
use Doctrine\ORM\Query\Expr\Andx;
|
||||
use Doctrine\ORM\QueryBuilder;
|
||||
use Symfony\Bridge\Doctrine\Form\Type\EntityType;
|
||||
@ -26,16 +28,21 @@ class CompositionFilter implements FilterInterface
|
||||
*/
|
||||
public function buildForm(FormBuilderInterface $builder)
|
||||
{
|
||||
$builder->add('accepted_composition', EntityType::class, [
|
||||
'class' => HouseholdCompositionType::class,
|
||||
'choice_label' => function (HouseholdCompositionType $type) {
|
||||
return $this->translatableStringHelper->localize(
|
||||
$type->getLabel()
|
||||
);
|
||||
},
|
||||
'multiple' => true,
|
||||
'expanded' => true,
|
||||
]);
|
||||
$builder
|
||||
->add('accepted_composition', EntityType::class, [
|
||||
'class' => HouseholdCompositionType::class,
|
||||
'choice_label' => function (HouseholdCompositionType $type) {
|
||||
return $this->translatableStringHelper->localize(
|
||||
$type->getLabel()
|
||||
);
|
||||
},
|
||||
'multiple' => true,
|
||||
'expanded' => true,
|
||||
])
|
||||
->add('on_date', ChillDateType::class, [
|
||||
'data' => new \DateTime('now'),
|
||||
])
|
||||
;
|
||||
}
|
||||
|
||||
/**
|
||||
@ -59,8 +66,9 @@ class CompositionFilter implements FilterInterface
|
||||
);
|
||||
}
|
||||
|
||||
return ['Filtered by composition: only %compositions%', [
|
||||
'%compositions%' => implode(", ou ", $compositions)
|
||||
return ['Filtered by composition: only %compositions% on %ondate%', [
|
||||
'%compositions%' => implode(", ou ", $compositions),
|
||||
'%ondate%' => $data['on_date']->format('d-m-Y')
|
||||
]];
|
||||
}
|
||||
|
||||
@ -79,7 +87,16 @@ class CompositionFilter implements FilterInterface
|
||||
{
|
||||
$where = $qb->getDQLPart('where');
|
||||
|
||||
$clause = $qb->expr()->in('composition.householdCompositionType', ':compositions');
|
||||
$clause = $qb->expr()->andX(
|
||||
$qb->expr()->in('composition.householdCompositionType', ':compositions'),
|
||||
$qb->expr()->andX(
|
||||
$qb->expr()->lte('composition.startDate', ':ondate'),
|
||||
$qb->expr()->orX(
|
||||
$qb->expr()->gt('composition.endDate', ':ondate'),
|
||||
$qb->expr()->isNull('composition.endDate')
|
||||
)
|
||||
)
|
||||
);
|
||||
|
||||
if ($where instanceof Andx) {
|
||||
$where->add($clause);
|
||||
@ -89,6 +106,7 @@ class CompositionFilter implements FilterInterface
|
||||
|
||||
$qb->add('where', $where);
|
||||
$qb->setParameter('compositions', $data['accepted_composition']);
|
||||
$qb->setParameter('ondate', $data['on_date'], Types::DATE_MUTABLE);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -532,7 +532,7 @@ is not specified: La date d'échéance n'est pas spécifiée
|
||||
|
||||
Filter by composition: Filtrer par composition familiale
|
||||
Accepted composition: Composition familiale
|
||||
"Filtered by composition: only %compositions%": "Filtré par composition familiale: uniquement %compositions%"
|
||||
"Filtered by composition: only %compositions% on %ondate%": "Filtré par composition familiale: uniquement %compositions%, en date du %ondate%"
|
||||
Group by composition: Grouper par composition familiale
|
||||
|
||||
## aggregators
|
||||
|
Loading…
x
Reference in New Issue
Block a user