/**
  * 更新试卷信息
  *
  * @param int $exam_id 考试期次id
  * @param int $paper_id 试卷id
  * @return void
  */
 public function update_question_info($exam_id, $paper_id)
 {
     if (!$this->check_power('exam_manage')) {
         exit;
     }
     $exam_id = (int) $exam_id;
     $exam_id && ($exam = ExamModel::get_exam($exam_id, 'exam_id,exam_pid,grade_id,class_id'));
     if (empty($exam)) {
         message('考试期次科目不存在', 'admin/exam/index');
         exit;
     }
     $is_mini_test = ExamModel::is_mini_test($exam['exam_pid']);
     //检查该学科考试状态
     $has_tested = false;
     if (!$is_mini_test) {
         $has_tested = ExamPlaceSubjectModel::exam_subject_has_test_action($exam_id);
     }
     if ($has_tested) {
         message('该期次科目已经被考生考过 或者 正在被考中,因此无法操作');
         exit;
     }
     /* 更新外部新试卷信息 */
     $paper_id = (int) $paper_id;
     /* 查询试卷信息 */
     $paper = PaperModel::get_paper_by_id($paper_id, 'exam_id,paper_id,admin_id,question_sort');
     if (empty($paper) or $exam_id != $paper['exam_id']) {
         message('试卷不在当前考试期次中!');
         exit;
     }
     /* 判定是否为外部试卷 */
     if ($paper['admin_id'] > 0) {
         $rst = PaperModel::update_paper_question($paper_id);
         if (!$rst) {
             message('更新试卷失败');
         } else {
             message('更新试卷成功', 'javascript');
         }
     } else {
         message('当前试卷不属于手工组卷,取消操作!');
     }
 }
Exemple #2
0
 /**
  * 添加试题
  *
  * @return void
  **/
 public function update_question()
 {
     $post = $this->input->post();
     $paper_id = (int) $post['paper_id'];
     /* exam_paper 试卷对应排序 */
     /* 限定用户只能更新跟自己相关的数据 */
     $admin_id = $this->session->userdata('admin_id');
     if (!$admin_id) {
         message('获取管理员数据失败,请从新登陆后重试!');
     }
     /* 获取试卷信息 */
     $paper = PaperModel::get_paper_by_id($paper_id);
     if (!$paper) {
         message('获取试卷数据失败,请重试!');
     }
     /* 用户可以编辑自己的试卷 管理员可以查看所有试卷 */
     if ($paper['admin_id'] != $admin_id && !$this->session->userdata('is_super')) {
         message('没有当前试卷编辑权限!');
     }
     if (!$this->is_super_user() && ExamPlaceSubjectModel::exam_subject_has_test_action($paper['exam_id'])) {
         message('当前试卷已进行考试,不可以修改更新!');
     }
     /* 计算排序 */
     $questions = $this->sort_question($post['ques_ids'], $post['sort']);
     $question_score = $this->sort_question($post['score'], $post['sort']);
     if (!$questions) {
         $questions = array();
     }
     /* 更新试卷信息 */
     $data = array();
     $data['question_sort'] = json_encode($questions);
     $data['question_score'] = json_encode($post['score']);
     $qtype_ques_num = array_fill(0, count(C('q_type')), '0');
     $this->db->trans_start();
     $this->db->delete('exam_question', array('paper_id' => $paper_id));
     $question_difficulty = array();
     if (count($questions) > 0) {
         foreach ($questions as $ques_id) {
             $sql = "select q.ques_id,q.type,AVG(rc.difficulty) as difficulty from\n                    {pre}question q left join {pre}relate_class rc on q.ques_id=rc.ques_id\n                    where q.ques_id={$ques_id}  group by q.ques_id";
             $question = $this->db->query($sql)->row_array();
             if (empty($question)) {
                 $this->db->trans_rollback();
                 message('当前试卷中存在不属于当前考试期次年级的试题!请检查试题!');
                 exit;
             }
             $data1 = array();
             $data1['paper_id'] = $paper_id;
             $data1['exam_id'] = $paper['exam_id'];
             $data1['ques_id'] = $ques_id;
             $this->db->insert('exam_question', $data1);
             /* 各个类型试题数量 */
             $qtype_ques_num[$question['type']]++;
             /* 试题难易度 */
             $question_difficulty[] = $question['difficulty'];
         }
     }
     /* 更新试题数量 */
     $data['ques_num'] = count($questions);
     $data['qtype_ques_num'] = implode(',', $qtype_ques_num);
     $data['difficulty'] = array_sum($question_difficulty) / count($question_difficulty);
     PaperModel::update_paper($paper_id, $data);
     $rst = $this->db->trans_commit();
     if (!$rst) {
         message('更新试卷信息失败!请重试!');
     } else {
         $sql = "SELECT exam_pid FROM rd_exam_subject_paper \n                    WHERE paper_id = {$paper_id}";
         $exam_pid = Fn::db()->fetchOne($sql);
         if ($exam_pid && ExamModel::is_mini_test($exam_pid)) {
             PaperModel::update_paper_question($paper_id);
         }
         message('更新试卷信息成功!', site_url('admin/paper_diy/question_manage/' . $paper_id));
     }
 }