/** * 获取试卷信息 * @param int $paper_id * @return array */ private function _paper($paper_id) { if (!$paper_id) { return array(); } $paper = ExamPaperModel::get_paper($paper_id); if (empty($paper)) { return array(); } $exam = ExamModel::get_exam($paper['exam_id'], 'grade_id, class_id, subject_id, qtype_score, total_score'); if (empty($exam)) { return array(); } // 分数计算 $score = array(); // 题目数量 $question_num = explode(',', $paper['qtype_ques_num']); // 题型分数 $qtype_score = explode(',', $exam['qtype_score']); // 总分 排除题组 $total_score = 0; foreach ($qtype_score as $key => $value) { $score[$key + 1]['score'] = $value; $score[$key + 1]['num'] = isset($question_num[$key + 1]) ? $question_num[$key + 1] : 0; $score[$key + 1]['total_score'] = $score[$key + 1]['score'] * $score[$key + 1]['num']; $total_score += $score[$key + 1]['score'] * $score[$key + 1]['num']; } // 题组总分 $total_0 = $exam['total_score'] - $total_score; $data = array(); $data['exam'] = $exam; $data['score'] = $score; $data['total_0'] = $total_0; if ($exam['subject_id'] == 3) { $group = array(1 => array(), 4 => array(), 0 => array(), 5 => array(), 6 => array(), 7 => array(), 2 => array(), 3 => array(), 8 => array(), 9 => array()); } else { $group = array(1 => array(), 2 => array(), 3 => array(), 0 => array()); } /** 题组分值系数总和 */ $sql = "SELECT sum(score_factor) as sum FROM {pre}question q\n LEFT JOIN {pre}exam_question eq ON eq.ques_id=q.ques_id\n LEFT JOIN {pre}relate_class rc ON rc.ques_id=q.ques_id\n AND rc.grade_id = {$exam['grade_id']} AND rc.class_id = {$exam['class_id']}\n WHERE eq.paper_id = {$paper_id} and q.type=0"; $query = $this->db->query($sql); $sum_score_factor = $query->row_array(); $sql = "SELECT q.ques_id,q.type,q.title,q.picture,q.answer,q.score_factor,q.children_num,rc.difficulty\n FROM {pre}exam_question eq\n LEFT JOIN {pre}question q ON eq.ques_id=q.ques_id\n LEFT JOIN {pre}relate_class rc ON rc.ques_id = q.ques_id AND rc.grade_id = {$exam['grade_id']}\n AND rc.class_id = {$exam['class_id']}\n WHERE eq.paper_id = {$paper_id} ORDER BY rc.difficulty DESC,q.ques_id ASC"; $query = $this->db->query($sql); foreach ($query->result_array() as $row) { $row['title'] = $this->_format_question_content($row['title'], in_array($row['type'], array(3, 9))); switch ($row['type']) { case 0: $row['children'] = QuestionModel::get_children($row['ques_id']); foreach ($row['children'] as &$child) { $child['title'] = $this->_format_question_content($child['title'], in_array($child['type'], array(3, 9))); } // 分值系数 if ($sum_score_factor > 0) { $row['total_score'] = round($total_0 * $row['score_factor'] / $sum_score_factor['sum'], 2); $row['score'] = round($row['total_score'] / $row['children_num'], 2); } else { $row['total_score'] = 0; $row['score'] = 0; } break; case 1: case 2: case 7: $row['options'] = QuestionModel::get_options($row['ques_id']); break; case 3: case 9: $row['answer'] = explode("\n", $row['answer']); break; case 4: case 5: case 6: case 8: $row['children'] = QuestionModel::get_children($row['ques_id']); break; default: } $group[$row['type']][] = $row; } $paper_info = array(); $types = array_keys($group); foreach ($types as $type) { $paper_info[$type] = isset($group[$type]) ? $group[$type] : array(); } $data['group'] = array_filter($paper_info); return $data; }
public function setexamrelatequestion($erq_examid, $erq_zmoss_examid) { $erq_examid = intval($erq_examid); $erq_zmoss_examid = intval($erq_zmoss_examid); $paper_id = intval(Fn::getParam('er_paperid')); $exam = ExamModel::get_exam($erq_examid); if (!$exam['exam_pid']) { message('请指定需要设置试题对应的考试学科!'); } $examrelate = ZmossModel::examRelateInfo($erq_examid, $erq_zmoss_examid); if (!$examrelate) { message('此考试学科没有对应关系,无法设置试题关系!'); } $zmossquestion = ZmossModel::examQuestionList($examrelate['er_zmoss_examid']); if (!$zmossquestion) { message('此考试学科对应阅卷系统的考试没有试题,无法设置试题关系!'); } $paperlist = ExamPaperModel::examSubjectPaperList($erq_examid); if (!$paperlist) { message('此考试学科没有设置考试试卷,无法设置试题关系!'); } if ($paper_id) { $paper = $paperlist[$paper_id]; } if (!$paper) { $paper = current($paperlist); } /* $paperquestion = ExamPaperModel::examPaperQuestion( $paper['paper_id'], 'q.ques_id, q.parent_id, q.type, IFNULL(pq.type, q.type) AS p_type', 'AND q.is_parent = 0', 'ORDER BY p_type ASC, q.parent_id ASC, q.ques_id ASC'); */ $question = json_decode($paper['question_sort'], true); $paperquestion = array(); foreach ($question as $k => $ques_id) { $info = QuestionModel::get_question($ques_id); $list = QuestionModel::get_children($ques_id); if ($list) { foreach ($list as $key => $val) { $paperquestion[$val['ques_id']] = array('ques_id' => $val['ques_id'], 'type' => $info['type'], 'parent_id' => $ques_id); } } else { $paperquestion[$ques_id] = array('ques_id' => $ques_id, 'type' => $info['type']); } } $examrelatequestion = ZmossModel::examRelateQuestionInfo($erq_examid, $erq_zmoss_examid, $paper['paper_id']); $erq_relate_data = array(); if ($examrelatequestion) { $erq_relate_data = json_decode($examrelatequestion['erq_relate_data'], true); } $data['examrelatequestion'] = $erq_relate_data; $data['examrelate'] = $examrelate; $data['paperquestion'] = $paperquestion; $data['zmossquestion'] = $zmossquestion; $data['qtype'] = C('qtype'); $data['paperlist'] = $paperlist; $this->load->view('zmoss/setexamrelatequestion', $data); }
/** * 学生对应考试答题卡 * * @param int $uid * @param int $exam_id * @param int $exam_pid * @return multitype:Ambigous <> */ private function _sheet($uid, $exam_pid, $exam_id) { if ($this->exam_info[$exam_id]['subject_id'] == 3) { $group = array(1 => array(), 4 => array(), 0 => array(), 5 => array(), 6 => array(), 7 => array(), 2 => array(), 3 => array(), 8 => array(), 9 => array()); $types = array('1', '4', '0', '5', '6', '7', '2', '3', '8', '9'); } else { $group = array(3 => array(), 1 => array(), 2 => array(), 0 => array()); $types = array('1', '2', '3', '0'); } $grade_id = (int) $this->exam_list[$exam_id]['grade_id']; $class_id = (int) $this->exam_list[$exam_id]['class_id']; $paper_id = (int) $this->exam_info[$exam_id]['paper_id']; $sql = "SELECT q.ques_id,q.type,q.answer FROM {pre}exam_question eq\n LEFT JOIN {pre}question q ON eq.ques_id=q.ques_id\n LEFT JOIN {pre}relate_class rc ON rc.ques_id=q.ques_id\n AND rc.grade_id={$grade_id}\n AND rc.class_id={$class_id}\n WHERE eq.paper_id={$paper_id}\n ORDER BY rc.difficulty DESC,q.ques_id ASC"; $question = $this->db->query($sql)->result_array(); if (!$question) { $this->_notice('此学科未分配试卷'); } foreach ($question as $row) { switch ($row['type']) { case 0: case 4: case 5: case 6: case 8: $row['children'] = QuestionModel::get_children((int) $row['ques_id']); break; case 1: case 2: case 7: $row['options'] = QuestionModel::get_options($row['ques_id']); break; case 3: case 9: $row['answer'] = explode("\n", $row['answer']); break; default: break; } $group[$row['type']][] = $row; } $tmp_arr = array(); foreach ($types as $type) { if (!empty($group[$type])) { $tmp_arr[$type] = $group[$type]; } } return $tmp_arr; }
/** * @description 试卷预览分数修改 * @author * @final * @param int $id 试卷id */ public function preview($id = 0) { if (!$this->check_power('exam_list,exam_manage')) { return; } $id = intval($id); $paper = ExamPaperModel::get_paper($id); if (empty($paper)) { message('试卷不存在', 'javascript'); return; } $exam = ExamModel::get_exam($paper['exam_id'], 'grade_id,class_id,subject_id,qtype_score,total_score'); if (empty($exam)) { message('考试期次不存在'); return; } // 分数计算 $score = array(); // 题目数量 $question_num = explode(',', $paper['qtype_ques_num']); // 题型分数 $qtype_score = explode(',', $exam['qtype_score']); // 总分 排除题组 $total_score = 0; foreach ($qtype_score as $key => $value) { $score[$key + 1]['score'] = round($value, 2); $score[$key + 1]['num'] = isset($question_num[$key + 1]) ? $question_num[$key + 1] : 0; $score[$key + 1]['total_score'] = $score[$key + 1]['score'] * $score[$key + 1]['num']; $total_score += $score[$key + 1]['score'] * $score[$key + 1]['num']; } // 题组总分 $total_0 = $exam['total_score'] - $total_score; $data['score'] = $score; $data['total_0'] = $total_0; if ($exam['subject_id'] == 3) { $group = array(1 => array(), 0 => array(), 4 => array(), 5 => array(), 8 => array(), 3 => array(), 7 => array(), 6 => array(), 2 => array(), 9 => array(), 14 => array()); } else { $group = array(1 => array(), 2 => array(), 3 => array(), 0 => array(), 14 => array()); } $paper = ExamPaperModel::get_paper_by_id($id); $questions_arr = json_decode($paper['question_sort'], true); /** 题组分值系数总和 */ $sql = "SELECT sum(score_factor) as sum FROM {pre}question q\n LEFT JOIN {pre}exam_question eq ON eq.ques_id=q.ques_id\n LEFT JOIN {pre}relate_class rc ON rc.ques_id=q.ques_id AND rc.grade_id='{$exam['grade_id']}' AND rc.class_id='{$exam['class_id']}'\n WHERE eq.paper_id={$id} and q.type=0"; $query = $this->db->query($sql); $sum_score_factor = $query->row_array(); $sql = "SELECT q.ques_id,q.type,q.title,q.picture,q.answer,q.score_factor,q.children_num,rc.difficulty\n FROM {pre}exam_question eq\n LEFT JOIN {pre}question q ON eq.ques_id=q.ques_id\n LEFT JOIN {pre}relate_class rc ON rc.ques_id=q.ques_id AND rc.grade_id='{$exam['grade_id']}' AND rc.class_id='{$exam['class_id']}'\n WHERE eq.paper_id={$id} ORDER BY rc.difficulty DESC,q.ques_id ASC"; $query = $this->db->query($sql); $questions_tmp = $query->result_array(); /* 重新排序 */ $sort = array(); if (!is_array($questions_arr)) { $sort = $questions_tmp; } else { foreach ($questions_arr as $v) { foreach ($questions_tmp as $value) { if ($v == $value['ques_id']) { $sort[$v] = $value; } } } } foreach ($sort as $row) { $row['title'] = str_replace("\r\n", '<br/>', $row['title']); //$row['title'] = str_replace(" ", ' ', $row['title']); switch ($row['type']) { case 0: $row['children'] = QuestionModel::get_children($row['ques_id']); // 分值系数 if ($sum_score_factor > 0) { $row['total_score'] = round($total_0 * $row['score_factor'] / $sum_score_factor['sum'], 2); $row['score'] = round($row['total_score'] / $row['children_num'], 2); $row['children_score'] = round($row['total_score'] / $row['children_num'], 2); } else { $row['total_score'] = 0; $row['score'] = 0; } break; case 2: //$row['answer'] = explode(',', $row['answer']); //$row['answer'] = explode(',', $row['answer']); case 1: $row['options'] = QuestionModel::get_options($row['ques_id']); break; case 3: $row['answer'] = explode("\n", $row['answer']); break; case 4: $row['children'] = QuestionModel::get_children($row['ques_id']); $row['children_score'] = round($score[$row['type']]['score'] / $row['children_num'], 2); break; case 5: $row['children'] = QuestionModel::get_children($row['ques_id']); $row['children_score'] = round($score[$row['type']]['score'] / $row['children_num'], 2); break; case 6: $row['children'] = QuestionModel::get_children($row['ques_id']); $row['children_score'] = round($score[$row['type']]['score'] / $row['children_num'], 2); break; case 7: $row['options'] = QuestionModel::get_options($row['ques_id']); break; case 8: $row['children'] = QuestionModel::get_children($row['ques_id']); $row['children_score'] = round($score[$row['type']]['score'] / $row['children_num'], 2); break; case 9: $row['answer'] = explode("\n", $row['answer']); break; default: break; } $group[$row['type']][] = $row; } $tmp_arr = array(); if ($exam['subject_id'] == 3) { $types = array('12', '1', '0', '5', '4', '8', '3', '15', '11', '7', '6', '2', '9', '10', '13', '14'); } else { $types = array('1', '2', '3', '0', '10', '14', '15', '11'); } foreach ($types as $type) { $tmp_arr[$type] = isset($group[$type]) ? $group[$type] : array(); } $data['paper'] = $paper; $data['qtypes'] = C('qtype'); $data['qtypes'] = C('qtype'); $data['group'] = $tmp_arr; // 模版 $this->load->view('paper/preview', $data); }
/** * 预览试卷 * * @return void **/ public function preview_paper($paper_id) { $paper = PaperModel::get_paper_by_id($paper_id); if (empty($paper)) { message('未查询到当前试卷,请重试!'); } /* $admin_info = $this->session->all_userdata(); if ($paper['admin_id']!=$admin_info['admin_id']&&!$admin_info['is_super']) { message('你没有该试卷的权限!'); } */ $questions_arr = json_decode($paper['question_sort'], true); $questions_score = json_decode($paper['question_score'], true); if (empty($questions_arr)) { echo "当前试卷暂无试题!"; exit; } /* 查询试题信息 */ $sql = "SELECT ques_id,type,title,picture,answer FROM {pre}question \n WHERE ques_id in (" . implode(',', $questions_arr) . ")"; $questions_tmp = $this->db->query($sql)->result_array(); $sort = array(); /* 重新排序 */ foreach ($questions_arr as $v) { foreach ($questions_tmp as $value) { if ($v == $value['ques_id']) { $sort[] = $value; } } } $questions = array(); $tmp_index = 0; foreach ($sort as $key => $row) { if (in_array($row['type'], array(3, 9))) { $row['title'] = $this->_format_question_content($row['title'], 1); } $row['score'] = array_sum($questions_score[$row['ques_id']]); switch ($row['type']) { case 0: case 12: case 13: case 15: $row['children'] = QuestionModel::get_children($row['ques_id']); foreach ($row['children'] as &$child) { $child['title'] = $this->_format_question_content($child['title'], in_array($child['type'], array(3, 9))); } break; case 1: case 2: case 7: case 14: $row['options'] = QuestionModel::get_options($row['ques_id']); break; case 3: case 9: $row['answer'] = explode("\n", $row['answer']); break; case 4: case 5: case 6: case 8: case 10: $row['children'] = QuestionModel::get_children($row['ques_id']); break; default: } if ($key <= 0) { $questions[$tmp_index]['type'] = $row['type']; $questions[$tmp_index]['questions'][] = $row; $questions[$tmp_index]['scores'] += $row['score']; } else { if ($row['type'] == $sort[$key - 1]['type']) { $questions[$tmp_index]['questions'][] = $row; $questions[$tmp_index]['scores'] += $row['score']; } else { $tmp_index++; $questions[$tmp_index]['type'] = $row['type']; $questions[$tmp_index]['questions'][] = $row; $questions[$tmp_index]['scores'] += $row['score']; } } } $data = array(); $subject = C('subject'); $data['subject'] = $subject; $data['qtypes'] = C('qtype'); $data['questions'] = $questions; $data['question_score'] = $questions_score; $data['paper'] = $paper; $data['group_index'] = array('一', '二', '三', '四', '五', '六', '七', '八', '九', '十', '十一', '十二', '十三', '十四'); $this->load->view('paper_diy/preview', $data); }