IcingaTemplateChoice: helper method for roles...

...and initial support for "main" choice
This commit is contained in:
Thomas Gelf 2017-09-27 20:44:50 +02:00
parent cd2ed5cfae
commit 07c4d3ceaa
1 changed files with 49 additions and 0 deletions

View File

@ -2,6 +2,7 @@
namespace Icinga\Module\Director\Objects;
use Icinga\Exception\ProgrammingError;
use Icinga\Module\Director\Web\Form\QuickForm;
class IcingaTemplateChoice extends IcingaObject
@ -27,6 +28,12 @@ class IcingaTemplateChoice extends IcingaObject
return substr(substr($this->table, 0, -16), 7);
}
public function isMainChoice()
{
return $this->hasBeenLoadedFromDb()
&& $this->connection->settings()->get('main_host_choice');
}
public function getObjectTableName()
{
return substr($this->table, 0, -16);
@ -181,6 +188,48 @@ class IcingaTemplateChoice extends IcingaObject
}
}
/**
* @param $roles
* @throws ProgrammingError
* @codingStandardsIgnoreStart
*/
public function setAllowed_roles($roles)
{
// @codingStandardsIgnoreEnd
$key = 'allowed_roles';
if (is_array($roles)) {
$this->reallySet($key, json_encode($roles));
} elseif (null === $roles) {
$this->reallySet($key, null);
} else {
throw new ProgrammingError(
'Expected array or null for allowed_roles, got %s',
var_export($roles, 1)
);
}
}
/**
* @return array|null
* @codingStandardsIgnoreStart
*/
public function getAllowed_roles()
{
// @codingStandardsIgnoreEnd
// Might be removed once all choice types have allowed_roles
if (! array_key_exists('allowed_roles', $this->properties)) {
return null;
}
$roles = $this->getProperty('allowed_roles');
if (is_string($roles)) {
return json_decode($roles);
} else {
return $roles;
}
}
/**
* @param $type
* @codingStandardsIgnoreStart