Пример #1
0
 /**
  * 获取试卷信息
  * @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;
 }
Пример #2
0
 /**
  * 学生成绩列表
  *
  * @param  int  $exam_id
  * @return  void
  */
 public function index($exam_pid = 0)
 {
     if (!$this->check_power('exam_list,exam_manage')) {
         return;
     }
     $page = intval($this->input->get('page'));
     $per_page = intval($this->input->get('per_page'));
     $exam_pid = intval($this->input->get('exam_pid'));
     $flag = $this->input->get('flag');
     $place_id = intval($this->input->get('place_id'));
     $school_id = intval($this->input->get('school_id'));
     $ticket = trim($this->input->get('ticket'));
     $score_start = trim($this->input->get('score_start'));
     $score_end = trim($this->input->get('score_end'));
     $subject_id = intval($this->input->get('subject_id'));
     $keyword = trim($this->input->get('keyword'));
     //var_dump($place_id);die;
     // 查询条件
     $query = array();
     $param = array();
     $search = array('exam_pid' => '', 'place_id' => '', 'flag' => '-2', 'keyword' => '', 'subject_id' => '', 'school_id' => '', 'school_name' => '', 'ticket' => '', 'score_start' => '', 'score_end' => '');
     $flags = array('-1' => '结果作废', '0' => '未生成分数(考试中)', '1' => '已交卷(未统计结果)', '2' => '已生成分数');
     //考试期次
     $exam_pid = !$exam_pid ? 0 : $exam_pid;
     if ($exam_pid) {
         $query['exam_pid'] = $exam_pid;
         $param[] = "exam_pid={$exam_pid}";
         $search['exam_pid'] = $exam_pid;
     }
     //状态
     if ($flag === false) {
     } else {
         if ($flag > -2) {
             $query['etp_flag'] = $flag;
             $param[] = "flag={$flag}";
             $search['flag'] = $flag;
         }
     }
     /*
     if (isset($query['etp_flag']) && $query['etp_flag'] == '2') {
     	$query['etp_flag'] = array('2', '-1');
     }
     */
     //考场
     if ($place_id) {
         $query['place_id'] = $place_id;
         $param[] = "place_id={$place_id}";
         $search['place_id'] = $place_id;
     }
     //学科
     if ($subject_id) {
         $query['subject_id'] = $subject_id;
         $param[] = "subject_id={$subject_id}";
         $search['subject_id'] = $subject_id;
     }
     //学科
     if ($keyword) {
         $escape_keyword = $this->db->escape_like_str($keyword);
         $where = "fullname LIKE '%" . $escape_keyword . "%'";
         $sql = "SELECT group_concat(uid) as uid FROM v_rd_student s WHERE {$where} ";
         $res = $this->db->query($sql)->row_array();
         $uids = explode(',', $res['uid']);
         $query['uid'] = $uids;
         $search['keyword'] = $keyword;
         $param[] = "keyword=" . urlencode($search['keyword']);
     }
     //得分查询
     if ($score_start != '') {
         $query['test_score']['>='] = $score_start;
         $param[] = "score_start={$score_start}";
         $search['score_start'] = $score_start;
     }
     if ($score_end != '') {
         $query['test_score']['<='] = $score_end;
         $param[] = "score_end={$score_end}";
         $search['score_end'] = $score_end;
     }
     //获取该学校下所有的学生
     if ($school_id) {
         $param[] = "school_id={$school_id}";
         $search['school_id'] = $school_id;
         $row = SchoolModel::schoolInfo($school_id, 'school_name');
         if ($row) {
             $school_name = trim($row['school_name']);
         } else {
             $school_name = '';
         }
         if (!count($school_name)) {
             $query = null;
             $search['school_name'] = $school_id;
         } else {
             $students = StudentModel::get_student_list(array('school_id' => $school_id), false, false, null, 'uid');
             if (count($students)) {
                 $uids = array();
                 foreach ($students as $student) {
                     $uids[] = $student['uid'];
                 }
                 $query['uid'] = $uids;
             } else {
                 $query = null;
             }
             $search['school_name'] = $school_name;
         }
     }
     //准考证号
     if ($ticket) {
         if (stripos($ticket, '@') === false) {
             $uid = StudentModel::get_student_by_exam_ticket($ticket, 'uid');
         } else {
             $uid = StudentModel::get_student_by_email($ticket, 'uid');
         }
         if (count($uid)) {
             $query['uid'] = $uid;
         } else {
             $query = null;
         }
         $param[] = "ticket={$ticket}";
         $search['ticket'] = $ticket;
     }
     $select_what = '*';
     $page = $page <= 0 ? 1 : $page;
     $per_page = $per_page <= 0 ? 10 : $per_page;
     $list = array();
     if (!is_null($query)) {
         $list = ExamTestPaperModel::get_test_paper_list($query, $page, $per_page, 'subject_id ASC,etp_id ASC', $select_what);
     }
     //获取学生信息
     $grades = C('grades');
     $subjects = C('subject');
     $data['subjects'] = $subjects;
     $tmp_list = array();
     foreach ($list as $k => $item) {
         $student = StudentModel::get_student($item['uid'], 'first_name, last_name, school_id, exam_ticket, grade_id');
         if (!count($student)) {
             $tmp_list[$k] = array_merge($item, array('truename' => '--', 'school_name' => '--', 'grade_name' => '--', 'subject_name' => '--'));
             continue;
         }
         $student['truename'] = $student['last_name'] . $student['first_name'];
         //获取学生学校信息
         $row = SchoolModel::schoolInfo($student['school_id'], 'school_name');
         if ($row) {
             $school_name = trim($row['school_name']);
         } else {
             $school_name = '';
         }
         $student['school_name'] = count($school_name) ? $school_name : '--';
         //获取该学生所在的年级
         $student['grade_name'] = isset($grades[$student['grade_id']]) ? $grades[$student['grade_id']] : '--';
         //获取科目
         $subject_name = SubjectModel::get_subject($item['subject_id'], 'subject_name');
         $student['subject_name'] = count($subject_name) ? $subject_name : '--';
         //获取考试试卷信息
         $paper_name = ExamPaperModel::get_paper($item['paper_id'], 'paper_name');
         $item['paper_name'] = count($paper_name) ? $paper_name : '--';
         //获取作废记录
         $etp_invalid_record = ExamTestPaperModel::get_etp_invalid_record($item['etp_id']);
         if (!$etp_invalid_record) {
             $item['invalid_record'] = false;
             $item['invalid_record_note'] = '';
         } else {
             $item['invalid_record'] = true;
             $item['invalid_record_note'] = $etp_invalid_record['note'];
         }
         $tmp_list[$k] = array_merge($item, $student);
     }
     $data['list'] =& $tmp_list;
     $data['search'] =& $search;
     $data['flags'] =& $flags;
     // 分页
     $purl = site_url('admin/exam_student_result/index/') . (count($param) ? '?' . implode('&', $param) : '');
     $total = ExamTestPaperModel::count_list($query);
     $data['pagination'] = multipage($total, $per_page, $page, $purl);
     $data['priv_manage'] = $this->check_power('exam_manage', FALSE);
     $this->load->view('exam_student_result/index', $data);
 }
Пример #3
0
 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);
 }
Пример #4
0
 /**
  * 批量删除试卷中的试题
  *
  * @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);
 }
Пример #5
0
 /**
  * @description 更新试卷统计
  * @author
  * @final
  * @param int $id 试卷id
  */
 public function renew($id = 0)
 {
     $id = intval($id);
     $exam_id = ExamPaperModel::get_paper($id, 'exam_id');
     if (empty($exam_id)) {
         message('试卷不存在');
         return;
     }
     if (QuestionModel::paper_has_test_action($id)) {
         message('该试卷已经被考生考过 或者 正在被考中,因此无法操作');
         return;
     }
     $back_url = isset($_SERVER['HTTP_REFERER']) ? $_SERVER['HTTP_REFERER'] : 'admin/paper/index/' . $exam_id;
     if (ExamPaperModel::renew($id)) {
         message('更新成功', $back_url);
     } else {
         message('更新失败');
     }
 }
Пример #6
0
 /**
  * 选择试题
  *
  * @return void
  **/
 public function select_question($paper_id = 0)
 {
     /* 查询条件 */
     $where = array();
     $param = array();
     /* 过滤题组子题目,在题组页面管理 */
     $where[] = "q.parent_id=0";
     /* 未禁用试题 */
     $where[] = "q.is_delete<>1";
     /* 纸质考试试题 */
     //$where[] = "q.test_way IN (1, 2, 3)";
     /* 录入人员 只能查看自己录入的题目 管理员可以看到所有题目 */
     $admin_id = $this->session->userdata('admin_id');
     if (!$admin_id) {
         message('获取管理员数据失败,请从新登陆后重试!');
     }
     //$where[] = "q.admin_id='{$admin_id}'";
     //限制只能查看自己创建的试题
     if (!$this->is_super_user() && !CpUserModel::is_action_type_all('question', 'r') && !CpUserModel::is_action_type_subject('question', 'r') && CpUserModel::is_action_type_self('question', 'r')) {
         $where[] = "q.admin_id='{$admin_id}'";
     } else {
         $where[] = "q.admin_id>0";
     }
     //限制只能查看所属学科
     $c_subject_id = array();
     if (!$this->is_super_user() && !CpUserModel::is_action_type_all('question', 'r') && CpUserModel::is_action_type_subject('question', 'r')) {
         $c_subject_id = rtrim($this->session->userdata('subject_id'), ',');
         if ($c_subject_id != '') {
             $c_subject_id = explode(',', $c_subject_id);
             $c_subject_id = array_values(array_filter($c_subject_id));
             $c_subject_id = implode(',', $c_subject_id);
             $where[] = "q.subject_id in({$c_subject_id})";
         }
     }
     //限制只能查看所属年级
     $c_grade_id = array();
     if (!$this->is_super_user() && !$this->is_all_grade_user()) {
         $c_grade_id = rtrim($this->session->userdata('grade_id'), ',');
         if ($c_grade_id != '') {
             $c_grade_id = explode(',', $c_grade_id);
             $c_grade_id = array_values(array_filter($c_grade_id));
             $c_grade_id = implode(',', $c_grade_id);
             $where_3 = " grade_id in({$c_grade_id})";
         } else {
             $where_3 = '1=1';
         }
     } else {
         $where_3 = '1=1';
     }
     //限制只能查看所属类型
     $c_class_id = array();
     if (!$this->is_super_user() && !$this->is_all_q_type_user()) {
         $c_q_type_id = rtrim($this->session->userdata('q_type_id'), ',');
         if ($c_q_type_id != '') {
             $c_q_type_id = explode(',', $c_q_type_id);
             $c_q_type_id = array_values(array_filter($c_q_type_id));
             $c_class_id = $c_q_type_id;
             $c_q_type_id = implode(',', $c_q_type_id);
             $where_4 = " class_id in ({$c_q_type_id})";
         } else {
             $where_4 = '1=1';
         }
     } else {
         $where_4 = '1=1';
     }
     if ($where_3 != '1=1' || $where_4 != '1=1') {
         $where[] = "q.ques_id IN (SELECT DISTINCT ques_id FROM rd_relate_class WHERE {$where_3} AND {$where_4}) ";
     }
     if ($paper_id) {
         $paper = ExamPaperModel::get_paper_by_id($paper_id);
         $where[] = "q.subject_id = {$paper['subject_id']}";
         $param[] = "subject_id={$paper['subject_id']}";
         $data['subject_id'] = $paper['subject_id'];
         if ($paper['exam_id']) {
             $exam = ExamModel::get_exam($paper['exam_id'], 'grade_id, class_id');
             list($grade_id, $class_id) = array_values($exam);
             $where[] = "q.start_grade <= {$grade_id} AND q.end_grade >= {$grade_id}";
             $param[] = "grade_id={$grade_id}";
             $data['grade_id'] = $exam['grade_id'];
             $where[] = "q.class_id LIKE '%,{$class_id},%'";
             $param[] = "class_id={$class_id}";
             $data['class_id'] = $exam['class_id'];
         }
     } else {
         if ($subject_id = $this->input->get('subject_id')) {
             $where[] = "q.subject_id = {$subject_id}";
             $param[] = "subject_id={$subject_id}";
         }
         if ($grade_id = $this->input->get('grade_id')) {
             $where[] = "q.start_grade <= {$grade_id} AND q.end_grade >= {$grade_id}";
             $param[] = "grade_id={$grade_id}";
         }
         if ($class_id = $this->input->get('class_id')) {
             $where[] = "q.class_id LIKE '%,{$class_id},%'";
             $param[] = "class_id={$class_id}";
         }
     }
     $type = $this->input->get('type');
     if (strlen($type) > 0 && $type >= 0) {
         $type = intval($type);
         $where[] = "q.type = {$type}";
         $param[] = "type={$type}";
     }
     if ($is_original = $this->input->get('is_original')) {
         $where[] = "q.is_original = {$is_original}";
         $param[] = "is_original={$is_original}";
     }
     if (Validate::isJoinedIntStr($this->input->get('ques_id'))) {
         $search_quesid = $this->input->get('ques_id');
         $where[] = "q.ques_id IN ({$search_quesid})";
         $param[] = "ques_id={$search_quesid}";
     }
     if ($remark = $this->input->get('remark')) {
         $where[] = "q.remark LIKE '%{$remark}%'";
         $param[] = "remark={$remark}";
     }
     $where = $where ? ' WHERE ' . implode(' AND ', $where) : ' 1 ';
     /* 统计数量 */
     $nums = QuestionModel::get_question_nums($where);
     $total = $nums['total'];
     /* 读取数据 */
     $size = 15;
     $page = $this->input->get('page') ? intval($this->input->get('page')) : 1;
     $offset = ($page - 1) * $size;
     $list = array();
     /* 学科 */
     $qtypes = C('q_type');
     /* 试题类型 */
     $subjects = C('subject');
     if ($total) {
         $sql = "SELECT q.*,a.admin_user,a.realname FROM {pre}question q\n                    LEFT JOIN {pre}admin a ON a.admin_id=q.admin_id\n                    {$where} ORDER BY q.ques_id DESC LIMIT {$offset},{$size}";
         $res = $this->db->query($sql);
         foreach ($res->result_array() as $row) {
             $row['title'] = strip_tags($row['title']);
             $row['qtype'] = isset($qtypes[$row['type']]) ? $qtypes[$row['type']] : '';
             $row['subject_name'] = isset($subjects[$row['subject_id']]) ? $subjects[$row['subject_id']] : '';
             $row['addtime'] = date('Y-m-d H:i', $row['addtime']);
             $list[] = $row;
         }
     }
     $data['list'] =& $list;
     $data['q_class'] = $this->db->get_where('question_class')->result_array();
     $data['c_subject_id'] = $c_subject_id ? explode(',', $c_subject_id) : array();
     $data['c_class_id'] = $c_class_id;
     $data['c_grade_id'] = $c_grade_id ? explode(',', $c_grade_id) : array();
     $data['search_data'] = $_GET;
     /* 分页 */
     $purl = site_url('admin/paper_diy/select_question/' . ($param ? '?' . implode('&', $param) : ''));
     $data['pagination'] = multipage($total, $size, $page, $purl, '', $nums['relate_num']);
     /* 模版 */
     $this->load->view('paper_diy/question_list', $data);
 }