IcingaNotificationForm: add related user(-groups)

This commit is contained in:
Thomas Gelf 2016-03-16 14:07:09 +01:00
parent 3aa5ecbd8e
commit 433cb887c0
2 changed files with 76 additions and 0 deletions

View File

@ -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);
}
}

View File

@ -415,6 +415,8 @@ abstract class DirectorObjectForm extends QuickForm
'address',
'address6',
'groups',
'users',
'user_groups',
'command_id', // Notification
'notification_interval',
'period',