Timeperiod: Add form, table, object and actions

This commit is contained in:
Alexander Fuhr 2015-06-03 13:02:44 +02:00
parent c61656c46c
commit 7d99342274
6 changed files with 148 additions and 0 deletions

View File

@ -48,6 +48,17 @@ class Director_ListController extends ActionController
$this->render('table');
}
public function timeperiodsAction()
{
$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 servicegroupsAction()
{
$this->view->addLink = $this->view->qlink(

View File

@ -175,6 +175,22 @@ class Director_ObjectController extends ActionController
$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')

View File

@ -0,0 +1,54 @@
<?php
namespace Icinga\Module\Director\Forms;
use Icinga\Module\Director\Web\Form\DirectorObjectForm;
class IcingaTimeperiodForm extends DirectorObjectForm
{
public function setup()
{
$isTemplate = isset($_POST['object_type']) && $_POST['object_type'] === 'template';
$this->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' => 'Timeperiod object',
'template' => 'Timeperiod template',
)
));
if ($isTemplate) {
$this->addElement('text', 'object_name', array(
'label' => $this->translate('Timeperiod template name'),
'required' => true,
'description' => $this->translate('Name for the Icinga timperiod template you are going to create')
));
} else {
$this->addElement('text', 'object_name', array(
'label' => $this->translate('Timeperiod'),
'required' => true,
'description' => $this->translate('Name for the Icinga timeperiod you are going to create')
));
}
$this->addElement('text', 'display_name', array(
'label' => $this->translate('Display Name'),
'description' => $this->translate('the display name')
));
$this->addElement('text', 'update_method', array(
'label' => $this->translate('Update Method'),
'description' => $this->translate('the update method'),
));
$this->addElement('select', 'zone_id', array(
'label' => $this->translate('Cluster Zone'),
'description' => $this->translate('Check this host in this specific Icinga cluster zone'),
'required' => true
));
$this->addElement('submit', $this->translate('Store'));
}
}

View File

@ -0,0 +1,48 @@
<?php
namespace Icinga\Module\Director\Tables;
use Icinga\Module\Director\Web\Table\QuickTable;
class IcingaTimeperiodTable extends QuickTable
{
public function getColumns()
{
return array(
'id' => 't.id',
'timeperiod' => 't.object_name',
'display_name' => 't.display_name',
'zone' => 'z.object_name',
);
}
protected function getActionUrl($row)
{
return $this->url('director/object/timeperiod', array('id' => $row->id));
}
public function getTitles()
{
$view = $this->view();
return array(
'timeperiod' => $view->translate('Timeperiod'),
'display_name' => $view->translate('Display Name'),
'zone' => $view->translate('Zone'),
);
}
public function fetchData()
{
$db = $this->connection()->getConnection();
$query = $db->select()->from(
array('t' => 'icinga_timeperiod'),
$this->getColumns()
)->joinLeft(
array('z' => 'icinga_zone'),
't.zone_id = z.id',
array()
);
return $db->fetchAll($query);
}
}

View File

@ -9,6 +9,8 @@ $section->add($this->translate('Commands'))
->setUrl('director/list/commands');
$section->add($this->translate('Command Arguments'))
->setUrl('director/list/commandarguments');
$section->add($this->translate('Timeperiods'))
->setUrl('director/list/timeperiods');
$section->add($this->translate('Hosts'))
->setUrl('director/list/hosts');
$section->add($this->translate('Hostgroups'))

View File

@ -0,0 +1,17 @@
<?php
namespace Icinga\Module\Director\Objects;
class IcingaTimeperiod extends IcingaObject
{
protected $table = 'icinga_timeperiod';
protected $defaultProperties = array(
'id' => null,
'zone_id' => null,
'object_name' => null,
'display_name' => null,
'update_method' => null,
'object_type' => null,
);
}