protected function fillObject($data)
 {
     $object = parent::fillObject($data);
     $model = new mealoptionsettypeModel();
     $type = $model->getfromId($object->getOptionsettypeid());
     if (count($type) == 1) {
         $type = $type[0];
         $object->setOptionsettypeid($type->getName());
     }
     return $object;
 }
 public function editoptionset($parameters = array())
 {
     $view = new ui($this);
     $model = new mealoptionsetModel();
     $new = true;
     if (isset($parameters['id'])) {
         $optionset = $model->getfromId($parameters['id']);
         if (count($optionset) == 1) {
             $optionset = $optionset[0];
             $new = false;
         } else {
             $optionset = new mealoptionsetObject();
         }
     } else {
         $optionset = new mealoptionsetObject();
     }
     $form = new mygridform($parameters, $parameters['-gridid-'], 'edit');
     $form->addField(new textField('name', 'Naam', $optionset->getName(), array('required')));
     $type = new selectField('type', 'Type', array('required'));
     $type->addOption(new selectoptionField('', '', $new));
     $typemodel = new mealoptionsettypeModel();
     $types = $typemodel->get();
     foreach ($types as $typeobj) {
         $select = false;
         if (!$new) {
             if ($optionset->getOptionsettypeid() == $typeobj->getId()) {
                 $select = true;
             }
         }
         $type->addOption(new selectoptionField($typeobj->getName(), $typeobj->getId(), $select));
     }
     $form->addField($type);
     if (!$new) {
         $form->addField(new hiddenField('id', $parameters['id']));
     }
     if ($form->validate()) {
         $optionset->setName($form->getFieldvalue('name'));
         $optionset->setOptionsettypeid($form->getFieldvalue('type'));
         $model->save($optionset);
         if ($new) {
             $parameters['id'] = $optionset->getId();
             unset($parameters['hidden_form_id']);
             $parameters['title'] = 'Optiegroep wijzigen';
             $gridcontroller = new mygridController();
             $gridcontroller->editrequest($parameters);
             return true;
         } else {
             $this->response->assign('formerror_' . $form->getId(), 'innerHTML', 'De gegevens zijn aangepast', true);
             return true;
         }
         return true;
     } elseif (!$form->isSent()) {
         $view->assign('form', $form);
         return $view->fetch('mycafetaria_editoptionset.tpl');
     } else {
         return false;
     }
 }