protected function fillObject($data) { $object = parent::fillObject($data); $mealorderoptionsetModel = new mealorderoptionsetModel(); $mealorderoptionModel = new mealorderoptionModel(); $optionsets = $mealorderoptionsetModel->getfromMealorderid($object->getId()); $opties = ''; foreach ($optionsets as $optionset) { $opties .= '<strong>' . $optionset->getOptionset() . ': </strong> '; $options = $mealorderoptionModel->getfromMealorderoptionsetid($optionset->getId()); if ($optionset->getOptionsettype() == 3) { if ($options[0] instanceof mealorderoptionObject) { if ($options[0]->isSelected()) { $opties .= 'Ja'; } else { $opties .= 'Nee'; } } } else { foreach ($options as $option) { if ($option->isSelected()) { $opties .= $option->getOption() . ', '; } } $opties = substr($opties, 0, -2); } $opties .= '<br />'; } //$object->setOption($opties); $object->setMeal('<strong>' . $object->getMeal() . '</strong><br /><br />' . $opties); $object->setPrinted($object->getPrinted() ? 'Ja' : 'Nee'); return $object; }
public function order($parameters = array()) { $view = new ui($this); $view->assign('price', $this->price); $form = $this->buildform($parameters); $form->setNofocus(false); if ($form->validate() && !$parameters['abort'] == 'true') { if ($form->confirmed($this, 'Bestellen: Bent u zeker?')) { $saved = true; try { $theorder = array(); $optionsetModel = new mealoptionsetModel(); $optionModel = new mealoptionModel(); $optionsetoptionModel = new mealoptionsetoptionModel(); $mealtypemodel = new mealtypeModel(); $mealModel = new mealModel(); $mealtype = $mealtypemodel->getfromId($this->order['mealtypeid']); $theorder['mealtype'] = $mealtype[0]; $meal = $mealModel->getfromId($this->order['mealid']); $theorder['meal'] = $meal[0]; $theorder['uur'] = $this->order['uur']; foreach ($this->order['optionsets'] as $optionsetid => $selectedoptions) { $optset = $optionsetModel->getfromId($optionsetid); $optset = $optset[0]; $theorder['optionsets'][$optionsetid]['name'] = $optset->getName(); $theorder['optionsets'][$optionsetid]['type'] = $optset->getOptionsettypeid(); $theorder['optionsets'][$optionsetid]['place'] = $optset->getPlace(); if ($optset->getOptionsettypeid() == 1) { foreach ($optset->getOptionid() as $optionid) { $option = $optionModel->getfromId($optionid); $option = $option[0]; if ($optionid == $selectedoptions) { $theorder['optionsets'][$optionsetid]['options']['wel'][] = $option->getName(); } else { $theorder['optionsets'][$optionsetid]['options']['niet'][] = $option->getName(); } } } elseif ($optset->getOptionsettypeid() == 2) { foreach ($optset->getOptionid() as $optionid) { $option = $optionModel->getfromId($optionid); $option = $option[0]; if (in_array($optionid, $selectedoptions)) { $theorder['optionsets'][$optionsetid]['options']['wel'][] = $option->getName(); } else { $theorder['optionsets'][$optionsetid]['options']['niet'][] = $option->getName(); } } } else { foreach ($optset->getOptionid() as $optionid) { $option = $optionModel->getfromId($optionid); $option = $option[0]; if ($optionid == $selectedoptions) { $theorder['optionsets'][$optionsetid]['options']['wel'][] = $option->getName(); } else { $theorder['optionsets'][$optionsetid]['options']['niet'][] = $option->getName(); } } } } $theorder['price'] = $this->price; $view->assign('order', $theorder); $mealorderObject = new mealorderObject(); $mealorderModel = new mealorderModel(); $mealorderObject->setMealtype($theorder['mealtype']->getName()); $mealorderObject->setMeal($theorder['meal']->getName()); $mealorderObject->setUur($this->order['uur']); $mealorderObject->setPrice($this->price); $mealorderObject->setPrinted(0); $mealorderObject->setOrderuur(time()); $mealorderObject->setOrderuurtext(date("H:i - d/m/Y", $mealorderObject->getOrderuur())); $mealorderObject->setUurtext(date("H:i - d/m/Y", $mealorderObject->getUur())); $ordername = $form->getFieldvalue('orderuser'); $usermodel = new userModel(); require FRAMEWORK . DS . 'conf' . DS . 'mycafetaria.php'; $orderuser = $usermodel->searchnamesforgroup('*' . $ordername . '*', $ordergroupdn); if (count($orderuser) == 1) { $orderuser = $orderuser[0]; $orderuserid = $orderuser->getId(); } else { $orderuserid = -1; } $mealorderObject->setOrderuserid(myauth::getCurrentuser()->getId()); $mealorderObject->setOrderuser(myauth::getCurrentuser()->getName()); $mealorderObject->setUserid($orderuserid); $mealorderObject->setUser($ordername); $mealorderModel->save($mealorderObject); $mealorderoptionsetModel = new mealorderoptionsetModel(); $mealorderoptionModel = new mealorderoptionModel(); foreach ($theorder['optionsets'] as $optionsetid => $optionset) { $tmp = new mealorderoptionsetObject(); $tmp->setMealorderid($mealorderObject->getId()); $tmp->setOptionset($optionset['name']); $tmp->setOptionsettype($optionset['type']); $tmp->setPlace($optionset['place']); $mealorderoptionsetModel->save($tmp); foreach ($optionset['options']['wel'] as $option) { $tmpopt = new mealorderoptionObject(); $tmpopt->setMealorderoptionsetid($tmp->getId()); $tmpopt->setOption($option); $tmpopt->setSelected(1); $mealorderoptionModel->save($tmpopt); } if ($optionset['type'] != 1) { foreach ($optionset['options']['niet'] as $option) { $tmpopt = new mealorderoptionObject(); $tmpopt->setMealorderoptionsetid($tmp->getId()); $tmpopt->setOption($option); $tmpopt->setSelected(0); $mealorderoptionModel->save($tmpopt); } } } } catch (Exception $e) { $x = $e; $saved = false; } if ($saved) { $type = 'success'; } else { $type = 'error'; } $tmpl = new ui($this); $tmpl->assign('saved', $saved); $popupcontroller = new popupController(); $popupcontroller->createflash(array('name' => 'flash_ordered', 'type' => $type, 'content' => $tmpl->fetch('mycafetaria_orderedflash.tpl'))); $this->listmyorders(array('orderuser' => $ordername)); //$this->response->assign($this->self,'innerHTML',$view->fetch('mycafetaria_ordered.tpl')); } } elseif (!$form->isSent() || $parameters['abort'] == 'true') { $view->assign('form', $form); $this->response->assign($this->self, 'innerHTML', $view->fetch('mycafetaria_order.tpl')); } else { $this->response->assign('formerror_' . $form->getId(), 'innerHTML', 'Gelieve alle benodigde velden correct in te vullen.', true); } }