parent
f12a5741b8
commit
3d352ba446
|
@ -132,12 +132,12 @@ abstract class Filter
|
||||||
public static function expression($col, $op, $expression)
|
public static function expression($col, $op, $expression)
|
||||||
{
|
{
|
||||||
switch ($op) {
|
switch ($op) {
|
||||||
case '=': return new FilterEqual($col, $op, $expression);
|
case '=': return new FilterMatch($col, $op, $expression);
|
||||||
case '<': return new FilterLessThan($col, $op, $expression);
|
case '<': return new FilterLessThan($col, $op, $expression);
|
||||||
case '>': return new FilterGreaterThan($col, $op, $expression);
|
case '>': return new FilterGreaterThan($col, $op, $expression);
|
||||||
case '>=': return new FilterEqualOrGreaterThan($col, $op, $expression);
|
case '>=': return new FilterEqualOrGreaterThan($col, $op, $expression);
|
||||||
case '<=': return new FilterEqualOrLessThan($col, $op, $expression);
|
case '<=': return new FilterEqualOrLessThan($col, $op, $expression);
|
||||||
case '!=': return new FilterNotEqual($col, $op, $expression);
|
case '!=': return new FilterMatchNot($col, $op, $expression);
|
||||||
default: throw new ProgrammingError(
|
default: throw new ProgrammingError(
|
||||||
'There is no such filter sign: %s',
|
'There is no such filter sign: %s',
|
||||||
$op
|
$op
|
||||||
|
|
|
@ -0,0 +1,22 @@
|
||||||
|
<?php
|
||||||
|
// {{{ICINGA_LICENSE_HEADER}}}
|
||||||
|
// {{{ICINGA_LICENSE_HEADER}}}
|
||||||
|
|
||||||
|
namespace Icinga\Data\Filter;
|
||||||
|
|
||||||
|
class FilterMatch extends FilterExpression
|
||||||
|
{
|
||||||
|
public function matches($row)
|
||||||
|
{
|
||||||
|
$expression = (string) $this->expression;
|
||||||
|
if (strpos($expression, '*') === false) {
|
||||||
|
return (string) $row->{$this->column} === $expression;
|
||||||
|
} else {
|
||||||
|
$parts = array();
|
||||||
|
foreach (preg_split('/\*/', $expression) as $part) {
|
||||||
|
$parts[] = preg_quote($part);
|
||||||
|
}
|
||||||
|
return preg_match('/^' . implode('.*', $parts) . '$/', $row->{$this->column});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,22 @@
|
||||||
|
<?php
|
||||||
|
// {{{ICINGA_LICENSE_HEADER}}}
|
||||||
|
// {{{ICINGA_LICENSE_HEADER}}}
|
||||||
|
|
||||||
|
namespace Icinga\Data\Filter;
|
||||||
|
|
||||||
|
class FilterMatchNot extends FilterExpression
|
||||||
|
{
|
||||||
|
public function matches($row)
|
||||||
|
{
|
||||||
|
$expression = (string) $this->expression;
|
||||||
|
if (strpos($expression, '*') === false) {
|
||||||
|
return (string) $row->{$this->column} !== $expression;
|
||||||
|
} else {
|
||||||
|
$parts = array();
|
||||||
|
foreach (preg_split('/\*/', $expression) as $part) {
|
||||||
|
$parts[] = preg_quote($part);
|
||||||
|
}
|
||||||
|
return ! preg_match('/^' . implode('.*', $parts) . '$/', $row->{$this->column});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,13 @@
|
||||||
|
<?php
|
||||||
|
// {{{ICINGA_LICENSE_HEADER}}}
|
||||||
|
// {{{ICINGA_LICENSE_HEADER}}}
|
||||||
|
|
||||||
|
namespace Icinga\Data\Filter;
|
||||||
|
|
||||||
|
class FilterNotEqual extends FilterExpression
|
||||||
|
{
|
||||||
|
public function matches($row)
|
||||||
|
{
|
||||||
|
return (string) $row->{$this->column} !== (string) $this->expression;
|
||||||
|
}
|
||||||
|
}
|
|
@ -183,9 +183,10 @@ class FilterEditor extends AbstractWidget
|
||||||
{
|
{
|
||||||
$name = 'sign_' . $filter->getId();
|
$name = 'sign_' . $filter->getId();
|
||||||
$signs = array(
|
$signs = array(
|
||||||
'=' => '=',
|
'=' => '=',
|
||||||
'>' => '>',
|
'!=' => '!=',
|
||||||
'<' => '<',
|
'>' => '>',
|
||||||
|
'<' => '<',
|
||||||
'>=' => '>=',
|
'>=' => '>=',
|
||||||
'<=' => '<=',
|
'<=' => '<=',
|
||||||
);
|
);
|
||||||
|
|
Loading…
Reference in New Issue