From a991e6815d71546b97bb371105a9e8b2889fb96a Mon Sep 17 00:00:00 2001 From: Alexander Fuhr Date: Tue, 2 Jun 2015 14:19:05 +0200 Subject: [PATCH] Usergroup: Add form, table, object and actions --- application/controllers/ListController.php | 11 +++++ application/controllers/ObjectController.php | 16 +++++++ application/forms/IcingaUsergroupForm.php | 48 ++++++++++++++++++++ application/tables/IcingaUsergroupTable.php | 48 ++++++++++++++++++++ configuration.php | 2 + library/Director/Objects/IcingaUsergroup.php | 16 +++++++ 6 files changed, 141 insertions(+) create mode 100644 application/forms/IcingaUsergroupForm.php create mode 100644 application/tables/IcingaUsergroupTable.php create mode 100644 library/Director/Objects/IcingaUsergroup.php diff --git a/application/controllers/ListController.php b/application/controllers/ListController.php index 32f6bb7b..67a42d6a 100644 --- a/application/controllers/ListController.php +++ b/application/controllers/ListController.php @@ -70,6 +70,17 @@ class Director_ListController extends ActionController $this->render('table'); } + public function usergroupsAction() + { + $this->view->addLink = $this->view->qlink( + $this->translate('Add Usergroup'), + 'director/object/usergroup' + ); + $this->view->title = $this->translate('Icinga Usergroups'); + $this->view->table = $this->loadTable('icingaUsergroup')->setConnection($this->db()); + $this->render('table'); + } + public function endpointsAction() { $this->view->addLink = $this->view->qlink( diff --git a/application/controllers/ObjectController.php b/application/controllers/ObjectController.php index 14be5a1e..95577c0e 100644 --- a/application/controllers/ObjectController.php +++ b/application/controllers/ObjectController.php @@ -100,6 +100,22 @@ class Director_ObjectController extends ActionController $this->render('form'); } + public function usergroupAction() + { + $this->view->form = $this->loadForm('icingaUsergroup') + ->setDb($this->db()) + ->setSuccessUrl('director/list/usergroups'); + + if ($id = $this->params->get('id')) { + $this->view->form->loadObject($id); + $this->view->title = $this->translate('Modify Icinga Usergroup'); + } else { + $this->view->title = $this->translate('Add new Icinga Usergroup'); + } + $this->view->form->handleRequest(); + $this->render('form'); + } + public function endpointAction() { $this->view->form = $this->loadForm('icingaEndpoint') diff --git a/application/forms/IcingaUsergroupForm.php b/application/forms/IcingaUsergroupForm.php new file mode 100644 index 00000000..938cd93c --- /dev/null +++ b/application/forms/IcingaUsergroupForm.php @@ -0,0 +1,48 @@ +addElement('select', 'object_type', array( + 'label' => $this->translate('Object type'), + 'description' => $this->translate('Whether this should be a template'), + 'multiOptions' => array( + null => '- please choose -', + 'object' => 'Usergroup object', + 'template' => 'Usergroup template', + ) + )); + + if ($isTemplate) { + $this->addElement('text', 'object_name', array( + 'label' => $this->translate('Usergroup template name'), + 'required' => true, + 'description' => $this->translate('Usergroup for the Icinga usergroup template you are going to create') + )); + } else { + $this->addElement('text', 'object_name', array( + 'label' => $this->translate('Usergroup'), + 'required' => true, + 'description' => $this->translate('Usergroup for the Icinga usergroup you are going to create') + )); + } + + $this->addElement('text', 'display_name', array( + 'label' => $this->translate('Display Name'), + 'description' => $this->translate('The name which should displayed.') + )); + + $this->addElement('select', 'zone_id', array( + 'label' => $this->translate('Cluster Zone'), + 'description' => $this->translate('Check this usergroup in this specific Icinga cluster zone') + )); + + $this->addElement('submit', $this->translate('Store')); + } +} diff --git a/application/tables/IcingaUsergroupTable.php b/application/tables/IcingaUsergroupTable.php new file mode 100644 index 00000000..d2c4918b --- /dev/null +++ b/application/tables/IcingaUsergroupTable.php @@ -0,0 +1,48 @@ + 'ug.id', + 'usergroup' => 'ug.object_name', + 'display_name' => 'ug.display_name', + 'zone' => 'z.object_name', + ); + } + + protected function getActionUrl($row) + { + return $this->url('director/object/usergroup', array('id' => $row->id)); + } + + public function getTitles() + { + $view = $this->view(); + return array( + 'usergroup' => $view->translate('Usergroup'), + 'display_name' => $view->translate('Display Name'), + 'zone' => $view->translate('Zone'), + ); + } + + public function fetchData() + { + $db = $this->connection()->getConnection(); + $query = $db->select()->from( + array('ug' => 'icinga_usergroup'), + $this->getColumns() + )->joinLeft( + array('z' => 'icinga_zone'), + 'ug.zone_id = z.id', + array() + ); + + return $db->fetchAll($query); + } +} diff --git a/configuration.php b/configuration.php index 2cb9cfd9..4d1e2d1c 100644 --- a/configuration.php +++ b/configuration.php @@ -17,6 +17,8 @@ $section->add($this->translate('Servicegroups')) ->setUrl('director/list/servicegroups'); $section->add($this->translate('Users')) ->setUrl('director/list/users'); +$section->add($this->translate('Usergroups')) + ->setUrl('director/list/usergroups'); $section->add($this->translate('Endpoints')) ->setUrl('director/list/endpoints'); $section->add($this->translate('Activity Log')) diff --git a/library/Director/Objects/IcingaUsergroup.php b/library/Director/Objects/IcingaUsergroup.php new file mode 100644 index 00000000..075770c4 --- /dev/null +++ b/library/Director/Objects/IcingaUsergroup.php @@ -0,0 +1,16 @@ + null, + 'object_name' => null, + 'display_name' => null, + 'object_type' => null, + 'zone_id' => null, + ); +}