person filters added

This commit is contained in:
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';
}
}