mirror of
https://github.com/Icinga/icingaweb2-module-director.git
synced 2025-07-27 07:44:05 +02:00
IcingaTemplateChoice: helper method for roles...
...and initial support for "main" choice
This commit is contained in:
parent
cd2ed5cfae
commit
07c4d3ceaa
@ -2,6 +2,7 @@
|
|||||||
|
|
||||||
namespace Icinga\Module\Director\Objects;
|
namespace Icinga\Module\Director\Objects;
|
||||||
|
|
||||||
|
use Icinga\Exception\ProgrammingError;
|
||||||
use Icinga\Module\Director\Web\Form\QuickForm;
|
use Icinga\Module\Director\Web\Form\QuickForm;
|
||||||
|
|
||||||
class IcingaTemplateChoice extends IcingaObject
|
class IcingaTemplateChoice extends IcingaObject
|
||||||
@ -27,6 +28,12 @@ class IcingaTemplateChoice extends IcingaObject
|
|||||||
return substr(substr($this->table, 0, -16), 7);
|
return substr(substr($this->table, 0, -16), 7);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function isMainChoice()
|
||||||
|
{
|
||||||
|
return $this->hasBeenLoadedFromDb()
|
||||||
|
&& $this->connection->settings()->get('main_host_choice');
|
||||||
|
}
|
||||||
|
|
||||||
public function getObjectTableName()
|
public function getObjectTableName()
|
||||||
{
|
{
|
||||||
return substr($this->table, 0, -16);
|
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
|
* @param $type
|
||||||
* @codingStandardsIgnoreStart
|
* @codingStandardsIgnoreStart
|
||||||
|
Loading…
x
Reference in New Issue
Block a user