예제 #1
0
 /**
  * Saving form state into database
  *
  * @param formID
  * @param value
  * @return json information for the front-end
  */
 function savestateJsonAction()
 {
     $formID = $this->_getParam('formID');
     $state = $this->_getParam('state');
     $columns = $this->_getParam('columns');
     $column1width = $this->_getParam('column1width');
     $column2width = $this->_getParam('column2width');
     $column3width = $this->_getParam('column3width');
     $unitTypeID = $this->_getParam('unitTypeID', RM_UnitTypes::DEFAULT_TYPE);
     $model = new RM_Forms();
     $form = $model->find($formID)->current();
     $unitTypesModel = new RM_UnitTypes();
     $unitType = $unitTypesModel->find($unitTypeID)->current();
     if ($unitType == null) {
         $unitTypeID = RM_UnitTypes::DEFAULT_TYPE;
         $unitType = $unitTypesModel->find($unitTypeID)->current();
     }
     $unitTypeFormsModel = new RM_UnitTypeForms();
     if ($unitTypeFormsModel->check($form, $unitType)) {
         $unitTypeForm = $unitTypeFormsModel->fetchBy($form, $unitType);
     } else {
         //We need to create a new row for this unit type
         $unitTypeForm = $unitTypeFormsModel->createRow();
         $unitTypeForm->form_id = $form->id;
         $unitTypeForm->unit_type_id = $unitTypeID;
     }
     $unitTypeForm->columns = $columns;
     $unitTypeForm->column1width = $column1width;
     $unitTypeForm->column2width = $column2width;
     $unitTypeForm->column3width = $column3width;
     $unitTypeForm->state = $state;
     $result = $unitTypeForm->save();
     $resultJson = false;
     if ($result) {
         $resultJson = true;
     }
     return array('data' => array('success' => $resultJson));
 }