예제 #1
0
 public function delete()
 {
     if (!empty($this->data['id'])) {
         $id = $this->data['id'];
         $field_model = new wformsFieldModel();
         $field_values_model = new wformsFieldValuesModel();
         $field_model->deleteByField('form_id', $id);
         $field_values_model->deleteByField('form_id', $id);
         $this->model->deleteById($id);
     }
 }
 public function execute()
 {
     $model = new wformsFieldModel();
     $id = waRequest::post('field_id', 0, waRequest::TYPE_INT);
     $after_id = waRequest::post('after_id', 0, waRequest::TYPE_INT);
     try {
         $model->move($id, $after_id);
     } catch (waException $e) {
         $this->setError($e->getMessage());
     }
 }
 public function execute()
 {
     try {
         $model = new wformsFieldModel();
         $field_values_model = new wformsFieldValuesModel();
         $id = waRequest::post('id');
         $model->deleteById($id);
         $field_values_model->deleteByField('field_id', $id);
     } catch (Exception $ex) {
         $this->setError($ex->getMessage());
     }
 }
 public function execute()
 {
     try {
         $model = new wformsFieldModel();
         $field_values_model = new wformsFieldValuesModel();
         $id = waRequest::post('id');
         $field = $model->getById($id);
         $field['values'] = $field_values_model->getByField('field_id', $id, true);
         $field['field_types'] = $this->getConfig()->getFieldTypes();
         $this->response['field'] = $field;
     } catch (Exception $ex) {
         $this->setError($ex->getMessage());
     }
 }
예제 #5
0
 public function execute()
 {
     $id = waRequest::get('id');
     $form_model = new wformsFormModel();
     $field_model = new wformsFieldModel();
     $field_values_model = new wformsFieldValuesModel();
     $form = $form_model->getById($id);
     if (!$form) {
         throw new waException('Форма #' . $id . ' не найдена');
     }
     $fields = $field_model->getFormFields($id);
     foreach ($fields as &$field) {
         $field['values'] = $field_values_model->getByField('field_id', $field['id'], true);
     }
     unset($field);
     $field_types = $this->getConfig()->getFieldTypes();
     $this->view->assign('form', $form);
     $this->view->assign('fields', $fields);
     $this->view->assign('field_types', $field_types);
 }
 public function execute()
 {
     try {
         $model = new wformsFieldModel();
         $model_values = new wformsFieldValuesModel();
         $data = waRequest::post('field');
         if (empty($data['form_id'])) {
             throw new waException('Форма не определена');
         }
         if (empty($data['id'])) {
             $id = $model->insert($data);
             $data['id'] = $id;
         } else {
             $model->updateById($data['id'], $data);
         }
         if (!empty($data['values'])) {
             $ids = $data['values']['id'];
             $names = $data['values']['name'];
             $values = $data['values']['value'];
             $_values = array();
             $model_values->deleteNotExists($data['id'], $ids);
             foreach ($names as $index => $value_name) {
                 $value = array('id' => $ids[$index], 'field_id' => $data['id'], 'form_id' => $data['form_id'], 'name' => $value_name, 'value' => $values[$index], 'sort' => (int) $index);
                 if (empty($value['id'])) {
                     $id = $model_values->insert($value);
                     $value['id'] = $id;
                 } else {
                     $model_values->updateById($value['id'], $value);
                 }
                 $_values[] = $value;
             }
             $data['values'] = $_values;
         }
         $this->response['field'] = $this->prepare($data);
     } catch (Exception $ex) {
         $this->setError($ex->getMessage());
     }
 }
예제 #7
0
 public function getFormData($form_id)
 {
     $form_model = new wformsFormModel();
     $field_model = new wformsFieldModel();
     $field_values_model = new wformsFieldValuesModel();
     $form = $form_model->getById($form_id);
     if (!$form) {
         throw new waException('Форма #' . $form_id . ' не найдена');
     }
     $fields = $field_model->getFormFields($form_id);
     foreach ($fields as &$field) {
         $field['values'] = $field_values_model->getByField('field_id', $field['id'], true);
     }
     unset($field);
     $form['fields'] = $fields;
     return $form;
 }