diff --git a/application/forms/IcingaNotificationForm.php b/application/forms/IcingaNotificationForm.php index a98382bd..9adf19ce 100644 --- a/application/forms/IcingaNotificationForm.php +++ b/application/forms/IcingaNotificationForm.php @@ -22,6 +22,8 @@ class IcingaNotificationForm extends DirectorObjectForm $this->addDisabledElement() ->addImportsElement() + ->addUsersElement() + ->addUsergroupsElement() ->addIntervalElement() ->addPeriodElement() ->addTimesElements() @@ -32,6 +34,50 @@ class IcingaNotificationForm extends DirectorObjectForm ->setButtons(); } + protected function addUsersElement() + { + $users = $this->enumUsers(); + if (empty($users)) { + return $this; + } + + $this->addElement( + 'extensibleSet', + 'users', + array( + 'label' => $this->translate('Users'), + 'description' => $this->translate( + 'Users that should be notified by this notifications' + ), + 'multiOptions' => $this->optionalEnum($users) + ) + ); + + return $this; + } + + protected function addUsergroupsElement() + { + $groups = $this->enumUsergroups(); + if (empty($groups)) { + return $this; + } + + $this->addElement( + 'extensibleSet', + 'user_groups', + array( + 'label' => $this->translate('User groups'), + 'description' => $this->translate( + 'User groups that should be notified by this notifications' + ), + 'multiOptions' => $this->optionalEnum($groups) + ) + ); + + return $this; + } + protected function addIntervalElement() { $this->addElement( @@ -109,4 +155,32 @@ class IcingaNotificationForm extends DirectorObjectForm return $this; } + + protected function enumUsers() + { + $db = $this->db->getDbAdapter(); + $select = $db->select()->from( + 'icinga_user', + array( + 'name' => 'object_name', + 'display' => 'COALESCE(display_name, object_name)' + ) + )->where('object_type = ?', 'object')->order('display'); + + return $db->fetchPairs($select); + } + + protected function enumUsergroups() + { + $db = $this->db->getDbAdapter(); + $select = $db->select()->from( + 'icinga_usergroup', + array( + 'name' => 'object_name', + 'display' => 'COALESCE(display_name, object_name)' + ) + )->where('object_type = ?', 'object')->order('display'); + + return $db->fetchPairs($select); + } } diff --git a/library/Director/Web/Form/DirectorObjectForm.php b/library/Director/Web/Form/DirectorObjectForm.php index 87ae09ce..4e1006c5 100644 --- a/library/Director/Web/Form/DirectorObjectForm.php +++ b/library/Director/Web/Form/DirectorObjectForm.php @@ -415,6 +415,8 @@ abstract class DirectorObjectForm extends QuickForm 'address', 'address6', 'groups', + 'users', + 'user_groups', 'command_id', // Notification 'notification_interval', 'period',