Skip to content

Commit

Permalink
Filter: Implement hasNotValue() & matchHasnotValue() methods
Browse files Browse the repository at this point in the history
  • Loading branch information
yhabteab committed Nov 15, 2021
1 parent bf75f7c commit a5d4a79
Showing 1 changed file with 32 additions and 0 deletions.
32 changes: 32 additions & 0 deletions src/Filter.php
Original file line number Diff line number Diff line change
Expand Up @@ -184,6 +184,36 @@ protected function matchHasValue($rule, $row)
return ! empty($this->extractValue($rule->getColumn(), $row));
}

/**
* Create a rule that applies rows where a column has no values, i.e. to all
* rows where this column hasn't been set.
*
* Value is optional, as it is not used anyway when executing the query, rather
* it is only being populated in the FilterEditor.
*
* @param string $column
* @param string|null $value
*
* @return HasNotValue
*/
public static function hasNotValue($column, $value = '')
{
return new HasNotValue($column, $value);
}

/**
* Get whether the given rule's column is null|doesn't contain any values
*
* @param HasNotValue $rule
* @param object $row
*
* @return bool
*/
public function matchHasNotValue(HasNotValue $rule, $row)
{
return ! $this->matchHasValue($rule, $row);
}

/**
* Create a rule that matches rows with a column that **equals** the given value
*
Expand Down Expand Up @@ -451,6 +481,8 @@ protected function performMatch(Rule $rule, $row)
return $this->matchUnequal($rule, $row);
case $rule instanceof HasValue:
return $this->matchHasValue($rule, $row);
case $rule instanceof HasNotValue:
return $this->matchHasNotValue($rule, $row);
default:
throw new InvalidArgumentException(sprintf(
'Unable to match filter. Rule type %s is unknown',
Expand Down

0 comments on commit a5d4a79

Please sign in to comment.