From 217232fe4f6aa5a22d869534e390d5dc7672574e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Julien=20Fastr=C3=A9?= Date: Wed, 13 Sep 2023 12:26:54 +0200 Subject: [PATCH] SocialActionFilter: use a subquery "exists" instead of a where clause (many-to-many association) --- .../unreleased/Fixed-20230913-122616.yaml | 5 +++ .../SocialActionFilter.php | 41 ++++++------------- 2 files changed, 18 insertions(+), 28 deletions(-) create mode 100644 .changes/unreleased/Fixed-20230913-122616.yaml diff --git a/.changes/unreleased/Fixed-20230913-122616.yaml b/.changes/unreleased/Fixed-20230913-122616.yaml new file mode 100644 index 000000000..230baed41 --- /dev/null +++ b/.changes/unreleased/Fixed-20230913-122616.yaml @@ -0,0 +1,5 @@ +kind: Fixed +body: Fix filter "accompanying course by social action" to avoid duplication in list +time: 2023-09-13T12:26:16.38720953+02:00 +custom: + Issue: "143" diff --git a/src/Bundle/ChillPersonBundle/Export/Filter/AccompanyingCourseFilters/SocialActionFilter.php b/src/Bundle/ChillPersonBundle/Export/Filter/AccompanyingCourseFilters/SocialActionFilter.php index 0c14ba73a..c485412cb 100644 --- a/src/Bundle/ChillPersonBundle/Export/Filter/AccompanyingCourseFilters/SocialActionFilter.php +++ b/src/Bundle/ChillPersonBundle/Export/Filter/AccompanyingCourseFilters/SocialActionFilter.php @@ -12,28 +12,17 @@ declare(strict_types=1); namespace Chill\PersonBundle\Export\Filter\AccompanyingCourseFilters; use Chill\MainBundle\Export\FilterInterface; -use Chill\MainBundle\Templating\TranslatableStringHelper; +use Chill\PersonBundle\Entity\AccompanyingPeriod; use Chill\PersonBundle\Entity\SocialWork\SocialAction; use Chill\PersonBundle\Export\Declarations; use Chill\PersonBundle\Form\Type\PickSocialActionType; use Chill\PersonBundle\Templating\Entity\SocialActionRender; use Doctrine\ORM\QueryBuilder; use Symfony\Component\Form\FormBuilderInterface; -use function in_array; -class SocialActionFilter implements FilterInterface +final readonly class SocialActionFilter implements FilterInterface { - private SocialActionRender $actionRender; - - private TranslatableStringHelper $translatableStringHelper; - - public function __construct( - TranslatableStringHelper $translatableStringHelper, - SocialActionRender $actionRender - ) { - $this->translatableStringHelper = $translatableStringHelper; - $this->actionRender = $actionRender; - } + public function __construct(private SocialActionRender $actionRender) {} public function addRole(): ?string { @@ -42,21 +31,17 @@ class SocialActionFilter implements FilterInterface public function alterQuery(QueryBuilder $qb, $data) { - if (!in_array('acpw', $qb->getAllAliases(), true)) { - $qb->join('acp.works', 'acpw'); - } + $qb->andWhere( + $qb->expr()->exists( + sprintf( + "SELECT 1 FROM %s acp_by_social_action_filter WHERE acp_by_social_action_filter.socialAction " + . "IN (:acp_by_social_action_filter_actions) AND acp_by_social_action_filter.accompanyingPeriod = acp", + AccompanyingPeriod\AccompanyingPeriodWork::class + ) + ) + ); - if (!in_array('acpwsocialaction', $qb->getAllAliases(), true)) { - $qb->join('acpw.socialAction', 'acpwsocialaction'); - } - - $clause = $qb->expr()->in('acpwsocialaction.id', ':socialactions'); - - $qb->andWhere($clause) - ->setParameter( - 'socialactions', - SocialAction::getDescendantsWithThisForActions($data['accepted_socialactions'])->toArray() - ); + $qb->setParameter('acp_by_social_action_filter_actions', SocialAction::getDescendantsWithThisForActions($data['accepted_socialactions'])); } public function applyOn(): string