timeperiod/ranges: add tables and form

This commit is contained in:
Thomas Gelf 2016-03-17 04:23:07 +01:00
parent 6ea94dd7a2
commit a7e1633b3f
3 changed files with 144 additions and 0 deletions

View File

@ -6,4 +6,43 @@ use Icinga\Module\Director\Web\Controller\ObjectController;
class TimeperiodController extends ObjectController
{
public function init()
{
parent::init();
if ($this->object && $this->object->hasBeenLoadedFromDb()) {
$this->getTabs()->add('ranges', array(
'url' => 'director/timeperiod/ranges',
'urlParams' => $this->object->getUrlParams(),
'label' => $this->translate('Ranges')
));
}
}
public function rangesAction()
{
$this->getTabs()->activate('ranges');
$this->view->form = $form = $this->loadForm('icingaTimePeriodRange');
$form
->setTimePeriod($this->object)
->setDb($this->db());
if ($name = $this->params->get('range')) {
$this->view->actionLinks = $this->view->qlink(
$this->translate('back'),
$this->getRequest()->getUrl()->without('range_id'),
null,
array('class' => 'icon-left-big')
);
$form->loadObject(array(
'timeperiod_id' => $this->object->id,
'timeperiod_key' => $name,
'range_type' => $this->params->get('range_type')
));
}
$form->handleRequest();
$this->view->table = $this->loadTable('icingaTimePeriodRange')
->setTimePeriod($this->object);
$this->view->title = $this->translate('Time period ranges');
$this->render('object/fields', null, true); // TODO: render table
}
}

View File

@ -0,0 +1,41 @@
<?php
namespace Icinga\Module\Director\Forms;
use Icinga\Module\Director\Objects\IcingaTimePeriod;
use Icinga\Module\Director\Web\Form\DirectorObjectForm;
class IcingaTimePeriodRangeForm extends DirectorObjectForm
{
/**
* @var IcingaTimePeriod
*/
private $period;
public function setup()
{
$this->addHidden('timeperiod_id', $this->period->id);
$this->addElement('text', 'timeperiod_key', array(
'label' => $this->translate('Day(s)'),
'description' => $this->translate(
'Might by, monday, tuesday, 2016-01-28 - have a look at the documentation for more examples'
),
));
$this->addElement('text', 'timeperiod_value', array(
'label' => $this->translate('Timerperiods'),
'description' => $this->translate(
'One or more time periods, e.g. 00:00-24:00 or 00:00-09:00,17:00-24:00'
),
));
$this->setButtons();
}
public function setTimePeriod(IcingaTimePeriod $period)
{
$this->period = $period;
return $this;
}
}

View File

@ -0,0 +1,64 @@
<?php
namespace Icinga\Module\Director\Tables;
use Icinga\Module\Director\Objects\IcingaTimePeriod;
use Icinga\Module\Director\Web\Table\QuickTable;
class IcingaTimePeriodRangeTable extends QuickTable
{
protected $period;
protected $searchColumns = array(
'timeperiod_key',
'timeperiod_value',
);
public function getColumns()
{
return array(
'timeperiod_id' => 'r.timeperiod_id',
'timeperiod_key' => 'r.timeperiod_key',
'timeperiod_value' => 'r.timeperiod_value',
);
}
public function setTimePeriod(IcingaTimePeriod $period)
{
$this->period = $period;
$this->setConnection($period->getConnection());
return $this;
}
protected function getActionUrl($row)
{
return $this->url(
'director/timeperiod/ranges',
array(
'name' => $this->period->object_name,
'range' => $row->timeperiod_key,
'range_type' => 'include'
)
);
}
public function getTitles()
{
$view = $this->view();
return array(
'timeperiod_key' => $view->translate('Day(s)'),
'timeperiod_value' => $view->translate('Timeperiods'),
);
}
public function getBaseQuery()
{
$db = $this->connection()->getConnection();
$query = $db->select()->from(
array('r' => 'icinga_timeperiod_range'),
array()
)->where('r.timeperiod_id = ?', $this->period->id);
return $query;
}
}