예제 #1
0
 /**
  * 题组子题保存
  */
 public function update_correct_question()
 {
     $act = $this->input->post('act');
     $act = $act == 'add' ? $act : 'edit';
     $parent_id = intval($this->input->post('parent_id'));
     $ques_id = intval($this->input->post('ques_id'));
     if ($act == 'edit') {
         $this->examine_permission($ques_id);
         $ques_id && ($old_question = QuestionModel::get_question($ques_id));
         if (empty($old_question) or $old_question['parent_id'] != $parent_id) {
             message('题组试题不存在', 'javascript');
             return;
         }
     }
     $parent_id && ($parent = QuestionModel::get_question($parent_id));
     if (empty($parent) or !$parent['is_parent']) {
         message('题组不存在', 'javascript');
         return;
     }
     //判断题组题干是否还有关联技能,知识点
     if ($parent['knowledge'] != '') {
         message('该题关联的题干还有未取消的技能或者知识点,请先取消再编辑该题', 'javascript');
         return;
     }
     $be_tested = QuestionModel::question_has_test_action($parent_id);
     if ($be_tested) {
         message('该试题已经被考生考过 或者 正在被考, 无法操作', 'javascript');
     }
     // 题目基本信息
     $question['type'] = intval($this->input->post('qtype'));
     $question['title'] = trim($this->input->post('title'));
     //检查知识点、认知过程
     $method_tactic_ids = $this->input->post('method_tactic_id');
     $knowledge_ids = $this->input->post('knowledge_id');
     $know_process = $this->input->post('know_process');
     $extends = array('skill_ids' => array(), 'knowledge_ids' => $knowledge_ids, 'group_id' => 0, 'relate_ques_id' => 0, 'relate_class' => array(), 'method_tactic_ids' => $method_tactic_ids, 'know_process' => $know_process);
     if (!empty($parent) && $parent['subject_id'] == 3) {
         $group_type_ids = $this->input->post('group_type_id');
         $extends['group_type_ids'] = $group_type_ids;
         $extends['subject_id'] = $parent['subject_id'];
     }
     $message = $this->_check_group_question($question, $extends);
     if ($message) {
         message(implode('<br>', $message), null, null, 10);
     }
     // 试题信息验证
     $message = array();
     if (empty($question['type'])) {
         $message[] = '请选择题型';
     }
     $answer = trim($this->input->post('input_answer'));
     if (empty($answer)) {
         $message[] = '请填写填空题答案';
     } else {
         $question['answer'] = $answer;
     }
     if ($act == 'add') {
         $question['parent_id'] = $parent_id;
         $question['admin_id'] = $this->session->userdata('admin_id');
         $ques_result = QuestionModel::add($question, $opt_result['options'], $opt_result['answer'], $extends);
     } else {
         $question['ques_id'] = $ques_id;
         $extends['old_opt_ids'] = $this->input->post('old_opt_id');
         $ques_result = QuestionModel::update($question, $opt_result['options'], $opt_result['answer'], $extends);
     }
     $url = site_url('/admin/question_external/edit_correct_question/' . $ques_result['ques_id']);
     if ($message) {
         message(implode('<br>', $message), $url, null, 10);
         return;
     }
     if ($opt_result['msg']) {
         message(implode('<br>', $opt_result['msg']), $url, null, 10);
         return;
     }
     if ($ques_result['success'] == TRUE) {
         message('试题编辑成功', 'admin/question_external/correct/' . $parent_id);
     } else {
         message($ques_result['msg']);
     }
 }