Skip to content

Commit

Permalink
PoC trying
Browse files Browse the repository at this point in the history
  • Loading branch information
kingjia90 committed Jan 29, 2025
1 parent 70573b4 commit 1d9af05
Showing 1 changed file with 11 additions and 9 deletions.
20 changes: 11 additions & 9 deletions src/CustomerList/Filter/CustomerSegment.php
Original file line number Diff line number Diff line change
Expand Up @@ -227,25 +227,28 @@ 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 Exception('Invalid condition value');

Check failure on line 236 in src/CustomerList/Filter/CustomerSegment.php

View workflow job for this annotation

GitHub Actions / Static Analysis with PHPStan (8.0, lowest)

Function Exception not found.

Check failure on line 236 in src/CustomerList/Filter/CustomerSegment.php

View workflow job for this annotation

GitHub Actions / Static Analysis with PHPStan (8.1, highest)

Function Exception not found.
}

$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 @@ -255,6 +258,5 @@ protected function addJoin(
$condition
);

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

0 comments on commit 1d9af05

Please sign in to comment.