Features: [export] Filter "persons who do not have a household composition"

This commit is contained in:
Julien Fastré 2022-11-10 15:11:45 +01:00
parent a942a24596
commit a7c44830d2
Signed by: julienfastre
GPG Key ID: BDE2190974723FCB
3 changed files with 93 additions and 0 deletions

View File

@ -0,0 +1,84 @@
<?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\PersonBundle\Entity\Household\HouseholdComposition;
use Chill\PersonBundle\Entity\Household\HouseholdMember;
use Chill\PersonBundle\Export\Declarations;
use Doctrine\DBAL\Types\Types;
use Doctrine\ORM\QueryBuilder;
use Symfony\Component\Form\FormBuilderInterface;
class WithoutHouseholdComposition implements FilterInterface
{
private RollingDateConverterInterface $rollingDateConverter;
public function __construct(
RollingDateConverterInterface $rollingDateConverter
) {
$this->rollingDateConverter = $rollingDateConverter;
}
public function addRole(): ?string
{
return null;
}
public function alterQuery(QueryBuilder $qb, $data)
{
$p = 'person_by_household_no_compo_filter';
$qb
->andWhere(
$qb->expr()->not(
$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)) "
)
)
)
->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('calc_date', PickRollingDateType::class, [
'label' => 'export.filter.person.by_no_composition.Date calc',
'data' => new RollingDate(RollingDate::T_TODAY),
]);
}
public function describeAction($data, $format = 'string')
{
return ['export.filter.person.by_no_composition.Persons filtered by no composition at %date%', [
'%date%' => $this->rollingDateConverter->convert($data['calc_date'])->format('d-m-Y'),
]];
}
public function getTitle()
{
return 'export.filter.person.by_no_composition.Filter persons without household composition';
}
}

View File

@ -114,6 +114,10 @@ services:
tags:
- { name: chill.export_filter, alias: person_by_household_composition_filter }
Chill\PersonBundle\Export\Filter\PersonFilters\WithoutHouseholdComposition:
tags:
- { name: chill.export_filter, alias: person_without_household_composition_filter }
## Aggregators
chill.person.export.aggregator_nationality:
class: Chill\PersonBundle\Export\Aggregator\PersonAggregators\NationalityAggregator

View File

@ -1045,6 +1045,11 @@ export:
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%'
by_no_composition:
Filter persons without household composition: Filtrer les personnes sans composition de ménage (ni ménage)
Persons filtered by no composition at %date%: Uniquement les personnes sans composition de ménage à la date du %date%
Date calc: Date de calcul
course:
by_user_scope:
Computation date for referrer: Date à laquelle le référent était actif