[icinga-checkins] icinga.org: icingaweb2/master: Repository: Allow for some more fine-grained control

git at icinga.org git at icinga.org
Thu Aug 18 13:36:58 CEST 2016


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

Author: Johannes Meyer <johannes.meyer at netways.de>
Date:   Thu Aug 18 13:35:52 2016 +0200

Repository: Allow for some more fine-grained control

Filter columns, search columns and sort rules can now be returned
dependent on a query's current target

---

 library/Icinga/Repository/Repository.php      |   57 +++++++++++++++++--------
 library/Icinga/Repository/RepositoryQuery.php |    6 +--
 2 files changed, 43 insertions(+), 20 deletions(-)

diff --git a/library/Icinga/Repository/Repository.php b/library/Icinga/Repository/Repository.php
index df6a893..2fd8ace 100644
--- a/library/Icinga/Repository/Repository.php
+++ b/library/Icinga/Repository/Repository.php
@@ -323,25 +323,30 @@ abstract class Repository implements Selectable
      *
      * Calls $this->initializeBlacklistedQueryColumns() in case $this->blacklistedQueryColumns is null.
      *
+     * @param   string  $table
+     *
      * @return  array
      */
-    public function getBlacklistedQueryColumns()
+    public function getBlacklistedQueryColumns($table = null)
     {
         if ($this->blacklistedQueryColumns === null) {
-            $this->blacklistedQueryColumns = $this->initializeBlacklistedQueryColumns();
+            $this->blacklistedQueryColumns = $this->initializeBlacklistedQueryColumns($table);
         }
 
         return $this->blacklistedQueryColumns;
     }
 
     /**
-     * Overwrite this in your repository implementation in case you
-     * need to initialize the blacklisted query columns lazily
+     * Overwrite this in your repository implementation in case you need to initialize the
+     * blacklisted query columns lazily or dependent on a query's current base table
+     *
+     * @param   string  $table
      *
      * @return  array
      */
     protected function initializeBlacklistedQueryColumns()
     {
+        // $table is not part of the signature due to PHP strict standards
         return array();
     }
 
@@ -350,24 +355,30 @@ abstract class Repository implements Selectable
      *
      * Calls $this->initializeFilterColumns() in case $this->filterColumns is null.
      *
+     * @param   string  $table
+     *
      * @return  array
      */
-    public function getFilterColumns()
+    public function getFilterColumns($table = null)
     {
         if ($this->filterColumns === null) {
-            $this->filterColumns = $this->initializeFilterColumns();
+            $this->filterColumns = $this->initializeFilterColumns($table);
         }
 
         return $this->filterColumns;
     }
 
     /**
-     * Overwrite this in your repository implementation in case you need to initialize the filter columns lazily
+     * Overwrite this in your repository implementation in case you need to initialize
+     * the filter columns lazily or dependent on a query's current base table
+     *
+     * @param   string  $table
      *
      * @return  array
      */
     protected function initializeFilterColumns()
     {
+        // $table is not part of the signature due to PHP strict standards
         return array();
     }
 
@@ -376,24 +387,30 @@ abstract class Repository implements Selectable
      *
      * Calls $this->initializeSearchColumns() in case $this->searchColumns is null.
      *
+     * @param   string  $table
+     *
      * @return  array
      */
-    public function getSearchColumns()
+    public function getSearchColumns($table = null)
     {
         if ($this->searchColumns === null) {
-            $this->searchColumns = $this->initializeSearchColumns();
+            $this->searchColumns = $this->initializeSearchColumns($table);
         }
 
         return $this->searchColumns;
     }
 
     /**
-     * Overwrite this in your repository implementation in case you need to initialize the search columns lazily
+     * Overwrite this in your repository implementation in case you need to initialize
+     * the search columns lazily or dependent on a query's current base table
+     *
+     * @param   string  $table
      *
      * @return  array
      */
     protected function initializeSearchColumns()
     {
+        // $table is not part of the signature due to PHP strict standards
         return array();
     }
 
@@ -402,24 +419,30 @@ abstract class Repository implements Selectable
      *
      * Calls $this->initializeSortRules() in case $this->sortRules is null.
      *
+     * @param   string  $table
+     *
      * @return  array
      */
-    public function getSortRules()
+    public function getSortRules($table = null)
     {
         if ($this->sortRules === null) {
-            $this->sortRules = $this->initializeSortRules();
+            $this->sortRules = $this->initializeSortRules($table);
         }
 
         return $this->sortRules;
     }
 
     /**
-     * Overwrite this in your repository implementation in case you need to initialize the sort rules lazily
+     * Overwrite this in your repository implementation in case you need to initialize
+     * the sort rules lazily or dependent on a query's current base table
+     *
+     * @param   string  $table
      *
      * @return  array
      */
     protected function initializeSortRules()
     {
+        // $table is not part of the signature due to PHP strict standards
         return array();
     }
 
@@ -900,7 +923,7 @@ abstract class Repository implements Selectable
             throw new ProgrammingError('Table name "%s" not found', $table);
         }
 
-        $blacklist = $this->getBlacklistedQueryColumns();
+        $blacklist = $this->getBlacklistedQueryColumns($table);
         $columns = array();
         foreach ($queryColumns[$table] as $alias => $column) {
             $name = is_string($alias) ? $alias : $column;
@@ -994,7 +1017,7 @@ abstract class Repository implements Selectable
             return false;
         }
 
-        return !in_array($alias, $this->getBlacklistedQueryColumns())
+        return !in_array($alias, $this->getBlacklistedQueryColumns($table))
             && $this->validateQueryColumnAssociation($table, $name);
     }
 
@@ -1019,7 +1042,7 @@ abstract class Repository implements Selectable
             throw new QueryException(t('Query column "%s" not found'), $name);
         }
 
-        if (in_array($alias, $this->getBlacklistedQueryColumns())) {
+        if (in_array($alias, $this->getBlacklistedQueryColumns($table))) {
             throw new QueryException(t('Column "%s" cannot be queried'), $name);
         }
 
@@ -1107,7 +1130,7 @@ abstract class Repository implements Selectable
             throw new StatementException('Statement column "%s" not found', $name);
         }
 
-        if (in_array($alias, $this->getBlacklistedQueryColumns())) {
+        if (in_array($alias, $this->getBlacklistedQueryColumns($table))) {
             throw new StatementException('Column "%s" cannot be referenced in a statement', $name);
         }
 
diff --git a/library/Icinga/Repository/RepositoryQuery.php b/library/Icinga/Repository/RepositoryQuery.php
index b1cd09a..5864038 100644
--- a/library/Icinga/Repository/RepositoryQuery.php
+++ b/library/Icinga/Repository/RepositoryQuery.php
@@ -204,7 +204,7 @@ class RepositoryQuery implements QueryInterface, SortRules, FilterColumns, Itera
      */
     public function getFilterColumns()
     {
-        return $this->repository->getFilterColumns();
+        return $this->repository->getFilterColumns($this->target);
     }
 
     /**
@@ -214,7 +214,7 @@ class RepositoryQuery implements QueryInterface, SortRules, FilterColumns, Itera
      */
     public function getSearchColumns()
     {
-        return $this->repository->getSearchColumns();
+        return $this->repository->getSearchColumns($this->target);
     }
 
     /**
@@ -294,7 +294,7 @@ class RepositoryQuery implements QueryInterface, SortRules, FilterColumns, Itera
      */
     public function getSortRules()
     {
-        return $this->repository->getSortRules();
+        return $this->repository->getSortRules($this->target);
     }
 
     /**



More information about the icinga-checkins mailing list