[icinga-checkins] icinga.org: icingaweb2/master: Data\Filter: add or/ andFilter implementations

git at icinga.org git at icinga.org
Fri Nov 14 23:07:19 CET 2014


Module: icingaweb2
Branch: master
Commit: 925348d1714dccbf9d4184800ee9451e36c35f37
URL:    https://git.icinga.org/?p=icingaweb2.git;a=commit;h=925348d1714dccbf9d4184800ee9451e36c35f37

Author: Thomas Gelf <thomas at gelf.net>
Date:   Fri Nov 14 23:06:20 2014 +0100

Data\Filter: add or/andFilter implementations

Those shortcuts make it easy to correctly add or/and conditions
regardless of the original filter type

---

 library/Icinga/Data/Filter/Filter.php           |    4 ++++
 library/Icinga/Data/Filter/FilterAnd.php        |   10 ++++++++++
 library/Icinga/Data/Filter/FilterExpression.php |   10 ++++++++++
 library/Icinga/Data/Filter/FilterNot.php        |   10 ++++++++++
 library/Icinga/Data/Filter/FilterOr.php         |   10 ++++++++++
 5 files changed, 44 insertions(+)

diff --git a/library/Icinga/Data/Filter/Filter.php b/library/Icinga/Data/Filter/Filter.php
index dcedfdf..a0a56e4 100644
--- a/library/Icinga/Data/Filter/Filter.php
+++ b/library/Icinga/Data/Filter/Filter.php
@@ -30,6 +30,10 @@ abstract class Filter
 
     abstract public function toQueryString();
 
+    abstract public function andFilter(Filter $filter);
+
+    abstract public function orFilter(Filter $filter);
+
     public function getUrlParams()
     {
         return UrlParams::fromQueryString($this->toQueryString());
diff --git a/library/Icinga/Data/Filter/FilterAnd.php b/library/Icinga/Data/Filter/FilterAnd.php
index 899f488..8fd2f24 100644
--- a/library/Icinga/Data/Filter/FilterAnd.php
+++ b/library/Icinga/Data/Filter/FilterAnd.php
@@ -30,4 +30,14 @@ class FilterAnd extends FilterChain
         }
         return true;
     }
+
+    public function andFilter(Filter $filter)
+    {
+        return $this->addFilter($filter);
+    }
+
+    public function orFilter(Filter $filter)
+    {
+        return Filter::matchAny($this, $filter);
+    }
 }
diff --git a/library/Icinga/Data/Filter/FilterExpression.php b/library/Icinga/Data/Filter/FilterExpression.php
index 8f78d6a..f87f360 100644
--- a/library/Icinga/Data/Filter/FilterExpression.php
+++ b/library/Icinga/Data/Filter/FilterExpression.php
@@ -107,4 +107,14 @@ class FilterExpression extends Filter
             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);
+    }
 }
diff --git a/library/Icinga/Data/Filter/FilterNot.php b/library/Icinga/Data/Filter/FilterNot.php
index a49a7ab..5e63691 100644
--- a/library/Icinga/Data/Filter/FilterNot.php
+++ b/library/Icinga/Data/Filter/FilterNot.php
@@ -22,6 +22,16 @@ class FilterNot extends FilterChain
         return true;
     }
 
+    public function andFilter(Filter $filter)
+    {
+        return Filter::matchAll($this, $filter);
+    }
+
+    public function orFilter(Filter $filter)
+    {
+        return Filter::matchAny($filter);
+    }
+
     public function toQueryString()
     {
         $parts = array();
diff --git a/library/Icinga/Data/Filter/FilterOr.php b/library/Icinga/Data/Filter/FilterOr.php
index 427c17f..4e4de2d 100644
--- a/library/Icinga/Data/Filter/FilterOr.php
+++ b/library/Icinga/Data/Filter/FilterOr.php
@@ -19,4 +19,14 @@ class FilterOr extends FilterChain
         }
         return false;
     }
+
+    public function andFilter(Filter $filter)
+    {
+        return Filter::matchAll($this, $filter);
+    }
+
+    public function orFilter(Filter $filter)
+    {
+        return $this->addFilter($filter);
+    }
 }



More information about the icinga-checkins mailing list