mirror of
https://github.com/Icinga/icingaweb2-module-director.git
synced 2025-07-30 17:24:18 +02:00
IcingaObject: render assignments (experimental)
This commit is contained in:
parent
4939b7d6c8
commit
b9ee674d3f
@ -5,6 +5,7 @@ namespace Icinga\Module\Director\Objects;
|
|||||||
use Icinga\Module\Director\CustomVariable\CustomVariables;
|
use Icinga\Module\Director\CustomVariable\CustomVariables;
|
||||||
use Icinga\Module\Director\Data\Db\DbObject;
|
use Icinga\Module\Director\Data\Db\DbObject;
|
||||||
use Icinga\Module\Director\Db;
|
use Icinga\Module\Director\Db;
|
||||||
|
use Icinga\Module\Director\IcingaConfig\AssignRenderer;
|
||||||
use Icinga\Module\Director\IcingaConfig\IcingaConfigRenderer;
|
use Icinga\Module\Director\IcingaConfig\IcingaConfigRenderer;
|
||||||
use Icinga\Module\Director\IcingaConfig\IcingaConfigHelper as c;
|
use Icinga\Module\Director\IcingaConfig\IcingaConfigHelper as c;
|
||||||
use Icinga\Data\Filter\Filter;
|
use Icinga\Data\Filter\Filter;
|
||||||
@ -665,6 +666,30 @@ abstract class IcingaObject extends DbObject implements IcingaConfigRenderer
|
|||||||
return $fields;
|
return $fields;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
protected function getAssignments()
|
||||||
|
{
|
||||||
|
if (! $this->isApplyRule()) {
|
||||||
|
throw new ProgrammingError('Assignments are available only for apply rules');
|
||||||
|
}
|
||||||
|
|
||||||
|
if (! $this->hasBeenLoadedFromDb()) {
|
||||||
|
return array();
|
||||||
|
}
|
||||||
|
|
||||||
|
$db = $this->getDb();
|
||||||
|
|
||||||
|
$query = $db->select()->from(
|
||||||
|
array('a' => $this->getTableName() . '_assignment'),
|
||||||
|
array(
|
||||||
|
'filter_string' => 'a.filter_string',
|
||||||
|
)
|
||||||
|
)->where('a.' . $this->getShortTableName() . '_id = ?', (int) $this->id);
|
||||||
|
|
||||||
|
return $db->fetchCol($query);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
public function isTemplate()
|
public function isTemplate()
|
||||||
{
|
{
|
||||||
return $this->hasProperty('object_type')
|
return $this->hasProperty('object_type')
|
||||||
@ -945,6 +970,28 @@ abstract class IcingaObject extends DbObject implements IcingaConfigRenderer
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
protected function renderAssignments()
|
||||||
|
{
|
||||||
|
if ($this->isApplyRule()) {
|
||||||
|
$rules = $this->getAssignments();
|
||||||
|
|
||||||
|
if (empty($rules)) {
|
||||||
|
return '';
|
||||||
|
}
|
||||||
|
|
||||||
|
$filters = array();
|
||||||
|
foreach ($rules as $rule) {
|
||||||
|
$filters[] = AssignRenderer::forFilter(
|
||||||
|
Filter::fromQueryString($rule)
|
||||||
|
)->renderAssign();
|
||||||
|
}
|
||||||
|
|
||||||
|
return "\n " . implode("\n ", $filters) . "\n";
|
||||||
|
} else {
|
||||||
|
return '';
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public function toConfigString()
|
public function toConfigString()
|
||||||
{
|
{
|
||||||
return implode(array(
|
return implode(array(
|
||||||
@ -956,6 +1003,7 @@ abstract class IcingaObject extends DbObject implements IcingaConfigRenderer
|
|||||||
$this->renderGroups(),
|
$this->renderGroups(),
|
||||||
$this->renderCustomExtensions(),
|
$this->renderCustomExtensions(),
|
||||||
$this->renderCustomVars(),
|
$this->renderCustomVars(),
|
||||||
|
$this->renderAssignments(),
|
||||||
$this->renderSuffix()
|
$this->renderSuffix()
|
||||||
));
|
));
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user