Repository: Allow to check for conversion rules of a specific column

This commit is contained in:
Johannes Meyer 2015-06-26 14:20:35 +02:00
parent 4ba84903f1
commit 5d3eb5e8cb
2 changed files with 35 additions and 7 deletions
library/Icinga/Repository

@ -463,17 +463,33 @@ abstract class DbRepository extends Repository implements Extensible, Updatable,
}
/**
* Return whether this repository is capable of converting values
* Return whether this repository is capable of converting values for the given table and optional column
*
* This does not check whether any conversion for the given table is available, as it may be possible
* that columns from another table where joined in which would otherwise not being converted.
* This does not check whether any conversion for the given table is available if $column is not given, as it
* may be possible that columns from another table where joined in which would otherwise not being converted.
*
* @param array|string $table
* @param string $column
*
* @return bool
*/
public function providesValueConversion($_)
public function providesValueConversion($table, $column = null)
{
if ($column !== null) {
if ($this->validateQueryColumnAssociation($table, $column)) {
return parent::providesValueConversion(
$this->removeTablePrefix($this->clearTableAlias($table)),
$column
);
}
if (($tableName = $this->findTableName($column))) {
return parent::providesValueConversion($tableName, $column);
}
return false;
}
$conversionRules = $this->getConversionRules();
return !empty($conversionRules);
}

@ -464,16 +464,28 @@ abstract class Repository implements Selectable
}
/**
* Return whether this repository is capable of converting values for the given table
* Return whether this repository is capable of converting values for the given table and optional column
*
* @param string $table
* @param string $column
*
* @return bool
*/
public function providesValueConversion($table)
public function providesValueConversion($table, $column = null)
{
$conversionRules = $this->getConversionRules();
return !empty($conversionRules) && isset($conversionRules[$table]);
if (empty($conversionRules)) {
return false;
}
if (! isset($conversionRules[$table])) {
return false;
} elseif ($column === null) {
return true;
}
$alias = $this->reassembleQueryColumnAlias($table, $column) ?: $column;
return array_key_exists($alias, $conversionRules[$table]) || in_array($alias, $conversionRules[$table]);
}
/**