diff --git a/application/controllers/TimeperiodController.php b/application/controllers/TimeperiodController.php index 66489926..0d4d3221 100644 --- a/application/controllers/TimeperiodController.php +++ b/application/controllers/TimeperiodController.php @@ -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 + } } diff --git a/application/forms/IcingaTimePeriodRangeForm.php b/application/forms/IcingaTimePeriodRangeForm.php new file mode 100644 index 00000000..d63d5335 --- /dev/null +++ b/application/forms/IcingaTimePeriodRangeForm.php @@ -0,0 +1,41 @@ +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; + } +} diff --git a/application/tables/IcingaTimePeriodRangeTable.php b/application/tables/IcingaTimePeriodRangeTable.php new file mode 100644 index 00000000..7c65524d --- /dev/null +++ b/application/tables/IcingaTimePeriodRangeTable.php @@ -0,0 +1,64 @@ + '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; + } +}