mirror of
https://gitlab.com/Chill-Projet/chill-bundles.git
synced 2025-06-07 18:44:08 +00:00
Fixes: [export] fixes filters by household composition, and apply them on persons directly
This commit is contained in:
parent
826a975fbe
commit
a942a24596
@ -9,20 +9,18 @@ declare(strict_types=1);
|
|||||||
* the LICENSE file that was distributed with this source code.
|
* the LICENSE file that was distributed with this source code.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
namespace Chill\PersonBundle\Export\Aggregator\AccompanyingCourseAggregators;
|
namespace Chill\PersonBundle\Export\Aggregator\PersonAggregators;
|
||||||
|
|
||||||
use Chill\MainBundle\Export\AggregatorInterface;
|
use Chill\MainBundle\Export\AggregatorInterface;
|
||||||
use Chill\MainBundle\Form\Type\ChillDateType;
|
use Chill\MainBundle\Form\Type\ChillDateType;
|
||||||
use Chill\MainBundle\Templating\TranslatableStringHelperInterface;
|
use Chill\MainBundle\Templating\TranslatableStringHelperInterface;
|
||||||
use Chill\PersonBundle\Entity\Household\HouseholdComposition;
|
use Chill\PersonBundle\Entity\Household\HouseholdComposition;
|
||||||
use Chill\PersonBundle\Entity\Household\HouseholdMember;
|
|
||||||
use Chill\PersonBundle\Export\Declarations;
|
use Chill\PersonBundle\Export\Declarations;
|
||||||
use Chill\PersonBundle\Repository\Household\HouseholdCompositionTypeRepositoryInterface;
|
use Chill\PersonBundle\Repository\Household\HouseholdCompositionTypeRepositoryInterface;
|
||||||
use DateTimeImmutable;
|
use DateTimeImmutable;
|
||||||
use Doctrine\ORM\Query\Expr\Join;
|
use Doctrine\ORM\Query\Expr\Join;
|
||||||
use Doctrine\ORM\QueryBuilder;
|
use Doctrine\ORM\QueryBuilder;
|
||||||
use Symfony\Component\Form\FormBuilderInterface;
|
use Symfony\Component\Form\FormBuilderInterface;
|
||||||
use function in_array;
|
|
||||||
|
|
||||||
class ByHouseholdCompositionAggregator implements AggregatorInterface
|
class ByHouseholdCompositionAggregator implements AggregatorInterface
|
||||||
{
|
{
|
||||||
@ -47,30 +45,20 @@ class ByHouseholdCompositionAggregator implements AggregatorInterface
|
|||||||
{
|
{
|
||||||
$p = self::PREFIX;
|
$p = self::PREFIX;
|
||||||
|
|
||||||
if (!in_array('acppart', $qb->getAllAliases(), true)) {
|
|
||||||
$qb->leftJoin('acp.participations', 'acppart');
|
|
||||||
}
|
|
||||||
|
|
||||||
$qb
|
$qb
|
||||||
->leftJoin(
|
->leftJoin(
|
||||||
HouseholdMember::class,
|
'person.householdParticipations',
|
||||||
"{$p}_hm",
|
"{$p}_hm"
|
||||||
Join::WITH,
|
|
||||||
$qb->expr()->orX(
|
|
||||||
$qb->expr()->isNull("{$p}_hm"),
|
|
||||||
$qb->expr()->andX(
|
|
||||||
$qb->expr()->lte("{$p}_hm.startDate", ":{$p}_date"),
|
|
||||||
$qb->expr()->orX(
|
|
||||||
$qb->expr()->isNull("{$p}_hm.endDate"),
|
|
||||||
$qb->expr()->gt("{$p}_hm.endDate", ":{$p}_date")
|
|
||||||
)
|
|
||||||
)
|
|
||||||
)
|
|
||||||
)
|
)
|
||||||
->leftJoin(
|
->leftJoin(
|
||||||
HouseholdComposition::class,
|
HouseholdComposition::class,
|
||||||
"{$p}_compo",
|
"{$p}_compo",
|
||||||
Join::WITH,
|
Join::WITH,
|
||||||
|
$qb->expr()->eq("{$p}_hm.household", "{$p}_compo.household"),
|
||||||
|
)
|
||||||
|
->andWhere("{$p}_hm.startDate <= :{$p}_date AND ({$p}_hm.endDate IS NULL OR {$p}_hm.endDate > :{$p}_date)")
|
||||||
|
->andWhere("{$p}_hm.shareHousehold = 'TRUE'")
|
||||||
|
->andWhere(
|
||||||
$qb->expr()->orX(
|
$qb->expr()->orX(
|
||||||
$qb->expr()->isNull("{$p}_compo"),
|
$qb->expr()->isNull("{$p}_compo"),
|
||||||
$qb->expr()->andX(
|
$qb->expr()->andX(
|
||||||
@ -89,13 +77,13 @@ class ByHouseholdCompositionAggregator implements AggregatorInterface
|
|||||||
|
|
||||||
public function applyOn()
|
public function applyOn()
|
||||||
{
|
{
|
||||||
return Declarations::ACP_TYPE;
|
return Declarations::PERSON_TYPE;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function buildForm(FormBuilderInterface $builder)
|
public function buildForm(FormBuilderInterface $builder)
|
||||||
{
|
{
|
||||||
$builder->add('date_calc', ChillDateType::class, [
|
$builder->add('date_calc', ChillDateType::class, [
|
||||||
'label' => 'export.aggregator.course.by_household_composition.Calc date',
|
'label' => 'export.aggregator.person.by_household_composition.Calc date',
|
||||||
'input_format' => 'datetime_immutable',
|
'input_format' => 'datetime_immutable',
|
||||||
'data' => new DateTimeImmutable('now'),
|
'data' => new DateTimeImmutable('now'),
|
||||||
]);
|
]);
|
||||||
@ -105,7 +93,7 @@ class ByHouseholdCompositionAggregator implements AggregatorInterface
|
|||||||
{
|
{
|
||||||
return function ($value) {
|
return function ($value) {
|
||||||
if ('_header' === $value) {
|
if ('_header' === $value) {
|
||||||
return 'export.aggregator.course.by_household_composition.Household composition';
|
return 'export.aggregator.person.by_household_composition.Household composition';
|
||||||
}
|
}
|
||||||
|
|
||||||
if (null === $value) {
|
if (null === $value) {
|
||||||
@ -127,6 +115,6 @@ class ByHouseholdCompositionAggregator implements AggregatorInterface
|
|||||||
|
|
||||||
public function getTitle()
|
public function getTitle()
|
||||||
{
|
{
|
||||||
return 'export.aggregator.course.by_household_composition.Group course by household composition';
|
return 'export.aggregator.person.by_household_composition.Group course by household composition';
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -100,7 +100,7 @@ class CountPerson implements ExportInterface, GroupedExportInterface
|
|||||||
|
|
||||||
$qb = $this->personRepository->createQueryBuilder('person');
|
$qb = $this->personRepository->createQueryBuilder('person');
|
||||||
|
|
||||||
$qb->select('COUNT(person.id) AS export_result')
|
$qb->select('COUNT(DISTINCT person.id) AS export_result')
|
||||||
->andWhere(
|
->andWhere(
|
||||||
$qb->expr()->exists(
|
$qb->expr()->exists(
|
||||||
'SELECT 1 FROM ' . PersonCenterHistory::class . ' pch WHERE pch.person = person.id AND pch.center IN (:authorized_centers)'
|
'SELECT 1 FROM ' . PersonCenterHistory::class . ' pch WHERE pch.person = person.id AND pch.center IN (:authorized_centers)'
|
||||||
|
@ -0,0 +1,110 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
declare(strict_types=1);
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Chill is a software for social workers
|
||||||
|
*
|
||||||
|
* For the full copyright and license information, please view
|
||||||
|
* the LICENSE file that was distributed with this source code.
|
||||||
|
*/
|
||||||
|
|
||||||
|
namespace Chill\PersonBundle\Export\Filter\PersonFilters;
|
||||||
|
|
||||||
|
use Chill\MainBundle\Export\FilterInterface;
|
||||||
|
use Chill\MainBundle\Form\Type\PickRollingDateType;
|
||||||
|
use Chill\MainBundle\Service\RollingDate\RollingDate;
|
||||||
|
use Chill\MainBundle\Service\RollingDate\RollingDateConverterInterface;
|
||||||
|
use Chill\MainBundle\Templating\TranslatableStringHelperInterface;
|
||||||
|
use Chill\PersonBundle\Entity\Household\HouseholdComposition;
|
||||||
|
use Chill\PersonBundle\Entity\Household\HouseholdCompositionType;
|
||||||
|
use Chill\PersonBundle\Entity\Household\HouseholdMember;
|
||||||
|
use Chill\PersonBundle\Export\Declarations;
|
||||||
|
use Chill\PersonBundle\Repository\Household\HouseholdCompositionTypeRepositoryInterface;
|
||||||
|
use Doctrine\DBAL\Types\Types;
|
||||||
|
use Doctrine\ORM\QueryBuilder;
|
||||||
|
use Symfony\Bridge\Doctrine\Form\Type\EntityType;
|
||||||
|
use Symfony\Component\Form\FormBuilderInterface;
|
||||||
|
|
||||||
|
class ByHouseholdCompositionFilter implements FilterInterface
|
||||||
|
{
|
||||||
|
private HouseholdCompositionTypeRepositoryInterface $householdCompositionTypeRepository;
|
||||||
|
|
||||||
|
private RollingDateConverterInterface $rollingDateConverter;
|
||||||
|
|
||||||
|
private TranslatableStringHelperInterface $translatableStringHelper;
|
||||||
|
|
||||||
|
public function __construct(
|
||||||
|
HouseholdCompositionTypeRepositoryInterface $householdCompositionTypeRepository,
|
||||||
|
RollingDateConverterInterface $rollingDateConverter,
|
||||||
|
TranslatableStringHelperInterface $translatableStringHelper
|
||||||
|
) {
|
||||||
|
$this->householdCompositionTypeRepository = $householdCompositionTypeRepository;
|
||||||
|
$this->rollingDateConverter = $rollingDateConverter;
|
||||||
|
$this->translatableStringHelper = $translatableStringHelper;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function addRole(): ?string
|
||||||
|
{
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function alterQuery(QueryBuilder $qb, $data)
|
||||||
|
{
|
||||||
|
$p = 'person_by_household_compo_filter';
|
||||||
|
|
||||||
|
$qb
|
||||||
|
->andWhere(
|
||||||
|
$qb->expr()->exists(
|
||||||
|
'SELECT 1 FROM ' . HouseholdMember::class . " {$p}_hm " .
|
||||||
|
'JOIN ' . HouseholdComposition::class . " {$p}_compo WITH {$p}_hm.household = {$p}_compo.household " .
|
||||||
|
"WHERE {$p}_hm.person = person AND {$p}_hm.shareHousehold = 'TRUE' " .
|
||||||
|
"AND ({$p}_hm.startDate <= :{$p}_date AND ({$p}_hm.endDate IS NULL OR {$p}_hm.endDate > :{$p}_date)) " .
|
||||||
|
"AND ({$p}_compo.startDate <= :{$p}_date AND ({$p}_compo.endDate IS NULL OR {$p}_compo.endDate > :{$p}_date)) " .
|
||||||
|
"AND {$p}_compo.householdCompositionType IN (:{$p}_accepted)"
|
||||||
|
)
|
||||||
|
)
|
||||||
|
->setParameter("{$p}_accepted", $data['compositions'])
|
||||||
|
->setParameter("{$p}_date", $this->rollingDateConverter->convert($data['calc_date']), Types::DATE_IMMUTABLE);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function applyOn()
|
||||||
|
{
|
||||||
|
return Declarations::PERSON_TYPE;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function buildForm(FormBuilderInterface $builder)
|
||||||
|
{
|
||||||
|
$builder
|
||||||
|
->add('compositions', EntityType::class, [
|
||||||
|
'class' => HouseholdCompositionType::class,
|
||||||
|
'choices' => $this->householdCompositionTypeRepository->findAllActive(),
|
||||||
|
'choice_label' => fn (HouseholdCompositionType $compositionType) => $this->translatableStringHelper->localize($compositionType->getLabel()),
|
||||||
|
'label' => 'export.filter.person.by_composition.Accepted compositions',
|
||||||
|
'multiple' => true,
|
||||||
|
'expanded' => true,
|
||||||
|
])
|
||||||
|
->add('calc_date', PickRollingDateType::class, [
|
||||||
|
'label' => 'export.filter.person.by_composition.Date calc',
|
||||||
|
'data' => new RollingDate(RollingDate::T_TODAY),
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function describeAction($data, $format = 'string')
|
||||||
|
{
|
||||||
|
$compos = array_map(
|
||||||
|
fn (HouseholdCompositionType $compositionType) => $this->translatableStringHelper->localize($compositionType->getLabel()),
|
||||||
|
$data['compositions']->toArray()
|
||||||
|
);
|
||||||
|
|
||||||
|
return ['export.filter.person.by_composition.Filtered by composition at %date%: only %compositions%', [
|
||||||
|
'%compositions%' => implode(', ', $compos),
|
||||||
|
'%date%' => $this->rollingDateConverter->convert($data['calc_date'])->format('d-m-Y'),
|
||||||
|
]];
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getTitle()
|
||||||
|
{
|
||||||
|
return 'export.filter.person.by_composition.Filter by household composition';
|
||||||
|
}
|
||||||
|
}
|
@ -214,10 +214,6 @@ services:
|
|||||||
tags:
|
tags:
|
||||||
- { name: chill.export_aggregator, alias: accompanyingcourse_ref_scope_aggregator }
|
- { name: chill.export_aggregator, alias: accompanyingcourse_ref_scope_aggregator }
|
||||||
|
|
||||||
Chill\PersonBundle\Export\Aggregator\AccompanyingCourseAggregators\ByHouseholdCompositionAggregator:
|
|
||||||
tags:
|
|
||||||
- { name: chill.export_aggregator, alias: accompanyingcourse_by_household_compo_aggregator }
|
|
||||||
|
|
||||||
Chill\PersonBundle\Export\Aggregator\AccompanyingCourseAggregators\ByActionNumberAggregator:
|
Chill\PersonBundle\Export\Aggregator\AccompanyingCourseAggregators\ByActionNumberAggregator:
|
||||||
tags:
|
tags:
|
||||||
- { name: chill.export_aggregator, alias: accompanyingcourse_by_action_number_aggregator }
|
- { name: chill.export_aggregator, alias: accompanyingcourse_by_action_number_aggregator }
|
||||||
|
@ -1,4 +1,7 @@
|
|||||||
services:
|
services:
|
||||||
|
_defaults:
|
||||||
|
autoconfigure: true
|
||||||
|
autowire: true
|
||||||
|
|
||||||
## Indicators
|
## Indicators
|
||||||
chill.person.export.count_person:
|
chill.person.export.count_person:
|
||||||
@ -107,6 +110,10 @@ services:
|
|||||||
tags:
|
tags:
|
||||||
- { name: chill.export_filter, alias: person_geog_filter }
|
- { name: chill.export_filter, alias: person_geog_filter }
|
||||||
|
|
||||||
|
Chill\PersonBundle\Export\Filter\PersonFilters\ByHouseholdCompositionFilter:
|
||||||
|
tags:
|
||||||
|
- { name: chill.export_filter, alias: person_by_household_composition_filter }
|
||||||
|
|
||||||
## Aggregators
|
## Aggregators
|
||||||
chill.person.export.aggregator_nationality:
|
chill.person.export.aggregator_nationality:
|
||||||
class: Chill\PersonBundle\Export\Aggregator\PersonAggregators\NationalityAggregator
|
class: Chill\PersonBundle\Export\Aggregator\PersonAggregators\NationalityAggregator
|
||||||
@ -156,3 +163,7 @@ services:
|
|||||||
tags:
|
tags:
|
||||||
- { name: chill.export_aggregator, alias: person_geog_aggregator }
|
- { name: chill.export_aggregator, alias: person_geog_aggregator }
|
||||||
|
|
||||||
|
Chill\PersonBundle\Export\Aggregator\PersonAggregators\ByHouseholdCompositionAggregator:
|
||||||
|
tags:
|
||||||
|
- { name: chill.export_aggregator, alias: person_household_compo_aggregator }
|
||||||
|
|
||||||
|
@ -996,6 +996,11 @@ export:
|
|||||||
count_persons: Nombre d'usagers concernés distincts
|
count_persons: Nombre d'usagers concernés distincts
|
||||||
count_acps: Nombre de parcours distincts
|
count_acps: Nombre de parcours distincts
|
||||||
aggregator:
|
aggregator:
|
||||||
|
person:
|
||||||
|
by_household_composition:
|
||||||
|
Household composition: Composition du ménage
|
||||||
|
Group course by household composition: Grouper les personnes par composition familiale
|
||||||
|
Calc date: Date de calcul de la composition du ménage
|
||||||
course:
|
course:
|
||||||
by_referrer:
|
by_referrer:
|
||||||
Computation date for referrer: Date à laquelle le référent était actif
|
Computation date for referrer: Date à laquelle le référent était actif
|
||||||
@ -1008,10 +1013,6 @@ export:
|
|||||||
week: Durée du parcours en semaines
|
week: Durée du parcours en semaines
|
||||||
month: Durée du parcours en mois
|
month: Durée du parcours en mois
|
||||||
Precision: Unité de la durée
|
Precision: Unité de la durée
|
||||||
by_household_composition:
|
|
||||||
Household composition: Composition du ménage
|
|
||||||
Group course by household composition: Grouper les parcours par composition familiale des ménages des usagers concernés
|
|
||||||
Calc date: Date de calcul de la composition du ménage
|
|
||||||
by_number_of_action:
|
by_number_of_action:
|
||||||
Number of actions: Nombre d'actions
|
Number of actions: Nombre d'actions
|
||||||
by_creator_job:
|
by_creator_job:
|
||||||
@ -1038,6 +1039,12 @@ export:
|
|||||||
Max date: Date d'échéance
|
Max date: Date d'échéance
|
||||||
|
|
||||||
filter:
|
filter:
|
||||||
|
person:
|
||||||
|
by_composition:
|
||||||
|
Filter by household composition: Filtrer les personnes par composition du ménage
|
||||||
|
Accepted compositions: Composition de ménages
|
||||||
|
Date calc: Date de calcul
|
||||||
|
'Filtered by composition at %date%: only %compositions%': 'Filtré par composition du ménage, le %date%, seulement %compositions%'
|
||||||
course:
|
course:
|
||||||
by_user_scope:
|
by_user_scope:
|
||||||
Computation date for referrer: Date à laquelle le référent était actif
|
Computation date for referrer: Date à laquelle le référent était actif
|
||||||
|
Loading…
x
Reference in New Issue
Block a user