/** * 试卷列表 */ function listAction() { $pagesize = 15; $courseId = (int) $this->get('course_id', 0); $paperId = (int) $this->get('paper_id', 0); $type = (int) $this->get('type', 0); $courseModel = new CourseModel(); $course = $courseModel->getCourse($courseId); if (!$course) { $this->redirect("/error/?errno=" . Common_Error::ERROR_COURSE_NOT_EXISTS); } $schoolModel = new SchoolModel(); $school = $schoolModel->getSchool($course['school_id']); if (!$school) { $this->redirect("/error/?errno=" . Common_Error::ERROR_SCHOOL_NOT_EXISTS); } $paperModel = new PaperModel(); //$list = $paperModel -> getList($courseId, $paperId, $type, $pagesize); $list = $paperModel->getAll($courseId); if (!$list) { $this->redirect("/error/?errno=" . Common_Error::ERROR_COURSE_NOT_EXISTS); } $courseModel = new CourseModel(); $practiseList = $courseModel->getCoursePractiseList($courseId); $uSecList = $courseModel->getUserCourseSection($this->uid, $courseId); $uSectionIds = $uSecList ? array_keys($uSecList) : array(); foreach ($list as $k => $section) { $list[$k] = array('id' => $section['id'], "name" => $section['name']); $list[$k]['last'] = isset($uSectionIds[0]) && $section['id'] == $uSectionIds[0] ? 1 : 0; $list[$k]['practise_video_list'] = isset($practiseList[$section['id']]) ? $practiseList[$section['id']] : array(); if (empty($list[$k]['practise_video_list'])) { $list[$k]['practise_video_list_for_android'] = array(); continue; } foreach ($list[$k]['practise_video_list'] as $seq => $videoId) { $list[$k]['practise_video_list_for_android'][] = array("practise_seq" => $seq, "practise_video_id" => $videoId); } } if ($this->isMobile) { $this->displayJson(Common_Error::ERROR_SUCCESS, $list); } $course['practise_num'] = $courseModel->getCoursePractiseNum($courseId); $course['user_practise_num'] = $courseModel->getUserCoursePractiseNum($this->uid, $courseId); $course['duration_minute'] = round($paperModel->getPaperDuration($courseId) / 60, 0); $course['user_spend_minute'] = round($paperModel->getUserPaperDuration($this->uid, $courseId) / 60, 0); $course['teachers'] = $courseModel->getCourseTeachers($courseId); $this->assign("school", $school); $this->assign("course", $course); $this->assign('paper_list', $list); }
/** * 学生答题详情 * * @author TCG * @param int $uid 用户ID * @param int $etp_id 考场-试卷-学生关联表 * @return void */ public function detail($uid = 0, $etp_id = 0) { $sql = "select subject_id,exam_id from {pre}exam_test_paper where etp_id='{$uid}' "; $res = $this->db->query($sql)->row_array(); $subject_id = $res['subject_id']; $exam_id = $res['exam_id']; $exam = $this->db->select('exam_id, subject_id, grade_id, class_id, total_score, qtype_score')->get_where('exam', array('exam_id' => $exam_id), 1)->row_array(); $sql = "SELECT q.type,etr.ques_id,etr.answer,etr.ques_subindex,etr.full_score,etr.test_score,etr.sub_ques_id \n from {pre}exam_test_result etr\n LEFT JOIN {pre}relate_class rc ON rc.ques_id=etr.ques_id AND rc.grade_id='{$exam['grade_id']}' AND rc.class_id='{$exam['class_id']}'\n LEFT JOIn {pre}question q ON etr.ques_id = q.ques_id \n where etp_id = ? and uid = ? order by rc.difficulty DESC,etr.ques_id ASC, q.sort ASC, etr.sub_ques_id"; $query = $this->db->query($sql, array($uid, $etp_id)); $sql = "SELECT paper_id FROM {pre}exam_test_paper WHERE etp_id='{$uid}' "; $res = $this->db->query($sql)->row_array(); $paper_id = $res['paper_id']; $paper = PaperModel::get_paper_by_id($paper_id); $questions_arr = json_decode($paper['question_sort'], true); $questions_score = json_decode($paper['question_score'], true); if ($query->num_rows() > 0) { $sort = array(); /* 重新排序 */ if (is_array($questions_arr)) { foreach ($questions_arr as $v) { foreach ($query->result_array() as $value) { if ($v == $value['ques_id']) { $sort[] = $value; } } } } else { $sort = $query->result_array(); } $result = array(); $result1 = array(); foreach ($sort as $key => $row) { if ($row['sub_ques_id'] > 0) { $result[$row['ques_id']][$row['sub_ques_id']]['answer'] = $row['answer']; $result[$row['ques_id']][$row['sub_ques_id']]['full_score'] = $row['full_score']; $result[$row['ques_id']][$row['sub_ques_id']]['test_score'] = $row['test_score']; } else { $result[$row['ques_id']]['answer'] = $row['answer']; $result[$row['ques_id']]['full_score'] = $row['full_score']; $result[$row['ques_id']]['test_score'] = $row['test_score']; } } // 试题类型 foreach ($result as $ques_id => $value) { $question['type'] = QuestionModel::get_question($ques_id, 'type'); $result[$ques_id]['type'] = $question['type']; if (in_array($question['type'], array(1, 2, 3, 7, 9, 11, 10, 14))) { if (in_array($question['type'], array(1, 2, 7, 14))) { $answer = explode(',', $value['answer']); $tmp_answer = array(); foreach ($answer as $k => $v) { if (!$v) { continue; } $option = QuestionModel::get_option($v); if ($option) { $tmp_answer[$k] = '<span>' . $option['option_name'] . '</span>'; if ($option['picture']) { $tmp_answer[$k] .= '<br/><img src="' . __IMG_ROOT_URL__ . $option['picture'] . '" />'; } } } $result[$ques_id]['answer'] = $tmp_answer; } else { if (in_array($question['type'], array(3, 9))) { $result[$ques_id]['answer'] = explode("\n", $value['answer']); } } } else { foreach ($value as $sub_ques_id => $item) { $sub_question['type'] = QuestionModel::get_question($sub_ques_id, 'type'); if (in_array($sub_question['type'], array(1, 2))) { $answer = explode(',', $item['answer']); $tmp_answer = array(); foreach ($answer as $k => $v) { if (!$v) { continue; } $option = QuestionModel::get_option($v); if ($option) { $tmp_answer[$k] = '<span>' . $option['option_name'] . '</span>'; if ($option['picture']) { $tmp_answer[$k] .= '<br/><img src="' . __IMG_ROOT_URL__ . $option['picture'] . '" />'; } } } $result[$ques_id][$sub_ques_id]['answer'] = $tmp_answer; } else { if ($sub_question['type'] == 3) { $result[$ques_id][$sub_ques_id]['answer'] = explode("\n", $item['answer']); } } } } $groups[$question['type']]['list'][$ques_id] = $result[$ques_id]; } $data['result'] = $groups; } else { die('暂无考生考试信息!'); } $data['group_index'] = array('一', '二', '三', '四', '五', '六', '七', '八', '九', '十', '十一', '十二', '十三', '十四'); $this->load->view('exam_student_result/detail', $data); }
/** * 目标匹配度 XX% * note: * xx%=班级的学科总得分/期望得分(班级考的试卷每题期望得分累加) * * @param Number $rule_id 评估规则id * @param number $exam_id 考试学科 * @param number $schcls_id 班级id */ public function module_match_percent($rule_id = 0, $exam_id = 0, $schcls_id = 0) { $rule_id = intval($rule_id); $exam_id = intval($exam_id); $schcls_id = intval($schcls_id); if (!$rule_id || !$exam_id || !$schcls_id) { return array(); } $match_percent = array(); $class = $this->class_common_model->get_class_info($schcls_id); $total_score = ExamModel::get_exam_by_id($exam_id, 'total_score'); $paper_id = $this->class_common_model->get_class_exam_paper($schcls_id, $exam_id); if (!$paper_id) { return array(); } if (!isset(self::$_data['paper_question_score'][$exam_id][$paper_id])) { $paper = PaperModel::get_paper_by_id($paper_id); $score = json_decode($paper['question_score'], true); self::$_data['paper_question_score'][$exam_id][$paper_id] = $score; } else { $score = self::$_data['paper_question_score'][$exam_id][$paper_id]; } // 获取该班级所考到的试卷题目 $sql = "SELECT etpq.ques_id\n \t FROM rd_exam_test_paper_question etpq\n \t LEFT JOIN rd_exam_test_paper etp ON etpq.etp_id=etp.etp_id\n \t WHERE etp.exam_id={$exam_id} AND etp.paper_id={$paper_id} AND etp.etp_flag=2\n \t "; $ques_id = trim(self::$_db->fetchOne($sql)); if (!$ques_id) { return array(); } $ques_ids = @explode(',', $ques_id); if (!is_array($ques_ids) || !$ques_ids) { return array(); } // 获取这些题目的难易度 $sql = "SELECT rc.ques_id,rc.difficulty\n \t FROM rd_relate_class rc\n \t LEFT JOIN rd_exam e ON rc.grade_id=e.grade_id AND rc.class_id=e.class_id\n \t AND rc.subject_type=e.subject_type\n \t WHERE e.exam_id={$exam_id} AND rc.ques_id IN({$ques_id})\n \t "; $ques_difficulties = self::$_db->fetchPairs($sql); //本次考试班级试题得分情况 $sql = "SELECT ques_id, ROUND(total_score / student_amount) AS full_score, avg_score\n \t FROM rd_summary_region_question\n \t WHERE exam_id = {$exam_id} AND region_id = {$schcls_id}\n \t AND is_school = 0 AND is_class = 1 AND ques_id IN ({$ques_id})"; $class_score = self::$_db->fetchAssoc($sql); //本次考试年级试题得分情况 $sql = "SELECT ques_id, ROUND(total_score / student_amount) AS full_score, avg_score\n \t FROM rd_summary_region_question\n \t WHERE exam_id = {$exam_id} AND region_id = {$class['school_id']}\n \t AND is_school = 1 AND is_class = 0 AND ques_id IN ({$ques_id})"; $grade_score = self::$_db->fetchAssoc($sql); $data = array(array('难易度', '低', '中', '高', '合计'), array('本班平均分', -1, -1, -1, 0), array('年级平均分', -1, -1, -1, 0), array('期望得分', -1, -1, -1, 0), array('总分', -1, -1, -1, 0)); $level = array('低' => 1, '中' => 2, '高' => 3); foreach ($ques_ids as $ques_id) { if (!isset($ques_difficulties[$ques_id])) { continue; } $q_diffculty = $ques_difficulties[$ques_id]; $cls_full_score = 0; $cls_test_score = 0; $grd_test_score = 0; if (isset($class_score[$ques_id])) { $cls_full_score = isset($score[$ques_id]) ? array_sum($score[$ques_id]) : $class_score[$ques_id]['full_score']; $cls_test_score = $class_score[$ques_id]['avg_score']; } if (isset($grade_score[$ques_id])) { $grd_test_score = $grade_score[$ques_id]['avg_score']; } $d_level = $this->class_common_model->convert_question_difficulty($q_diffculty); $expect_score = $cls_full_score * $q_diffculty / 100; $k = $level[$d_level]; if ($data[1][$k] == -1) { $data[1][$k] = 0; } $data[1][$k] += $cls_test_score; $data[1][4] += $cls_test_score; if ($data[2][$k] == -1) { $data[2][$k] = 0; } $data[2][$k] += $grd_test_score; $data[2][4] += $grd_test_score; if ($data[3][$k] == -1) { $data[3][$k] = 0; } $data[3][$k] += $expect_score; $data[3][4] += $expect_score; if ($data[4][$k] == -1) { $data[4][$k] = 0; } $data[4][$k] += $cls_full_score; } $data[4][4] = $total_score; return array('data' => $data, 'percent' => round(end($data[1]) / end($data[3]) * 100)); }
/** * 批量删除试卷中的试题 * * @param int $paper_id 试卷id * @param int $ids 试卷中的试题id * @return void */ public function batch_delete() { if (!$this->check_power('exam_manage')) { return; } $paper_id = (int) $this->input->post('paper_id'); $ids = $this->input->post('ids'); if (empty($ids) or !is_array($ids)) { message('请选择要操作的项目!'); return; } $paper = PaperModel::get_paper_by_id($paper_id); if (!$paper) { message('试卷不存在'); return; } $exam_pid = ExamModel::get_exam($paper['exam_id'], 'exam_pid'); $is_mini_test = ExamModel::is_mini_test($exam_pid); //判断该试卷已经被考试过 或 正在被考 $count_fail = 0; $count_success = 0; $tmp_ids = array(); foreach ($ids as $ques_id) { if (!$is_mini_test) { $be_tested = QuestionModel::paper_question_has_been_tested($paper_id, $ques_id); if ($be_tested) { $count_fail++; continue; } } $tmp_ids[] = $ques_id; $count_success++; } $back_url = isset($_SERVER['HTTP_REFERER']) ? $_SERVER['HTTP_REFERER'] : 'admin/exam_question/index/' . $paper_id; $this->db->where_in('id', $tmp_ids)->delete('exam_question'); ExamPaperModel::renew($paper_id); if ($is_mini_test && $count_success) { SummaryModel::summary_paper($exam_pid, 0, $paper_id, true); } message("批量操作完成(成功 {$count_success}个,失败 {$count_fail} 个)", $back_url); }
/** * 更新试卷试题 * @param array $paper_id 试卷ID * @return boolen 成功返回true, 失败返回false */ public static function update_paper_question($paper_id) { /* 更新外部新试卷信息 */ $paper_id = (int) $paper_id; if (!$paper_id) { return false; } /* 查询试卷信息 */ $paper = self::get_paper_by_id($paper_id, 'exam_id,paper_id,admin_id,question_sort'); if (!$paper) { return false; } $exam = ExamModel::get_exam($paper['exam_id'], 'exam_id,exam_pid,grade_id,class_id'); if (!$exam) { return false; } $db = Fn::db(); /* 判定是否为外部试卷 */ if ($paper['admin_id'] > 0) { $questions = json_decode($paper['question_sort'], true); $question_difficulty = array(); $qtype_ques_num = array_fill(0, count(C('qtype')), '0'); if (!$db->beginTransaction()) { return false; } /* 清除exam_question原有信息 */ $db->delete('rd_exam_question', 'exam_id =? AND paper_id = ?', array($paper['exam_id'], $paper_id)); if (count($questions) > 0) { foreach ($questions as $ques_id) { $sql = "SELECT q.ques_id,q.type,rc.difficulty FROM\n rd_question q \n LEFT JOIN rd_relate_class rc ON q.ques_id=rc.ques_id\n WHERE q.ques_id={$ques_id} AND rc.grade_id={$exam['grade_id']} \n AND rc.class_id={$exam['class_id']}"; $question = $db->fetchRow($sql); if (empty($question)) { $db->rollBack(); throw new Exception('当前试卷中存在不属于当前考试期次年级的试题!请检查试题!'); } /* 补全exam_question信息 */ $data = array(); $data['paper_id'] = $paper_id; $data['exam_id'] = $paper['exam_id']; $data['ques_id'] = $ques_id; $db->insert('rd_exam_question', $data); /* 试题难易度 */ $question_difficulty[] = $question['difficulty']; /* 各个类型试题数量 */ $qtype_ques_num[$question['type']]++; } } /* 补全exam_pager信息 */ $data = array(); $data['exam_id'] = $paper['exam_id']; $data['difficulty'] = array_sum($question_difficulty) / count($question_difficulty); $data['qtype_ques_num'] = implode(',', $qtype_ques_num); PaperModel::update_paper($paper_id, $data); $flag = $db->commit(); if (!$flag) { $db->rollBack(); } //如果是mini测试卷,则更新试卷统计 if (ExamModel::is_mini_test($exam['exam_pid'])) { $sql = "SELECT exam_pid FROM rd_exam_subject_paper \n WHERE paper_id = {$paper_id} AND exam_id = " . $exam['exam_id']; if (Fn::db()->fetchOne($sql)) { SummaryModel::summary_paper($exam['exam_pid'], 0, $paper_id, true); } } return $flag; } }
/** * @description 删除期次科目试卷 * @author * @final * @param int $exam_id 考试期次id * @param array $ids 试卷id */ public function batch_delete() { if (!$this->check_power('exam_manage')) { return; } $ids = $this->input->post('ids'); $exam_id = (int) $this->input->post('exam_id'); if (empty($ids) or !is_array($ids)) { message('请至少选择一项'); return; } //检查该学科考试状态 $has_tested = ExamPlaceSubjectModel::exam_subject_has_test_action($exam_id); if ($has_tested) { message('该期次科目已经被考生考过 或者 正在被考中,因此无法操作'); } $back_url = empty($_SERVER['HTTP_REFERER']) ? '' : $_SERVER['HTTP_REFERER']; if (empty($back_url) && $exam_id) { $back_url = 'admin/subject_paper/' . $exam_id; } $id_string = implode(',', array_filter(array_values($ids))); $sql0 = " select group_concat( distinct paper_id) as paper_ids from {pre}exam_subject_paper where id in({$id_string})"; try { $this->db->trans_start(); $paper_ids = $this->db->query($sql0)->row_array(); $paper_ids = $paper_ids['paper_ids']; //查询学生已分配的试卷 $sql = "select group_concat(uid) as uids,place_id from {pre}exam_test_paper where paper_id in( {$paper_ids} ) group by place_id"; $res = $this->db->query($sql)->result_array(); //插入计划任务 foreach ($res as $row) { $insert_data = array('place_id' => $row['place_id'], 'uid_data' => json_encode(explode(',', $row['uids']))); $this->cron_place_student_paper_model->insert($insert_data); } //删除学生试卷试题 $sql1 = "select group_concat(distinct etp_id) etp_ids from {pre}exam_test_paper where paper_id in ( {$paper_ids} )"; $etp_ids = $this->db->query($sql1)->row_array(); $etp_ids = $paper_ids['etp_ids']; $sql = "delete from {pre}exam_test_paper_question where etp_id in( {$etp_ids} ) "; $this->db->query($sql); //删除学生试卷 $sql = "delete from {pre}exam_test_paper where paper_id in( {$paper_ids}) "; $this->db->query($sql); //更新试卷归属 $sql = "update {pre}exam_paper set exam_id=0 where paper_id in( {$paper_ids}) and question_sort<>''"; $this->db->query($sql); //恢复试卷难易度 $pp = explode(',', $paper_ids); foreach ($pp as $val) { /* 获取试卷信息 */ $paper = PaperModel::get_paper_by_id($val); $question_difficulty = array(); if ($paper['paper_id']) { $quetion_sort = json_decode($paper['question_sort'], true); if (is_array($quetion_sort)) { foreach ($quetion_sort 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(); /* 试题难易度 */ $question_difficulty[] = $question['difficulty']; } $difficulty = array_sum($question_difficulty) / count($question_difficulty); if ($difficulty) { $sql = "update {pre}exam_paper set difficulty={$difficulty} where paper_id in( {$val}) "; $this->db->query($sql); } //删除试卷试题 // $sql = "delete from {pre}exam_question where paper_id in( $val) "; // $this->db->query($sql ); } } } //删除学科试卷 $this->db->where_in('id', $ids)->delete('exam_subject_paper'); $this->db->trans_complete(); message('删除成功', $back_url); } catch (Exception $e) { $this->db->trans_complete(); message('删除失败', $back_url); } }
/** * 添加试题 * * @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)); } }