person filters added

This commit is contained in:
Julie Lenaerts 2022-08-03 14:35:55 +02:00
parent ebb6ee4a41
commit cf7cf664a9
10 changed files with 548 additions and 20 deletions

View File

@ -13,11 +13,14 @@ namespace Chill\PersonBundle\Export\Filter;
use Chill\MainBundle\Export\ExportElementValidatedInterface;
use Chill\MainBundle\Export\FilterInterface;
use Chill\MainBundle\Form\Type\ChillDateType;
use Chill\PersonBundle\Export\Declarations;
use DateTime;
use Doctrine\ORM\Query\Expr;
use Doctrine\ORM\QueryBuilder;
use Symfony\Component\Form\Extension\Core\Type\DateType;
use Symfony\Component\Form\Extension\Core\Type\IntegerType;
use Symfony\Component\Form\FormBuilderInterface;
use Symfony\Component\Validator\Context\ExecutionContextInterface;
class AgeFilter implements ExportElementValidatedInterface, FilterInterface
@ -27,7 +30,7 @@ class AgeFilter implements ExportElementValidatedInterface, FilterInterface
return null;
}
public function alterQuery(\Doctrine\ORM\QueryBuilder $qb, $data)
public function alterQuery(QueryBuilder $qb, $data)
{
$where = $qb->getDQLPart('where');
@ -61,7 +64,7 @@ class AgeFilter implements ExportElementValidatedInterface, FilterInterface
return Declarations::PERSON_TYPE;
}
public function buildForm(\Symfony\Component\Form\FormBuilderInterface $builder)
public function buildForm(FormBuilderInterface $builder)
{
$builder->add('min_age', IntegerType::class, [
'label' => 'Minimum age',
@ -71,12 +74,9 @@ class AgeFilter implements ExportElementValidatedInterface, FilterInterface
'label' => 'Maximum age',
]);
$builder->add('date_calc', DateType::class, [
$builder->add('date_calc', ChillDateType::class, [
'label' => 'Calculate age in relation to this date',
'data' => new DateTime('now'),
'attr' => ['class' => 'datepicker'],
'widget' => 'single_text',
'format' => 'dd-MM-yyyy',
]);
}

View File

@ -13,6 +13,7 @@ namespace Chill\PersonBundle\Export\Filter;
use Chill\MainBundle\Export\ExportElementValidatedInterface;
use Chill\MainBundle\Export\FilterInterface;
use Chill\MainBundle\Form\Type\ChillDateType;
use DateTime;
use Doctrine\ORM\Query\Expr;
use Symfony\Component\Form\Extension\Core\Type\DateType;
@ -52,26 +53,20 @@ class BirthdateFilter implements ExportElementValidatedInterface, FilterInterfac
public function buildForm(\Symfony\Component\Form\FormBuilderInterface $builder)
{
$builder->add('date_from', DateType::class, [
$builder->add('date_from', ChillDateType::class, [
'label' => 'Born after this date',
'data' => new DateTime(),
'attr' => ['class' => 'datepicker'],
'widget' => 'single_text',
'format' => 'dd-MM-yyyy',
'data' => new DateTime()
]);
$builder->add('date_to', DateType::class, [
$builder->add('date_to', ChillDateType::class, [
'label' => 'Born before this date',
'data' => new DateTime(),
'attr' => ['class' => 'datepicker'],
'widget' => 'single_text',
'format' => 'dd-MM-yyyy',
'data' => new DateTime()
]);
}
public function describeAction($data, $format = 'string')
{
return ['Filtered by person\'s birtdate: '
return ['Filtered by person\'s birthdate: '
. 'between %date_from% and %date_to%', [
'%date_from%' => $data['date_from']->format('d-m-Y'),
'%date_to%' => $data['date_to']->format('d-m-Y'),

View File

@ -0,0 +1,113 @@
<?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;
use Chill\MainBundle\Export\FilterInterface;
use Chill\MainBundle\Form\Type\ChillDateType;
use Chill\PersonBundle\Export\Declarations;
use DateTime;
use Doctrine\ORM\Query\Expr;
use Doctrine\ORM\QueryBuilder;
use Symfony\Component\Form\Extension\Core\Type\ChoiceType;
use Symfony\Component\Form\FormBuilderInterface;
class DeadOrAliveFilter implements FilterInterface
{
public function addRole()
{
return null;
}
public function alterQuery(QueryBuilder $qb, $data)
{
$where = $qb->getDQLPart('where');
$personState = $data['person_state'];
$calc = $data['date_calc'];
if ($personState == 'alive') {
$clause = $qb->expr()->orX(
$qb->expr()->andX(
$qb->expr()->isNull('person.deathdate'),
$qb->expr()->lte(
'person.birthdate',
':date_calc'
)
),
$qb->expr()->andX(
$qb->expr()->isNotNull('person.deathdate'),
$qb->expr()->gt(
'person.deathdate',
':date_calc'
),
$qb->expr()->lte(
'person.birthdate',
':date_calc'
)
)
);
} else {
$clause = $qb->expr()->andX(
$qb->expr()->isNotNull('person.deathdate'),
$qb->expr()->lte(
'person.deathdate',
':date_calc'
)
);
}
if ($where instanceof Expr\Andx) {
$where->add($clause);
} else {
$where = $qb->expr()->andX($clause);
}
$qb->add('where', $where);
$qb->setParameter('date_calc', $calc);
}
public function applyOn()
{
return Declarations::PERSON_TYPE;
}
public function buildForm(FormBuilderInterface $builder)
{
$builder->add('person_state', ChoiceType::class, [
'choices' => [
'Alive' => 'alive',
'Deceased' => 'deceased',
],
'multiple' => false,
'expanded' => true,
]);
$builder->add('date_calc', ChillDateType::class, [
'label' => 'Filter in relation to this date',
'data' => new DateTime('now'),
]);
}
public function describeAction($data, $format = 'string')
{
return ['Filtered by a state of %deadOrAlive%: '
. 'at this date %date_calc%', [
'%date_calc%' => $data['date_calc']->format('d-m-Y'),
'%deadOrAlive%' => $data['person_state'],
], ];
}
public function getTitle()
{
return 'Filtered by person\'s that are alive or have deceased at a certain date';
}
}

View File

@ -0,0 +1,109 @@
<?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;
use Chill\MainBundle\Export\ExportElementValidatedInterface;
use Chill\MainBundle\Export\FilterInterface;
use Chill\MainBundle\Form\Type\ChillDateType;
use Chill\PersonBundle\Export\Declarations;
use DateTime;
use Doctrine\ORM\Query\Expr;
use Doctrine\ORM\QueryBuilder;
use Symfony\Component\Form\FormBuilderInterface;
use Symfony\Component\Validator\Context\ExecutionContextInterface;
class DeathdateFilter implements ExportElementValidatedInterface, FilterInterface
{
public function addRole()
{
return null;
}
public function alterQuery(QueryBuilder $qb, $data)
{
$where = $qb->getDQLPart('where');
$clause = $qb->expr()->between(
'person.deathdate',
':date_from',
':date_to'
);
if ($where instanceof Expr\Andx) {
$where->add($clause);
} else {
$where = $qb->expr()->andX($clause);
}
$qb->add('where', $where);
$qb->setParameter('date_from', $data['date_from']);
$qb->setParameter('date_to', $data['date_to']);
}
public function applyOn()
{
return Declarations::PERSON_TYPE;
}
public function buildForm(FormBuilderInterface $builder)
{
$builder->add('date_from', ChillDateType::class, [
'label' => 'Death after this date',
'data' => new DateTime(),
]);
$builder->add('date_to', ChillDateType::class, [
'label' => 'Deathdate before',
'data' => new DateTime(),
]);
}
public function describeAction($data, $format = 'string')
{
return ['Filtered by person\'s deathdate: '
. 'between %date_from% and %date_to%', [
'%date_from%' => $data['date_from']->format('d-m-Y'),
'%date_to%' => $data['date_to']->format('d-m-Y'),
], ];
}
public function getTitle()
{
return 'Filter by person\'s deathdate';
}
public function validateForm($data, ExecutionContextInterface $context)
{
$date_from = $data['date_from'];
$date_to = $data['date_to'];
if (null === $date_from) {
$context->buildViolation('The "date from" should not be empty')
//->atPath('date_from')
->addViolation();
}
if (null === $date_to) {
$context->buildViolation('The "date to" should not be empty')
//->atPath('date_to')
->addViolation();
}
if (
(null !== $date_from && null !== $date_to)
&& $date_from >= $date_to
) {
$context->buildViolation('The date "date to" should be after the '
. 'date given in "date from" field')
->addViolation();
}
}
}

View File

@ -0,0 +1,65 @@
<?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;
use Chill\MainBundle\Export\FilterInterface;
use Chill\PersonBundle\Export\Declarations;
use DateTime;
use Doctrine\ORM\Query\Expr\Andx;
class EntrustedChildFilter implements FilterInterface
{
public function addRole()
{
return null;
}
public function alterQuery(\Doctrine\ORM\QueryBuilder $qb, $data)
{
$qb->resetDQLPart('from');
$qb->from('App:VendeePersonMineur', 'vpm');
$qb->join('vpm.person', 'person');
$qb->join('person.center', 'center');
$where = $qb->getDQLPart('where');
$clause = $qb->expr()->eq('vpm.enfantConfie', 'true');
if ($where instanceof Andx) {
$where->add($clause);
} else {
$where = $qb->expr()->andX($clause);
}
$qb->add('where', $where);
}
public function applyOn()
{
return Declarations::PERSON_TYPE;
}
public function buildForm(\Symfony\Component\Form\FormBuilderInterface $builder)
{
// No form needed
}
public function describeAction($data, $format = 'string')
{
return ['Filtered by entrusted child status'];
}
public function getTitle()
{
return 'Filter by entrusted child status';
}
}

View File

@ -0,0 +1,55 @@
<?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;
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,64 @@
<?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;
use Chill\MainBundle\Export\FilterInterface;
use Chill\PersonBundle\Export\Declarations;
use Doctrine\ORM\Query\Expr\Andx;
class NomadicFilter implements FilterInterface
{
public function addRole()
{
return null;
}
public function alterQuery(\Doctrine\ORM\QueryBuilder $qb, $data)
{
$qb->resetDQLPart('from');
$qb->from('App:VendeePerson', 'vp');
$qb->join('vp.person', 'person');
$qb->join('person.center', 'center');
$where = $qb->getDQLPart('where');
$clause = $qb->expr()->eq('vp.gensDuVoyage', 'true');
if ($where instanceof Andx) {
$where->add($clause);
} else {
$where = $qb->expr()->andX($clause);
}
$qb->add('where', $where);
}
public function applyOn()
{
return Declarations::PERSON_TYPE;
}
public function buildForm(\Symfony\Component\Form\FormBuilderInterface $builder)
{
// No form needed
}
public function describeAction($data, $format = 'string')
{
return ['Filtered by nomadic status'];
}
public function getTitle()
{
return 'Filter by nomadic status';
}
}

View File

@ -0,0 +1,67 @@
<?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;
use Chill\MainBundle\Export\FilterInterface;
use Chill\PersonBundle\Export\Declarations;
use Doctrine\ORM\Query\Expr;
use Doctrine\ORM\QueryBuilder;
class ResidentialAddressAtUserFilter implements FilterInterface
{
public function addRole()
{
return null;
}
public function alterQuery(QueryBuilder $qb, $data)
{
$qb->resetDQLPart('from');
$qb->from('ChillPersonBundle:Person:ResidentialAddress', 'ra');
$qb->join('ra.person', 'person');
$qb->join('person.center', 'center');
$where = $qb->getDQLPart('where');
$clause = $qb->expr()->isNotNull('ra.hostPerson');
if ($where instanceof Expr\Andx) {
$where->add($clause);
} else {
$where = $qb->expr()->andX($clause);
}
$qb->add('where', $where);
dump($qb->getQuery());
}
public function applyOn()
{
return Declarations::PERSON_TYPE;
}
public function buildForm(\Symfony\Component\Form\FormBuilderInterface $builder)
{
// No form needed unless validity date should be added ( not specified in doc as a parameter ).
}
public function describeAction($data, $format = 'string')
{
return ['Filtered by person\'s who have a residential address located at another user'];
}
public function getTitle()
{
return 'Filtered by person\'s who have a residential address located at another user';
}
}

View File

@ -44,6 +44,16 @@ services:
tags:
- { name: chill.export_filter, alias: person_birthdate_filter }
chill.person.export.filter_deathdate:
class: Chill\PersonBundle\Export\Filter\DeathdateFilter
tags:
- { name: chill.export_filter, alias: person_deathdate_filter }
chill.person.export.filter_dead_or_alive:
class: Chill\PersonBundle\Export\Filter\DeadOrAliveFilter
tags:
- { name: chill.export_filter, alias: person_dead_or_alive_filter }
chill.person.export.filter_nationality:
class: Chill\PersonBundle\Export\Filter\NationalityFilter
autowire: true
@ -51,6 +61,27 @@ services:
tags:
- { name: chill.export_filter, alias: person_nationality_filter }
chill.person.export.filter_residential_address_at_user:
class: Chill\PersonBundle\Export\Filter\ResidentialAddressAtUserFilter
autowire: true
autoconfigure: true
tags:
- { name: chill.export_filter, alias: person_residential_address_at_user_filter }
chill.person.export.filter_entrusted_child:
class: Chill\PersonBundle\Export\Filter\EntrustedChildFilter
autowire: true
autoconfigure: true
tags:
- { name: chill.export_filter, alias: person_entrusted_child_filter }
chill.person.export.filter_nomadic:
class: Chill\PersonBundle\Export\Filter\NomadicFilter
autowire: true
autoconfigure: true
tags:
- { name: chill.export_filter, alias: person_nomadic_filter }
# AGGREGATORS
chill.person.export.aggregator_nationality:
class: Chill\PersonBundle\Export\Aggregator\NationalityAggregator

View File

@ -329,8 +329,8 @@ Accompanyied people: Personnes accompagnées
## exports
Exports of persons: Exports des personnes
Count peoples by various parameters.: Compte le nombre de personnes en fonction de différents filtres.
Count peoples: Nombre de personnes
Count people by various parameters.: Compte le nombre de personnes en fonction de différents filtres.
Count people: Nombre de personnes
List peoples: Liste des personnes
Create a list of people according to various filters.: Crée une liste des personnes selon différents filtres.
Fields to include in export: Champs à inclure dans l'export
@ -364,7 +364,36 @@ Born after this date: Nés après cette date
Born before this date: Nés avant cette date
This field should not be empty: Ce champ ne peut pas être vide
This date should be after the date given in "born after" field: Cette date doit être après la date donnée du le champ "nés après le"
"Filtered by person's birtdate: between %date_from% and %date_to%": "Filtré par date de naissance de la personne: uniquement nés entre le %date_from% et %date_to%"
"Filtered by person's birthdate: between %date_from% and %date_to%": "Filtré par date de naissance de la personne: uniquement nés entre le %date_from% et %date_to%"
Filter by person's deathdate: Filtrer par date de décès de la personne
"Filtered by person's deathdate: between %date_from% and %date_to%": "Filtré par date de naissance de la personne: uniquement nés entre le %date_from% et %date_to%"
Death after this date: Décédé après cette date
Deathdate before: Décédé avant cette date
Alive: Vivant
Deceased: Décédé
Filter in relation to this date: Filtrer par rapport à cette date
"Filtered by a state of %deadOrAlive% at this date %date_calc%": Filtré par personnes qui sont %deadOrAlive% à cette date %date_calc%
Filter by person's age: Filtrer par âge de la personne
Filtered by person's age: Filtré par âge de la personne
Minimum age: Âge minimum
Maximum age: Âge maximum
The minimum age should be less than the maximum age.: L'âge minimum doit être plus bas que l'âge maximum.
Family composition: Composition familiale
Family composition at this time: Composition familiale à cette date.
Filtered by entrusted child status: Uniquement les personnes qui sont "enfant confié"
Filter by entrusted child status: Uniquement les personnes qui sont "enfant confié"
Filtered by nomadic status: Uniquement les personnes qui sont "gens de voyage"
Filter by nomadic status: Uniquement les personnes qui sont "gens de voyage"
Filtered by person's who have a residential address located at another user: Uniquement les usagers qui ont une addresse de résidence chez un autre usager
Filtered by person's that are alive or have deceased at a certain date: Filtrer par usagers qui sont décédé ou vivant à une certaine date
"Filter by accompanying period: active period": "Filtrer par période d'accompagnement: en file active"
Having an accompanying period opened after this date: Ayant une période d'accompagnement ouverte après cette date