Data\Filter: add or/andFilter implementations

Those shortcuts make it easy to correctly add or/and conditions
regardless of the original filter type
This commit is contained in:
Thomas Gelf 2014-11-14 23:06:20 +01:00
parent 6aefc4b491
commit 925348d171
5 changed files with 44 additions and 0 deletions

View File

@ -30,6 +30,10 @@ abstract class Filter
abstract public function toQueryString(); abstract public function toQueryString();
abstract public function andFilter(Filter $filter);
abstract public function orFilter(Filter $filter);
public function getUrlParams() public function getUrlParams()
{ {
return UrlParams::fromQueryString($this->toQueryString()); return UrlParams::fromQueryString($this->toQueryString());

View File

@ -30,4 +30,14 @@ class FilterAnd extends FilterChain
} }
return true; return true;
} }
public function andFilter(Filter $filter)
{
return $this->addFilter($filter);
}
public function orFilter(Filter $filter)
{
return Filter::matchAny($this, $filter);
}
} }

View File

@ -107,4 +107,14 @@ class FilterExpression extends Filter
return (bool) preg_match($pattern, $row->{$this->column}); return (bool) preg_match($pattern, $row->{$this->column});
} }
} }
public function andFilter(Filter $filter)
{
return Filter::matchAll($this, $filter);
}
public function orFilter(Filter $filter)
{
return Filter::matchAny($this, $filter);
}
} }

View File

@ -22,6 +22,16 @@ class FilterNot extends FilterChain
return true; return true;
} }
public function andFilter(Filter $filter)
{
return Filter::matchAll($this, $filter);
}
public function orFilter(Filter $filter)
{
return Filter::matchAny($filter);
}
public function toQueryString() public function toQueryString()
{ {
$parts = array(); $parts = array();

View File

@ -19,4 +19,14 @@ class FilterOr extends FilterChain
} }
return false; return false;
} }
public function andFilter(Filter $filter)
{
return Filter::matchAll($this, $filter);
}
public function orFilter(Filter $filter)
{
return $this->addFilter($filter);
}
} }