From 6badbd04acab5774ea28ac06d8ebda5d1574c590 Mon Sep 17 00:00:00 2001 From: Yonas Habteab Date: Mon, 15 Nov 2021 16:57:57 +0100 Subject: [PATCH 1/3] Validate HasValue & HasNotValue filter rules operator --- src/Control/SearchBar/ValidatedOperator.php | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/Control/SearchBar/ValidatedOperator.php b/src/Control/SearchBar/ValidatedOperator.php index 05e569a8..b28c82c4 100644 --- a/src/Control/SearchBar/ValidatedOperator.php +++ b/src/Control/SearchBar/ValidatedOperator.php @@ -22,9 +22,11 @@ public static function fromFilterCondition(Filter\Condition $condition) { switch (true) { case $condition instanceof Filter\Unequal: + case $condition instanceof Filter\HasNotValue: $operator = '!='; break; case $condition instanceof Filter\Equal: + case $condition instanceof Filter\HasValue: $operator = '='; break; case $condition instanceof Filter\GreaterThan: From 060f401a9d02d853822b7ce8d88eb865d1889e9e Mon Sep 17 00:00:00 2001 From: Yonas Habteab Date: Mon, 15 Nov 2021 17:00:03 +0100 Subject: [PATCH 2/3] Filter: Render HasValue & HasNotValue filter rules operator --- src/Filter/QueryString.php | 2 ++ src/Filter/Renderer.php | 2 ++ 2 files changed, 4 insertions(+) diff --git a/src/Filter/QueryString.php b/src/Filter/QueryString.php index d1ec1880..5b2b2ecd 100644 --- a/src/Filter/QueryString.php +++ b/src/Filter/QueryString.php @@ -67,8 +67,10 @@ public static function getRuleSymbol(Filter\Rule $rule) { switch (true) { case $rule instanceof Filter\Unequal: + case $rule instanceof Filter\HasNotValue: return '!='; case $rule instanceof Filter\Equal: + case $rule instanceof Filter\HasValue: return '='; case $rule instanceof Filter\GreaterThan: return '>'; diff --git a/src/Filter/Renderer.php b/src/Filter/Renderer.php index 28267439..d249a0bf 100644 --- a/src/Filter/Renderer.php +++ b/src/Filter/Renderer.php @@ -152,9 +152,11 @@ protected function renderCondition(Filter\Condition $condition) switch (true) { case $condition instanceof Filter\Unequal: + case $condition instanceof Filter\HasNotValue: $this->string .= '!='; break; case $condition instanceof Filter\Equal: + case $condition instanceof Filter\HasValue: $this->string .= '='; break; case $condition instanceof Filter\GreaterThan: From 186455b6c892debdbe28e8bf4ad2ae8a0ce3d941 Mon Sep 17 00:00:00 2001 From: Yonas Habteab Date: Mon, 15 Nov 2021 18:15:09 +0100 Subject: [PATCH 3/3] Don't use Filter::equal()|Filter::unequal() `*` to filter nullable columns --- src/Control/SearchEditor.php | 8 ++++++++ src/Filter/Parser.php | 8 ++++++++ 2 files changed, 16 insertions(+) diff --git a/src/Control/SearchEditor.php b/src/Control/SearchEditor.php index 5657822d..62217399 100644 --- a/src/Control/SearchEditor.php +++ b/src/Control/SearchEditor.php @@ -175,8 +175,16 @@ protected function applyChanges(Filter\Rule $rule, array &$values, array $path = if ($newOperator !== null && QueryString::getRuleSymbol($rule) !== $newOperator) { switch ($newOperator) { case '=': + if ($rule->getValue() === '*') { + return Filter::hasValue($rule->getColumn(), $rule->getValue()); + } + return Filter::equal($rule->getColumn(), $rule->getValue()); case '!=': + if ($rule->getValue() === '*') { + return Filter::hasNotValue($rule->getColumn(), $rule->getValue()); + } + return Filter::unequal($rule->getColumn(), $rule->getValue()); case '>': return Filter::greaterThan($rule->getColumn(), $rule->getValue()); diff --git a/src/Filter/Parser.php b/src/Filter/Parser.php index 23fcb64e..72a27830 100644 --- a/src/Filter/Parser.php +++ b/src/Filter/Parser.php @@ -516,8 +516,16 @@ protected function createCondition($column, $operator, $value) switch ($operator) { case '=': + if ($value === '*') { + return Filter::hasValue($column, $value); + } + return Filter::equal($column, $value); case '!=': + if ($value === '*') { + return Filter::hasNotValue($column, $value); + } + return Filter::unequal($column, $value); case '>': return Filter::greaterThan($column, $value);