Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/MAUT-11467' into development
Browse files Browse the repository at this point in the history
  • Loading branch information
dadarya0 committed Jun 4, 2024
2 parents c44a223 + 5755b83 commit 3ced5d3
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 8 deletions.
27 changes: 19 additions & 8 deletions Helper/QueryFilterHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ public function addCustomFieldValueExpressionFromSegmentFilter(
$expression = $this->getCustomValueValueExpression(
$segmentQueryBuilder,
$tableAlias,
$filter->getOperator(),
$filter,
$valueParameter,
$filterAlreadyNegated,
$filter->getParameterValue()
Expand Down Expand Up @@ -165,11 +165,12 @@ private function addOperatorExpression(
private function getCustomValueValueExpression(
SegmentQueryBuilder $customQuery,
string $tableAlias,
string $operator,
ContactSegmentFilter $filter,
string $valueParameter,
bool $alreadyNegated = false,
$filterParameterValue = null
) {
$operator = $filter->getOperator();
if ($alreadyNegated) {
switch ($operator) {
case 'empty':
Expand All @@ -185,15 +186,22 @@ private function getCustomValueValueExpression(
case 'empty':
$expression = $customQuery->expr()->orX(
$customQuery->expr()->isNull($tableAlias.'_value.value'),
$customQuery->expr()->eq($tableAlias.'_value.value', $customQuery->expr()->literal(''))
);

if ($filter->doesColumnSupportEmptyValue()) {
$expression->add(
$customQuery->expr()->eq($tableAlias.'_value.value', $customQuery->expr()->literal(''))
);
}
break;
case 'notEmpty':
$expression = $customQuery->expr()->andX(
$customQuery->expr()->isNotNull($tableAlias.'_value.value'),
$customQuery->expr()->neq($tableAlias.'_value.value', $customQuery->expr()->literal(''))
);
if ($filter->doesColumnSupportEmptyValue()) {
$expression->add(
$customQuery->expr()->neq($tableAlias.'_value.value', $customQuery->expr()->literal(''))
);
}

break;
case 'notIn':
Expand Down Expand Up @@ -354,7 +362,9 @@ public function createMergeFilterQuery(
$segmentFilterFieldType = $filter['type'] ?: $this->queryFilterFactory
->getCustomFieldTypeById($segmentFilterFieldId);
$dataTable = $this->queryFilterFactory->getTableNameFromType($segmentFilterFieldType);
$segmentMergedFilter = $filter['filter'];
$segmentFilterFieldOperator = (string) $filter['operator'];

$alias = $customItemXrefContactAlias.'_'.$segmentFilterFieldId.'_'.$filter['type'];
$aliasValue = $alias.'_value';
$isCmoFilter = $filter['cmo_filter'] ?? false;
Expand Down Expand Up @@ -383,7 +393,7 @@ public function createMergeFilterQuery(
$qb,
$cinAlias,
$alias,
$segmentFilterFieldOperator,
$segmentMergedFilter,
$valueParameter
),
$segmentFilterFieldOperator,
Expand Down Expand Up @@ -436,9 +446,10 @@ private function getMergeExpression(
SegmentQueryBuilder $qb,
string $cinAlias,
string $alias,
string $segmentFilterFieldOperator,
ContactSegmentFilter $filter,
string $valueParameter
) {
$segmentFilterFieldOperator = $filter->getOperator();
if ($isCmoFilter) {
$expression = $this->getCustomObjectNameExpression(
$qb,
Expand All @@ -450,7 +461,7 @@ private function getMergeExpression(
$expression = $this->getCustomValueValueExpression(
$qb,
$alias,
$segmentFilterFieldOperator,
$filter,
$valueParameter
);
}
Expand Down
28 changes: 28 additions & 0 deletions Tests/Functional/Helper/QueryFilterHelperTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,34 @@ public function testGetCustomValueValueExpression(): void
],
]
);

$this->assertMatchWhere(
'test_value.value IS NULL',
[
'glue' => 'and',
'field' => 'cmf_'.$this->getFixtureById('custom_object_product')->getId(),
'object' => 'custom_object',
'type' => 'datetime',
'operator' => 'empty',
'properties' => [
'filter' => [],
],
]
);

$this->assertMatchWhere(
'test_value.value IS NOT NULL',
[
'glue' => 'and',
'field' => 'cmf_'.$this->getFixtureById('custom_object_product')->getId(),
'object' => 'custom_object',
'type' => 'datetime',
'operator' => '!empty',
'properties' => [
'filter' => [],
],
]
);
}

protected function assertMatchWhere(string $expectedWhere, array $filter): void
Expand Down

0 comments on commit 3ced5d3

Please sign in to comment.