2015-06-30 11:19:31 +02:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace Icinga\Module\Director\Web\Controller;
|
|
|
|
|
|
|
|
use Icinga\Web\Url;
|
|
|
|
|
|
|
|
abstract class ObjectController extends ActionController
|
|
|
|
{
|
|
|
|
protected $object;
|
|
|
|
|
|
|
|
public function init()
|
|
|
|
{
|
|
|
|
$type = $this->getType();
|
|
|
|
$ltype = strtolower($type);
|
|
|
|
$params = array();
|
2015-07-02 14:31:35 +02:00
|
|
|
if ($name = $this->params->get('name')) {
|
|
|
|
$params['name'] = $name;
|
2015-06-30 11:19:31 +02:00
|
|
|
|
|
|
|
$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());
|
2015-07-02 14:31:35 +02:00
|
|
|
$form->loadObject($this->params->get('name'));
|
2015-06-30 11:19:31 +02:00
|
|
|
|
|
|
|
$url = Url::fromPath(
|
|
|
|
sprintf('director/%s', $ltype),
|
2015-07-02 14:31:35 +02:00
|
|
|
array('name' => $form->getObject()->object_name)
|
2015-06-30 11:19:31 +02:00
|
|
|
);
|
|
|
|
$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');
|
2015-07-23 16:19:22 +02:00
|
|
|
$this->view->table = $this->applyPaginationLimits(
|
|
|
|
$this->loadTable('activityLog')->setConnection($this->db())
|
2015-06-30 11:19:31 +02:00
|
|
|
->filterObject('icinga_' . $type, $object->object_name)
|
2015-07-23 16:19:22 +02:00
|
|
|
);
|
2015-06-30 11:19:31 +02:00
|
|
|
$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()
|
|
|
|
{
|
2015-07-02 14:31:35 +02:00
|
|
|
if ($name = $this->params->get('name')) {
|
|
|
|
$this->object = $this->loadObject($name);
|
2015-06-30 11:19:31 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
}
|