IcingaObject: generic relation render helper

This commit is contained in:
Thomas Gelf 2015-12-03 17:09:51 +01:00
parent 71f8b0f107
commit 3656e8ed98
1 changed files with 19 additions and 0 deletions

View File

@ -66,6 +66,13 @@ abstract class IcingaObject extends DbObject implements IcingaConfigRenderer
return __NAMESPACE__ . '\\' . $this->relations[$property]; return __NAMESPACE__ . '\\' . $this->relations[$property];
} }
protected function getRelatedObjectName($property, $id)
{
$class = $this->getRelationClass($property);
$object = $class::loadWithAutoIncId($id, $this->connection);
return $object->object_name;
}
public function supportsCustomVars() public function supportsCustomVars()
{ {
return $this->supportsCustomVars; return $this->supportsCustomVars;
@ -679,6 +686,11 @@ abstract class IcingaObject extends DbObject implements IcingaConfigRenderer
c::renderBoolean($value) c::renderBoolean($value)
); );
} }
} elseif (
substr($key, -3) === '_id'
&& $this->hasRelation($relKey = substr($key, 0, -3))
) {
$out .= $this->renderRelationProperty($relKey, $value);
} else { } else {
$out .= c::renderKeyValue($key, c::renderString($value)); $out .= c::renderKeyValue($key, c::renderString($value));
} }
@ -747,6 +759,13 @@ abstract class IcingaObject extends DbObject implements IcingaConfigRenderer
} }
} }
protected function renderRelationProperty($propertyName, $id)
{
return c::renderKeyValue(
$propertyName,
c::renderString($this->getRelatedObjectName($propertyName, $id))
);
}
protected function renderCommandProperty($commandId, $propertyName = 'check_command') protected function renderCommandProperty($commandId, $propertyName = 'check_command')
{ {
return c::renderKeyValue( return c::renderKeyValue(