[export] fix 2 job/scope 'WorkingOnCourse' filters in acp

This commit is contained in:
Mathieu Jaumotte 2023-09-28 17:21:24 +02:00
parent fa3fc2c781
commit c00c26c3e5
5 changed files with 112 additions and 116 deletions

View File

@ -57,20 +57,17 @@ final readonly class JobWorkingOnCourseAggregator implements AggregatorInterface
Join::WITH, Join::WITH,
$qb->expr()->eq("{$p}_history.user", "{$p}_user") $qb->expr()->eq("{$p}_history.user", "{$p}_user")
) )
// job_at based on _info.infoDate
->andWhere( ->andWhere(
$qb->expr()->andX( $qb->expr()->andX(
$qb->expr()->lte("{$p}_history.startDate", ":{$p}_at"), $qb->expr()->lte("{$p}_history.startDate", "acpinfo.infoDate"),
$qb->expr()->orX( $qb->expr()->orX(
$qb->expr()->isNull("{$p}_history.endDate"), $qb->expr()->isNull("{$p}_history.endDate"),
$qb->expr()->gt("{$p}_history.endDate", ":{$p}_at") $qb->expr()->gt("{$p}_history.endDate", "acpinfo.infoDate")
) )
) )
) )
->addSelect("IDENTITY({$p}_history.job) AS {$p}_select") ->addSelect("IDENTITY({$p}_history.job) AS {$p}_select")
->setParameter(
"{$p}_at",
$this->rollingDateConverter->convert($data['job_at'])
)
->addGroupBy("{$p}_select"); ->addGroupBy("{$p}_select");
} }
@ -81,15 +78,11 @@ final readonly class JobWorkingOnCourseAggregator implements AggregatorInterface
public function buildForm(FormBuilderInterface $builder) public function buildForm(FormBuilderInterface $builder)
{ {
$builder->add('job_at', PickRollingDateType::class, [
'label' => 'export.aggregator.course.by_job_working.Calc date',
'required' => true
]);
} }
public function getFormDefaultData(): array public function getFormDefaultData(): array
{ {
return ['job_at' => new RollingDate(RollingDate::T_TODAY)]; return [];
} }
public function getLabels($key, array $values, $data): \Closure public function getLabels($key, array $values, $data): \Closure

View File

@ -57,20 +57,17 @@ final readonly class ScopeWorkingOnCourseAggregator implements AggregatorInterfa
Join::WITH, Join::WITH,
$qb->expr()->eq("{$p}_history.user", "{$p}_user") $qb->expr()->eq("{$p}_history.user", "{$p}_user")
) )
// scope_at based on _info.infoDate
->andWhere( ->andWhere(
$qb->expr()->andX( $qb->expr()->andX(
$qb->expr()->lte("{$p}_history.startDate", ":{$p}_at"), $qb->expr()->lte("{$p}_history.startDate", "acpinfo.infoDate"),
$qb->expr()->orX( $qb->expr()->orX(
$qb->expr()->isNull("{$p}_history.endDate"), $qb->expr()->isNull("{$p}_history.endDate"),
$qb->expr()->gt("{$p}_history.endDate", ":{$p}_at") $qb->expr()->gt("{$p}_history.endDate", "acpinfo.infoDate")
) )
) )
) )
->addSelect("IDENTITY({$p}_history.scope) AS {$p}_select") ->addSelect("IDENTITY({$p}_history.scope) AS {$p}_select")
->setParameter(
"{$p}_at",
$this->rollingDateConverter->convert($data['scope_at'])
)
->addGroupBy("{$p}_select"); ->addGroupBy("{$p}_select");
} }
@ -81,15 +78,11 @@ final readonly class ScopeWorkingOnCourseAggregator implements AggregatorInterfa
public function buildForm(FormBuilderInterface $builder) public function buildForm(FormBuilderInterface $builder)
{ {
$builder->add('scope_at', PickRollingDateType::class, [
'label' => 'export.aggregator.course.by_scope_working.Calc date',
'required' => true,
]);
} }
public function getFormDefaultData(): array public function getFormDefaultData(): array
{ {
return ['scope_at' => new RollingDate(RollingDate::T_TODAY)]; return [];
} }
public function getLabels($key, array $values, $data): \Closure public function getLabels($key, array $values, $data): \Closure

View File

@ -11,17 +11,15 @@ declare(strict_types=1);
namespace Chill\PersonBundle\Export\Filter\AccompanyingCourseFilters; namespace Chill\PersonBundle\Export\Filter\AccompanyingCourseFilters;
use Chill\MainBundle\Entity\User; use Chill\MainBundle\Entity\User\UserJobHistory;
use Chill\MainBundle\Entity\UserJob; use Chill\MainBundle\Entity\UserJob;
use Chill\MainBundle\Export\FilterInterface; use Chill\MainBundle\Export\FilterInterface;
use Chill\MainBundle\Form\Type\PickRollingDateType; use Chill\MainBundle\Form\Type\PickRollingDateType;
use Chill\MainBundle\Form\Type\PickUserDynamicType;
use Chill\MainBundle\Repository\UserJobRepositoryInterface; use Chill\MainBundle\Repository\UserJobRepositoryInterface;
use Chill\MainBundle\Service\RollingDate\RollingDate; use Chill\MainBundle\Service\RollingDate\RollingDate;
use Chill\MainBundle\Service\RollingDate\RollingDateConverterInterface; use Chill\MainBundle\Service\RollingDate\RollingDateConverterInterface;
use Chill\MainBundle\Templating\Entity\UserRender;
use Chill\MainBundle\Templating\TranslatableStringHelperInterface; use Chill\MainBundle\Templating\TranslatableStringHelperInterface;
use Chill\PersonBundle\Entity\AccompanyingPeriod; use Chill\PersonBundle\Entity\AccompanyingPeriod\AccompanyingPeriodInfo;
use Chill\PersonBundle\Export\Declarations; use Chill\PersonBundle\Export\Declarations;
use Doctrine\ORM\QueryBuilder; use Doctrine\ORM\QueryBuilder;
use Symfony\Bridge\Doctrine\Form\Type\EntityType; use Symfony\Bridge\Doctrine\Form\Type\EntityType;
@ -34,12 +32,50 @@ use Symfony\Component\Form\FormBuilderInterface;
*/ */
readonly class JobWorkingOnCourseFilter implements FilterInterface readonly class JobWorkingOnCourseFilter implements FilterInterface
{ {
private const PREFIX = 'acp_filter_user_job_working_on_course';
public function __construct( public function __construct(
private UserJobRepositoryInterface $userJobRepository, private UserJobRepositoryInterface $userJobRepository,
private RollingDateConverterInterface $rollingDateConverter, private RollingDateConverterInterface $rollingDateConverter,
private TranslatableStringHelperInterface $translatableStringHelper, private TranslatableStringHelperInterface $translatableStringHelper,
) {} ) {}
public function addRole(): ?string
{
return null;
}
public function alterQuery(QueryBuilder $qb, $data): void
{
$p = self::PREFIX;
$qb
->andWhere(
$qb->expr()->exists(
"SELECT 1 FROM " . AccompanyingPeriodInfo::class . " {$p}_info "
. "JOIN {$p}_info.user {$p}_user "
. "JOIN " . UserJobHistory::class . " {$p}_history WITH {$p}_history.user = {$p}_user "
. "WHERE IDENTITY({$p}_info.accompanyingPeriod) = acp.id "
. "AND {$p}_history.job IN (:{$p}_jobs) "
// job_at based on _info.infoDate
. "AND {$p}_history.startDate <= {$p}_info.infoDate "
. "AND ({$p}_history.endDate IS NULL OR {$p}_history.endDate > {$p}_info.infoDate) "
. "AND {$p}_info.infoDate >= :{$p}_start and {$p}_info.infoDate < :{$p}_end"
)
)
->setParameters([
"{$p}_jobs" => $data['jobs'],
"{$p}_start" => $this->rollingDateConverter->convert($data['start_date']),
"{$p}_end" => $this->rollingDateConverter->convert($data['end_date'])
])
;
}
public function applyOn(): string
{
return Declarations::ACP_TYPE;
}
public function buildForm(FormBuilderInterface $builder): void public function buildForm(FormBuilderInterface $builder): void
{ {
$jobs = $this->userJobRepository->findAllActive(); $jobs = $this->userJobRepository->findAllActive();
@ -59,23 +95,14 @@ readonly class JobWorkingOnCourseFilter implements FilterInterface
->add('end_date', PickRollingDateType::class, [ ->add('end_date', PickRollingDateType::class, [
'label' => 'export.filter.course.by_job_working.Job working before' 'label' => 'export.filter.course.by_job_working.Job working before'
]) ])
//->add('job_at', PickRollingDateType::class, [
// 'label' => 'bla',
// 'help' => 'bli',
// 'required' => false,
//])
; ;
} }
public function getFormDefaultData(): array
{
return [
'jobs' => [],
'start_date' => new RollingDate(RollingDate::T_YEAR_CURRENT_START),
'end_date' => new RollingDate(RollingDate::T_TODAY),
];
}
public function getTitle(): string
{
return 'export.filter.course.by_job_working.title';
}
public function describeAction($data, $format = 'string'): array public function describeAction($data, $format = 'string'): array
{ {
return [ return [
@ -93,37 +120,18 @@ readonly class JobWorkingOnCourseFilter implements FilterInterface
]; ];
} }
public function addRole(): ?string public function getFormDefaultData(): array
{ {
return null; return [
'jobs' => [],
'start_date' => new RollingDate(RollingDate::T_YEAR_CURRENT_START),
'end_date' => new RollingDate(RollingDate::T_TODAY),
//'job_at' => null,
];
} }
public function alterQuery(QueryBuilder $qb, $data): void public function getTitle(): string
{ {
$ai_alias = 'jobs_working_on_course_filter_acc_info'; return 'export.filter.course.by_job_working.title';
$ai_user_alias = 'jobs_working_on_course_filter_user';
$ai_jobs = 'jobs_working_on_course_filter_jobs';
$start = 'acp_jobs_work_on_start';
$end = 'acp_jobs_work_on_end';
$qb
->andWhere(
$qb->expr()->exists(
"SELECT 1 FROM " . AccompanyingPeriod\AccompanyingPeriodInfo::class . " {$ai_alias} JOIN {$ai_alias}.user {$ai_user_alias} " .
"WHERE IDENTITY({$ai_alias}.accompanyingPeriod) = acp.id
AND {$ai_user_alias}.userJob IN (:{$ai_jobs})
AND {$ai_alias}.infoDate >= :{$start} and {$ai_alias}.infoDate < :{$end}
"
)
)
->setParameter($ai_jobs, $data['jobs'])
->setParameter($start, $this->rollingDateConverter->convert($data['start_date']))
->setParameter($end, $this->rollingDateConverter->convert($data['end_date']))
;
}
public function applyOn(): string
{
return Declarations::ACP_TYPE;
} }
} }

View File

@ -12,18 +12,14 @@ declare(strict_types=1);
namespace Chill\PersonBundle\Export\Filter\AccompanyingCourseFilters; namespace Chill\PersonBundle\Export\Filter\AccompanyingCourseFilters;
use Chill\MainBundle\Entity\Scope; use Chill\MainBundle\Entity\Scope;
use Chill\MainBundle\Entity\User; use Chill\MainBundle\Entity\User\UserScopeHistory;
use Chill\MainBundle\Entity\UserJob;
use Chill\MainBundle\Export\FilterInterface; use Chill\MainBundle\Export\FilterInterface;
use Chill\MainBundle\Form\Type\PickRollingDateType; use Chill\MainBundle\Form\Type\PickRollingDateType;
use Chill\MainBundle\Form\Type\PickUserDynamicType;
use Chill\MainBundle\Repository\ScopeRepositoryInterface; use Chill\MainBundle\Repository\ScopeRepositoryInterface;
use Chill\MainBundle\Repository\UserJobRepositoryInterface;
use Chill\MainBundle\Service\RollingDate\RollingDate; use Chill\MainBundle\Service\RollingDate\RollingDate;
use Chill\MainBundle\Service\RollingDate\RollingDateConverterInterface; use Chill\MainBundle\Service\RollingDate\RollingDateConverterInterface;
use Chill\MainBundle\Templating\Entity\UserRender;
use Chill\MainBundle\Templating\TranslatableStringHelperInterface; use Chill\MainBundle\Templating\TranslatableStringHelperInterface;
use Chill\PersonBundle\Entity\AccompanyingPeriod; use Chill\PersonBundle\Entity\AccompanyingPeriod\AccompanyingPeriodInfo;
use Chill\PersonBundle\Export\Declarations; use Chill\PersonBundle\Export\Declarations;
use Doctrine\ORM\QueryBuilder; use Doctrine\ORM\QueryBuilder;
use Symfony\Bridge\Doctrine\Form\Type\EntityType; use Symfony\Bridge\Doctrine\Form\Type\EntityType;
@ -36,12 +32,50 @@ use Symfony\Component\Form\FormBuilderInterface;
*/ */
readonly class ScopeWorkingOnCourseFilter implements FilterInterface readonly class ScopeWorkingOnCourseFilter implements FilterInterface
{ {
private const PREFIX = 'acp_filter_user_scope_working_on_course';
public function __construct( public function __construct(
private ScopeRepositoryInterface $scopeRepository, private ScopeRepositoryInterface $scopeRepository,
private RollingDateConverterInterface $rollingDateConverter, private RollingDateConverterInterface $rollingDateConverter,
private TranslatableStringHelperInterface $translatableStringHelper, private TranslatableStringHelperInterface $translatableStringHelper,
) {} ) {}
public function addRole(): ?string
{
return null;
}
public function alterQuery(QueryBuilder $qb, $data): void
{
$p = self::PREFIX;
$qb
->andWhere(
$qb->expr()->exists(
"SELECT 1 FROM " . AccompanyingPeriodInfo::class . " {$p}_info "
. "JOIN {$p}_info.user {$p}_user "
. "JOIN " . UserScopeHistory::class . " {$p}_history WITH {$p}_history.user = {$p}_user "
. "WHERE IDENTITY({$p}_info.accompanyingPeriod) = acp.id "
. "AND {$p}_history.scope IN ( :{$p}_scopes ) "
// scope_at based on _info.infoDate
. "AND {$p}_history.startDate <= {$p}_info.infoDate "
. "AND ({$p}_history.endDate IS NULL OR {$p}_history.endDate > {$p}_info.infoDate) "
. "AND {$p}_info.infoDate >= :{$p}_start AND {$p}_info.infoDate < :{$p}_end"
)
)
->setParameters([
"{$p}_scopes" => $data["scopes"],
"{$p}_start" => $this->rollingDateConverter->convert($data["start_date"]),
"{$p}_end" => $this->rollingDateConverter->convert($data["end_date"])
])
;
}
public function applyOn(): string
{
return Declarations::ACP_TYPE;
}
public function buildForm(FormBuilderInterface $builder): void public function buildForm(FormBuilderInterface $builder): void
{ {
$scopes = $this->scopeRepository->findAllActive(); $scopes = $this->scopeRepository->findAllActive();
@ -64,20 +98,6 @@ readonly class ScopeWorkingOnCourseFilter implements FilterInterface
; ;
} }
public function getFormDefaultData(): array
{
return [
'scopes' => [],
'start_date' => new RollingDate(RollingDate::T_YEAR_CURRENT_START),
'end_date' => new RollingDate(RollingDate::T_TODAY),
];
}
public function getTitle(): string
{
return 'export.filter.course.by_scope_working.title';
}
public function describeAction($data, $format = 'string'): array public function describeAction($data, $format = 'string'): array
{ {
return [ return [
@ -95,37 +115,17 @@ readonly class ScopeWorkingOnCourseFilter implements FilterInterface
]; ];
} }
public function addRole(): ?string public function getFormDefaultData(): array
{ {
return null; return [
'scopes' => [],
'start_date' => new RollingDate(RollingDate::T_YEAR_CURRENT_START),
'end_date' => new RollingDate(RollingDate::T_TODAY),
];
} }
public function alterQuery(QueryBuilder $qb, $data): void public function getTitle(): string
{ {
$ai_alias = 'scopes_working_on_course_filter_acc_info'; return 'export.filter.course.by_scope_working.title';
$ai_user_alias = 'scopes_working_on_course_filter_user';
$ai_scopes = 'scopes_working_on_course_filter_scopes';
$start = 'acp_scopes_work_on_start';
$end = 'acp_scopes_work_on_end';
$qb
->andWhere(
$qb->expr()->exists(
"SELECT 1 FROM " . AccompanyingPeriod\AccompanyingPeriodInfo::class . " {$ai_alias} JOIN {$ai_alias}.user {$ai_user_alias} " .
"WHERE IDENTITY({$ai_alias}.accompanyingPeriod) = acp.id
AND {$ai_user_alias}.mainScope IN (:{$ai_scopes})
AND {$ai_alias}.infoDate >= :{$start} and {$ai_alias}.infoDate < :{$end}
"
)
)
->setParameter($ai_scopes, $data['scopes'])
->setParameter($start, $this->rollingDateConverter->convert($data['start_date']))
->setParameter($end, $this->rollingDateConverter->convert($data['end_date']))
;
}
public function applyOn(): string
{
return Declarations::ACP_TYPE;
} }
} }

View File

@ -1108,11 +1108,13 @@ export:
'Filtered by job working on course: only %jobs%, between %start_date% and %end_date%': 'Filtré par métier des intervenants sur le parcours: seulement %jobs%, entre le %start_date% et le %end_date%' 'Filtered by job working on course: only %jobs%, between %start_date% and %end_date%': 'Filtré par métier des intervenants sur le parcours: seulement %jobs%, entre le %start_date% et le %end_date%'
Job working after: Intervention après le Job working after: Intervention après le
Job working before: Intervention avant le Job working before: Intervention avant le
Calc date:
by_scope_working: by_scope_working:
title: Filtrer les parcours par service de l'intervenant, entre deux dates title: Filtrer les parcours par service de l'intervenant, entre deux dates
'Filtered by scope working on course: only %scopes%, between %start_date% and %end_date%': 'Filtré par service des intervenants sur le parcours: seulement %scopes%, entre le %start_date% et le %end_date%' 'Filtered by scope working on course: only %scopes%, between %start_date% and %end_date%': 'Filtré par service des intervenants sur le parcours: seulement %scopes%, entre le %start_date% et le %end_date%'
Scope working after: Intervention après le Scope working after: Intervention après le
Scope working before: Intervention avant le Scope working before: Intervention avant le
Calc date:
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