AbstractQuery implements QueryInterface, added addColumn, fixed sort

This commit is contained in:
Thomas Gelf 2013-08-20 23:17:43 +02:00 committed by Eric Lippmann
parent 86945152b4
commit 1eb0fcdff8

@ -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;