From 1eb0fcdff8a8d8e0ef90436a6bda515b85a8f354 Mon Sep 17 00:00:00 2001 From: Thomas Gelf Date: Tue, 20 Aug 2013 23:17:43 +0200 Subject: [PATCH] AbstractQuery implements QueryInterface, added addColumn, fixed sort --- library/Icinga/Data/AbstractQuery.php | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/library/Icinga/Data/AbstractQuery.php b/library/Icinga/Data/AbstractQuery.php index 7bed9b472..a961d7804 100644 --- a/library/Icinga/Data/AbstractQuery.php +++ b/library/Icinga/Data/AbstractQuery.php @@ -4,7 +4,7 @@ namespace Icinga\Data; use Icinga\Exception; -abstract class AbstractQuery +abstract class AbstractQuery implements QueryInterface { /** * Sort ascending @@ -72,6 +72,17 @@ abstract class AbstractQuery $this->init(); } + public function addColumn($name, $alias = null) + { + // TODO: Fail if adding column twice, but allow same col with new alias + if ($alias === null) { + $this->columns[] = $name; + } else { + $this->columns[$alias] = $name; + } + return $this; + } + public function getDatasource() { return $this->ds; @@ -158,7 +169,7 @@ abstract class AbstractQuery $col = substr($col, 0, $pos); } } else { - if (strtoupper($dir) === 'DESC') { + if ($dir === self::SORT_DESC || strtoupper($dir) === 'DESC') { $dir = self::SORT_DESC; } else { $dir = self::SORT_ASC;