Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Render Hasvalue and Hasnotvalue filter rules #61

Draft
wants to merge 3 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions src/Control/SearchBar/ValidatedOperator.php
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
8 changes: 8 additions & 0 deletions src/Control/SearchEditor.php
Original file line number Diff line number Diff line change
Expand Up @@ -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());
Expand Down
8 changes: 8 additions & 0 deletions src/Filter/Parser.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
2 changes: 2 additions & 0 deletions src/Filter/QueryString.php
Original file line number Diff line number Diff line change
Expand Up @@ -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 '>';
Expand Down
2 changes: 2 additions & 0 deletions src/Filter/Renderer.php
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down