exports: add a new GeographicUnitStat Filter (wip)

This commit is contained in:
Mathieu Jaumotte 2022-08-03 13:34:06 +02:00
parent 6921e4a40d
commit 2413c986ed
2 changed files with 108 additions and 0 deletions

View File

@ -0,0 +1,101 @@
<?php
namespace Chill\PersonBundle\Export\Filter;
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\Component\Form\FormBuilderInterface;
/**
* e) par zone géographique
*
* Paramètre:
* * Date
* * Choix unique entre: territoire, epci, canton, commune, secteur d'intervention
* * une fois le premier choix effectué, l'utilisateur choisi parmi les zones (choix multiple)
*
* Le filtre retiendra les parcours localisé dans un des territoires cochés, à la date indiquée en paramètre.
*/
class GeographicalUnitStatFilter implements FilterInterface
{
private const LOCTYPE = [
'center' => 'territoire',
// TODO not yet implemented: https://gitlab.com/champs-libres/departement-de-la-vendee/chill/-/issues/626
];
/**
* @inheritDoc
*/
public function buildForm(FormBuilderInterface $builder)
{
$builder
->add('date', ChillDateType::class, [
'data' => new \DateTime(),
])
->add('accepted_loctype', ChoiceType::class, [
'choices' => self::LOCTYPE,
'multiple' => false,
'expanded' => true,
])
;
}
/**
* @inheritDoc
*/
public function getTitle(): string
{
return 'Filter by geographic unit';
}
/**
* @inheritDoc
*/
public function describeAction($data, $format = 'string'): array
{
return ['Filtered by geographic unit: only %date%', [
'%date%' => $data['date']->format('d-m-Y'),
]];
}
/**
* @inheritDoc
*/
public function addRole()
{
return null;
}
/**
* @inheritDoc
*/
public function alterQuery(QueryBuilder $qb, $data)
{
$where = $qb->getDQLPart('where');
$clause = $qb->expr()->eq(1, 1);
if ($where instanceof Andx) {
$where->add($clause);
} else {
$where = $qb->expr()->andX($clause);
}
$qb->add('where', $where);
$qb->setParameter('date', $data['date'], Types::DATE_MUTABLE);
$qb->setParameter('loctype', $data['accepted_loctype']);
}
/**
* @inheritDoc
*/
public function applyOn(): string
{
return Declarations::ACP_TYPE;
}
}

View File

@ -60,6 +60,13 @@ services:
tags:
- { name: chill.export_filter, alias: accompanyingcourse_step_filter }
chill.person.export.filter_geographicalunitstat:
class: Chill\PersonBundle\Export\Filter\GeographicalUnitStatFilter
autowire: true
autoconfigure: true
tags:
- { name: chill.export_filter, alias: accompanyingcourse_geographicalunitstat_filter }
chill.person.export.filter_socialaction:
class: Chill\PersonBundle\Export\Filter\SocialActionFilter
autowire: true