Repository: Accept parameter $filter in method requireFiltercolumn()

This allows to adjust more than the name of the column if necessary.

refs #10364
This commit is contained in:
Johannes Meyer 2015-11-11 16:05:54 +01:00
parent 39f4d869b7
commit d2b8ed243f
3 changed files with 8 additions and 8 deletions

View File

@ -688,19 +688,20 @@ abstract class DbRepository extends Repository implements Extensible, Updatable,
* @param string $name The name or alias of the column to validate * @param string $name The name or alias of the column to validate
* @param RepositoryQuery $query An optional query to pass as context, * @param RepositoryQuery $query An optional query to pass as context,
* if not given the column is considered being used for a statement filter * if not given the column is considered being used for a statement filter
* @param FilterExpression $filter An optional filter to pass as context
* *
* @return string The given column's name * @return string The given column's name
* *
* @throws QueryException In case the given column is not a valid filter column * @throws QueryException In case the given column is not a valid filter column
*/ */
public function requireFilterColumn($table, $name, RepositoryQuery $query = null) public function requireFilterColumn($table, $name, RepositoryQuery $query = null, FilterExpression $filter = null)
{ {
if ($query === null) { if ($query === null) {
return $this->requireStatementColumn($table, $name); return $this->requireStatementColumn($table, $name);
} }
if ($this->validateQueryColumnAssociation($table, $name)) { if ($this->validateQueryColumnAssociation($table, $name)) {
return parent::requireFilterColumn($table, $name, $query); return parent::requireFilterColumn($table, $name, $query, $filter);
} }
return $this->joinColumn($name, $table, $query); return $this->joinColumn($name, $table, $query);

View File

@ -6,6 +6,7 @@ namespace Icinga\Repository;
use DateTime; use DateTime;
use Icinga\Application\Logger; use Icinga\Application\Logger;
use Icinga\Data\Filter\Filter; use Icinga\Data\Filter\Filter;
use Icinga\Data\Filter\FilterExpression;
use Icinga\Data\Selectable; use Icinga\Data\Selectable;
use Icinga\Exception\ProgrammingError; use Icinga\Exception\ProgrammingError;
use Icinga\Exception\QueryException; use Icinga\Exception\QueryException;
@ -872,7 +873,7 @@ abstract class Repository implements Selectable
if ($filter->isExpression()) { if ($filter->isExpression()) {
$column = $filter->getColumn(); $column = $filter->getColumn();
$filter->setColumn($this->requireFilterColumn($table, $column, $query)); $filter->setColumn($this->requireFilterColumn($table, $column, $query, $filter));
$filter->setExpression($this->persistColumn($table, $column, $filter->getExpression(), $query)); $filter->setExpression($this->persistColumn($table, $column, $filter->getExpression(), $query));
} elseif ($filter->isChain()) { } elseif ($filter->isChain()) {
foreach ($filter->filters() as $chainOrExpression) { foreach ($filter->filters() as $chainOrExpression) {
@ -1049,12 +1050,13 @@ abstract class Repository implements Selectable
* @param string $table The table where to look for the column or alias * @param string $table The table where to look for the column or alias
* @param string $name The name or alias of the column to validate * @param string $name The name or alias of the column to validate
* @param RepositoryQuery $query An optional query to pass as context (unused by the base implementation) * @param RepositoryQuery $query An optional query to pass as context (unused by the base implementation)
* @param FilterExpression $filter An optional filter to pass as context (unused by the base implementation)
* *
* @return string The given column's name * @return string The given column's name
* *
* @throws QueryException In case the given column is not a valid filter column * @throws QueryException In case the given column is not a valid filter column
*/ */
public function requireFilterColumn($table, $name, RepositoryQuery $query = null) public function requireFilterColumn($table, $name, RepositoryQuery $query = null, FilterExpression $filter = null)
{ {
if (($column = $this->resolveQueryColumnAlias($table, $name)) !== null) { if (($column = $this->resolveQueryColumnAlias($table, $name)) !== null) {
$alias = $name; $alias = $name;

View File

@ -206,10 +206,7 @@ class RepositoryQuery implements QueryInterface, SortRules, FilterColumns, Itera
*/ */
public function where($column, $value = null) public function where($column, $value = null)
{ {
$this->query->where( $this->addFilter(Filter::where($column, $value));
$this->repository->requireFilterColumn($this->target, $column, $this),
$this->repository->persistColumn($this->target, $column, $value, $this)
);
return $this; return $this;
} }