Skip to content

Commit

Permalink
try with different approach
Browse files Browse the repository at this point in the history
  • Loading branch information
kingjia90 committed Jan 29, 2025
1 parent 70573b4 commit 2df491e
Showing 1 changed file with 10 additions and 12 deletions.
22 changes: 10 additions & 12 deletions src/CustomerList/Filter/CustomerSegment.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,6 @@
use CustomerManagementFrameworkBundle\Listing\Filter\AbstractFilter;
use CustomerManagementFrameworkBundle\Listing\Filter\OnCreateQueryFilterInterface;
use CustomerManagementFrameworkBundle\Service\MariaDb;
use Doctrine\DBAL\Connection;
use Doctrine\DBAL\ParameterType;
use Doctrine\DBAL\Query\QueryBuilder;
use Exception;
use InvalidArgumentException;
Expand Down Expand Up @@ -227,25 +225,27 @@ protected function addJoin(
);

$condition = $baseCondition;
$valuePlaceholder = $joinName . '_value';
$parameterType = ParameterType::INTEGER;
if ($this->type === self::OPERATOR_OR) {
// must match any of the passed IDs

$valueKeys = array_keys($conditionValue);
$isNumericArray = $valueKeys == array_filter($valueKeys, 'is_numeric');
if (!$isNumericArray) {
throw new Exception('Invalid condition value');
}

$condition .= sprintf(
' AND %1$s.dest_id IN (%2$s)',
$joinName,
':' . $valuePlaceholder
implode(',', $valueKeys)
);
$value = array_keys($conditionValue);
$parameterType = Connection::PARAM_INT_ARRAY;
} else {
// runs an extra join for every ID - all joins must match
$condition .= sprintf(
' AND %1$s.dest_id = %2$s',
' AND %1$s.dest_id = %2$d',
$joinName,
':' . $valuePlaceholder
is_numeric($conditionValue) ? $conditionValue : 0
);
$value = $conditionValue;
}

$queryBuilder->join(
Expand All @@ -254,7 +254,5 @@ protected function addJoin(
$joinName,
$condition
);

$queryBuilder->setParameter($valuePlaceholder, $value, $parameterType);
}
}

0 comments on commit 2df491e

Please sign in to comment.