complete maritalStatusFilter

This commit is contained in:
Julie Lenaerts 2022-09-05 11:51:17 +02:00
parent 6dbee02d82
commit 8688e4d502
3 changed files with 88 additions and 55 deletions

View File

@ -1,55 +0,0 @@
<?php
/**
* 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.
*/
declare(strict_types=1);
namespace Chill\PersonBundle\Export\Filter\PersonFilters;
use Chill\MainBundle\Export\FilterInterface;
use Chill\PersonBundle\Entity\Household\HouseholdCompositionType;
use Chill\PersonBundle\Export\Declarations;
use DateTime;
use Symfony\Component\Form\Extension\Core\Type\DateType;
class FamilySituationFilter implements FilterInterface
{
//TODO where to find this property? On VendeePerson rather than Person. Not sure what this refers to exactly...
public function addRole()
{
return null;
}
public function alterQuery(\Doctrine\ORM\QueryBuilder $qb, $data)
{
}
public function applyOn()
{
return Declarations::PERSON_TYPE;
}
public function buildForm(\Symfony\Component\Form\FormBuilderInterface $builder)
{
$builder->add('date_calc', DateType::class, [
'label' => 'Family composition(s) at this time',
'data' => new DateTime(),
]);
}
public function describeAction($data, $format = 'string')
{
return ['Filtered by person\'s family situation'];
}
public function getTitle()
{
return 'Filter by person\'s family situation';
}
}

View File

@ -0,0 +1,84 @@
<?php
/**
* 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.
*/
declare(strict_types=1);
namespace Chill\PersonBundle\Export\Filter\PersonFilters;
use Chill\MainBundle\Entity\UserJob;
use Chill\MainBundle\Export\FilterInterface;
use Chill\PersonBundle\Entity\Household\HouseholdCompositionType;
use Chill\PersonBundle\Entity\MaritalStatus;
use Chill\PersonBundle\Export\Declarations;
use DateTime;
use Doctrine\ORM\Query\Expr\Andx;
use Symfony\Bridge\Doctrine\Form\Type\EntityType;
use Symfony\Component\Form\Extension\Core\Type\DateType;
class MaritalStatusFilter implements FilterInterface
{
public function addRole()
{
return null;
}
public function alterQuery(\Doctrine\ORM\QueryBuilder $qb, $data)
{
$where = $qb->getDQLPart('where');
$clause = $qb->expr()->andX(
$qb->expr()->in('p.maritalStatus', ':maritalStatus'),
$qb->expr()->eq('p.maritalStatusDate', ':calc_date')
);
if ($where instanceof Andx) {
$where->add($clause);
} else {
$where = $qb->expr()->andX($clause);
}
$qb->add('where', $where);
$qb->setParameter('maritalStatus', $data['maritalStatus']);
$qb->setParameter('maritalStatusDate', $data['calc_date']);
}
public function applyOn()
{
return Declarations::PERSON_TYPE;
}
public function buildForm(\Symfony\Component\Form\FormBuilderInterface $builder)
{
$builder->add('maritalStatus', EntityType::class, [
'class' => MaritalStatus::class,
'choice_label' => function (MaritalStatus $ms) {
return $this->translatableStringHelper->localize(
$ms->getLabel()
);
},
'multiple' => true,
'expanded' => true
]);
$builder->add('date_calc', DateType::class, [
'label' => 'Marital status at this time',
'data' => new DateTime(),
]);
}
public function describeAction($data, $format = 'string')
{
return ['Filtered by person\'s marital status'];
}
public function getTitle()
{
return 'Filter by person\'s marital status';
}
}

View File

@ -400,6 +400,10 @@ Filtered by person\'s who have a residential address located at a thirdparty of
Family composition: Composition familiale
Family composition at this time: Composition familiale à cette date.
Filtered by person's marital status: Filtré par état matrimonial
Filter by person's marital status: Filtrer par état matrimonial à une certaine date.
Marital status at this time: État matrimonial à cette date.
Filter by entrusted child status: Filtrer les usagers qui sont "enfant confié"
Filtered by entrusted child status: Uniquement les usagers qui sont "enfant confié"