mirror of
https://gitlab.com/Chill-Projet/chill-bundles.git
synced 2025-06-07 18:44:08 +00:00
SocialActionFilter: use a subquery "exists" instead of a where clause (many-to-many association)
This commit is contained in:
parent
981be7b363
commit
217232fe4f
5
.changes/unreleased/Fixed-20230913-122616.yaml
Normal file
5
.changes/unreleased/Fixed-20230913-122616.yaml
Normal file
@ -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"
|
@ -12,28 +12,17 @@ declare(strict_types=1);
|
|||||||
namespace Chill\PersonBundle\Export\Filter\AccompanyingCourseFilters;
|
namespace Chill\PersonBundle\Export\Filter\AccompanyingCourseFilters;
|
||||||
|
|
||||||
use Chill\MainBundle\Export\FilterInterface;
|
use Chill\MainBundle\Export\FilterInterface;
|
||||||
use Chill\MainBundle\Templating\TranslatableStringHelper;
|
use Chill\PersonBundle\Entity\AccompanyingPeriod;
|
||||||
use Chill\PersonBundle\Entity\SocialWork\SocialAction;
|
use Chill\PersonBundle\Entity\SocialWork\SocialAction;
|
||||||
use Chill\PersonBundle\Export\Declarations;
|
use Chill\PersonBundle\Export\Declarations;
|
||||||
use Chill\PersonBundle\Form\Type\PickSocialActionType;
|
use Chill\PersonBundle\Form\Type\PickSocialActionType;
|
||||||
use Chill\PersonBundle\Templating\Entity\SocialActionRender;
|
use Chill\PersonBundle\Templating\Entity\SocialActionRender;
|
||||||
use Doctrine\ORM\QueryBuilder;
|
use Doctrine\ORM\QueryBuilder;
|
||||||
use Symfony\Component\Form\FormBuilderInterface;
|
use Symfony\Component\Form\FormBuilderInterface;
|
||||||
use function in_array;
|
|
||||||
|
|
||||||
class SocialActionFilter implements FilterInterface
|
final readonly class SocialActionFilter implements FilterInterface
|
||||||
{
|
{
|
||||||
private SocialActionRender $actionRender;
|
public function __construct(private SocialActionRender $actionRender) {}
|
||||||
|
|
||||||
private TranslatableStringHelper $translatableStringHelper;
|
|
||||||
|
|
||||||
public function __construct(
|
|
||||||
TranslatableStringHelper $translatableStringHelper,
|
|
||||||
SocialActionRender $actionRender
|
|
||||||
) {
|
|
||||||
$this->translatableStringHelper = $translatableStringHelper;
|
|
||||||
$this->actionRender = $actionRender;
|
|
||||||
}
|
|
||||||
|
|
||||||
public function addRole(): ?string
|
public function addRole(): ?string
|
||||||
{
|
{
|
||||||
@ -42,21 +31,17 @@ class SocialActionFilter implements FilterInterface
|
|||||||
|
|
||||||
public function alterQuery(QueryBuilder $qb, $data)
|
public function alterQuery(QueryBuilder $qb, $data)
|
||||||
{
|
{
|
||||||
if (!in_array('acpw', $qb->getAllAliases(), true)) {
|
$qb->andWhere(
|
||||||
$qb->join('acp.works', 'acpw');
|
$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->setParameter('acp_by_social_action_filter_actions', SocialAction::getDescendantsWithThisForActions($data['accepted_socialactions']));
|
||||||
$qb->join('acpw.socialAction', 'acpwsocialaction');
|
|
||||||
}
|
|
||||||
|
|
||||||
$clause = $qb->expr()->in('acpwsocialaction.id', ':socialactions');
|
|
||||||
|
|
||||||
$qb->andWhere($clause)
|
|
||||||
->setParameter(
|
|
||||||
'socialactions',
|
|
||||||
SocialAction::getDescendantsWithThisForActions($data['accepted_socialactions'])->toArray()
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public function applyOn(): string
|
public function applyOn(): string
|
||||||
|
Loading…
x
Reference in New Issue
Block a user