diff --git a/application/controllers/CommandController.php b/application/controllers/CommandController.php new file mode 100644 index 00000000..5295fea9 --- /dev/null +++ b/application/controllers/CommandController.php @@ -0,0 +1,7 @@ +setHostTabs()->activate('hosts'); - $this->view->addLink = $this->view->qlink( - $this->translate('Add Host'), - 'director/object/host' - ); - $this->view->title = $this->translate('Icinga Hosts'); - $this->view->table = $this->loadTable('icingaHost')->setConnection($this->db()); - $this->render('table'); - } - - public function hostgroupsAction() - { - $this->setHostTabs()->activate('hostgroups'); - $this->view->addLink = $this->view->qlink( - $this->translate('Add Hostgroup'), - 'director/object/hostgroup' - ); - $this->view->title = $this->translate('Icinga Hostgroups'); - $this->view->table = $this->loadTable('icingaHostGroup')->setConnection($this->db()); - $this->render('table'); - } - - public function timeperiodsAction() - { - $this->setGlobalTabs()->activate('timeperiods'); - $this->view->addLink = $this->view->qlink( - $this->translate('Add Timeperiod'), - 'director/object/timeperiod' - ); - $this->view->title = $this->translate('Icinga Timeperiods'); - $this->view->table = $this->loadTable('icingaTimePeriod')->setConnection($this->db()); - $this->render('table'); - } - - public function servicesAction() - { - $this->setServiceTabs()->activate('services'); - $this->view->addLink = $this->view->qlink( - $this->translate('Add Service'), - 'director/object/service' - ); - $this->view->title = $this->translate('Icinga Services'); - $this->view->table = $this->loadTable('icingaService')->setConnection($this->db()); - $this->render('table'); - } - - public function servicegroupsAction() - { - $this->setServiceTabs()->activate('servicegroups'); - $this->view->addLink = $this->view->qlink( - $this->translate('Add Servicegroup'), - 'director/object/servicegroup' - ); - $this->view->title = $this->translate('Icinga Servicegroups'); - $this->view->table = $this->loadTable('icingaServiceGroup')->setConnection($this->db()); - $this->render('table'); - } - - public function commandsAction() - { - $this->setGlobalTabs()->activate('commands'); - $this->view->addLink = $this->view->qlink( - $this->translate('Add Command'), - 'director/object/command' - ); - $this->view->title = $this->translate('Icinga Commands'); - $this->view->table = $this->loadTable('icingaCommand')->setConnection($this->db()); - $this->render('table'); - } - - public function commandargumentsAction() - { - $this->setGlobalTabs()->activate('commandarguments'); - $this->view->addLink = $this->view->qlink( - $this->translate('Add Command Argument'), - 'director/object/commandargument' - ); - $this->view->title = $this->translate('Icinga Command Arguments'); - $this->view->table = $this->loadTable('icingaCommandArgument')->setConnection($this->db()); - $this->render('table'); - } - - public function usersAction() - { - $this->setUserTabs()->activate('users'); - $this->view->addLink = $this->view->qlink( - $this->translate('Add User'), - 'director/object/user' - ); - $this->view->title = $this->translate('Icinga Users'); - $this->view->table = $this->loadTable('icingaUser')->setConnection($this->db()); - $this->render('table'); - } - - public function usergroupsAction() - { - $this->setUserTabs()->activate('usergroups'); - $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->setGlobalTabs()->activate('endpoints'); - $this->view->addLink = $this->view->qlink( - $this->translate('Add Endpoint'), - 'director/object/endpoint' - ); - $this->view->title = $this->translate('Icinga Endpoints'); - $this->view->table = $this->loadTable('icingaEndpoint')->setConnection($this->db()); - $this->render('table'); - } - - public function zonesAction() - { - $this->setGlobalTabs()->activate('zones'); - $this->view->addLink = $this->view->qlink( - $this->translate('Add Zone'), - 'director/object/zone' - ); - $this->view->title = $this->translate('Icinga Zones'); - $this->view->table = $this->loadTable('icingaZone')->setConnection($this->db()); - $this->render('table'); - } - public function activitylogAction() { $this->setConfigTabs()->activate('activitylog'); diff --git a/application/controllers/ObjectController.php b/application/controllers/ObjectController.php deleted file mode 100644 index de81aa92..00000000 --- a/application/controllers/ObjectController.php +++ /dev/null @@ -1,182 +0,0 @@ -view->form = $this->loadForm('icingaHost') - ->setDb($this->db()) - ->setSuccessUrl('director/list/hosts'); - - if ($id = $this->params->get('id')) { - $this->view->form->loadObject($id); - $this->view->title = $this->translate('Modify Icinga Host'); - } else { - $this->view->title = $this->translate('Add new Icinga Host'); - } - $this->view->form->handleRequest(); - $this->render('form'); - } - - public function hostgroupAction() - { - $this->view->form = $this->loadForm('icingaHostGroup') - ->setDb($this->db()) - ->setSuccessUrl('director/list/hostgroups'); - - if ($id = $this->params->get('id')) { - $this->view->form->loadObject($id); - $this->view->title = $this->translate('Modify Icinga Hostgroup'); - } else { - $this->view->title = $this->translate('Add new Icinga Hostgroup'); - } - $this->view->form->handleRequest(); - $this->render('form'); - } - - public function serviceAction() - { - $this->view->form = $this->loadForm('icingaService') - ->setDb($this->db()) - ->setSuccessUrl('director/list/services'); - - if ($id = $this->params->get('id')) { - $this->view->form->loadObject($id); - $this->view->title = $this->translate('Modify Icinga Service'); - } else { - $this->view->title = $this->translate('Add new Icinga Service'); - } - $this->view->form->handleRequest(); - $this->render('form'); - } - - public function servicegroupAction() - { - $this->view->form = $this->loadForm('icingaServiceGroup') - ->setDb($this->db()) - ->setSuccessUrl('director/list/servicegroups'); - - if ($id = $this->params->get('id')) { - $this->view->form->loadObject($id); - $this->view->title = $this->translate('Modify Icinga Servicegroup'); - } else { - $this->view->title = $this->translate('Add new Icinga Servicegroup'); - } - $this->view->form->handleRequest(); - $this->render('form'); - } - - public function commandAction() - { - $this->view->form = $this->loadForm('icingaCommand') - ->setDb($this->db()) - ->setSuccessUrl('director/list/commands'); - - if ($id = $this->params->get('id')) { - $this->view->form->loadObject($id); - $this->view->title = $this->translate('Modify Icinga Command'); - } else { - $this->view->title = $this->translate('Add new Icinga Command'); - } - $this->view->form->handleRequest(); - $this->render('form'); - } - - public function commandargumentAction() - { - $this->view->form = $this->loadForm('icingaCommandArgument') - ->setDb($this->db()) - ->setSuccessUrl('director/list/commandarguments'); - - if ($id = $this->params->get('id')) { - $this->view->form->loadObject($id); - $this->view->title = $this->translate('Modify Icinga Command Argument'); - } else { - $this->view->title = $this->translate('Add new Icinga Command Argument'); - } - $this->view->form->handleRequest(); - $this->render('form'); - } - - public function userAction() - { - $this->view->form = $this->loadForm('icingaUser') - ->setDb($this->db()) - ->setSuccessUrl('director/list/users'); - - if ($id = $this->params->get('id')) { - $this->view->form->loadObject($id); - $this->view->title = $this->translate('Modify Icinga User'); - } else { - $this->view->title = $this->translate('Add new Icinga User'); - } - $this->view->form->handleRequest(); - $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') - ->setDb($this->db()) - ->setSuccessUrl('director/list/endpoints'); - - if ($id = $this->params->get('id')) { - $this->view->form->loadObject($id); - $this->view->title = $this->translate('Modify Icinga Endpoint'); - } else { - $this->view->title = $this->translate('Add new Icinga Endpoint'); - } - $this->view->form->handleRequest(); - $this->render('form'); - } - - public function timeperiodAction() - { - $this->view->form = $this->loadForm('icingaTimePeriod') - ->setDb($this->db()) - ->setSuccessUrl('director/list/timeperiods'); - - if ($id = $this->params->get('id')) { - $this->view->form->loadObject($id); - $this->view->title = $this->translate('Modify Icinga Timeperiod'); - } else { - $this->view->title = $this->translate('Add new Icinga Timeperiod'); - } - $this->view->form->handleRequest(); - $this->render('form'); - } - - public function zoneAction() - { - $this->view->form = $this->loadForm('icingaZone') - ->setDb($this->db()) - ->setSuccessUrl('director/list/zones'); - - if ($id = $this->params->get('id')) { - $this->view->title = $this->translate('Modify Icinga Zone'); - $this->view->form->loadObject($id); - } else { - $this->view->title = $this->translate('Add new Icinga Zone'); - } - $this->view->form->handleRequest(); - $this->render('form'); - } -} diff --git a/application/controllers/ServiceController.php b/application/controllers/ServiceController.php new file mode 100644 index 00000000..eb1aeec2 --- /dev/null +++ b/application/controllers/ServiceController.php @@ -0,0 +1,7 @@ +filters[] = array('l.object_type = ?', $type); + $this->filters[] = array('l.object_name = ?', $name); + + return $this; + } + public function fetchData() { $db = $this->connection()->getConnection(); @@ -40,6 +50,10 @@ class ActivityLogTable extends QuickTable $this->getColumns() )->order('change_time DESC'); + foreach ($this->filters as $filter) { + $query->where($filter[0], $filter[1]); + } + return $db->fetchAll($query); } } diff --git a/application/tables/IcingaCommandArgumentTable.php b/application/tables/IcingaCommandArgumentTable.php index b41953b0..228abd0f 100644 --- a/application/tables/IcingaCommandArgumentTable.php +++ b/application/tables/IcingaCommandArgumentTable.php @@ -19,7 +19,7 @@ class IcingaCommandArgumentTable extends QuickTable protected function getActionUrl($row) { - return $this->url('director/object/commandargument', array('id' => $row->id)); + return $this->url('director/commandargument', array('id' => $row->id)); } public function getTitles() diff --git a/application/tables/IcingaCommandTable.php b/application/tables/IcingaCommandTable.php index 176ef6fa..3f7dcf46 100644 --- a/application/tables/IcingaCommandTable.php +++ b/application/tables/IcingaCommandTable.php @@ -18,7 +18,7 @@ class IcingaCommandTable extends QuickTable protected function getActionUrl($row) { - return $this->url('director/object/command', array('id' => $row->id)); + return $this->url('director/command', array('id' => $row->id)); } public function getTitles() diff --git a/application/tables/IcingaEndpointTable.php b/application/tables/IcingaEndpointTable.php index 29e0b4a1..e178c57b 100644 --- a/application/tables/IcingaEndpointTable.php +++ b/application/tables/IcingaEndpointTable.php @@ -18,7 +18,7 @@ class IcingaEndpointTable extends QuickTable protected function getActionUrl($row) { - return $this->url('director/object/endpoint', array('id' => $row->id)); + return $this->url('director/endpoint', array('id' => $row->id)); } public function getTitles() diff --git a/application/tables/IcingaHostGroupTable.php b/application/tables/IcingaHostGroupTable.php index 9b3d4e36..8823c704 100644 --- a/application/tables/IcingaHostGroupTable.php +++ b/application/tables/IcingaHostGroupTable.php @@ -17,7 +17,7 @@ class IcingaHostGroupTable extends QuickTable protected function getActionUrl($row) { - return $this->url('director/object/hostgroup', array('id' => $row->id)); + return $this->url('director/hostgroup', array('id' => $row->id)); } public function getTitles() diff --git a/application/tables/IcingaHostTable.php b/application/tables/IcingaHostTable.php index 58f6fef5..d1d65e09 100644 --- a/application/tables/IcingaHostTable.php +++ b/application/tables/IcingaHostTable.php @@ -18,7 +18,7 @@ class IcingaHostTable extends QuickTable protected function getActionUrl($row) { - return $this->url('director/object/host', array('id' => $row->id)); + return $this->url('director/host', array('id' => $row->id)); } public function getTitles() diff --git a/application/tables/IcingaServiceGroupTable.php b/application/tables/IcingaServiceGroupTable.php index 1b65c88f..d1f9140c 100644 --- a/application/tables/IcingaServiceGroupTable.php +++ b/application/tables/IcingaServiceGroupTable.php @@ -17,15 +17,15 @@ class IcingaServiceGroupTable extends QuickTable protected function getActionUrl($row) { - return $this->url('director/object/servicegroup', array('id' => $row->id)); + return $this->url('director/servicegroup', array('id' => $row->id)); } public function getTitles() { $view = $this->view(); return array( - 'servicegroup' => $view->translate('Servicegroup'), - 'display_name' => $view->translate('Display Name'), + 'servicegroup' => $view->translate('Servicegroup'), + 'display_name' => $view->translate('Display Name'), ); } diff --git a/application/tables/IcingaServiceTable.php b/application/tables/IcingaServiceTable.php index 242ca9b4..2c6fef98 100644 --- a/application/tables/IcingaServiceTable.php +++ b/application/tables/IcingaServiceTable.php @@ -17,7 +17,7 @@ class IcingaServiceTable extends QuickTable protected function getActionUrl($row) { - return $this->url('director/object/service', array('id' => $row->id)); + return $this->url('director/service', array('id' => $row->id)); } public function getTitles() diff --git a/application/tables/IcingaTimePeriodTable.php b/application/tables/IcingaTimePeriodTable.php index 8abc0ec8..9ca20fb0 100644 --- a/application/tables/IcingaTimePeriodTable.php +++ b/application/tables/IcingaTimePeriodTable.php @@ -18,7 +18,7 @@ class IcingaTimePeriodTable extends QuickTable protected function getActionUrl($row) { - return $this->url('director/object/timeperiod', array('id' => $row->id)); + return $this->url('director/timeperiod', array('id' => $row->id)); } public function getTitles() diff --git a/application/tables/IcingaUserGroupTable.php b/application/tables/IcingaUserGroupTable.php index 60a287fe..1d9b6d5f 100644 --- a/application/tables/IcingaUserGroupTable.php +++ b/application/tables/IcingaUserGroupTable.php @@ -18,7 +18,7 @@ class IcingaUserGroupTable extends QuickTable protected function getActionUrl($row) { - return $this->url('director/object/usergroup', array('id' => $row->id)); + return $this->url('director/usergroup', array('id' => $row->id)); } public function getTitles() diff --git a/application/tables/IcingaUserTable.php b/application/tables/IcingaUserTable.php index 06d09467..bd3a2584 100644 --- a/application/tables/IcingaUserTable.php +++ b/application/tables/IcingaUserTable.php @@ -22,7 +22,7 @@ class IcingaUserTable extends QuickTable protected function getActionUrl($row) { - return $this->url('director/object/user', array('id' => $row->id)); + return $this->url('director/user', array('id' => $row->id)); } public function getTitles() diff --git a/application/tables/IcingaZoneTable.php b/application/tables/IcingaZoneTable.php index 886de87e..b0986548 100644 --- a/application/tables/IcingaZoneTable.php +++ b/application/tables/IcingaZoneTable.php @@ -8,22 +8,30 @@ class IcingaZoneTable extends QuickTable { public function getColumns() { + if ($this->connection()->getDbType() === 'pgsql') { + $endpoints = "ARRAY_TO_STRING(ARRAY_AGG(e.object_name), ', ')"; + } else { + $endpoints = "GROUP_CONCAT(e.object_name ORDER BY e.object_name SEPARATOR ', ')"; + } + return array( - 'id' => 'z.id', - 'zone' => 'z.object_name', + 'id' => 'z.id', + 'zone' => 'z.object_name', + 'endpoints' => $endpoints, ); } protected function getActionUrl($row) { - return $this->url('director/object/zone', array('id' => $row->id)); + return $this->url('director/zone', array('id' => $row->id)); } public function getTitles() { $view = $this->view(); return array( - 'zone' => $view->translate('Zone'), + 'zone' => $view->translate('Zone'), + 'endpoints' => $view->translate('Endpoints'), ); } @@ -33,7 +41,11 @@ class IcingaZoneTable extends QuickTable $query = $db->select()->from( array('z' => 'icinga_zone'), $this->getColumns() - ); + )->joinLeft( + array('e' => 'icinga_endpoint'), + 'z.id = e.zone_id', + array() + )->group('z.id'); return $db->fetchAll($query); } diff --git a/application/views/scripts/object/form.phtml b/application/views/scripts/object/form.phtml index 317e8f20..7adf827f 100644 --- a/application/views/scripts/object/form.phtml +++ b/application/views/scripts/object/form.phtml @@ -1,13 +1,8 @@
+tabs ?>

escape($this->title) ?>

form ?> -getObject(); -if ($object->hasBeenLoadedFromDb()) { - echo '
' . $this->escape($object) . '
'; -} -?>
diff --git a/application/views/scripts/object/history.phtml b/application/views/scripts/object/history.phtml new file mode 100644 index 00000000..ccaa702f --- /dev/null +++ b/application/views/scripts/object/history.phtml @@ -0,0 +1,8 @@ +
+tabs ?> +

escape($this->title) ?>

+
+ +
+table->render() ?> +
diff --git a/application/views/scripts/object/show.phtml b/application/views/scripts/object/show.phtml new file mode 100644 index 00000000..d992f1a9 --- /dev/null +++ b/application/views/scripts/object/show.phtml @@ -0,0 +1,8 @@ +
+tabs ?> +

escape($this->title) ?>

+
+ +
+
escape($object) ?>
+
diff --git a/application/views/scripts/list/table.phtml b/application/views/scripts/objects/table.phtml similarity index 100% rename from application/views/scripts/list/table.phtml rename to application/views/scripts/objects/table.phtml diff --git a/configuration.php b/configuration.php index 829fad83..e974e193 100644 --- a/configuration.php +++ b/configuration.php @@ -12,10 +12,10 @@ $section = $this->menuSection( $this->translate('Icinga Director') )->setIcon('cubes'); -$section->add($this->translate('Global'))->setUrl('director/list/commands'); -$section->add($this->translate('Hosts'))->setUrl('director/list/hosts'); -$section->add($this->translate('Services'))->setUrl('director/list/services'); -$section->add($this->translate('Users'))->setUrl('director/list/users'); +$section->add($this->translate('Global'))->setUrl('director/commands'); +$section->add($this->translate('Hosts'))->setUrl('director/hosts'); +$section->add($this->translate('Services'))->setUrl('director/services'); +$section->add($this->translate('Users'))->setUrl('director/users'); $section->add($this->translate('Config')) ->setUrl('director/list/generatedconfig') ->setPriority(902); diff --git a/library/Director/ActionController.php b/library/Director/ActionController.php index 438c13f1..3fa24a66 100644 --- a/library/Director/ActionController.php +++ b/library/Director/ActionController.php @@ -17,6 +17,7 @@ abstract class ActionController extends Controller public function init() { + // TODO: this is obsolete I guess $m = Icinga::app()->getModuleManager(); if (! $m->hasLoaded('monitoring') && $m->hasInstalled('monitoring')) { $m->loadModule('monitoring'); diff --git a/library/Director/Objects/IcingaObject.php b/library/Director/Objects/IcingaObject.php index 282ca3ce..3fc5f129 100644 --- a/library/Director/Objects/IcingaObject.php +++ b/library/Director/Objects/IcingaObject.php @@ -323,6 +323,11 @@ abstract class IcingaObject extends DbObject implements IcingaConfigRenderer )); } + public function isGroup() + { + return substr($this->getType(), -5) === 'Group'; + } + protected function getType() { if ($this->type === null) { diff --git a/library/Director/Web/Controller/ObjectController.php b/library/Director/Web/Controller/ObjectController.php new file mode 100644 index 00000000..71b2fa59 --- /dev/null +++ b/library/Director/Web/Controller/ObjectController.php @@ -0,0 +1,143 @@ +getType(); + $ltype = strtolower($type); + $params = array(); + if ($id = $this->params->get('id')) { + $params['id'] = $id; + + $this->getTabs()->add($type, array( + 'url' => sprintf('director/%s', $ltype), + 'urlParams' => $params, + 'label' => $this->translate(ucfirst($ltype)), + ))->add('modify', array( + 'url' => sprintf('director/%s/edit', $ltype), + 'urlParams' => $params, + 'label' => $this->translate('Modify') + ))->add('history', array( + 'url' => sprintf('director/%s/history', $ltype), + 'urlParams' => $params, + 'label' => $this->translate('History') + )); + } else { + $this->getTabs()->add('add', array( + 'url' => sprintf('director/%s', $type), + 'label' => sprintf($this->translate('Add %s'), ucfirst($type)), + )); + } + } + + public function indexAction() + { + $type = $this->getType(); + $this->getTabs()->activate($type); + $this->view->object = $this->object(); + $this->render('object/show', null, true); + } + + public function editAction() + { + $this->getTabs()->activate('modify'); + $type = $this->getType(); + $ltype = strtolower($type); + + $this->view->form = $form = $this->loadForm( + 'icinga' . ucfirst($type) + )->setDb($this->db()); + $form->loadObject($this->params->get('id')); + + $url = Url::fromPath( + sprintf('director/%s', $ltype), + array('id' => $form->getObject()->id) + ); + $form->setSuccessUrl($url); + + $this->view->title = sprintf( + $this->translate('Modify Icinga %s'), + ucfirst($ltype) + ); + $this->view->form->handleRequest(); + $this->render('object/form', null, true); + } + + public function addAction() + { + $this->getTabs()->activate('add'); + $type = $this->getType(); + $ltype = strtolower($type); + + $url = sprintf('director/%ss', $ltype); + $this->view->form = $this->loadForm('icinga' . ucfirst($type)) + ->setDb($this->db()) + ->setSuccessUrl($url); + + $this->view->title = sprintf( + $this->translate('Add new Icinga %s'), + ucfirst($ltype) + ); + $this->view->form->handleRequest(); + $this->render('object/form', null, true); + } + + public function historyAction() + { + $type = $this->getType(); + $this->getTabs()->activate('history'); + $object = $this->object(); + $this->view->title = $this->translate('Activity Log'); + $this->view->table = $this->loadTable('activityLog') + ->setConnection($this->db()) + ->filterObject('icinga_' . $type, $object->object_name) + ; + $this->render('object/history', null, true); + } + + protected function getType() + { + // Strip final 's' and upcase an eventual 'group' + return preg_replace( + array('/group$/', '/period$/', '/argument$/'), + array('Group', 'Period', 'Argument'), + $this->getRequest()->getControllerName() + ); + } + + protected function object() + { + if ($id = $this->params->get('id')) { + $this->object = $this->loadObject($id); + } + + return $this->object; + } + + protected function getObjectClassname() + { + return 'Icinga\\Module\\Director\\Objects\\Icinga' + . ucfirst($this->getType()); + } + + protected function loadObject($id) + { + $class = $this->getObjectClassname(); + $object = $class::load($id, $this->db()); + $this->view->title = sprintf( + '%s "%s"', + $this->translate(ucfirst(strtolower($this->getType()))), + $object->object_name + ); + + return $object; + } +} diff --git a/library/Director/Web/Controller/ObjectsController.php b/library/Director/Web/Controller/ObjectsController.php new file mode 100644 index 00000000..7380ef26 --- /dev/null +++ b/library/Director/Web/Controller/ObjectsController.php @@ -0,0 +1,116 @@ +getType(); + $ltype = strtolower($type); + + $object = $this->dummyObject(); + + if (in_array(ucfirst($type), $this->globalTypes)) { + + $tabs = $this->getTabs(); + foreach ($this->globalTypes as $tabType) { + $ltabType = strtolower($tabType); + $tabs->add($ltabType, array( + 'label' => $this->translate(ucfirst($ltabType) . 's'), + 'url' => sprintf('director/%ss', $ltabType) + )); + } + $tabs->activate($ltype); + + } elseif ($object->isGroup()) { + + $singleType = substr($type, 0, -5); + $tabs = $this->getTabs()->add('objects', array( + 'url' => sprintf('director/%ss', $singleType), + 'label' => $this->translate(ucfirst($singleType) . 's'), + )); + + $tabs->add('objectgroups', array( + 'url' => sprintf('director/%ss', strtolower($type)), + 'label' => $this->translate(ucfirst(strtolower($type)) . 's') + )); + + } else { + + $tabs = $this->getTabs()->add('objects', array( + 'url' => sprintf('director/%ss', strtolower($type)), + 'label' => $this->translate(ucfirst($type) . 's'), + )); + if ($object->supportsGroups()) { + $tabs->add('objectgroups', array( + 'url' => sprintf('director/%sgroups', $type), + 'label' => $this->translate(ucfirst($type) . 'groups') + )); + } + + } + } + + public function indexAction() + { + $type = $this->getType(); + $ltype = strtolower($type); + + + if (! in_array($type, $this->globalTypes)) { + if ($this->dummyObject()->isGroup()) { + $this->getTabs()->activate('objectgroups'); + } else { + $this->getTabs()->activate('objects'); + } + } + + $this->view->addLink = $this->view->qlink( + $this->translate('Add ' . ucfirst($ltype)), + 'director/' . $ltype . '/add' + ); + $this->view->title = $this->translate('Icinga ' . ucfirst($ltype)); + $this->view->table = $this->loadTable('icinga' . ucfirst($type)) + ->setConnection($this->db()); + $this->render('objects/table', null, true); + } + + protected function dummyObject() + { + if ($this->dummy === null) { + $class = $this->getObjectClassname(); + $this->dummy = $class::create(array()); + } + + return $this->dummy; + } + + protected function getType() + { + // Strip final 's' and upcase an eventual 'group' + return preg_replace( + array('/group$/', '/period$/', '/argument$/'), + array('Group', 'Period', 'Argument'), + substr($this->getRequest()->getControllerName(), 0, -1) + ); + } + + protected function getObjectClassname() + { + return 'Icinga\\Module\\Director\\Objects\\Icinga' + . ucfirst($this->getType()); + } +}