Feature: [export] Finalize HasTemporaryLocation filter on accompanying

course
This commit is contained in:
Julien Fastré 2022-11-02 12:55:10 +01:00
parent 371a7dc05c
commit 2767075be7
2 changed files with 61 additions and 7 deletions

View File

@ -12,8 +12,12 @@ declare(strict_types=1);
namespace Chill\PersonBundle\Export\Filter\AccompanyingCourseFilters; namespace Chill\PersonBundle\Export\Filter\AccompanyingCourseFilters;
use Chill\MainBundle\Export\FilterInterface; use Chill\MainBundle\Export\FilterInterface;
use Chill\MainBundle\Form\Type\ChillDateType;
use Chill\PersonBundle\Export\Declarations; use Chill\PersonBundle\Export\Declarations;
use DateTimeImmutable;
use Doctrine\ORM\QueryBuilder; use Doctrine\ORM\QueryBuilder;
use LogicException;
use Symfony\Component\Form\Extension\Core\Type\ChoiceType;
use Symfony\Component\Form\FormBuilderInterface; use Symfony\Component\Form\FormBuilderInterface;
class HasTemporaryLocationFilter implements FilterInterface class HasTemporaryLocationFilter implements FilterInterface
@ -26,10 +30,25 @@ class HasTemporaryLocationFilter implements FilterInterface
public function alterQuery(QueryBuilder $qb, $data) public function alterQuery(QueryBuilder $qb, $data)
{ {
$qb $qb
->andWhere( ->join('acp.locationHistories', 'acp_having_temporarily_location')
$qb->expr()->in('', ':') ->andWhere('acp_having_temporarily_location.startDate <= :acp_having_temporarily_location_date
) AND (acp_having_temporarily_location.endDate IS NULL OR acp_having_temporarily_location.endDate > :acp_having_temporarily_location_date)')
->setParameter('', $data[]); ->setParameter('acp_having_temporarily_location_date', $data['calc_date']);
switch ($data['having_temporarily']) {
case true:
$qb->andWhere('acp_having_temporarily_location.addressLocation IS NOT NULL');
break;
case false:
$qb->andWhere('acp_having_temporarily_location.personLocation IS NOT NULL');
break;
default:
throw new LogicException('value not supported');
}
} }
public function applyOn(): string public function applyOn(): string
@ -39,13 +58,44 @@ class HasTemporaryLocationFilter implements FilterInterface
public function buildForm(FormBuilderInterface $builder) public function buildForm(FormBuilderInterface $builder)
{ {
//$builder->add(); $builder
->add('having_temporarily', ChoiceType::class, [
'choices' => [
'export.filter.course.having_temporarily.Having a temporarily location' => true,
'export.filter.course.having_temporarily.Having a person\'s location' => false,
],
'choice_label' => static function ($choice) {
switch ($choice) {
case true:
return 'export.filter.course.having_temporarily.Having a temporarily location';
case false:
return 'export.filter.course.having_temporarily.Having a person\'s location';
default:
throw new LogicException('this choice is not supported');
}
},
])
->add('calc_date', ChillDateType::class, [
'label' => 'export.filter.course.having_temporarily.Calculation date',
'input' => 'datetime_immutable',
'data' => new DateTimeImmutable(),
]);
} }
public function describeAction($data, $format = 'string'): array public function describeAction($data, $format = 'string'): array
{ {
return ['', [ switch ($data['having_temporarily']) {
]]; case true:
return ['export.filter.course.having_temporarily.Having a temporarily location', []];
case false:
return ['export.filter.course.having_temporarily.Having a person\'s location', []];
default:
throw new LogicException('value not supported');
}
} }
public function getTitle(): string public function getTitle(): string

View File

@ -1021,6 +1021,10 @@ export:
Computation date for referrer: Date à laquelle le référent était actif Computation date for referrer: Date à laquelle le référent était actif
by_referrer: by_referrer:
Computation date for referrer: Date à laquelle le référent était actif Computation date for referrer: Date à laquelle le référent était actif
having_temporarily:
Having a temporarily location: Ayant une localisation temporaire
Having a person's location: Ayant une localisation auprès d'un usager
Calculation date: Date de la localisation
list: list:
person_with_acp: person_with_acp:
List peoples having an accompanying period: Liste des personnes ayant un parcours d'accompagnement List peoples having an accompanying period: Liste des personnes ayant un parcours d'accompagnement