/** * 考场添加学科 * * @param int $exam_id 考试期次ID * @param int $place_id 考场ID * @return void */ public function index($exam_id = 0, $place_id = 0) { if (!$this->check_power('exam_list,exam_manage')) { return; } if (empty($exam_id) || empty($place_id)) { message('参数错误!'); } $query = "select * from {pre}exam_place where place_id={$place_id}"; $place = $this->db->query($query)->row_array(); if (!$place) { message('未查询到考场信息!'); } $query = "select * from {pre}exam where exam_id={$exam_id}"; $exam = $this->db->query($query)->row_array(); if (!$exam) { message('未查询到考场信息!'); } //获取考试期次下的学科 $exams = $this->db->query("select exam_id,subject_id from {pre}exam where rd_exam.exam_pid={$exam_id}")->result_array(); if (empty($exams)) { message('该考试期次不存在学科!'); } //控制考场只能在未开始考试操作 $no_start = ExamPlaceModel::place_is_no_start($place_id); $place['no_start'] = $no_start; $query = array('exam_pid' => $exam_id, 'place_id' => $place_id); $result = ExamPlaceSubjectModel::get_exam_place_subject_list($query); $old_subjects = array(); foreach ($result as $key => $value) { $old_subjects[$value['subject_id']] = $value; } $data = array(); $data['exam'] = $exam; $data['place'] = $place; //$data['allow_subject'] = CpUserModel::get_allowed_subjects(); $data['subjects'] = $exams; $data['subjects_name'] = C('subject'); $data['old_subjects'] = $old_subjects; $data['priv_manage'] = $this->check_power('exam_manage', FALSE); // 模版 $this->load->view('place_subject/index', $data); }
/** * 考试期次列表 * * @param int $pid * @param date $begin_time 开始时间 * @param date $end_time 结束时间 * @param string $keyword 关键字 * @return void */ public function index($pid = 0) { if (!$this->check_power('exam_list,exam_manage')) { return; } // 加载分类数据 $class_list = ClassModel::get_class_list(); $grades = C('grades'); $subjects = C('subject'); $states = C('exam_status'); $subject_types = C('subject_type'); // 查询条件 $where = array(); $param = array(); $search = array(); $pid = intval($pid); $where[] = "e.exam_pid={$pid}"; if ($pid) { $parent = ExamModel::get_exam($pid); if (empty($parent)) { message('考试期次不存在', 'admin/exam/index'); return; } $data['parent'] = $parent; } // 时间 $begin_time = $this->input->get('begin_time'); $end_time = $this->input->get('end_time'); if ($btime = (int) strtotime($begin_time)) { $search['begin_time'] = $begin_time; $where[] = "e.addtime >= {$btime}"; $param[] = "begin_time={$begin_time}"; } else { $search['begin_time'] = ''; } if ($etime = (int) strtotime($end_time)) { $etime += 86400; $search['end_time'] = $end_time; $where[] = "e.addtime < {$etime}"; $param[] = "end_time={$end_time}"; } else { $search['end_time'] = ''; } if ($search['keyword'] = trim($this->input->get('keyword'))) { $escape_keyword = $this->db->escape_like_str($search['keyword']); $where[] = "e.exam_name LIKE '%" . $escape_keyword . "%'"; $param[] = "keyword=" . urlencode($search['keyword']); } if (!$this->is_super_user()) { $admin_id = intval($this->session->userdata('admin_id')); $where[] = "((exam_id IN (SELECT DISTINCT(exam_pid) \n FROM rd_exam_managers WHERE admin_id = {$admin_id})) \n OR creator_id = {$admin_id})"; } $where = $where ? ' WHERE ' . implode(' AND ', $where) : ''; /* * 所有考试期次数量统计 */ $sql = "SELECT COUNT(*) nums FROM {pre}exam e {$where}"; $res = $this->db->query($sql); $row = $res->row_array(); $total = $row['nums']; //已公布成绩的期次 $exam_result_publish = array(); $query = $this->db->select('exam_pid')->from('exam_result_publish')->get(); foreach ($query->result_array() as $item) { $exam_result_publish[] = $item['exam_pid']; } /* * 分页获取考试期次,并处理考试期次数据 */ $size = 15; $page = isset($_GET['page']) && intval($_GET['page']) > 1 ? intval($_GET['page']) : 1; $offset = ($page - 1) * $size; $list = array(); if ($total) { $sql = "SELECT * FROM {pre}exam e {$where} ORDER BY e.exam_id desc LIMIT {$offset},{$size}"; $res = $this->db->query($sql); foreach ($res->result_array() as $row) { $row['class_name'] = isset($class_list[$row['class_id']]['class_name']) ? $class_list[$row['class_id']]['class_name'] : ''; $row['grade_name'] = isset($grades[$row['grade_id']]) ? $grades[$row['grade_id']] : ''; $row['subject'] = isset($subjects[$row['subject_id']]) ? $subjects[$row['subject_id']] : ''; $row['addtime'] = date('Y-m-d H:i', $row['addtime']); $row['state'] = $states[$row['status']]; $row['subject_type'] = $subject_types[$row['subject_type']]; $row['managers'] = $row['managers'] ? json_decode($row['managers'], true) : array(); if (in_array($row['exam_id'], $exam_result_publish)) { $row['is_publish'] = true; } $list[$row['exam_id']] = $row; } } /* * 查询考试期次下安排的科目考试 */ if ($list) { $query = $this->db->where_in('exam_pid', array_keys($list))->order_by('exam_index', 'asc')->order_by('subject_id', 'asc')->get('exam'); foreach ($query->result_array() as $row) { $row['class_name'] = isset($class_list[$row['class_id']]['class_name']) ? $class_list[$row['class_id']]['class_name'] : ''; $row['grade_name'] = isset($grades[$row['grade_id']]) ? $grades[$row['grade_id']] : ''; $row['subject'] = isset($subjects[$row['subject_id']]) ? $subjects[$row['subject_id']] : ''; $row['addtime'] = date('Y-m-d H:i', $row['addtime']); $row['state'] = $states[$row['status']]; $row['subject_type'] = $subject_types[$row['subject_type']]; //检查该学科考试状态 $has_tested = ExamPlaceSubjectModel::exam_subject_has_test_action($row['exam_id']); $row['has_tested'] = $has_tested; $list[$row['exam_pid']]['has_tested'] = $has_tested; $list[$row['exam_pid']]['subjects'][] = $row; } } $data['priv_manage'] = $this->check_power('exam_manage', FALSE); $data['list'] = $list; // 分页 $purl = site_url('admin/exam/index/' . $pid) . ($param ? '?' . implode('&', $param) : ''); $data['pagination'] = multipage($total, $size, $page, $purl); $data['search'] = $search; $tpl = $pid ? 'exam/index_subject' : 'exam/index'; $data['login_admin_id'] = $this->session->userdata('admin_id'); $data['is_super_user'] = $this->is_super_user(); $admin_list = $this->db->select('admin_id,realname')->get_where('admin', array('is_delete' => 0))->result_array(); foreach ($admin_list as $item) { $data['admin_list'][$item['admin_id']] = $item['realname']; } $this->demo_exams($data); // 模版 $this->load->view($tpl, $data); }
/** * desription 批量导入学生分数 * @author * @final */ public function import($exam_id) { $data = array(); $data['exam_id'] = $exam_id; $data['subjects'] = C('subject'); $data['place_subjects'] = ExamPlaceSubjectModel::get_exam_place_subject_list(array('exam_pid' => $exam_id), 1, time(), null, 'DISTINCT(subject_id) AS subject_id'); $this->load->view('place_student/import', $data); }
/** * @description 添加期次科目样卷 * @author * @final * @param int $exam_id 考试期次id * @param array $ids 试卷id */ public function add_demo($exam_id = 0) { if (!$this->check_power('exam_manage')) { return; } $exam_id = intval($exam_id); $exam_id && ($exam = ExamModel::get_exam($exam_id, 'exam_name,exam_id,exam_pid,subject_id')); if (empty($exam)) { message('考试期次科目不存在', 'admin/exam/index'); return; } //样卷,跳到样卷选择 if ($exam['exam_pid'] > 1) { redirect('admin/subject_paper/add/' . $exam_id); } //检查该学科考试状态 $has_tested = ExamPlaceSubjectModel::exam_subject_has_test_action($exam_id); if ($has_tested) { message('该期次科目已经被考生考过 或者 正在被考中,因此无法操作'); } $subject_id = $exam['subject_id']; $subjects = CpUserModel::get_allowed_subjects(); $exam['subject_name'] = $subjects[$subject_id]; $demo_subject_papers = C('demo_subject_paper', 'app/admin/exam/demo'); $paper_list = array(); $size = 30; $page = isset($_GET['page']) && intval($_GET['page']) > 1 ? intval($_GET['page']) : 1; $offset = ($page - 1) * $size; $total = 0; if (isset($demo_subject_papers[$subject_id]) && count($demo_subject_papers[$subject_id])) { $total = count($demo_subject_papers[$subject_id]); $sql = "SELECT * FROM {pre}exam_paper p WHERE p.exam_id={$exam_id} AND p.is_delete=0 AND p.paper_id in(" . implode(',', $demo_subject_papers[$subject_id]) . ") LIMIT {$offset},{$size}"; $query = $this->db->query($sql); foreach ($query->result_array() as $row) { $row['qtype_ques_num'] = explode(',', $row['qtype_ques_num']); $paper_list[] = $row; } } $data['exam'] =& $exam; $data['paper_list'] =& $paper_list; // 分页 $purl = site_url('admin/subject_paper/add_demo/' . $exam_id); $data['pagination'] = multipage($total, $size, $page, $purl); // 模版 $this->load->view('subject_paper/add', $data); }
/** * 添加试题 * * @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)); } }