From 07c4d3ceaa4eeaf48dc4b078da5fe8604c622e3e Mon Sep 17 00:00:00 2001 From: Thomas Gelf Date: Wed, 27 Sep 2017 20:44:50 +0200 Subject: [PATCH] IcingaTemplateChoice: helper method for roles... ...and initial support for "main" choice --- .../Director/Objects/IcingaTemplateChoice.php | 49 +++++++++++++++++++ 1 file changed, 49 insertions(+) diff --git a/library/Director/Objects/IcingaTemplateChoice.php b/library/Director/Objects/IcingaTemplateChoice.php index 484c8db0..b558d3a0 100644 --- a/library/Director/Objects/IcingaTemplateChoice.php +++ b/library/Director/Objects/IcingaTemplateChoice.php @@ -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