From c00c26c3e55302ecfa344bb7f588a388d6e68319 Mon Sep 17 00:00:00 2001 From: Mathieu Jaumotte Date: Thu, 28 Sep 2023 17:21:24 +0200 Subject: [PATCH] [export] fix 2 job/scope 'WorkingOnCourse' filters in acp --- .../JobWorkingOnCourseAggregator.php | 15 +-- .../ScopeWorkingOnCourseAggregator.php | 15 +-- .../JobWorkingOnCourseFilter.php | 100 ++++++++++-------- .../ScopeWorkingOnCourseFilter.php | 96 ++++++++--------- .../translations/messages.fr.yml | 2 + 5 files changed, 112 insertions(+), 116 deletions(-) diff --git a/src/Bundle/ChillPersonBundle/Export/Aggregator/AccompanyingCourseAggregators/JobWorkingOnCourseAggregator.php b/src/Bundle/ChillPersonBundle/Export/Aggregator/AccompanyingCourseAggregators/JobWorkingOnCourseAggregator.php index ccc108cd0..a58f6dcaa 100644 --- a/src/Bundle/ChillPersonBundle/Export/Aggregator/AccompanyingCourseAggregators/JobWorkingOnCourseAggregator.php +++ b/src/Bundle/ChillPersonBundle/Export/Aggregator/AccompanyingCourseAggregators/JobWorkingOnCourseAggregator.php @@ -57,20 +57,17 @@ final readonly class JobWorkingOnCourseAggregator implements AggregatorInterface Join::WITH, $qb->expr()->eq("{$p}_history.user", "{$p}_user") ) + // job_at based on _info.infoDate ->andWhere( $qb->expr()->andX( - $qb->expr()->lte("{$p}_history.startDate", ":{$p}_at"), + $qb->expr()->lte("{$p}_history.startDate", "acpinfo.infoDate"), $qb->expr()->orX( $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") - ->setParameter( - "{$p}_at", - $this->rollingDateConverter->convert($data['job_at']) - ) ->addGroupBy("{$p}_select"); } @@ -81,15 +78,11 @@ final readonly class JobWorkingOnCourseAggregator implements AggregatorInterface 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 { - return ['job_at' => new RollingDate(RollingDate::T_TODAY)]; + return []; } public function getLabels($key, array $values, $data): \Closure diff --git a/src/Bundle/ChillPersonBundle/Export/Aggregator/AccompanyingCourseAggregators/ScopeWorkingOnCourseAggregator.php b/src/Bundle/ChillPersonBundle/Export/Aggregator/AccompanyingCourseAggregators/ScopeWorkingOnCourseAggregator.php index 08bddabb5..e45f7d479 100644 --- a/src/Bundle/ChillPersonBundle/Export/Aggregator/AccompanyingCourseAggregators/ScopeWorkingOnCourseAggregator.php +++ b/src/Bundle/ChillPersonBundle/Export/Aggregator/AccompanyingCourseAggregators/ScopeWorkingOnCourseAggregator.php @@ -57,20 +57,17 @@ final readonly class ScopeWorkingOnCourseAggregator implements AggregatorInterfa Join::WITH, $qb->expr()->eq("{$p}_history.user", "{$p}_user") ) + // scope_at based on _info.infoDate ->andWhere( $qb->expr()->andX( - $qb->expr()->lte("{$p}_history.startDate", ":{$p}_at"), + $qb->expr()->lte("{$p}_history.startDate", "acpinfo.infoDate"), $qb->expr()->orX( $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") - ->setParameter( - "{$p}_at", - $this->rollingDateConverter->convert($data['scope_at']) - ) ->addGroupBy("{$p}_select"); } @@ -81,15 +78,11 @@ final readonly class ScopeWorkingOnCourseAggregator implements AggregatorInterfa 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 { - return ['scope_at' => new RollingDate(RollingDate::T_TODAY)]; + return []; } public function getLabels($key, array $values, $data): \Closure diff --git a/src/Bundle/ChillPersonBundle/Export/Filter/AccompanyingCourseFilters/JobWorkingOnCourseFilter.php b/src/Bundle/ChillPersonBundle/Export/Filter/AccompanyingCourseFilters/JobWorkingOnCourseFilter.php index 142cfd307..393a726fc 100644 --- a/src/Bundle/ChillPersonBundle/Export/Filter/AccompanyingCourseFilters/JobWorkingOnCourseFilter.php +++ b/src/Bundle/ChillPersonBundle/Export/Filter/AccompanyingCourseFilters/JobWorkingOnCourseFilter.php @@ -11,17 +11,15 @@ declare(strict_types=1); 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\Export\FilterInterface; use Chill\MainBundle\Form\Type\PickRollingDateType; -use Chill\MainBundle\Form\Type\PickUserDynamicType; use Chill\MainBundle\Repository\UserJobRepositoryInterface; use Chill\MainBundle\Service\RollingDate\RollingDate; use Chill\MainBundle\Service\RollingDate\RollingDateConverterInterface; -use Chill\MainBundle\Templating\Entity\UserRender; use Chill\MainBundle\Templating\TranslatableStringHelperInterface; -use Chill\PersonBundle\Entity\AccompanyingPeriod; +use Chill\PersonBundle\Entity\AccompanyingPeriod\AccompanyingPeriodInfo; use Chill\PersonBundle\Export\Declarations; use Doctrine\ORM\QueryBuilder; use Symfony\Bridge\Doctrine\Form\Type\EntityType; @@ -34,12 +32,50 @@ use Symfony\Component\Form\FormBuilderInterface; */ readonly class JobWorkingOnCourseFilter implements FilterInterface { + private const PREFIX = 'acp_filter_user_job_working_on_course'; + public function __construct( private UserJobRepositoryInterface $userJobRepository, private RollingDateConverterInterface $rollingDateConverter, 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 { $jobs = $this->userJobRepository->findAllActive(); @@ -59,23 +95,14 @@ readonly class JobWorkingOnCourseFilter implements FilterInterface ->add('end_date', PickRollingDateType::class, [ '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 { 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'; - $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; + return 'export.filter.course.by_job_working.title'; } } diff --git a/src/Bundle/ChillPersonBundle/Export/Filter/AccompanyingCourseFilters/ScopeWorkingOnCourseFilter.php b/src/Bundle/ChillPersonBundle/Export/Filter/AccompanyingCourseFilters/ScopeWorkingOnCourseFilter.php index 6aef4e3da..97f592c3d 100644 --- a/src/Bundle/ChillPersonBundle/Export/Filter/AccompanyingCourseFilters/ScopeWorkingOnCourseFilter.php +++ b/src/Bundle/ChillPersonBundle/Export/Filter/AccompanyingCourseFilters/ScopeWorkingOnCourseFilter.php @@ -12,18 +12,14 @@ declare(strict_types=1); namespace Chill\PersonBundle\Export\Filter\AccompanyingCourseFilters; use Chill\MainBundle\Entity\Scope; -use Chill\MainBundle\Entity\User; -use Chill\MainBundle\Entity\UserJob; +use Chill\MainBundle\Entity\User\UserScopeHistory; use Chill\MainBundle\Export\FilterInterface; use Chill\MainBundle\Form\Type\PickRollingDateType; -use Chill\MainBundle\Form\Type\PickUserDynamicType; use Chill\MainBundle\Repository\ScopeRepositoryInterface; -use Chill\MainBundle\Repository\UserJobRepositoryInterface; use Chill\MainBundle\Service\RollingDate\RollingDate; use Chill\MainBundle\Service\RollingDate\RollingDateConverterInterface; -use Chill\MainBundle\Templating\Entity\UserRender; use Chill\MainBundle\Templating\TranslatableStringHelperInterface; -use Chill\PersonBundle\Entity\AccompanyingPeriod; +use Chill\PersonBundle\Entity\AccompanyingPeriod\AccompanyingPeriodInfo; use Chill\PersonBundle\Export\Declarations; use Doctrine\ORM\QueryBuilder; use Symfony\Bridge\Doctrine\Form\Type\EntityType; @@ -36,12 +32,50 @@ use Symfony\Component\Form\FormBuilderInterface; */ readonly class ScopeWorkingOnCourseFilter implements FilterInterface { + private const PREFIX = 'acp_filter_user_scope_working_on_course'; + public function __construct( private ScopeRepositoryInterface $scopeRepository, private RollingDateConverterInterface $rollingDateConverter, 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 { $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 { 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'; - $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; + return 'export.filter.course.by_scope_working.title'; } } diff --git a/src/Bundle/ChillPersonBundle/translations/messages.fr.yml b/src/Bundle/ChillPersonBundle/translations/messages.fr.yml index 08027db7e..fadfbdc51 100644 --- a/src/Bundle/ChillPersonBundle/translations/messages.fr.yml +++ b/src/Bundle/ChillPersonBundle/translations/messages.fr.yml @@ -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%' Job working after: Intervention après le Job working before: Intervention avant le + Calc date: by_scope_working: 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%' Scope working after: Intervention après le Scope working before: Intervention avant le + Calc date: by_step: 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