public function edittime($parameters = array()) { $view = new ui($this); $model = new mealblackoutModel(); $new = true; if (isset($parameters['id'])) { $blackout = $model->getfromId($parameters['id']); if (count($blackout) == 1) { $blackout = $blackout[0]; $new = false; } else { $blackout = new mealblackoutObject(); } } else { $blackout = new mealblackoutObject(); } $form = new mygridform($parameters, $parameters['-gridid-'], 'edit'); $today = strtotime('today'); $start = new selectField('blackoutperiodstart', 'Starttijd', array('required')); $start->addOption(new selectoptionField('', '', !$new)); for ($i = 0; $i < 60 * 60 * 24; $i += 60 * 30) { $uur = $today + $i; $select = false; if (!$new) { if ($i == $blackout->getBlackoutperiodstart()) { $select = true; } } $start->addOption(new selectoptionField(date('H:i', $uur), $i, $select)); } $form->addField($start); $end = new selectField('blackoutperiodend', 'Eindtijd', array('required')); $end->addOption(new selectoptionField('', '', !$new)); for ($i = 0; $i <= 60 * 60 * 24; $i += 60 * 30) { $uur = $today + $i; $select = false; if (!$new) { if ($i == $blackout->getBlackoutperiodend()) { $select = true; } } $end->addOption(new selectoptionField(date('H:i', $uur), $i, $select)); } $form->addField($end); $trigger = new selectField('triggertime', 'Trigger tijd', array('required')); $trigger->addOption(new selectoptionField('', '', $new)); $altijd = false; if ($blackout->getTriggertime() == -1) { $altijd = true; } $trigger->addOption(new selectoptionField('Altijd', -1, $altijd)); for ($i = 0; $i <= 60 * 60 * 24; $i += 60 * 30) { $uur = $today + $i; $select = false; if (!$new) { if ($i == $blackout->getTriggertime()) { $select = true; } } $trigger->addOption(new selectoptionField(date('H:i', $uur), $i, $select)); } $form->addField($trigger); $days = new selectField('days', 'Dagen', array('required')); switch ($blackout->getDays()) { case 1: $one = true; $two = false; $three = false; break; case 2: $one = false; $two = true; $three = false; break; case 3: $one = false; $two = false; $three = true; break; default: $one = false; $two = false; $three = false; } $days->addOption(new selectoptionField('', '', $new)); $days->addOption(new selectoptionField('Weekdagen', 1, $one)); $days->addOption(new selectoptionField('Weekend', 2, $two)); $days->addOption(new selectoptionField('Alle dagen', 3, $three)); $form->addField($days); if (!$new) { $form->addField(new hiddenField('id', $parameters['id'])); } if ($form->validate()) { $blackout->setBlackoutperiodstart($form->getFieldvalue('blackoutperiodstart')); $blackout->setBlackoutperiodend($form->getFieldvalue('blackoutperiodend')); $blackout->setTriggertime($form->getFieldvalue('triggertime')); $blackout->setDays($form->getFieldvalue('days')); $model->save($blackout); return true; } elseif (!$form->isSent()) { $view->assign('form', $form); return $view->fetch('mycafetaria_edittime.tpl'); } else { return false; } }