mirror of
https://gitlab.com/Chill-Projet/chill-bundles.git
synced 2025-06-07 18:44:08 +00:00
Add startDate and endDate on UserJobFilter
This commit is contained in:
parent
90b615c5b2
commit
cbd9489810
@ -13,23 +13,28 @@ namespace Chill\PersonBundle\Export\Filter\AccompanyingCourseFilters;
|
|||||||
|
|
||||||
use Chill\MainBundle\Entity\User\UserJobHistory;
|
use Chill\MainBundle\Entity\User\UserJobHistory;
|
||||||
use Chill\MainBundle\Entity\UserJob;
|
use Chill\MainBundle\Entity\UserJob;
|
||||||
|
use Chill\MainBundle\Export\DataTransformerFilterInterface;
|
||||||
use Chill\MainBundle\Export\FilterInterface;
|
use Chill\MainBundle\Export\FilterInterface;
|
||||||
|
use Chill\MainBundle\Form\Type\PickRollingDateType;
|
||||||
use Chill\MainBundle\Repository\UserJobRepositoryInterface;
|
use Chill\MainBundle\Repository\UserJobRepositoryInterface;
|
||||||
|
use Chill\MainBundle\Service\RollingDate\RollingDate;
|
||||||
|
use Chill\MainBundle\Service\RollingDate\RollingDateConverterInterface;
|
||||||
use Chill\MainBundle\Templating\TranslatableStringHelper;
|
use Chill\MainBundle\Templating\TranslatableStringHelper;
|
||||||
|
use Chill\PersonBundle\Entity\AccompanyingPeriod\UserHistory;
|
||||||
use Chill\PersonBundle\Export\Declarations;
|
use Chill\PersonBundle\Export\Declarations;
|
||||||
use Doctrine\Common\Collections\Collection;
|
use Doctrine\Common\Collections\Collection;
|
||||||
use Doctrine\ORM\Query\Expr\Join;
|
|
||||||
use Doctrine\ORM\QueryBuilder;
|
use Doctrine\ORM\QueryBuilder;
|
||||||
use Symfony\Bridge\Doctrine\Form\Type\EntityType;
|
use Symfony\Bridge\Doctrine\Form\Type\EntityType;
|
||||||
use Symfony\Component\Form\FormBuilderInterface;
|
use Symfony\Component\Form\FormBuilderInterface;
|
||||||
|
|
||||||
class UserJobFilter implements FilterInterface
|
final readonly class UserJobFilter implements FilterInterface, DataTransformerFilterInterface
|
||||||
{
|
{
|
||||||
private const PREFIX = 'acp_filter_user_job';
|
private const PREFIX = 'acp_filter_user_job';
|
||||||
|
|
||||||
public function __construct(
|
public function __construct(
|
||||||
private readonly TranslatableStringHelper $translatableStringHelper,
|
private TranslatableStringHelper $translatableStringHelper,
|
||||||
private readonly UserJobRepositoryInterface $userJobRepository,
|
private UserJobRepositoryInterface $userJobRepository,
|
||||||
|
private RollingDateConverterInterface $rollingDateConverter,
|
||||||
) {
|
) {
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -42,42 +47,31 @@ class UserJobFilter implements FilterInterface
|
|||||||
{
|
{
|
||||||
$p = self::PREFIX;
|
$p = self::PREFIX;
|
||||||
|
|
||||||
$qb
|
$qb->andWhere(
|
||||||
->leftJoin(
|
$qb->expr()->exists(
|
||||||
'acp.userHistories',
|
sprintf(
|
||||||
"{$p}_userHistory",
|
<<<DQL
|
||||||
Join::WITH,
|
SELECT 1
|
||||||
$qb->expr()->andX(
|
FROM %s {$p}_userHistory
|
||||||
$qb->expr()->eq("{$p}_userHistory.accompanyingPeriod", 'acp.id'),
|
JOIN %s {$p}_userJobHistory
|
||||||
$qb->expr()->andX(
|
WITH
|
||||||
$qb->expr()->gte('COALESCE(acp.closingDate, CURRENT_TIMESTAMP())', "{$p}_userHistory.startDate"),
|
{$p}_userHistory.user = {$p}_userJobHistory.user
|
||||||
$qb->expr()->orX(
|
AND OVERLAPSI({$p}_userHistory.startDate, {$p}_userHistory.endDate),({$p}_userJobHistory.startDate, {$p}_userJobHistory.endDate) = TRUE
|
||||||
$qb->expr()->isNull("{$p}_userHistory.endDate"),
|
WHERE {$p}_userHistory.accompanyingPeriod = acp
|
||||||
$qb->expr()->lt('COALESCE(acp.closingDate, CURRENT_TIMESTAMP())', "{$p}_userHistory.endDate")
|
AND {$p}_userHistory.startDate <= :{$p}_endDate
|
||||||
)
|
AND ({$p}_userHistory.endDate IS NULL OR {$p}_userHistory.endDate > :{$p}_startDate)
|
||||||
)
|
AND {$p}_userJobHistory.startDate <= :{$p}_endDate
|
||||||
)
|
AND ({$p}_userJobHistory.endDate IS NULL OR {$p}_userJobHistory.endDate > :{$p}_startDate)
|
||||||
)
|
AND {$p}_userJobHistory.job IN (:{$p}_jobs)
|
||||||
->leftJoin(
|
DQL,
|
||||||
|
UserHistory::class,
|
||||||
UserJobHistory::class,
|
UserJobHistory::class,
|
||||||
"{$p}_jobHistory",
|
),
|
||||||
Join::WITH,
|
|
||||||
$qb->expr()->andX(
|
|
||||||
$qb->expr()->eq("{$p}_jobHistory.user", "{$p}_userHistory.user"),
|
|
||||||
$qb->expr()->andX(
|
|
||||||
$qb->expr()->lte("{$p}_jobHistory.startDate", "{$p}_userHistory.startDate"),
|
|
||||||
$qb->expr()->orX(
|
|
||||||
$qb->expr()->isNull("{$p}_jobHistory".'.endDate'),
|
|
||||||
$qb->expr()->gt("{$p}_jobHistory.endDate", "{$p}_userHistory.startDate")
|
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
)
|
->setParameter("{$p}_jobs", $data['jobs'])
|
||||||
)
|
->setParameter("{$p}_startDate", $this->rollingDateConverter->convert($data['start_date']))
|
||||||
->andWhere($qb->expr()->in("{$p}_jobHistory.job", ":{$p}_job"))
|
->setParameter("{$p}_endDate", $this->rollingDateConverter->convert($data['end_date']))
|
||||||
->setParameter(
|
|
||||||
"{$p}_job",
|
|
||||||
$data['jobs'],
|
|
||||||
)
|
|
||||||
;
|
;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -96,20 +90,29 @@ class UserJobFilter implements FilterInterface
|
|||||||
'expanded' => true,
|
'expanded' => true,
|
||||||
'choice_label' => fn (UserJob $job) => $this->translatableStringHelper->localize($job->getLabel()),
|
'choice_label' => fn (UserJob $job) => $this->translatableStringHelper->localize($job->getLabel()),
|
||||||
'label' => 'Job',
|
'label' => 'Job',
|
||||||
]);
|
])
|
||||||
|
->add('start_date', PickRollingDateType::class, [
|
||||||
|
'label' => 'export.filter.course.by_user_job.Start from',
|
||||||
|
])
|
||||||
|
->add('end_date', PickRollingDateType::class, [
|
||||||
|
'label' => 'export.filter.course.by_user_job.Until',
|
||||||
|
])
|
||||||
|
;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function describeAction($data, $format = 'string')
|
public function describeAction($data, $format = 'string')
|
||||||
{
|
{
|
||||||
return [
|
return [
|
||||||
'export.filter.course.by_user_job.Filtered by user job: only %job%', [
|
'exports.filter.course.by_user_job.Filtered by user job: only job', [
|
||||||
'%job%' => implode(
|
'job' => implode(
|
||||||
', ',
|
', ',
|
||||||
array_map(
|
array_map(
|
||||||
fn (UserJob $job) => $this->translatableStringHelper->localize($job->getLabel()),
|
fn (UserJob $job) => $this->translatableStringHelper->localize($job->getLabel()),
|
||||||
$data['jobs'] instanceof Collection ? $data['jobs']->toArray() : $data['jobs']
|
$data['jobs'] instanceof Collection ? $data['jobs']->toArray() : $data['jobs']
|
||||||
)
|
)
|
||||||
),
|
),
|
||||||
|
'startDate' => $this->rollingDateConverter->convert($data['start_date']),
|
||||||
|
'endDate' => $this->rollingDateConverter->convert($data['end_date']),
|
||||||
],
|
],
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
@ -118,9 +121,30 @@ class UserJobFilter implements FilterInterface
|
|||||||
{
|
{
|
||||||
return [
|
return [
|
||||||
'jobs' => [],
|
'jobs' => [],
|
||||||
|
'start_date' => new RollingDate(RollingDate::T_YEAR_CURRENT_START),
|
||||||
|
'end_date' => new RollingDate(RollingDate::T_TODAY),
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function transformData(?array $before): array
|
||||||
|
{
|
||||||
|
$default = $this->getFormDefaultData();
|
||||||
|
|
||||||
|
if (null === $before) {
|
||||||
|
return $default;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!array_key_exists('start_date', $before) || null === $before['start_date']) {
|
||||||
|
$before['start_date'] = $default['start_date'];
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!array_key_exists('end_date', $before) || null === $before['end_date']) {
|
||||||
|
$before['end_date'] = $default['end_date'];
|
||||||
|
}
|
||||||
|
|
||||||
|
return $before;
|
||||||
|
}
|
||||||
|
|
||||||
public function getTitle(): string
|
public function getTitle(): string
|
||||||
{
|
{
|
||||||
return 'export.filter.course.by_user_job.Filter by user job';
|
return 'export.filter.course.by_user_job.Filter by user job';
|
||||||
|
@ -50,12 +50,14 @@ final class UserJobFilterTest extends AbstractFilterTest
|
|||||||
|
|
||||||
yield [
|
yield [
|
||||||
'jobs' => new ArrayCollection($jobs),
|
'jobs' => new ArrayCollection($jobs),
|
||||||
'date_calc' => new RollingDate(RollingDate::T_TODAY),
|
'start_date' => new RollingDate(RollingDate::T_YEAR_CURRENT_START),
|
||||||
|
'end_date' => new RollingDate(RollingDate::T_TODAY),
|
||||||
];
|
];
|
||||||
|
|
||||||
yield [
|
yield [
|
||||||
'jobs' => $jobs,
|
'jobs' => $jobs,
|
||||||
'date_calc' => new RollingDate(RollingDate::T_TODAY),
|
'start_date' => new RollingDate(RollingDate::T_YEAR_CURRENT_START),
|
||||||
|
'end_date' => new RollingDate(RollingDate::T_TODAY),
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -143,6 +143,8 @@ exports:
|
|||||||
by_referrer_between_dates:
|
by_referrer_between_dates:
|
||||||
description: >-
|
description: >-
|
||||||
Filtré par référent du parcours, entre deux dates: depuis le {start_date, date, medium}, jusqu'au {end_date, date, medium}, seulement {agents}
|
Filtré par référent du parcours, entre deux dates: depuis le {start_date, date, medium}, jusqu'au {end_date, date, medium}, seulement {agents}
|
||||||
|
by_user_job:
|
||||||
|
"Filtered by user job: only job": "Filtré par métier du référent entre le {startDate, date, short} et le {endDate, date, short}: uniquement {job}"
|
||||||
work:
|
work:
|
||||||
by_treating_agent:
|
by_treating_agent:
|
||||||
Filtered by treating agent at date: >-
|
Filtered by treating agent at date: >-
|
||||||
|
@ -1232,7 +1232,8 @@ export:
|
|||||||
'Filtered by creator job: only %jobs%': "Filtré par métier du créateur: uniquement %jobs%"
|
'Filtered by creator job: only %jobs%': "Filtré par métier du créateur: uniquement %jobs%"
|
||||||
by_user_job:
|
by_user_job:
|
||||||
Filter by user job: Filtrer les parcours par métier du référent
|
Filter by user job: Filtrer les parcours par métier du référent
|
||||||
"Filtered by user job: only %job%": "Filtré par métier du référent: uniquement %job%"
|
Start from: Référent et métier depuis le
|
||||||
|
Until: Jusqu'au
|
||||||
by_social_action:
|
by_social_action:
|
||||||
title: Filtrer les parcours par action d'accompagnement
|
title: Filtrer les parcours par action d'accompagnement
|
||||||
Accepted socialactions: Actions d'accompagnement
|
Accepted socialactions: Actions d'accompagnement
|
||||||
|
Loading…
x
Reference in New Issue
Block a user