IdoQuery: Move resolveColumns() to the columns() function

Since the BaseQuery no longer allows passing the columns to select via
its the constructor, the columns are resolved when set by the
columns() function.
This commit is contained in:
Eric Lippmann 2014-04-16 10:06:44 +02:00
parent eeadc17a6e
commit 62e044d888
1 changed files with 19 additions and 21 deletions

View File

@ -31,10 +31,7 @@ namespace Icinga\Module\Monitoring\Backend\Ido\Query;
use Icinga\Logger\Logger;
use Icinga\Data\Db\Query;
use Icinga\Application\Benchmark;
use Icinga\Exception\ProgrammingError;
use Icinga\Filter\Query\Tree;
use Icinga\Module\Monitoring\Filter\UrlViewFilter;
/**
* Base class for Ido Queries
@ -317,7 +314,7 @@ abstract class IdoQuery extends Query
reset($this->columnMap);
$table = key($this->columnMap);
$this->baseQuery = $this->db->select()->from(
$this->select->from(
array($table => $this->prefix . $table),
array()
);
@ -338,26 +335,15 @@ abstract class IdoQuery extends Query
}
}
/**
* Prepare query execution
*
* @see IdoQuery::resolveColumns() For column alias resolving
*/
protected function beforeQueryCreation()
{
$this->resolveColumns();
$classParts = explode('\\', get_class($this));
Benchmark::measure(sprintf('%s ready to run', array_pop($classParts)));
}
/**
* Resolve columns aliases to their database field using the columnMap
*
* @return self Fluent interface
* @param array $columns
*
* @return array
*/
public function resolveColumns()
public function resolveColumns($columns)
{
$columns = $this->getColumns();
$resolvedColumns = array();
foreach ($columns as $alias => $col) {
@ -373,9 +359,8 @@ abstract class IdoQuery extends Query
$resolvedColumns[$alias] = preg_replace('|\n|', ' ', $name);
}
$this->setColumns($resolvedColumns);
return $this;
return $resolvedColumns;
}
/**
@ -580,4 +565,17 @@ abstract class IdoQuery extends Query
$query = new $class($this->ds, $columns);
return $query;
}
/**
* Set columns to select
*
* @param array $columns
*
* @return self
*/
public function columns(array $columns)
{
$this->columns = $this->resolveColumns($columns);
return $this;
}
}