From fde6000d0b05e8bcebe0ed951bbd2c0fdcc2a296 Mon Sep 17 00:00:00 2001 From: Mathieu Jaumotte Date: Tue, 14 Nov 2023 13:43:28 +0100 Subject: [PATCH] filters alterQuery --- .../SocialWorkFilters/CreatorFilter.php | 4 +--- .../SocialWorkFilters/CreatorJobFilter.php | 22 ++++++++++++++++--- .../SocialWorkFilters/CreatorScopeFilter.php | 22 ++++++++++++++++--- 3 files changed, 39 insertions(+), 9 deletions(-) diff --git a/src/Bundle/ChillPersonBundle/Export/Filter/SocialWorkFilters/CreatorFilter.php b/src/Bundle/ChillPersonBundle/Export/Filter/SocialWorkFilters/CreatorFilter.php index 1907edb57..100bcfdc4 100644 --- a/src/Bundle/ChillPersonBundle/Export/Filter/SocialWorkFilters/CreatorFilter.php +++ b/src/Bundle/ChillPersonBundle/Export/Filter/SocialWorkFilters/CreatorFilter.php @@ -22,8 +22,6 @@ class CreatorFilter implements FilterInterface { private const PREFIX = 'acpw_filter_creator'; - public function __construct() {} - public function addRole(): ?string { return null; @@ -34,7 +32,7 @@ class CreatorFilter implements FilterInterface $p = self::PREFIX; $qb - ->join('acpw.createdBy', "{$p}_creator") + ->leftJoin('acpw.createdBy', "{$p}_creator") ->andWhere($qb->expr()->in("{$p}_creator", ":{$p}_creators")) ->setParameter("{$p}_creators", $data['creators']); } diff --git a/src/Bundle/ChillPersonBundle/Export/Filter/SocialWorkFilters/CreatorJobFilter.php b/src/Bundle/ChillPersonBundle/Export/Filter/SocialWorkFilters/CreatorJobFilter.php index 28d31920d..47b5f4c9c 100644 --- a/src/Bundle/ChillPersonBundle/Export/Filter/SocialWorkFilters/CreatorJobFilter.php +++ b/src/Bundle/ChillPersonBundle/Export/Filter/SocialWorkFilters/CreatorJobFilter.php @@ -11,11 +11,13 @@ declare(strict_types=1); namespace Chill\PersonBundle\Export\Filter\SocialWorkFilters; +use Chill\MainBundle\Entity\User\UserJobHistory; use Chill\MainBundle\Entity\UserJob; use Chill\MainBundle\Export\FilterInterface; use Chill\MainBundle\Repository\UserJobRepository; use Chill\MainBundle\Templating\TranslatableStringHelper; use Chill\PersonBundle\Export\Declarations; +use Doctrine\ORM\Query\Expr\Join; use Doctrine\ORM\QueryBuilder; use Symfony\Bridge\Doctrine\Form\Type\EntityType; use Symfony\Component\Form\FormBuilderInterface; @@ -39,9 +41,23 @@ class CreatorJobFilter implements FilterInterface $p = self::PREFIX; $qb - ->setParameter("{$p}_jobs", $data['jobs']) - ; - + ->leftJoin( + UserJobHistory::class, + "{$p}_history", + Join::WITH, + $qb->expr()->andX( + $qb->expr()->eq("{$p}_history.user", "acpw.createdBy"), + $qb->expr()->andX( + $qb->expr()->lte("{$p}_history.startDate", "acpw.createdAt"), + $qb->expr()->orX( + $qb->expr()->isNull("{$p}_history.endDate"), + $qb->expr()->gt("{$p}_history.endDate", "acpw.createdAt") + ) + ) + ) + ) + ->andWhere($qb->expr()->in("{$p}_history.job", ":{$p}_jobs")) + ->setParameter("{$p}_jobs", $data['jobs']); } public function applyOn(): string diff --git a/src/Bundle/ChillPersonBundle/Export/Filter/SocialWorkFilters/CreatorScopeFilter.php b/src/Bundle/ChillPersonBundle/Export/Filter/SocialWorkFilters/CreatorScopeFilter.php index f21bf320e..996aa5272 100644 --- a/src/Bundle/ChillPersonBundle/Export/Filter/SocialWorkFilters/CreatorScopeFilter.php +++ b/src/Bundle/ChillPersonBundle/Export/Filter/SocialWorkFilters/CreatorScopeFilter.php @@ -12,10 +12,12 @@ declare(strict_types=1); namespace Chill\PersonBundle\Export\Filter\SocialWorkFilters; use Chill\MainBundle\Entity\Scope; +use Chill\MainBundle\Entity\User\UserScopeHistory; use Chill\MainBundle\Export\FilterInterface; use Chill\MainBundle\Repository\ScopeRepository; use Chill\MainBundle\Templating\TranslatableStringHelper; use Chill\PersonBundle\Export\Declarations; +use Doctrine\ORM\Query\Expr\Join; use Doctrine\ORM\QueryBuilder; use Symfony\Bridge\Doctrine\Form\Type\EntityType; use Symfony\Component\Form\FormBuilderInterface; @@ -39,9 +41,23 @@ class CreatorScopeFilter implements FilterInterface $p = self::PREFIX; $qb - ->setParameter("{$p}_scopes", $data['scopes']) - ; - + ->leftJoin( + UserScopeHistory::class, + "{$p}_history", + Join::WITH, + $qb->expr()->andX( + $qb->expr()->eq("{$p}_history.user", "acpw.createdBy"), + $qb->expr()->andX( + $qb->expr()->lte("{$p}_history.startDate", "acpw.createdAt"), + $qb->expr()->orX( + $qb->expr()->isNull("{$p}_history.endDate"), + $qb->expr()->gt("{$p}_history.endDate", "acpw.createdAt") + ) + ) + ) + ) + ->andWhere($qb->expr()->in("{$p}_history.scope", ":{$p}_scopes")) + ->setParameter("{$p}_scopes", $data['scopes']); } public function applyOn(): string