Skip to content

Commit a5d4a79

Browse files
committed
Filter: Implement hasNotValue() & matchHasnotValue() methods
1 parent bf75f7c commit a5d4a79

File tree

1 file changed

+32
-0
lines changed

1 file changed

+32
-0
lines changed

src/Filter.php

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -184,6 +184,36 @@ protected function matchHasValue($rule, $row)
184184
return ! empty($this->extractValue($rule->getColumn(), $row));
185185
}
186186

187+
/**
188+
* Create a rule that applies rows where a column has no values, i.e. to all
189+
* rows where this column hasn't been set.
190+
*
191+
* Value is optional, as it is not used anyway when executing the query, rather
192+
* it is only being populated in the FilterEditor.
193+
*
194+
* @param string $column
195+
* @param string|null $value
196+
*
197+
* @return HasNotValue
198+
*/
199+
public static function hasNotValue($column, $value = '')
200+
{
201+
return new HasNotValue($column, $value);
202+
}
203+
204+
/**
205+
* Get whether the given rule's column is null|doesn't contain any values
206+
*
207+
* @param HasNotValue $rule
208+
* @param object $row
209+
*
210+
* @return bool
211+
*/
212+
public function matchHasNotValue(HasNotValue $rule, $row)
213+
{
214+
return ! $this->matchHasValue($rule, $row);
215+
}
216+
187217
/**
188218
* Create a rule that matches rows with a column that **equals** the given value
189219
*
@@ -451,6 +481,8 @@ protected function performMatch(Rule $rule, $row)
451481
return $this->matchUnequal($rule, $row);
452482
case $rule instanceof HasValue:
453483
return $this->matchHasValue($rule, $row);
484+
case $rule instanceof HasNotValue:
485+
return $this->matchHasNotValue($rule, $row);
454486
default:
455487
throw new InvalidArgumentException(sprintf(
456488
'Unable to match filter. Rule type %s is unknown',

0 commit comments

Comments
 (0)