/** * 修改重新计算考试成绩任务 */ public static function setCronTaskExamResultStatus($exam_pid) { if (!Validate::isInt($exam_pid) || $exam_pid <= 0) { throw new Exception('请指定考试期次!'); } if (ExamModel::get_exam($exam_pid, 'exam_ticket_maprule')) { //外部考试 $db = Fn::db(); $bOk = false; if ($db->beginTransaction()) { $db->delete('rd_cron_task_exam_result', 'exam_pid = ' . $exam_pid); $bind = array('er_flag' => 1); $db->update('t_exam_relate', $bind, 'er_flag = 3 AND er_exampid = ' . $exam_pid); $sql = "UPDATE tmp_table9700 SET s = 0 \n WHERE place_id IN (\n SELECT place_id FROM rd_exam_place \n WHERE exam_pid = {$exam_pid}\n )"; $db->query($sql); $bOk = $db->commit(); if (!$bOk) { $db->rollBack(); } } return $bOk; } else { //机考 $param = array('exam_pid' => $exam_pid, 'status' => 0, 'c_time' => time()); return Fn::db()->replace('rd_cron_task_exam_result', $param); } }
/** * 补全学生考试未分配试卷 */ public static function completionExamTestPaper($exam_pid) { $exam_pid = intval($exam_pid); if (!$exam_pid) { return false; } $db = Fn::db(); $exam = ExamModel::get_exam($exam_pid); if (!$exam) { return false; } $sql = "SELECT esp.exam_id, esp.paper_id, ep.question_sort, esp.subject_id \n FROM rd_exam_paper ep\n LEFT JOIN rd_exam_subject_paper esp ON esp.paper_id = ep.paper_id\n WHERE esp.exam_pid = {$exam_pid}"; $stmt = $db->query($sql); $paperlist = array(); while ($item = $stmt->fetch(PDO::FETCH_ASSOC)) { if (!$item['question_sort']) { $sql = "SELECT q.ques_id, q.type FROM rd_exam_question eq\n LEFT JOIN rd_question q ON eq.ques_id=q.ques_id\n LEFT JOIN rd_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={$item['paper_id']}\n ORDER BY rc.difficulty DESC,q.ques_id ASC"; $result = $db->fetchPairs($sql); if ($item['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'); } $paper_array = array(); foreach ($types as $type) { foreach ($result as $ques_id => $q_type) { if ($q_type != $type) { continue; } unset($result[$ques_id]); $paper_array[] = $ques_id; } } $item['question_sort'] = implode(',', $paper_array); } else { $item['question_sort'] = implode(',', json_decode($item['question_sort'], true)); } $paperlist[$item['exam_id']][$item['paper_id']] = $item['question_sort']; } if (!$paperlist) { return false; } $sql = "SELECT eps2.exam_id, eps2.subject_id, e.total_score, eps.place_id, eps.uid \n FROM rd_exam_place_student eps\n LEFT JOIN rd_exam_place ep ON eps.place_id = ep.place_id\n LEFT JOIN rd_exam_place_subject eps2 ON eps2.place_id = eps.place_id\n LEFT JOIN rd_exam e ON e.exam_id = eps2.exam_id\n WHERE ep.exam_pid = {$exam_pid} AND NOT EXISTS (\n SELECT uid FROM rd_exam_test_paper etp\n WHERE etp.uid = eps.uid AND etp.place_id = etp.place_id\n )"; $stmt = $db->query($sql); while ($item = $stmt->fetch(PDO::FETCH_ASSOC)) { $paper = $paperlist[$item['exam_id']]; if (!$paper) { continue; } $paper_ids = array_keys($paper); $paper_id = $paper_ids[rand(1, count($paper_ids)) - 1]; $param = array('exam_pid' => $exam_pid, 'exam_id' => $item['exam_id'], 'uid' => $item['uid'], 'paper_id' => $paper_id, 'place_id' => $item['place_id'], 'subject_id' => $item['subject_id'], 'full_score' => $item['total_score'], 'test_score' => '0.00', 'etp_flag' => 0, 'ctime' => time()); $db->insert('rd_exam_test_paper', $param); $etp_id = $db->lastInsertId('rd_exam_test_paper', 'etp_id'); $db->insert('rd_exam_test_paper_question', array('etp_id' => $etp_id, 'ques_id' => $paper[$paper_id])); } return $etp_id ? true : false; }
/** * 添加 生成考试期次学生的成绩任务 */ public function insert($data) { if (empty($data['exam_pid'])) { return false; } $data['c_time'] = time(); $data['status'] = 0; $exam_ticket_maprule = ExamModel::get_exam($data['exam_pid'], 'exam_ticket_maprule'); if ($exam_ticket_maprule > 0) { $data['status'] = 1; } return Fn::db()->replace('rd_cron_task_exam_result', $data); }
/** * 控制界面首页 */ public function index($exam_pid = 0) { Fn::ajax_call($this, 'regenerateExamRecord', 'regenerateExamResults', 'endPlaceExam', 'regenerateSummaryReportData', 'regenerateReport', 'removeCronTaskReport'); $exam_pid = intval($exam_pid); $param['exam_pid'] = 0; $param['exam_isfree'] = 0; $examlist = ExamModel::get_exam_list_all($param); $exam = array(); if ($exam_pid > 0) { $exam = ExamModel::get_exam($exam_pid); } if (!$exam) { $exam = current($examlist); } $db = Fn::db(); /////////////////////////考试记录是否生成///////////// $sql = "SELECT uid_data FROM rd_cron_task_place_student_paper ctps\n LEFT JOIN rd_exam_place ep ON ep.place_id = ctps.place_id\n WHERE ep.exam_pid ={$exam['exam_id']} AND ctps.status=2"; $uid_arr = $db->fetchCol($sql); $paper_count = 0; foreach ($uid_arr as $item) { $paper_count += count(json_decode($item)); } $sql = "SELECT COUNT(*) FROM rd_exam_place_student eps\n LEFT JOIN rd_exam_place ep ON ep.place_id = eps.place_id\n WHERE ep.exam_pid = {$exam['exam_id']}"; $student_count = $db->fetchOne($sql); if ($paper_count == $student_count) { $data['paper_status'] = true; //考试记录是否完全生成 } else { $data['paper_status'] = false; } ///////////////////////////////////////// $sql = "SELECT status FROM rd_cron_task_exam_result \n WHERE exam_pid = {$exam['exam_id']}"; $data['cter_status'] = $db->fetchOne($sql); ////////////////////////////////////////// $sql = "SELECT DISTINCT(status) FROM rd_cron_task_report ctr \n LEFT JOIN rd_evaluate_rule er ON er.id = ctr.rule_id \n WHERE exam_pid = {$exam['exam_id']}"; $data['ctr_status'] = $db->fetchCol($sql); //////////////////////////////////////// $data['exam'] = $exam; $data['demo_exam'] = $this->demo_exam_list(); $data['examlist'] = $examlist; $data['place'] = ExamPlaceModel::get_exam_place($exam_pid, 'MAX(end_time) as end_time'); $data['crontaskexamresult'] = ReportCommandModel::cronTaskExamResultInfo($exam['exam_id']); $data['evaluerulelist'] = ReportCommandModel::cronTaskReportLists($exam['exam_id']); $this->load->view('report_command/index', $data); }
/** * 生成某一期考试的考生成绩 * * @param int $exam_pid * @return void */ public function generate($exam_pid = 0) { if (!$this->check_power('exam_manage')) { return; } $exam_pid = intval($exam_pid); if (!$exam_pid) { message('不存在该考试期次.'); } $exam = ExamModel::get_exam($exam_pid, 'exam_id, status'); if (!count($exam)) { message('不存在该考试期次.'); } if (!$exam['status']) { message('该考试期次未被启用,无法生成考试成绩.'); } //获取当前考试期次下考场信息 $place_time = ExamPlaceModel::get_exam_place($exam_pid, 'MAX(end_time) as end_time'); /* $place_id=array(); foreach ($place_time as $val) { $place_id[] = $val['place_id']; } //查询日志信息是否存在已生成的考场信息 $success=0; $fail=0; foreach ($place_id as &$v) { $log_info = "生成考生成绩(".$v.")"; $row = $this->admin_log_model->get_admin_log($log_info); if($row['id']>0) { $fail++; unset($v); } else $success++; } */ //end if ($place_time['end_time'] > time()) { message('目前没有成绩可以生成.'); } //end //如果日志信息不存在考场信息,且该考场未生成考试成绩 $this->load->model('cron/cron_exam_result_model', 'cer_model'); $result = $this->cer_model->insert(array('exam_pid' => $exam_pid)); if ($result) { message("生成考生成绩操作已加入定时任务中,请耐心等候..."); } else { message("生成考生成绩操作加入定时任务失败,请重新执行..."); } exit; // /*if ($success>0&&count($place_id)>0) // {*/ // try { // require_once (APPPATH.'cron/exam.php'); // $exam_cron = new Exam(); // try { // /* // //开启事务 // $this->db->trans_start(); // $exam_cron->fill_unanswer_questions($exam_pid);//先补齐考生未做的题目 // $exam_cron->cal_test_result_score($exam_pid);//计算考生试题分数 // $exam_cron->cal_test_paper_score($exam_pid);//计算考生试卷分数 // //提交事务 // $this->db->trans_complete(); // */ // $exam_cron->cal_test_score($exam_pid); // } catch(Exception $e) { // //$this->db->trans_complete(); // throw new Exception('更新 考生试卷 得分失败,更新字段:' . $t_test_paper . '->test_score, Error:' . $e->getMessage()); // } // /* // foreach ($place_id as $v) // { // admin_log('generate', 'exam_student_result', $v); // } // */ // message("考生成绩生成成功."); // //message("考生成绩生成,成功(".$success.")个,失败(".$fail.")个"); // } catch(Exception $e) { // message('考生成绩生成失败,请重试.'); // } /*}*/ //不存在考场信息 /* else message('目前没有成绩可以生成.'); */ }
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 $rule_id * @param int $exam_id * @param int $stu_id * @return mixed */ public static function studentTranscriptInfo($rule_id, $exam_id, $stu_id) { $rule_id = intval($rule_id); $exam_id = intval($exam_id); $stu_id = intval($stu_id); if (!$rule_id || !$exam_id || !$stu_id) { return array(); } //考试信息 $exam = self::$_data['exam_info'][$exam_id]; if (!$exam) { $exam = ExamModel::get_exam($exam_id); if (!$exam) { return array(); } self::$_data['exam_info'][$exam_id] = $exam; } //学生信息 $stu_info = StudentModel::get_student($stu_id, 'school_id,last_name,first_name,external_account,exam_ticket'); if (!$stu_info) { return array(); } $db = Fn::db(); $data = array(); $subject_id = $exam['subject_id']; $exam_pid = $exam['exam_pid']; $subject_name = C('subject/' . $subject_id); if (!isset(self::$_data['school_rank'][$exam_id][$stu_info['school_id']])) { $sql = "SELECT uid, rank\n FROM rd_summary_region_student_rank\n WHERE exam_id = {$exam_id} AND region_id = ?\n AND is_school = 1 AND is_class = 0\n ORDER BY rank ASC"; $grade_rank = $db->fetchPairs($sql, array($stu_info['school_id'])); self::$_data['school_rank'][$exam_id][$stu_info['school_id']] = $grade_rank; } else { $grade_rank = self::$_data['school_rank'][$exam_id][$stu_info['school_id']]; } $sql = "SELECT a.etp_id, paper_id, test_score, ques_id FROM rd_exam_test_paper a\n LEFT JOIN rd_exam_test_paper_question b ON a.etp_id = b.etp_id\n WHERE uid = ? AND exam_id = ?"; $bind = array($stu_id, $exam_id); $etp = $db->fetchRow($sql, $bind); if (!$etp) { return array(); } $proportion = self::$_data['distribution_proportion'][$rule_id]; if (!$proportion) { $proportion = json_decode(EvaluateRuleModel::get_evaluate_rule($rule_id, 'distribution_proportion'), true); if (!$proportion) { $proportion = array('高分段' => 27, '中分段' => 73, '低分段' => 100); } $proportion = array_values($proportion); self::$_data['distribution_proportion'][$rule_id] = $proportion; } $level_results = 'A'; $prev_rank = 0; $stu_num = count($grade_rank); $stu_rank = $grade_rank[$stu_id]; foreach ($proportion as $k => $rate) { $rank = $stu_num * $rate / 100; if ($prev_rank < $stu_rank && $stu_rank <= $rank) { break; } $level_results++; $prev_rank = $rank; } $sch_name = self::$_data['school_info'][$stu_info['school_id']]; if (!$sch_name) { $school = SchoolModel::schoolInfo($stu_info['school_id'], 'school_name'); $sch_name = $school['school_name']; self::$_data['school_info'][$stu_info['school_id']] = $sch_name; } //成绩信息 $data['results'] = array('exam_name' => $exam['exam_name'], 'stu_fullname' => $stu_info['last_name'] . $stu_info['first_name'], 'stu_schname' => $sch_name, 'subject_name' => $subject_name, 'exam_ticket' => $stu_info['external_account'] ? $stu_info['external_account'] : $stu_info['exam_ticket'], 'test_score' => $etp['test_score'], 'level_results' => $level_results); //试题得分 //计算学校总体试卷试题得分率 $level_percent = self::$_data['school_question_level_percent'][$etp['paper_id']][$stu_info['school_id']]; if (!$level_percent) { $sql = "SELECT ques_id, ROUND(test_score / total_score * 100) AS percent\n FROM rd_summary_region_question\n WHERE exam_id = {$exam_id} AND region_id = {$stu_info['school_id']}\n AND is_school = 1"; $stmt = $db->query($sql); while ($item = $stmt->fetch(PDO_DB::FETCH_ASSOC)) { self::calLevelPercent($item['ques_id'], $item['percent'], $level_percent); } self::$_data['school_level_percent'][$etp['paper_id']][$stu_info['school_id']] = $level_percent; } //计算本次学生试题得分率 $sql = "SELECT ques_id, ROUND(SUM(test_score) / SUM(full_score) * 100) AS percent\n FROM rd_exam_test_result WHERE etp_id = ?\n GROUP BY ques_id"; $stu_percent = $db->fetchPairs($sql, array($etp['etp_id'])); //计算学生考试试题得分率对应等级 $ques_ids = explode(',', $etp['ques_id']); $data['question'] = array(1 => array(), 2 => array(), 3 => array(), 4 => array(), 5 => array()); foreach ($ques_ids as $index => $ques_id) { $percent = $stu_percent[$ques_id] > 100 ? 100 : (int) $stu_percent[$ques_id]; foreach ($level_percent[$ques_id] as $level => $v) { if ($v[0] <= $percent && $percent <= $v[1]) { $data['question'][$level][] = $index + 1; break; } } } ksort($data['question']); //知识点 $level_percent = self::$_data['school_knowledge_level_percent'][$etp['paper_id']][$stu_info['school_id']]; if (!$level_percent) { $sql = "SELECT knowledge_id, ROUND(test_score / total_score * 100) AS percent\n FROM rd_summary_region_knowledge\n WHERE exam_id = {$exam_id} AND region_id = {$stu_info['school_id']}\n AND is_school = 1 AND is_parent = 0"; $stmt = $db->query($sql); while ($item = $stmt->fetch(PDO::FETCH_ASSOC)) { self::calLevelPercent($item['knowledge_id'], $item['percent'], $level_percent); } self::$_data['school_knowledge_level_percent'][$etp['paper_id']][$stu_info['school_id']] = $level_percent; } //计算本次学生知识点得分率 $sql = "SELECT knowledge_id, knowledge_name, ROUND(test_score / total_score * 100) AS percent\n FROM rd_summary_student_knowledge ssk\n LEFT JOIN rd_knowledge k ON k.id = ssk.knowledge_id\n WHERE paper_id = ? AND uid = ? AND is_parent = 0"; $stu_percent = $db->fetchAssoc($sql, array($etp['paper_id'], $stu_id)); $data['knowledge'] = array(1 => array(), 2 => array(), 3 => array(), 4 => array(), 5 => array()); foreach ($level_percent as $knowledge_id => $levels) { $percent = $stu_percent[$knowledge_id]['percent'] > 100 ? 100 : (int) $stu_percent[$knowledge_id]['percent']; foreach ($levels as $level => $v) { if ($v[0] <= $percent && $percent <= $v[1]) { $data['knowledge'][$level][] = $stu_percent[$knowledge_id]['knowledge_name']; break; } } } ksort($data['knowledge']); //方法策略 $sql = "SELECT DISTINCT(subject_id) FROM rd_subject_category_subject"; $subject_ids = $db->fetchCol($sql); if (in_array($subject_id, $subject_ids)) { $level_percent = self::$_data['school_method_tactic_level_percent'][$etp['paper_id']][$stu_info['school_id']]; if (!$level_percent) { $sql = "SELECT method_tactic_id, ROUND(test_score / total_score * 100) AS percent\n FROM rd_summary_region_method_tactic\n WHERE exam_id = {$exam_id} AND region_id = {$stu_info['school_id']}\n AND is_school = 1"; $stmt = $db->query($sql); while ($item = $stmt->fetch(PDO::FETCH_ASSOC)) { self::calLevelPercent($item['method_tactic_id'], $item['percent'], $level_percent); } self::$_data['school_method_tactic_level_percent'][$etp['paper_id']][$stu_info['school_id']] = $level_percent; } //计算本次学生方法策略得分率 $sql = "SELECT method_tactic_id, name, ROUND(test_score / total_score * 100) AS percent\n FROM rd_summary_student_method_tactic ssmt\n LEFT JOIN rd_method_tactic mt ON mt.id = ssmt.method_tactic_id\n WHERE paper_id = ? AND uid = ?"; $stu_percent = $db->fetchAssoc($sql, array($etp['paper_id'], $stu_id)); $data['method_tactic'] = array(1 => array(), 2 => array(), 3 => array(), 4 => array(), 5 => array()); foreach ($level_percent as $method_tactic_id => $levels) { $percent = $stu_percent[$method_tactic_id]['percent'] > 100 ? 100 : (int) $stu_percent[$method_tactic_id]['percent']; foreach ($levels as $level => $v) { if ($v[0] <= $percent && $percent <= $v[1]) { $data['method_tactic'][$level][] = $stu_percent[$method_tactic_id]['name']; break; } } } ksort($data['method_tactic']); } else { if ($subject_id == 3) { $level_percent = self::$_data['school_group_type_level_percent'][$etp['paper_id']][$stu_info['school_id']]; if (!$level_percent) { $sql = "SELECT group_type_id, ROUND(test_score / total_score * 100) AS percent\n FROM rd_summary_region_group_type\n WHERE exam_id = {$exam_id} AND region_id = {$stu_info['school_id']}\n AND is_school = 1 AND is_parent = 0"; $stmt = $db->query($sql); while ($item = $stmt->fetch(PDO::FETCH_ASSOC)) { self::calLevelPercent($item['group_type_id'], $item['percent'], $level_percent); } self::$_data['school_group_type_level_percent'][$etp['paper_id']][$stu_info['school_id']] = $level_percent; } //计算本次学生信息提取方式得分率 $sql = "SELECT group_type_id, group_type_name, ROUND(test_score / total_score * 100) AS percent\n FROM rd_summary_student_group_type ssgt\n LEFT JOIN rd_group_type gt ON gt.id = ssgt.group_type_id\n WHERE paper_id = ? AND uid = ? AND is_parent = 0"; $stu_percent = $db->fetchAssoc($sql, array($etp['paper_id'], $stu_id)); $data['group_type'] = array(1 => array(), 2 => array(), 3 => array(), 4 => array(), 5 => array()); foreach ($level_percent as $group_type_id => $levels) { $percent = $stu_percent[$group_type_id]['percent'] > 100 ? 100 : (int) $stu_percent[$group_type_id]['percent']; foreach ($levels as $level => $v) { if ($v[0] <= $percent && $percent <= $v[1]) { $data['group_type'][$level][] = $stu_percent[$group_type_id]['group_type_name']; break; } } } ksort($data['group_type']); } } return $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); }
/** * 获取试卷信息 * @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 batch_mail($rule_id = 0) { $rule_id = intval($rule_id); $rule_id && ($rule = EvaluateRuleModel::get_evaluate_rule($rule_id)); if (empty($rule)) { message('不存在该评估规则'); } $uid = $this->input->post('uid'); $send_all = intval($this->input->post('send_all')); if (!$send_all && (!is_array($uid) || !count($uid))) { message('请选择要通知的考生'); } $uids = array(); if ($send_all) { $sql = "select uids from {pre}evaluate_student where rule_id={$rule_id}"; $result = $this->db->query($sql)->row_array(); $uids = isset($result['uids']) ? trim($result['uids']) : ''; $uids = explode(',', $uids); } else { $uids = $uid; } //获取考试期次信息 $rule['exam_name'] = ExamModel::get_exam($rule['exam_pid'], 'exam_name'); //获取该期次所考到的科目 $exam_subjects = array(); $exam_names = array(); $sql = "select exam_id, subject_id from {pre}exam where exam_pid=" . $rule['exam_pid']; $result = $this->db->query($sql)->result_array(); foreach ($result as $item) { $exam_names[$item['exam_id']] = C('subject/' . $item['subject_id']); } $rule['exams'] = $exam_names; //获取未生成zip的考生 $sql = "select uid from {pre}evaluate_student_stat where rule_id={$rule_id} and zip_ready=0 and uid in(" . implode(',', $uids) . ")"; $result = $this->db->query($sql)->result_array(); $no_zip_ready_uids = array(); foreach ($result as $item) { $no_zip_ready_uids[] = $item['uid']; } $data = array(); $fails = array(); $email_tpl = C('email_template/send_zip'); foreach ($uids as $uid) { $uid && ($student = StudentModel::get_student($uid, 'uid, email, last_name, first_name')); if (empty($student)) { $fails[] = 'uid:' . $uid . '【原因:考生不存在】'; continue; } if (in_array($uid, $no_zip_ready_uids)) { $fails[] = 'uid:' . $uid . '【原因:未生成zip压缩包】'; continue; } $email = $student['email']; if (!is_email($email)) { $fails[] = 'uid:' . $uid . '->email:' . $email . '【原因:邮件地址格式不正确】'; continue; } $email_content = $this->load->view($email_tpl['tpl'], array('rule' => $rule, 'student' => $student), true); $data[] = array('type' => 1, 'target_id' => "{$rule_id}-{$uid}", 'email' => $email, 'title' => $email_tpl['subject'], 'content' => $email_content, 'attache' => "report/{$rule_id}/{$uid}.zip"); } $res = $this->cron_task_email_model->insert_batch($data); if ($res) { if (count($fails)) { message('已成功将部分该考生加入通知队列中,等待系统处理中,以下考生出现异常:<br/>' . implode('<hr/>', $fails)); } else { message('已成功将该考生加入通知队列中,等待系统处理中'); } } else { message('操作失败,请重试.'); } }
/** * 导入 */ public function import($exam_pid = 0) { if ($_GET['dl'] == '1') { Func::dumpFile('application/vnd.ms-excel', 'file/import_teacher_stundent_template.xlsx', '师生关联模板.xlsx'); exit; } if (!$exam_pid) { message('参数错误'); } $data = array(); while (isset($_FILES['file'])) { $param = $_POST; $col_char = array(); $rows = Excel::readSimpleUploadFile2($_FILES['file']); if (!is_array($rows)) { $data['error'] = $rows; break; } $subject_map = array_flip(C('subject')); $db = Fn::db(); $exam_ticket_maprule = ExamModel::get_exam($exam_pid, 'exam_ticket_maprule'); $sql = "SELECT subject_id, exam_id FROM rd_exam\n WHERE exam_pid = {$exam_pid}"; $subject_exam = $db->fetchPairs($sql); if (!is_array($subject_exam)) { $data['error'] = '考试期次没有考试学科'; break; } $exam_subjectid = array_keys($subject_exam); $list = array(); $subject_key = array(); foreach ($rows as $k => $row) { if ($k == 0) { for ($i = 2; $i <= count($row); $i++) { $subject_id = $subject_map[str_replace("'", "", trim($row[$i]))]; if ($subject_id && in_array($subject_id, $exam_subjectid)) { $subject_key[$i] = $subject_id; } } } else { $student = array(); for ($i = 1; $i <= count($row); $i++) { if ($i == 1) { $exam_ticket = trim($row[$i]); if (!$exam_ticket) { break; } $exam_ticket = exam_ticket_maprule_encode($exam_ticket, $exam_ticket_maprule); $sql = "SELECT uid, school_id FROM rd_student\n WHERE exam_ticket = '{$exam_ticket}'"; $student = $db->fetchRow($sql); if (!$student) { break; } $list[$student['uid']]['uid'] = $student['uid']; } else { $ct_name = str_replace("'", "", trim($row[$i])); if (!$ct_name) { continue; } $sql = "SELECT ct_id FROM t_cteacher \n LEFT JOIN t_cteacher_school ON scht_ctid = ct_id\n WHERE scht_schid = {$student['school_id']} \n AND ct_name = '{$ct_name}'"; $ct_id = $db->fetchOne($sql); if (!$ct_id) { continue; } $list[$student['uid']]['teacher'][$subject_key[$i]] = $ct_id; } } } } try { if (!$db->beginTransaction()) { throw new Exception('开始导入事务处理失败'); } $insert = 0; // 导入教师 foreach ($list as $uid => $row) { foreach ($row['teacher'] as $subject_id => $ct_id) { $bind = array('tstu_ctid' => $ct_id, 'tstu_stuid' => $uid, 'tstu_exampid' => $exam_pid, 'tstu_examid' => $subject_exam[$subject_id], 'tstu_subjectid' => $subject_id); TeacherStudentModel::addTeacherStudent($bind); $insert++; } } if ($db->commit()) { $data['success'] = <<<EOT 导入Excel文件({$_FILES['file']['name']})成功,共插入{$insert}条师生记录 EOT; admin_log('import', 'teacher_student', $data['success']); } else { $err = $db->errorInfo()[2]; $db->rollBack(); throw new Exception($err); } } catch (Exception $e) { $data['error'] = $e->getMessage(); } break; } $data['exam_pid'] = $exam_pid; $data['param'] = $param; $this->load->view('teacher_student/import', $data); }
/** * 获取考试期次列表 * * @param number $exam_id * @return void */ public function ajax_get_exams($exam_pid = 0) { $exams = ExamModel::get_exam_list(array('exam_pid' => '0', 'status' => array('1', '2')), false, false, null, 'exam_id, exam_name'); $output = array(); $output[] = '<option value="0">--请选择考试期次--</option>'; foreach ($exams as $exam) { $t_exam_pid = $exam['exam_id']; $exam_name = $exam['exam_name']; $output[] = "<option value='{$t_exam_pid}'" . ($exam_pid == $t_exam_pid ? 'selected="selected"' : '') . ">{$exam_name}</option>"; } echo implode('', $output); die; }
/** * 更新试卷试题 * @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 $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 mixed void */ public function save() { ini_set("display_errors", "On"); error_reporting(-1); $post = $this->input->post(); /** 上传文件 */ $config['upload_path'] = '../../cache/excel/'; $config['allowed_types'] = '*'; $config['max_size'] = 1024 * 10; #单位kb $config['overwrite'] = false; $this->load->library('upload', $config); if (!$this->upload->do_upload('file')) { $data = array(); $data['exam_id'] = $post['exam_id']; $data['error'] = $this->upload->display_errors(); $data['exams'] = ExamModel::get_exam_list_all(array('exam_pid' => '0', 'status' => '1'), 'exam_id,exam_name'); $this->load->view('interview/interview_import', $data); } else { /** 实时输出导入结果 */ ob_end_flush(); set_time_limit(0); $start_time = microtime(true); $upload_data = $this->upload->data(); /** 读取excel */ $this->load->library('PHPExcel'); $this->load->library('PHPExcel/IOFactory'); $inputFileType = IOFactory::identify($upload_data['file_relative_path']); $objReader = IOFactory::createReader($inputFileType); $objPHPExcel = $objReader->load($upload_data['file_relative_path']); $data = $objPHPExcel->getSheet(0)->toArray(); $end_time = microtime(true); $execute_time = $end_time - $start_time; if (!empty($data)) { echo '文件载入成功!执行时间:' . sprintf('%.4f', $execute_time) . 's' . '<hr/>'; flush(); } /** 评分标准信息 */ $start_time = microtime(true); $relation = EvaluationStandardExamModel::get_standard_by_exam($post['exam_id']); $standard = EvaluationStandardModel::get_one($relation['standard_id']); $option_count = count(explode(',', $standard['options'])); $end_time = microtime(true); $execute_time = $end_time - $start_time; if ($standard && !empty($standard) && $option_count >= 1) { echo '获取考试期次对应评分标准信息成功!执行时间:' . sprintf('%.4f', $execute_time) . 's' . '<hr/>'; flush(); } else { echo '获取考试期次对应评分标准信息失败!请检查本期次对应评分标准及评分项!'; flush(); exit; } if ($standard['status'] != 1) { echo '当前评分标准已禁用!停止导入!<hr/>'; flush(); exit; } /** 导入结果 */ $start_time = microtime(true); foreach ($data as $key => $value) { if ($key < 1) { continue; } $student_ticket = trim($value[0]); $sql = "select * from {pre}exam_student_list where student_ticket={$student_ticket}"; $ruidabei_student = $this->db->query($sql)->row_array(); if (!$ruidabei_student['uid'] > 0) { echo "未查询到当前用户数据,在第" . ($key + 1) . "行。姓名:" . $value['1'] . "<br/>"; continue; } if (!$ruidabei_student) { echo "未查询到当前用户数据,在第" . ($key + 1) . "行。姓名:" . $value['1'] . "<br/>"; continue; } if ($ruidabei_student['student_name'] != $value[1]) { echo "当前用户睿达杯准考证号与姓名不符,在第" . ($key + 1) . "行。姓名:" . $value[1] . "<br/>"; continue; } $option_index = 1; /* 获取学科信息 */ $subject_name = "%" . $value[2] . "%"; $subject_id = $this->db->select('subject_id')->get_where('subject', array('subject_name like' => $subject_name))->row_array(); foreach ($value as $k => $v) { if ($k < 3 || $k >= 3 + $option_count) { continue; } /** 判断数据是否已存在数据库中 */ $param = array(); $param['exam_id'] = $post['exam_id']; $param['student_id'] = $ruidabei_student['uid']; $param['subject_id'] = $subject_id['subject_id']; $param['option_index'] = $option_index; $row = array(); $row['exam_id'] = $post['exam_id']; $row['student_id'] = $ruidabei_student['uid']; $row['subject_id'] = $subject_id['subject_id']; $row['option_index'] = $option_index; $row['scroe'] = $v ? $v : 0; $row['create_time'] = time(); $option_index++; $result = InterviewResultModel::get_one($param); if ($result && !empty($result)) { echo '<p style="color:red;">警告!本条数据已存在!将覆盖原有数据!在第' . ($key + 1) . '行:' . $param['student_id'] . '</p><br/>'; $result = InterviewResultModel::update(array('id' => $result['id']), $row); } else { $result = InterviewResultModel::add($row); } if ($result) { echo '<p style="color:green;">第' . ($key + 1) . '行' . '第' . ($k - 2) . '条导入成功!</p><br/>'; flush(); } else { echo '<p style="color:red;">错误!第' . ($key + 1) . '行' . '第' . ($k - 2) . '条导入失败!</p><br/>'; flush(); } } } $end_time = microtime(true); $execute_time = $end_time - $start_time; echo '导入成功!用时:' . $execute_time . 's'; } }
/** * 编辑信息 * * @param int $id * @return void */ public function edit($id) { if (!$this->check_power('evaluate_rule_manage')) { return; } $data = array(); $query = array('id' => $id); $detail = EvaluateRuleModel::get_evaluate_rule_list($query); if (!$id || !count($detail)) { message('不存在评估规则信息'); return; } $detail = $detail[0]; $detail['is_reportting'] = $this->rule_is_reportting($id); // 获取关联知识点 $query = array('er_id' => $id); $knowledge_list = EvaluateRuleModel::get_evaluate_knowledge_list($query, null, null, null, null, true); // 按照 等级 归档 $tmp_knowledge_list = array(); foreach ($knowledge_list as $k => $v) { $subject_id = $k; foreach ($v as $i) { $knowledge_id = $i['knowledge_id']; $tmp_knowledge_list['s_' . $subject_id]['k_' . $knowledge_id]['l_' . $i['level']] = array('comment' => $i['comment'], 'suggest' => $i['suggest']); } } // 获取关联 方法策略 $query = array('er_id' => $id); $method_tactic_list = EvaluateRuleModel::get_evaluate_method_tactic_list($query, null, null, null, null, true); $method_tactic_ids = array(); foreach ($method_tactic_list as $val) { foreach ($val as $item) { $method_tactic_ids[] = $item['method_tactic_id']; } } $method_tactic_ids = array_filter($method_tactic_ids); $method_tactic_ids = array_unique($method_tactic_ids); $method_tactic_ids = count($method_tactic_ids) ? $method_tactic_ids : array(0); $method_tactic_ids = implode(',', $method_tactic_ids); $subject_category = $this->db->query("select sc.id as subject_category_id,mt.id as method_tactic_id, mt.name, scs.subject_id from {pre}method_tactic mt, {pre}subject_category_subject scs,{pre}subject_category sc where mt.subject_category_id=scs.subject_category_id and sc.id=scs.subject_category_id and mt.id in ({$method_tactic_ids})")->result_array(); // 按照 等级 归档 $tmp_method_tactic_list = array(); foreach ($method_tactic_list as $k => $v) { $subject_id = $k; foreach ($v as $i) { $method_tactic_id = $i['method_tactic_id']; foreach ($subject_category as $item) { if ($method_tactic_id == $item['method_tactic_id']) { $tmp_method_tactic_list['sc_' . $item['subject_category_id']]['method_tactic_' . $method_tactic_id]['l_' . $i['level']] = array('comment' => $i['comment'], 'suggest' => $i['suggest']); continue; } else { $tmp_method_tactic_list['s_' . $subject_id]['method_tactic_' . $method_tactic_id]['l_' . $i['level']] = array('comment' => $i['comment'], 'suggest' => $i['suggest']); } } } } // 获取关联信息提取方式 $query = array('er_id' => $id); $group_type_list = EvaluateRuleModel::get_evaluate_group_type_list($query, null, null, null, null, true); // 按照 等级 归档 $tmp_group_type_list = array(); foreach ($group_type_list as $k => $v) { $subject_id = $k; foreach ($v as $i) { $gr_id = $i['group_type_id']; $tmp_group_type_list['s_' . $subject_id]['gr_' . $gr_id]['l_' . $i['level']] = array('comment' => $i['comment'], 'suggest' => $i['suggest']); } } // 获取单人模式下被搜索考生 $student = array(); if ($detail['generate_mode'] == '1') { $student = StudentModel::get_student($detail['generate_uid']); } $detail['generate_u_keyword'] = count($student) ? $student['email'] : ''; // 获取当前期次 $exam = ExamModel::get_exam($detail['exam_pid'], 'exam_id, exam_name'); $detail['exam_name'] = count($exam) ? $exam['exam_name'] : '该考试期次已经被删除'; // 获取当前考场 $place = ExamPlaceModel::get_place($detail['place_id'], 'place_id, place_name'); $detail['place_name'] = is_array($place) && count($place) ? $place['place_name'] : ($detail['place_id'] == 0 ? '所有考场' : '该考场已经被删除'); // 外部对比信息 $comparison_info = unserialize($detail['comparison_info']); $comparison_info = is_array($comparison_info) ? $comparison_info : array(); $detail['comparison_info'] = $comparison_info; $this->session->set_userdata(array('comparison_info' => $detail['comparison_info'])); $data['detail'] =& $detail; $data['knowledge_list'] =& $tmp_knowledge_list; $data['method_tactic_list'] =& $tmp_method_tactic_list; $data['group_type_list'] =& $tmp_group_type_list; $data['comparison_types'] = $this->_get_comparison_info(); $data['mode'] = 'edit'; $data['comparison_levels'] = C('evaluate_comparison_level'); $this->load->view('evaluate_rule/add', $data); }
/** * 一键更新试题缓存 * * @author TCG * @param int $exam_id 考试期次科目id * @return mixed 返回成功及失败提示 */ public function update_questions_cache($exam_id) { $exam_id = (int) $exam_id; $exam = Fn::db()->fetchRow("SELECT exam_id, exam_pid, subject_id, grade_id, class_id, total_score, qtype_score FROM rd_exam WHERE exam_id=?", $exam_id); if (empty($exam)) { return false; } $is_mini_test = ExamModel::is_mini_test($exam['exam_pid']); /** 载入缓存功能 */ if ($is_mini_test) { $this->load->driver('cache'); /** 缓存时间 单位second 默认缓存30天 */ $cache_time = 24 * 3600 * 20; } else { $cache = Fn::factory('File'); } /** 写入缓存 */ $is_mini_test && $this->cache->file->save('get_paper_question_detail_p_exam_' . $exam_id, $exam, $cache_time); $sql = "SELECT paper_id FROM rd_exam_paper WHERE exam_id={$exam_id}"; $rows = Fn::db()->fetchAll($sql); foreach ($rows as $row) { /** 写入缓存 */ $is_mini_test && $this->cache->file->save('get_paper_question_detail_p_exam_id_' . $row['paper_id'], $exam_id, $cache_time); $question_sort = Fn::db()->fetchOne('SELECT question_sort FROM rd_exam_paper WHERE paper_id = ?', array($row[paper_id])); $question_sort = json_decode($question_sort, true); $sql = <<<EOT SELECT q.ques_id,q.type,q.title,q.score_factor,rc.difficulty FROM rd_exam_question eq LEFT JOIN rd_question q ON eq.ques_id=q.ques_id LEFT JOIN rd_relate_class rc ON rc.ques_id = q.ques_id AND rc.grade_id = ? AND rc.class_id = ? WHERE eq.paper_id = ? ORDER BY rc.difficulty DESC,q.ques_id ASC EOT; if ($question_sort) { $res = Fn::db()->fetchAssoc($sql, array($exam['grade_id'], $exam['class_id'], $row['paper_id'])); $sort = explode(',', $question_sort); $result = array(); foreach ($question_sort as $ques_id) { $result[] = $res[$ques_id]; unset($res[$ques_id]); } } else { $result = Fn::db()->fetchAll($sql, array($exam[grade_id], $exam[class_id], $row[paper_id])); } $key = 'get_paper_question_detail_p_' . $exam[grade_id] . '_' . $exam[class_id] . '_' . $row[paper_id]; !$is_mini_test && $cache->save('/zmexam/' . $key, $result); /** 写入缓存 */ $is_mini_test && $this->cache->file->save($key, $result, $cache_time); } //$domain=C('memcache_pre'); /** 获取考试期次所有试题 */ $sql = "SELECT ques_id FROM {pre}exam_question WHERE exam_id={$exam_id}"; $query = $this->db->query($sql); $rows = $query->result_array(); /** 生成缓存 (执行时间可能过长) */ if (count($rows) > 0 && !empty($rows)) { $questions = array(); /** 获取试题数据 */ foreach ($rows as $key => $value) { $question = QuestionModel::get_question($value['ques_id'], 'ques_id, type, title, picture, parent_id,subject_id'); if (!$question) { continue; } /** 题组 */ if (in_array($question['type'], array(0, 4, 5, 6, 8))) { $pid = $question['ques_id']; $sql = "SELECT ques_id,type,title,picture,parent_id,subject_id FROM {pre}question WHERE parent_id={$pid}"; $query = $this->db->query($sql); $group_rows = $query->result_array(); /** 写入题组子题 */ $question['children'] = $group_rows; /** 子题加入缓存列表 */ $questions = array_merge($questions, $group_rows); } $questions[] = $question; } foreach ($questions as $key => &$question) { /** 样式修正 */ $question['title'] && $this->_format_question_content($question['ques_id'], $question['title'], in_array($question['type'], array(3, 9))); /** 获取试题选项数据(选择题) */ if (in_array($question['type'], array(1, 2, 7, 14))) { $question['options'] = QuestionModel::get_options($question['ques_id']); } /** 获取题组子题选项 */ if (in_array($question['type'], array(0, 4, 5, 6, 8)) && !empty($question['children'])) { foreach ($question['children'] as $k => &$v) { $v['title'] && $this->_format_question_content($v['ques_id'], $v['title'], $v['type'] == 3); $question['children'][$k]['options'] = QuestionModel::get_options($v['ques_id']); } } !$is_mini_test && $cache->save('/zmexam/question_' . $question['ques_id'], $question); /** 写入缓存 */ $is_mini_test && $this->cache->file->save($question['ques_id'], $question, $cache_time); } /** 成功提示页面 */ message('生成成功.', 'admin/exam/index'); } else { /** 失败提示页面 */ message('生成失败!!!请尝试从新输入!', 'admin/exam/index'); } /** $this->output->enable_profiler(TRUE); */ }
/** * 导入处理 * * @return mixed void */ public function save() { $post = $this->input->post(); /** 上传文件 */ $config['upload_path'] = '../../cache/excel/'; $config['allowed_types'] = '*'; $config['max_size'] = 1024 * 10; #单位kb $config['overwrite'] = false; $this->load->library('upload', $config); if (!$this->upload->do_upload('file')) { $data = array(); $data['exam_id'] = $post['exam_id']; $data['error'] = $this->upload->display_errors(); $data['exams'] = ExamModel::get_exam_list_all(array('exam_pid' => '0', 'status' => '1'), 'exam_id,exam_name'); $this->load->view('ruidabei/import', $data); } else { /** 实时输出导入结果 */ ob_end_flush(); set_time_limit(0); $start_time = microtime(true); $upload_data = $this->upload->data(); /** 读取excel */ $this->load->library('PHPExcel'); $this->load->library('PHPExcel/IOFactory'); $inputFileType = IOFactory::identify($upload_data['file_relative_path']); $objReader = IOFactory::createReader($inputFileType); $objPHPExcel = $objReader->load($upload_data['file_relative_path']); $data = $objPHPExcel->getSheet(0)->toArray(); $end_time = microtime(true); $execute_time = $end_time - $start_time; if (!empty($data)) { echo '文件载入成功!执行时间:' . sprintf('%.4f', $execute_time) . 's' . '<hr/>'; flush(); } /** 导入结果 */ $start_time = microtime(true); foreach ($data as $key => $value) { if ($key < 1) { continue; } $student_ticket = $value[0]; $sql = "select * from {pre}exam_student_list where student_ticket={$student_ticket}"; $ruidabei_student = $this->db->query($sql)->row_array(); if (!$ruidabei_student) { echo "未查询到当前用户数据,在第" . ($key + 1) . "行:" . $value[1]; continue; } if ($ruidabei_student['student_name'] != $value[1]) { echo "当前用户睿达杯准考证号与姓名不符,在第" . ($key + 1) . "行" . $value[1]; continue; } /** 判断数据是否已存在数据库中 */ $param = array(); $param['exam_id'] = $post['exam_id']; $param['student_id'] = $ruidabei_student['uid']; $param['school_name'] = $value[2]; $param['grade'] = $value[7]; $param['subject'] = $value[6]; $row = array(); $row['exam_id'] = $post['exam_id']; $row['student_id'] = $ruidabei_student['uid']; $row['student_name'] = $value[1]; $row['school_name'] = $value[2]; $row['awards'] = $value[3]; $row['score'] = $value[4]; $row['ranks'] = $value[5]; $row['subject'] = $value[6]; $row['grade'] = $value[7]; $row['create_time'] = time(); $query_result = RuidabeiResultModel::get_one($param); if ($query_result) { echo '<p style="color:red;">警告!本条数据已存在!将覆盖原有数据!在第' . ($key + 1) . '行' . '</p><br/>'; $result = RuidabeiResultModel::update(array('id' => $query_result['id']), $row); } else { $result = RuidabeiResultModel::add($row); } if ($result) { echo '<p style="color:green;">第' . ($key + 1) . '行导入成功!</p><br/>'; flush(); } else { echo '<p style="color:red;">错误!第' . ($key + 1) . '行导入失败!</p><br/>'; flush(); } } $end_time = microtime(true); $execute_time = $end_time - $start_time; echo '导入成功!用时:' . $execute_time . 's'; } }
/** * 生成试卷 * * @param int $rule_id 组题规则id * @param int $exam_id 考试期次id * @param string $method 试卷生成方式 * @return void */ public function gen($exam_id = 0, $rule_id = 0, $method = 'new') { if ($rule_id = intval($rule_id)) { $query = $this->db->get_where('exam_rule', array('rule_id' => $rule_id)); $rule = $query->row_array(); } if (empty($rule)) { message('规则不存在'); return; } /* * 检查提交数据是否有效 */ $exam_id = intval($exam_id); $method = $method == 'new' ? 'generate' : 'generate_rand'; if ($exam_id) { $exam = ExamModel::get_exam($exam_id); } if (empty($exam) || $exam['status']) { die('请选择考试期次.'); } else { if ($exam['subject_id'] != $rule['subject_id'] || $exam['grade_id'] != $rule['grade_id'] || $exam['class_id'] != $rule['class_id']) { die('组题规则和考试期次不匹配(学科、年级或类型)'); } } $rule['knowledge_id_arr'] = explode(',', $rule['knowledge_ids']); $rule['ques_num'] = explode(',', $rule['ques_num']); if (count($rule['ques_num']) < 4) { for ($i = count($rule['ques_num']); $i < 4; $i++) { $rule['ques_num'][$i] = 0; } } /* 读取重点知识点 */ $sub_rules = array(); $query = $this->db->get_where('exam_rule_knowledge', array('rule_id' => $rule_id)); foreach ($query->result_array() as $row) { $row['nums'] = explode(',', $row['setting']); $row['pid'] = KnowledgeModel::get_knowledge($row['knowledge_id'], 'pid'); // 一级知识点规则 if ($row['pid'] == 0) { $children = KnowledgeModel::get_knowledge_list(0, $row['knowledge_id'], 0); $children_ids = array_keys($children); $row['children'] = array_intersect($children_ids, $rule['knowledge_id_arr']); } $sub_rules[$row['knowledge_id']] = $row; } $res = ExamPaperModel::$method($exam, $rule, $sub_rules); if ($res['success'] == true) { die('试卷生成成功'); } else { die($res['msg']); } }
/** * 设定学生考卷(每科考试随机选一份试卷) * * @param int 考试场次id(place_id) * @param int 学生id * @return array */ public static function set_student_test_paper($place_id, $uid, $is_trans = true) { $subjects = ExamPlaceModel::get_exam_place_subject($place_id); if (empty($subjects)) { return FALSE; } $test_papers = array(); $no_paper_subjects = false; foreach ($subjects as $row) { $sql = <<<EOT SELECT paper_id, exam_pid FROM rd_exam_subject_paper WHERE exam_id = ? ORDER BY RAND() LIMIT 1 EOT; $arr = Fn::db()->fetchRow($sql, $row['exam_id']); if (!isset($arr['paper_id'])) { $no_paper_subjects = true; break; } $exam = ExamModel::get_exam_by_id($row['exam_id'], 'total_score, class_id, grade_id'); $total_score = $exam['total_score']; $class_id = $exam['class_id']; $grade_id = $exam['grade_id']; $test_papers[] = array('exam_pid' => $row['exam_pid'], 'exam_id' => $row['exam_id'], 'uid' => $uid, 'paper_id' => $arr['paper_id'], 'place_id' => $place_id, 'subject_id' => $row['subject_id'], 'full_score' => $total_score, 'test_score' => '0.00', 'etp_flag' => 0, 'ctime' => time()); } if ($no_paper_subjects) { return false; } $db = Fn::db(); if ($is_trans) { $db->beginTransaction(); } // save $insert_ids = array(); foreach ($test_papers as $val) { $sql = "SELECT etp_id FROM rd_exam_test_paper\n WHERE exam_pid = {$val['exam_pid']} AND exam_id = {$val['exam_id']}\n AND uid = {$val['uid']} AND paper_id = {$val['paper_id']}\n AND place_id = {$val['place_id']} AND subject_id = {$val['subject_id']} "; $res1 = $db->fetchRow($sql); if (isset($res1['etp_id']) && $res1['etp_id'] > 0) { $res = $db->update('rd_exam_test_paper', $val, 'etp_id = ' . $res1['etp_id']); $etp_id = $res1['etp_id']; } else { $res = $db->insert('rd_exam_test_paper', $val); //添加试卷试题 $etp_id = $db->lastInsertId('rd_exam_test_paper', 'etp_id'); } if ($etp_id) { $etp_id_where = "etp_id = {$etp_id}"; $db->delete('rd_exam_test_paper_question', $etp_id_where); $sql = "SELECT q.ques_id,q.type\n FROM rd_exam_question eq\n LEFT JOIN rd_question q ON eq.ques_id=q.ques_id\n LEFT JOIN rd_relate_class rc ON rc.ques_id=q.ques_id AND rc.grade_id={$grade_id}\n AND rc.class_id={$class_id} WHERE eq.paper_id={$val['paper_id']}\n ORDER BY rc.difficulty DESC,q.ques_id ASC"; $result = $db->fetchAll($sql); if ($val['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'); } $paper_array = array(); foreach ($types as $type) { foreach ($result as $key => $row) { if ($row['type'] != $type) { continue; } $paper_array[] = $row['ques_id']; unset($result[$key]); } } $ques_ids = implode(',', $paper_array); $res = $db->insert('rd_exam_test_paper_question', array('etp_id' => $etp_id, 'ques_id' => $ques_ids)); } if (!$res) { break; } } if ($is_trans && $res) { $res = $db->commit(); if (!$res) { $db->rollBack(); } } else { if ($is_trans && !$res) { $db->rollBack(); return false; } } return $res; }
/** * 添加试卷试题--搜索试题 * * @param int $paper_id 试卷id * @param int $qtype 题型 * @param int $start_difficulty 难易度 * @param int $end_difficulty 难易度 * @param int $keyword 关键字 * @param int $que_id 试题ID * @param int $page 分页 * @return void */ public function search() { if (!$this->check_power('exam_list,exam_manage')) { return; } $result = array('error' => '', 'list' => array()); $paper_id = intval($this->input->post('paper_id')); $qtype = intval($this->input->post('qtype')); $start_difficulty = intval($this->input->post('start_difficulty')); $end_difficulty = intval($this->input->post('end_difficulty')); $keyword = trim($this->input->post('keyword')); $que_id = intval($this->input->post('que_id')); $page = intval($this->input->post('page')); $is_original = intval($this->input->post('is_original')); $page = $page < 1 ? 1 : $page; $size = 15; $offset = ($page - 1) * $size; $result['next_page'] = $page + 1; $result['prev_page'] = $page > 1 ? $page - 1 : ''; $query = $this->db->select('exam_id')->get_where('exam_paper', array('paper_id' => $paper_id), 1); $paper = $query->row_array(); if (empty($paper)) { $result['error'] = '试卷不存在'; die(json_encode($result)); } $exam = ExamModel::get_exam($paper['exam_id'], 'subject_id,grade_id,class_id'); if (empty($exam)) { $result['error'] = '考试不存在'; die(json_encode($result)); } //根据试题ID搜索时,其他附带条件都作废 if ($que_id > 0) { $where[] = "q.ques_id = {$que_id}"; } else { $where[] = "q.is_delete<>1 AND q.parent_id=0"; $where[] = "q.type={$qtype}"; $where[] = "q.subject_id={$exam['subject_id']}"; if ($is_original > 0) { $where[] = "q.is_original = {$is_original}"; } if ($start_difficulty && $end_difficulty) { $where[] = "rc.difficulty BETWEEN {$start_difficulty} AND {$end_difficulty}"; } elseif ($start_difficulty) { $where[] = "rc.difficulty >= {$start_difficulty}"; } elseif ($end_difficulty) { $where[] = "rc.difficulty <= {$end_difficulty}"; } // 排除原试题 $where[] = "q.ques_id NOT IN (SELECT ques_id FROM {pre}exam_question WHERE paper_id={$paper_id})"; // 排除原分组 $where[] = "q.group_id NOT IN (SELECT group_id FROM {pre}exam_question eq,{pre}question q WHERE eq.ques_id=q.ques_id AND q.group_id>0)"; //搜索关键字 if ($keyword != '') { $where[] = "(q.title like '%{$keyword}%')"; } } $sql = "SELECT q.ques_id,q.group_id,q.title,rc.difficulty FROM {pre}question q\n RIGHT 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 " . implode(' AND ', $where) . " ORDER BY q.ques_id DESC LIMIT {$offset}, {$size}"; $query = $this->db->query($sql); foreach ($query->result_array() as $row) { $title = mb_substr($row['title'], 0, 300); if ($keyword != '') { $title = str_ireplace($keyword, "<font color='red'>{$keyword}</font>", $title); } $row['title'] = $title; $result['list'][] = $row; } die(json_encode($result)); }
public function getallscore($eid) { $field = array('choosescore', 'judgescore', 'fillscore', 'prgans', 'prgfill', 'programscore'); $allScore = ExamModel::instance()->getExamInfoById($eid, $field); return $allScore; }
/** * 检查学生是否在考试期次中 */ private function _check_exam_student_list(array &$student) { $exam_pid = $this->session->userdata('reg_student_exam_pid'); if ($exam_pid > 0) { $exam = ExamModel::get_exam_select($exam_pid); if (empty($exam)) { message('考试期次不存在', '/'); } if ($exam['status'] != 1) { message('该考试期次还没有启动报名', '/'); } $student_name = $student['last_name'] . $student['first_name']; $student_ticket = trim($student['external_account']); //判断是否存在考试期次 $uid = $this->session->userdata('uid'); if (!$uid) { $row = $this->db->get_where('exam_student_list', array('exam_pid' => $exam_pid, 'student_name' => $student_name, 'student_ticket' => $student_ticket))->row_array(); if (!$row) { message('你不在此次考试期次中,无法报名!'); } if ($row['uid'] > 0 && $this->db->select('uid')->get_where('student', array('uid' => $row['uid']))->row_array()) { message('您已报名该考试了,无需重复报名!'); } } } }
/** * 设置MINI测配置 */ public function save_config() { $dec_id = intval($this->input->post('dec_id')); $dec_name = trim($this->input->post('dec_name')); $grade_id = intval($this->input->post('grade_id')); $exam_pid = intval($this->input->post('exam_pid')); if (empty($dec_name)) { message('名称不能为空'); } if ($grade_id < 1 || $grade_id > 12) { message('年级不合法'); } if ($exam_pid < 1) { message('考试期次不存在'); } $config = DemoConfigModel::get_demo_config($dec_id); if ($config && $config['dec_grade_id'] == $grade_id && $config['dec_exam_pid'] == $exam_pid) { } else { if ($config && $config['dec_grade_id'] == $grade_id && $config['dec_exam_pid'] != $exam_pid) { $param = array('exam_pid' => $exam_pid); if (DemoConfigModel::check_config_exist($param)) { message('考试期次已经在配置中设置过了'); } } else { if ($config && $config['dec_grade_id'] != $grade_id && $config['dec_exam_pid'] == $exam_pid) { $param = array('grade_id' => $grade_id); if (DemoConfigModel::check_config_exist($param)) { message('年级已经在配置中设置过了'); } } else { $param = array('grade_id' => $grade_id, 'exam_pid' => $exam_pid); if (DemoConfigModel::check_config_exist($param)) { message('年级或考试期次已经在配置中设置过了'); } } } } $exam = ExamModel::get_exam($exam_pid); if (empty($exam)) { message('考试期次不存在'); } if ($exam['grade_id'] != $grade_id) { message('考试期次与所选的年级不匹配'); } $exam_subject = DemoConfigModel::get_parent_exam($exam_pid); if (empty($exam_subject)) { message('该考试期次未设置考试学科'); } $subject = C('subject'); $subject_name = array(); foreach ($exam_subject as $item) { $exam_paper = $this->db->get_where("exam_subject_paper", array('exam_id' => $item['exam_id']))->row_array(); if (empty($exam_paper)) { $subject_name[] = $subject[$item['subject_id']]; } } if ($subject_name) { message("该考试期次中【" . implode("、", $subject_name) . "】学科未分配试卷"); } $place = ExamPlaceModel::get_exam_place_list(array('exam_pid' => $exam_pid)); if (empty($place)) { message('该考试期次未设置考场'); } /* $this->load->model('admin/exam_place_subject_model'); $place_subject = $this->exam_place_subject_model->get_exam_place_subject_list(array('place_id'=>$place[0]['place_id'])); if (empty($place_subject)) { message('该考试期次考场未添加考试学科'); } */ $data = array('dec_name' => $dec_name, 'dec_grade_id' => $grade_id, 'dec_exam_pid' => $exam_pid, 'place_id' => $place[0]['place_id']); if ($dec_id > 0) { $res = DemoConfigModel::update($data, $dec_id); admin_log('edit', 'demo_exam_config', $dec_id); } else { $res = DemoConfigModel::add($data); admin_log('add', 'demo_exam_config', $this->db->insert_id()); } if ($res) { $this->load->model('cron/summary_paper_model'); $this->summary_paper_model->do_all($exam_pid); } DemoConfigModel::update_cache(); $back_url = "/admin/demo_config/index"; message('MINI测' . ($dec_id ? '修改' : '添加') . ($res ? '成功' : '失败'), $back_url); }
/** * 更新页面 * * @return void */ public function update($id) { if (!is_numeric($id)) { message('参数错误!', 'admin/evaluation_standard/index'); } $data = array(); $data['row'] = EvaluationStandardModel::get_one($id); if (!$data['row']) { message('评分标准不存在!', 'admin/evaluation_standard/index'); } $data['row']['subject_id'] = explode(',', $data['row']['subject_id']); $data['row']['weight'] = json_decode($data['row']['weight'], true); $data['row']['level'] = json_decode($data['row']['level'], true); /** 评分项信息 */ $option_ids = json_decode($data['row']['options'], true); if ($option_ids) { foreach ($option_ids as $subject_id => $value) { foreach ($value as $option_id) { $data['options'][$subject_id][] = EvaluationOptionModel::get_one($option_id, 'id,title'); } } } else { $data['options'] = array(); } /** 考试期次信息 */ $data['exams'] = array(); $exam_ids = EvaluationStandardExamModel::get_exam_by_standard($data['row']['id']); if (count($exam_ids) >= 1) { foreach ($exam_ids as $key => $value) { $data['exams'][] = ExamModel::get_exam($value['exam_id'], 'exam_id,exam_name'); } } $data['subject'] = C('subject'); $this->load->view('interview/evaluation_standard_update', $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)); }
public function import_save() { $post = $this->input->post(); $subject_id = $this->input->post('subject_id'); if (!Validate::isInt($subject_id)) { message('请选择导入成绩的学科'); } $exam_id = $this->input->post('exam_id'); $exam = ExamModel::get_exam($exam_id, 'exam_pid, exam_ticket_maprule'); if (!$exam || $exam['exam_pid']) { message('考试期次不存在,无法导入学生成绩!'); } $exam_ticket_maprule = $exam['exam_ticket_maprule']; /* 上传文件 */ $config['upload_path'] = '../../cache/excel/'; $config['allowed_types'] = '*'; $config['max_size'] = 1024 * 10; // 位kb $config['overwrite'] = false; $this->load->library('upload', $config); if (!$this->upload->do_upload('file')) { echo "传入参数不正确"; die; } else { /* 实时输出导入结果 */ ob_end_flush(); set_time_limit(0); $start_time = microtime(true); $upload_data = $this->upload->data(); /* 读取excel */ $this->load->library('PHPExcel'); $this->load->library('PHPExcel/IOFactory'); $inputFileType = IOFactory::identify($upload_data['file_relative_path']); $objReader = IOFactory::createReader($inputFileType); $objPHPExcel = $objReader->load($upload_data['file_relative_path']); $data = $objPHPExcel->getSheet(0)->toArray(); @unlink($upload_data['file_relative_path']); $db = Fn::db(); $bok = false; $start_time = microtime(true); if ($db->beginTransaction()) { $sql = "CREATE TABLE IF NOT EXISTS tmp_table9700 (\n \t\tv int(10) NOT NULL,\n \t\tk text NOT NULL,\n \t\t\ts tinyint NOT NULL default 0,\n \t\tplace_id int(10) NOT NULL,\n subject_id int(10) NOT NULL,\n \t\tuid int(10) NOT NULL default 0)\n "; $db->query($sql); $sql = "SELECT place_name, place_id \n FROM rd_exam_place\n WHERE exam_pid = {$exam_id}"; $place_ids = $db->fetchPairs($sql); $table_header = array(); //表头信息 $insert_header = array(); //已插入表头的考场 foreach ($data as $key => $value) { if ($key > 3) { $place_name = trim($value[4]); $place_id = $place_ids[$place_name]; if (!$place_id) { echo "未查询到当前考场信息,在第" . ($key + 1) . "行:" . $place_name . '<br/>'; continue; } //插入每个考场的表头信息 if (!in_array($place_id, $insert_header)) { $insert_header[] = $place_id; foreach ($table_header as $bind) { $bind['place_id'] = $place_id; $db->replace('tmp_table9700', $bind); } } $student_ticket = exam_ticket_maprule_encode(str_replace("'", '', trim($value[0])), $exam_ticket_maprule); $sql = "SELECT s.uid FROM rd_student s\n LEFT JOIN rd_exam_place_student eps ON eps.uid = s.uid\n WHERE s.exam_ticket = '{$student_ticket}' \n AND eps.place_id='{$place_id}'"; $uid = $db->fetchOne($sql); if (!$uid) { echo "未查询到当前用户数据,在第" . ($key + 1) . "行:" . $value[1] . '<br/>'; continue; } $bind = array('v' => $key, 'k' => json_encode($value), 's' => 0, 'place_id' => $place_id, 'subject_id' => $subject_id, 'uid' => $uid); $db->replace('tmp_table9700', $bind); } else { if (in_array($key, array(1, 3))) { $table_header[] = array('v' => $key, 'k' => json_encode($value), 's' => 0, 'place_id' => '', 'subject_id' => $subject_id, 'uid' => 0); } } } $bok = $db->commit(); if (!$bok) { $db->rollBack(); } } $end_time = microtime(true); $execute_time = $end_time - $start_time; if (!empty($data)) { echo '文件载入成功!执行时间:' . sprintf('%.4f', $execute_time) . 's' . '<hr/>'; flush(); } $end_time = microtime(true); $execute_time = $end_time - $start_time; if ($bok) { echo '导入成功!用时:' . $execute_time . 's'; } else { echo '导入失败!用时:' . $execute_time . 's'; } flush(); } }
/** * 设置考试成绩同步状态 * @param int $er_examid 考试id * @param int $er_flag 同步状态 */ public static function setExamRelateFlag($er_examid, $er_zmoss_examid, $er_flag) { if (!Validate::isInt($er_examid) || $er_examid <= 0 || !Validate::isInt($er_zmoss_examid) || $er_zmoss_examid <= 0) { throw new Exception('请指定需要同步成绩的考试学科'); } $er_flag = intval($er_flag); if (!in_array($er_flag, array(0, 1, 2, 3))) { throw new Exception('请设置合理的状态'); } if (!ExamModel::get_exam($er_examid, 'exam_pid')) { throw new Exception('请指定需要同步成绩的考试学科!'); } $db = Fn::db(); $sql = "SELECT COUNT(*) FROM t_exam_relate_question \n WHERE erq_examid = ? AND erq_zmoss_examid = ?"; if (!$db->fetchOne($sql, array($er_examid, $er_zmoss_examid))) { throw new Exception('当前考试学科还未设置试题对应关系,无法同步成绩!'); } return $db->update('t_exam_relate', array('er_flag' => $er_flag), 'er_examid = ? AND er_zmoss_examid = ?', array($er_examid, $er_zmoss_examid)); }
/** * 当前用户可以参与的考试期次 */ private function u_exam_list() { $exam_list = ExamModel::get_exam_list_all(array('exam_pid > ' => 0), 'exam_id, exam_name, subject_id, managers, creator_id'); $data = array(); $admin_id = $this->session->userdata('admin_id'); $is_super = self::is_super_user(); foreach ($exam_list as $item) { $managers = $item['managers']; $creator_id = $item['creator_id']; unset($item['managers']); unset($item['creator_id']); if ($is_super || $creator_id == $admin_id || $managers && in_array($admin_id, json_decode($managers, true))) { $data[] = $item; } } return $exam_list; }