From 1c2142be2739b3abb33acbdf8f6b87c5b1e2d2e3 Mon Sep 17 00:00:00 2001 From: Thomas Gelf Date: Tue, 20 Aug 2013 22:44:30 +0200 Subject: [PATCH] Prepared filter support for aggregated columns (where VS having) --- .../Backend/Ido/Query/AbstractQuery.php | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/modules/monitoring/library/Monitoring/Backend/Ido/Query/AbstractQuery.php b/modules/monitoring/library/Monitoring/Backend/Ido/Query/AbstractQuery.php index 6e4e01b1a..f22507c9b 100644 --- a/modules/monitoring/library/Monitoring/Backend/Ido/Query/AbstractQuery.php +++ b/modules/monitoring/library/Monitoring/Backend/Ido/Query/AbstractQuery.php @@ -26,8 +26,15 @@ abstract class AbstractQuery extends Query protected $contact_id = 'contact_id'; protected $contactgroup_id = 'contactgroup_id'; + protected $aggregateColumnIdx = array(); + protected $allowCustomVars = false; + protected function isAggregateColumn($column) + { + return array_key_exists($column, $this->aggregateColumnIdx); + } + protected function init() { parent::init(); @@ -145,7 +152,17 @@ abstract class AbstractQuery extends Query 'If you finished here, code has been messed up' ); } - $this->baseQuery->where($this->prepareFilterStringForColumn($col, $value)); + + $func = 'filter' . ucfirst($alias); + if (method_exists($this, $func)) { + $this->$func($value); + return; + } + if ($this->isAggregateColumn($alias)) { + $this->baseQuery->having($this->prepareFilterStringForColumn($col, $value)); + } else { + $this->baseQuery->where($this->prepareFilterStringForColumn($col, $value)); + } } }