[export] add dates for filter "user working on course"

This commit is contained in:
Julien Fastré 2023-06-29 13:16:40 +02:00
parent c019fffbe7
commit 4a5ac170ba
Signed by: julienfastre
GPG Key ID: BDE2190974723FCB
3 changed files with 40 additions and 10 deletions

View File

@ -0,0 +1,6 @@
kind: Feature
body: '[export] on "filter by user working" on accompanying period, add two dates
to filters intervention within a period'
time: 2023-06-29T13:15:58.070316708+02:00
custom:
Issue: "113"

View File

@ -13,7 +13,10 @@ namespace Chill\PersonBundle\Export\Filter\AccompanyingCourseFilters;
use Chill\MainBundle\Entity\User; use Chill\MainBundle\Entity\User;
use Chill\MainBundle\Export\FilterInterface; use Chill\MainBundle\Export\FilterInterface;
use Chill\MainBundle\Form\Type\PickRollingDateType;
use Chill\MainBundle\Form\Type\PickUserDynamicType; use Chill\MainBundle\Form\Type\PickUserDynamicType;
use Chill\MainBundle\Service\RollingDate\RollingDate;
use Chill\MainBundle\Service\RollingDate\RollingDateConverterInterface;
use Chill\MainBundle\Templating\Entity\UserRender; use Chill\MainBundle\Templating\Entity\UserRender;
use Chill\PersonBundle\Entity\AccompanyingPeriod; use Chill\PersonBundle\Entity\AccompanyingPeriod;
use Chill\PersonBundle\Export\Declarations; use Chill\PersonBundle\Export\Declarations;
@ -27,11 +30,9 @@ use Symfony\Component\Form\FormBuilderInterface;
*/ */
readonly class UserWorkingOnCourseFilter implements FilterInterface readonly class UserWorkingOnCourseFilter implements FilterInterface
{ {
private const AI_ALIAS = 'user_working_on_course_filter_acc_info';
private const AI_USERS = 'user_working_on_course_filter_users';
public function __construct( public function __construct(
private UserRender $userRender, private UserRender $userRender,
private RollingDateConverterInterface $rollingDateConverter,
) { ) {
} }
@ -40,11 +41,23 @@ readonly class UserWorkingOnCourseFilter implements FilterInterface
$builder $builder
->add('users', PickUserDynamicType::class, [ ->add('users', PickUserDynamicType::class, [
'multiple' => true, 'multiple' => true,
]); ])
->add('start_date', PickRollingDateType::class, [
'label' => 'export.filter.course.by_user_working.User working after'
])
->add('end_date', PickRollingDateType::class, [
'label' => 'export.filter.course.by_user_working.User working before'
])
;
} }
public function getFormDefaultData(): array public function getFormDefaultData(): array
{ {
return []; return [
'users' => [],
'start_date' => new RollingDate(RollingDate::T_YEAR_CURRENT_START),
'end_date' => new RollingDate(RollingDate::T_TODAY),
];
} }
public function getTitle(): string public function getTitle(): string
@ -55,7 +68,7 @@ readonly class UserWorkingOnCourseFilter implements FilterInterface
public function describeAction($data, $format = 'string'): array public function describeAction($data, $format = 'string'): array
{ {
return [ return [
'export.filter.course.by_user_working.Filtered by user working on course: only %users%', [ 'export.filter.course.by_user_working.Filtered by user working on course: only %users%, between %start_date% and %end_date%', [
'%users%' => implode( '%users%' => implode(
', ', ', ',
array_map( array_map(
@ -63,6 +76,8 @@ readonly class UserWorkingOnCourseFilter implements FilterInterface
$data['users'] $data['users']
) )
), ),
'%start_date%' => $this->rollingDateConverter->convert($data['start_date'])?->format('d-m-Y'),
'%end_date%' => $this->rollingDateConverter->convert($data['end_date'])?->format('d-m-Y'),
], ],
]; ];
} }
@ -74,14 +89,21 @@ readonly class UserWorkingOnCourseFilter implements FilterInterface
public function alterQuery(QueryBuilder $qb, $data): void public function alterQuery(QueryBuilder $qb, $data): void
{ {
$ai_alias = 'user_working_on_course_filter_acc_info';
$ai_users = 'user_working_on_course_filter_users';
$start = 'acp_use_work_on_start';
$end = 'acp_use_work_on_end';
$qb $qb
->andWhere( ->andWhere(
$qb->expr()->exists( $qb->expr()->exists(
"SELECT 1 FROM " . AccompanyingPeriod\AccompanyingPeriodInfo::class . " " . self::AI_ALIAS . " " . "SELECT 1 FROM " . AccompanyingPeriod\AccompanyingPeriodInfo::class . " {$ai_alias} " .
"WHERE " . self::AI_ALIAS . ".user IN (:" . self::AI_USERS .") AND IDENTITY(" . self::AI_ALIAS . ".accompanyingPeriod) = acp.id" "WHERE {$ai_alias}.user IN (:{$ai_users}) AND IDENTITY({$ai_alias}.accompanyingPeriod) = acp.id AND {$ai_alias}.infoDate >= :{$start} and {$ai_alias}.infoDate < :{$end}"
) )
) )
->setParameter(self::AI_USERS, $data['users']) ->setParameter($ai_users, $data['users'])
->setParameter($start, $this->rollingDateConverter->convert($data['start_date']))
->setParameter($end, $this->rollingDateConverter->convert($data['end_date']))
; ;
} }

View File

@ -1082,7 +1082,9 @@ export:
Only course with events between %startDate% and %endDate%: Seulement les parcours ayant reçu une intervention entre le %startDate% et le %endDate% Only course with events between %startDate% and %endDate%: Seulement les parcours ayant reçu une intervention entre le %startDate% et le %endDate%
by_user_working: by_user_working:
title: Filter les parcours par intervenant title: Filter les parcours par intervenant
'Filtered by user working on course: only %users%': 'Filtré par intervenants sur le parcours: seulement %users%' 'Filtered by user working on course: only %users%, between %start_date% and %end_date%': 'Filtré par intervenants sur le parcours: seulement %users%, entre le %start_date% et le %end_date%'
User working after: Intervention après le
User working before: Intervention avant le
by_step: by_step:
Filter by step: Filtrer les parcours par statut du parcours Filter by step: Filtrer les parcours par statut du parcours
Filter by step between dates: Filtrer les parcours par statut du parcours entre deux dates Filter by step between dates: Filtrer les parcours par statut du parcours entre deux dates