From 386447b847b909978b54cdb902ca748a24d32e4c Mon Sep 17 00:00:00 2001
From: Johannes Meyer <johannes.meyer@netways.de>
Date: Thu, 18 Jun 2015 09:29:58 +0200
Subject: [PATCH] DbQuery: Add getter for GROUP BY clauses

Allows to override this in a child to provide group by clauses not
until they are actually required.

refs #9009
---
 library/Icinga/Data/Db/DbQuery.php | 20 ++++++++++++++++----
 1 file changed, 16 insertions(+), 4 deletions(-)

diff --git a/library/Icinga/Data/Db/DbQuery.php b/library/Icinga/Data/Db/DbQuery.php
index 2f82b06b2..28287df99 100644
--- a/library/Icinga/Data/Db/DbQuery.php
+++ b/library/Icinga/Data/Db/DbQuery.php
@@ -145,8 +145,9 @@ class DbQuery extends SimpleQuery
             }
         }
 
-        if ($this->group) {
-            $select->group($this->group);
+        $group = $this->getGroup();
+        if ($group) {
+            $select->group($group);
         }
 
         $select->columns($this->columns);
@@ -321,8 +322,9 @@ class DbQuery extends SimpleQuery
     {
         // TODO: there may be situations where we should clone the "select"
         $count = $this->dbSelect();
-        if ($this->group) {
-            $count->group($this->group);
+        $group = $this->getGroup();
+        if ($group) {
+            $count->group($group);
         }
         $this->applyFilterSql($count);
         if ($this->useSubqueryCount || $this->group) {
@@ -393,6 +395,16 @@ class DbQuery extends SimpleQuery
         return $this;
     }
 
+    /**
+     * Return the GROUP BY clause
+     *
+     * @return  string|array
+     */
+    public function getGroup()
+    {
+        return $this->group;
+    }
+
     /**
      * Return whether the given table has been joined
      *