private function buildform($parameters) { require FRAMEWORK . DS . 'conf' . DS . 'mycafetaria.php'; if (isset($parameters['__field__'])) { $changedfield = $parameters['__field__']; } $form = new form($parameters, 'mycafetaria', 'order'); $form->setPhasedrequest(new ajaxrequest('mycafetaria', 'updateorderform')); $form->setSubmittext('Bestel'); $currentuser = myauth::getCurrentuser(); $currentname = ''; $groups = $currentuser->getGroupid(); if (!isset($groups[$algemenegebruikers])) { $currentname = $currentuser->getName(); } if (!isset($groups[$externgroup])) { $pricefield = 'price'; } else { $pricefield = 'price2'; } $form->addField(new suggesttextField('mycafetaria', 'listusers', 'orderuser', 'Voor wie', $currentname, array('required'))); if ($currentname != '' || $form->getFieldvalue('orderuser') != '') { $form->setFocusfield('mealtype'); } $mealtypemodel = new mealtypeModel(); $mealModel = new mealModel(); $optionsetModel = new mealoptionsetModel(); $optionModel = new mealoptionModel(); $mealtypes = $mealtypemodel->get(); $typeSelect = new selectField('mealtype', 'Soort maaltijd', array('required')); $typeSelect->addOption(new selectoptionField('', '')); foreach ($mealtypes as $mealtype) { $typeSelect->addOption(new selectoptionField($mealtype->getName(), $mealtype->getId())); } $form->addField($typeSelect); if ($form->getFieldvalue('mealtype') != '') { $form->setFocusfield($changedfield); $this->order['mealtypeid'] = $form->getFieldvalue('mealtype'); $meals = $mealModel->getfromMealtypeid($form->getFieldvalue('mealtype'), array('fields' => array('place'), 'type' => 'ASC')); $mealselect = new selectField('meal', 'Maaltijd', array('required')); $mealselect->addOption(new selectoptionField('', '')); foreach ($meals as $meal) { $label = $meal->getName(); if ($meal->_get($pricefield) > 0) { $label .= ' (+ €' . $meal->_get($pricefield) . ')'; } $mealselect->addOption(new selectoptionField($label, $meal->getId())); } $form->addField($mealselect); } if ($changedfield == 'mealtype') { return $form; } if ($form->getFieldvalue('meal') != '') { $meal = $mealModel->getfromId($form->getFieldvalue('meal')); $this->order['mealid'] = $form->getFieldvalue('meal'); if (count($meal) > 0) { $object = $meal[0]; $this->price += $object->_get($pricefield); if (count($object->getOptionsetid()) > 0) { $optionsetconditions = array('id' => array('mode' => 'IN', 'value' => $object->getOptionsetid())); $optionsets = $optionsetModel->get($optionsetconditions, array('fields' => array('place'), 'type' => 'ASC')); $ready = true; foreach ($optionsets as $optionset) { $tmp = $this->resolveOptionset($form, $optionset); if (!$tmp) { $ready = false; } } if ($ready) { $form->setReady(true); } } else { $form->setReady(true); } $uurselect = new selectField('uur', 'Uur', array('required')); $uurselect->addOption(new selectoptionField('', '')); $today = strtotime('today'); $dayofweek = date('w', $today); if ($dayofweek == 0 || $dayofweek == 6) { $daytype = 2; } else { $times = array_flip($holidays); if (isset($times[$today])) { $daytype = 2; } else { $daytype = 1; } } $cond = array('AND' => array(array('id' => array('mode' => 'IN', 'value' => $object->getBlackoutid())), array('AND' => array('OR' => array(array('days' => array('mode' => '=', 'value' => 3)), array('days' => array('mode' => '=', 'value' => $daytype))))))); $blackoutmodel = new mealblackoutModel(); $blackouts = $blackoutmodel->get($cond); // Van 'nu + 30 mins afgerond tot 30 mins' tot 24u per halfuur $nu = time() - $today; if ($nu < 0) { $nu = 0; } for ($i = 0; $i < 60 * 60 * 24; $i += 60 * 30) { $valid = true; if ($i <= $nu + 60 * 30) { $valid = false; } foreach ($blackouts as $blackout) { if ($i >= $blackout->getBlackoutperiodstart() && $i <= $blackout->getBlackoutperiodend() && $nu > $blackout->getTriggertime()) { $valid = false; break; } } if ($valid) { $uur = $today + $i; $uurselect->addOption(new selectoptionField(date('H:i', $uur), $uur)); } } $form->addField($uurselect); if ($form->getFieldvalue('uur') == '') { $form->setReady(false); } else { $this->order['uur'] = $form->getFieldvalue('uur'); } } } if ($changedfield == 'meal') { return $form; } return $form; }