public function search() { try { $this->_checkSession(); $search = isset($_POST['search']) ? trim($_POST['search']) : NULL; $this->_setView('search'); $results = new KnowledgeModel(); $results->setSearch($search); $foo = $results->searchValue(); $this->_view->set('vulnerabilities', $foo); $this->_view->set('title', 'Security Knowledge Framework:: Knowledge Base vulnerabilities'); return $this->_view->output(); } catch (Exception $e) { echo "Application error:" . $e->getMessage(); } }
public function edit($learnstyle_id = null) { if ($learnstyle_id) { $data['info'] = LearnStyleModel::learnStyleInfo($learnstyle_id); } else { $data['knowledge_list'] = KnowledgeModel::get_knowledge_children_list(14); $data['learnstyle_knowledgeids'] = LearnStyleModel::learnStyleKnowledgeid(); } $this->load->view('learn_style/edit', $data); }
public function edit($pr_id = null) { if ($pr_id) { $data['info'] = ProfessionRelatedModel::professionRelatedInfo($pr_id); } else { $data['knowledge_list'] = KnowledgeModel::get_knowledge_children_list(self::$pr_subjectid); $data['pr_knowledgeids'] = ProfessionRelatedModel::professionRelatedKnowledgeid(self::$pr_subjectid); } $data['profession'] = ProfessionModel::professionList(null, null, 1000); $this->load->view('vocational_aptitude/edit', $data); }
public function index($mode = '') { // 加载分类数据 $class_list = ClassModel::get_class_list(); //限制只能查看所属学科 $subjects = CpUserModel::get_allowed_subjects(); $grades = C('grades'); $qtypes = C('qtype'); $knowledge_list = KnowledgeModel::get_knowledge_list(); // 查询条件 $where = array(); $param = array(); $search = array(); $where[] = "q.parent_id=0"; // 过滤题组子题目,在题组页面管理 $mode = $mode == 'trash' ? 'trash' : ''; if ($mode == 'trash') { $where[] = "q.is_delete = 1"; } else { $where[] = "q.is_delete <> 1"; } /* 用户信息 */ $admin_info = $this->session->all_userdata(); if (empty($admin_info['admin_id'])) { message('获取管理员数据失败,请从新登陆后重试!'); } else { $where[] = "q.admin_id={$admin_info['admin_id']}"; $param[] = "admin_id={$admin_info['admin_id']}"; $search['admin_id'] = $admin_info['admin_id']; } // 操作时间 $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[] = "q.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[] = "q.addtime < {$etime}"; $param[] = "end_time={$end_time}"; } else { $search['end_time'] = ''; } // 分组 if ($search['group_id'] = intval($this->input->get('group_id'))) { $where[] = "q.group_id={$search['group_id']}"; $param[] = "group_id={$search['group_id']}"; } // 题型 $search['type'] = $this->input->get('qtype'); if (strlen($search['type']) > 0) { $search['type'] = intval($search['type']); $where[] = "q.type={$search['type']}"; $param[] = "qtype={$search['type']}"; } // 考试方式 $search['test_way'] = $this->input->get('test_way'); if (strlen($search['test_way']) > 0) { $search['test_way'] = intval($search['test_way']); $where[] = "q.test_way IN ({$search['test_way']}, 3)"; $param[] = "test_way={$search['test_way']}"; } // 审核 $search['check'] = $this->input->get('check'); if (strlen($search['check']) > 0) { $search['check'] = intval($search['check']); $where[] = "q.check={$search['check']}"; $param[] = "check={$search['check']}"; } if ($search['subject_id'] = intval($this->input->get('subject_id'))) { $where[] = "q.subject_id={$search['subject_id']}"; $param[] = "subject_id={$search['subject_id']}"; $knowledge_parents = KnowledgeModel::get_knowledge_list($search['subject_id'], 0); } //信息提取方式 if ($search['group_type_id'] = intval($this->input->get('group_type_id'))) { $where[] = "q.group_type LIKE '%," . $search['group_type_id'] . ",%'"; $param[] = "group_type_id=" . $search['group_type_id']; } if ($search['group_type_pid'] = intval($this->input->get('group_type_pid'))) { $param[] = "group_type_pid=" . $search['group_type_pid']; if (isset($group_type_list[$search['group_type_pid']]['childlist']) && !$search['group_type_id']) { $group_type = $group_type_list[$search['group_type_pid']]['childlist']; $tmp_str = ''; foreach ($group_type as $item) { if ($tmp_str) { $tmp_str .= " OR q.group_type LIKE '%," . $item['id'] . ",%'"; } else { $tmp_str .= "q.group_type LIKE '%," . $item['id'] . ",%'"; } } $where[] = "(" . $tmp_str . ")"; } } // 题目类型 $search['is_original'] = $this->input->get('is_original'); $search['exam_year'] = $this->input->get('exam_year'); $search['remark'] = $this->input->get('remark'); if ($search['is_original'] > 0) { $search['is_original'] = intval($search['is_original']); $where[] = "q.is_original={$search['is_original']}"; $param[] = "is_original={$search['is_original']}"; //真题年份 if ($search['is_original'] == 2 && strlen($search['exam_year']) > 0) { $search['exam_year'] = intval($search['exam_year']); $where[] = "q.exam_year='{$search['exam_year']}'"; $param[] = "exam_year={$search['exam_year']}"; } // 真题备注关键词 if ($search['is_original'] == 2 && strlen($search['remark']) > 0) { $search['remark'] = $search['remark']; $where[] = "q.remark like '%" . $search['remark'] . "%'"; $param[] = "remark={$search['remark']}"; } } //标签 if ($search['tags'] = $this->input->get('tags')) { $tmp_item = explode('-', $search['tags']); if (strlen($search['type']) > 0) { $where[] = "q.tags = " . $tmp_item[1]; $param[] = "tags=" . $search['tags']; } else { $where[] = "q.type = " . $tmp_item[0] . " AND q.tags = " . $tmp_item[1]; $param[] = "tags=" . $search['tags']; } } $where[] = "q.ques_id IN (SELECT DISTINCT ques_id FROM rd_relate_class) "; if ($search['subject_id_str'] = $this->input->get('subject_str')) { $param[] = implode('&subject_str[]=', $search['subject_id_str']); $search['subject_id_str'] = implode(',', $search['subject_id_str']); $where[] = "q.subject_id_str = '," . $search['subject_id_str'] . ",'"; } //-----------------------------------------// // 年级区间、试题类型、难易度区间、文理科 //-----------------------------------------// $search['start_grade'] = intval($this->input->get('start_grade')); $search['end_grade'] = intval($this->input->get('end_grade')); $search['class_id'] = $this->input->get('class_id'); $search['start_difficulty'] = floatval($this->input->get('start_difficulty')); $search['end_difficulty'] = floatval($this->input->get('end_difficulty')); $search['subject_type'] = trim($this->input->get('subject_type')); if (is_array($search['class_id'])) { $search['class_id'] = my_intval($search['class_id']); } else { $search['class_id'] = array(); } if ($search['class_id'] or $search['start_difficulty'] or $search['end_difficulty'] or is_numeric($search['subject_type'])) { $class_where = array(); if ($search['end_grade']) { $class_where[] = "grade_id BETWEEN {$search['start_grade']} AND {$search['end_grade']}"; } elseif ($search['start_grade']) { $class_where[] = "grade_id >= {$search['start_grade']}"; } if ($search['class_id']) { if (count($search['class_id']) == 1) { $class_where[] = "class_id='" . $search['class_id'][0] . "'"; } else { $class_where[] = "class_id IN (" . my_implode($search['class_id']) . ")"; } } //文理科 if (is_numeric($search['subject_type'])) { $class_where[] = "subject_type='" . $search['subject_type'] . "'"; } if ($search['end_difficulty']) { $class_where[] = "difficulty BETWEEN {$search['start_difficulty']} AND {$search['end_difficulty']}"; } elseif ($search['start_difficulty']) { $class_where[] = "difficulty >= {$search['start_difficulty']}"; } if ($class_where) { $where[] = "q.ques_id IN (SELECT DISTINCT ques_id FROM {pre}relate_class WHERE " . implode(' AND ', $class_where) . ")"; } } elseif ($search['start_grade'] && $search['end_grade']) { if ($search['start_grade'] <= $search['end_grade']) { $where[] = "q.start_grade <= {$search['end_grade']} AND q.end_grade>= {$search['start_grade']}"; } } elseif ($search['start_grade']) { $where[] = "q.start_grade <= {$search['start_grade']} AND q.end_grade>= {$search['start_grade']}"; } elseif ($search['end_grade']) { $where[] = "q.start_grade <= {$search['end_grade']} AND q.end_grade>= {$search['end_grade']}"; } // url参数 if ($search['start_grade']) { $param[] = "start_grade=" . $search['start_grade']; } else { $search['start_grade'] = ''; } if ($search['end_grade']) { $param[] = "end_grade=" . $search['end_grade']; } else { $search['end_grade'] = ''; } if ($search['class_id']) { $param[] = "class_id[]=" . implode('&class_id[]=', $search['class_id']); } if (is_numeric($search['subject_type'])) { $param[] = "subject_type=" . $search['subject_type']; } if ($search['start_difficulty']) { $param[] = "start_difficulty=" . $search['start_difficulty']; } else { $search['start_difficulty'] = ''; } if ($search['end_difficulty']) { $param[] = "end_difficulty=" . $search['end_difficulty']; } else { $search['end_difficulty'] = ''; } // 试题技能 $search['skill_id'] = $this->input->get('skill_id'); if ($search['skill_id'] && is_array($search['skill_id'])) { foreach ($search['skill_id'] as $sid) { $sid = intval($sid); $where[] = "q.skill LIKE '%,{$sid},%'"; $param[] = "skill_id[]={$sid}"; } } else { $search['skill_id'] = array(); } // 试题方法策略 $method_tactic_ids = trim($this->input->get('method_tactic_ids')); $method_tactic_arr = my_intval(explode(',', $method_tactic_ids)); $search['method_tactic_ids'] = implode(',', $method_tactic_arr); if ($search['method_tactic_ids']) { $param[] = "method_tactic_ids=" . $search['method_tactic_ids']; $where[] = "exists(select ques_id from {pre}relate_method_tactic rmt WHERE q.ques_id=rmt.ques_id AND rmt.method_tactic_id IN ({$search['method_tactic_ids']}) and rmt.is_child=0)"; } // 试题知识点 $knowledge_ids = trim($this->input->get('knowledge_ids')); $knowledge_arr = my_intval(explode(',', $knowledge_ids)); $search['knowledge_ids'] = implode(',', $knowledge_arr); $know_processes = $this->input->get('know_process'); $search['know_process'] = my_intval($know_processes); if ($search['knowledge_ids']) { $param[] = "knowledge_ids=" . $search['knowledge_ids']; if ($search['know_process']) { $tmp_know_process = implode(',', $search['know_process']); $param[] = "know_process[]=" . implode('&know_process[]=', $search['know_process']); $where[] = "exists(select ques_id from {pre}relate_knowledge rk WHERE q.ques_id=rk.ques_id AND rk.knowledge_id IN ({$search['knowledge_ids']}) AND rk.know_process IN ({$tmp_know_process}) AND rk.is_child=0)"; } else { $where[] = "exists(select ques_id from {pre}relate_knowledge rk WHERE q.ques_id=rk.ques_id AND rk.knowledge_id IN ({$search['knowledge_ids']}) AND rk.is_child=0)"; } } else { if ($search['know_process']) { $tmp_know_process = implode(',', $search['know_process']); $param[] = "know_process[]=" . implode('&know_process[]=', $search['know_process']); $where[] = "exists(select ques_id from {pre}relate_knowledge rk WHERE q.ques_id=rk.ques_id AND rk.know_process IN ({$tmp_know_process}) AND rk.is_child=0)"; } } if ($search['keyword'] = trim($this->input->get('keyword'))) { $escape_keyword = $this->db->escape_like_str($search['keyword']); $where[] = "q.title LIKE '%" . $escape_keyword . "%'"; $param[] = "keyword=" . urlencode($search['keyword']); } if ($ques_id = intval($this->input->get('ques_id'))) { $search['ques_id'] = $ques_id; $where[] = "q.ques_id={$ques_id}"; $param[] = "ques_id={$ques_id}"; } $where = $where ? ' WHERE ' . implode(' AND ', $where) : ' 1 '; //echo $where; // 统计数量 $nums = QuestionModel::get_question_nums($where); $total = $nums['total']; // 读取数据 $size = 15; $page = isset($_GET['page']) && intval($_GET['page']) > 1 ? intval($_GET['page']) : 1; $offset = ($page - 1) * $size; $list = array(); 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_cids = explode(',', trim($row['class_id'], ',')); $row_cname = array(); foreach ($row_cids as $cid) { $row_cname[] = isset($class_list[$cid]['class_name']) ? $class_list[$cid]['class_name'] : ''; } if ($row['exam_year'] == 0) { $row['exam_year'] = ''; } if ($row['related'] == 0) { $row['related'] = ''; } $row['class_name'] = implode(',', $row_cname); $row['qtype'] = isset($qtypes[$row['type']]) ? $qtypes[$row['type']] : ''; $row['start_grade'] = isset($grades[$row['start_grade']]) ? $grades[$row['start_grade']] : ''; $row['end_grade'] = isset($grades[$row['end_grade']]) ? $grades[$row['end_grade']] : ''; $row['subject_name'] = isset($subjects[$row['subject_id']]) ? $subjects[$row['subject_id']] : ''; $row['addtime'] = date('Y-m-d H:i', $row['addtime']); //判断该试题已经被考试过 或 正在被考 $row['be_tested'] = QuestionModel::question_has_test_action($row['ques_id']); //判断试题已经被考过 $row['be_tested_1'] = QuestionModel::question_has_be_tested($row['ques_id']); $row['has_edit_power'] = true; /* * 检查是否有关联信息 * 非题组:关联技能 * 题组:题干关联技能、知识点,子题必须要全部添加知识点 */ $no_relate_info = false; $q_type = $row['type']; if ($q_type > 0) { //非题组 $no_relate_info = $row['skill'] == ''; } else { //题组 //判断是否所有子题都已添加知识点 $tmp_ques_id = $row['ques_id']; $child_questions = $this->db->query("select count(*) as `count` from {pre}question where parent_id={$tmp_ques_id}")->row_array(); $count_child = $child_questions['count']; $child_count_result = $this->db->query("select count(*) as `count` from {pre}question where parent_id={$tmp_ques_id} and knowledge != ''")->row_array(); $tmp_count = $child_count_result['count']; if ($count_child == $tmp_count && $row['skill'] == '' && $row['knowledge'] == '') { $no_relate_info = true; } } $row['no_relate_info'] = $no_relate_info; //获取回收站信息 if ($mode == 'trash') { $recycle = RecycleModel::get_recycle_list(array('type' => RECYCLE_QUESTION, 'obj_id' => $row['ques_id']), null, null, 'ctime asc'); $row['recycle'] = $recycle; } else { $row['recycle'] = array(); } $list[] = $row; } } $data['list'] =& $list; // 分页 $purl = site_url('admin/question_external/index/' . $mode) . ($param ? '?' . implode('&', $param) : ''); $data['pagination'] = multipage($total, $size, $page, $purl, '', $nums['relate_num']); if ($search['group_id'] && $list) { $row = array_pop($list); $data['relate_ques_id'] = $row['ques_id']; } $data['mode'] = $mode; $data['search'] = $search; $data['grades'] = $grades; $data['subjects'] = $subjects; $data['qtypes'] = $qtypes; $data['q_tags'] = C('q_tags'); $data['class_list'] = $class_list; $data['all_grade_class'] = ClassModel::all_grade_class(); $data['relate_class'] = array(); $data['knowledge_list'] = $knowledge_list; $data['priv_delete'] = true; $data['priv_trash'] = true; $data['priv_manage'] = true; $query = $this->db->select('admin_id,admin_user,realname')->get_where('admin', array('is_delete' => 0)); $data['admin_list'] = $query->result_array(); //文理科 $data['subject_types'] = C('subject_type'); $data['all_subjects'] = C('subject'); //认知过程 $data['know_processes'] = C('know_process'); $data['is_english_admin'] = true; // 模版 $this->load->view('question_external/index', $data); }
public function question_count() { $result = array('error' => '', 'count' => array(), 'group_count' => array()); $type = intval($this->input->post('type')); $subject_id = intval($this->input->post('subject_id')); $grade_id = intval($this->input->post('grade_id')); $class_id = intval($this->input->post('class_id')); $subject_type = intval($this->input->post('subject_type')); $is_original = intval($this->input->post('is_original')); if (empty($subject_id) || empty($grade_id) || empty($class_id)) { $result['error'] = '请选择学科、年级、类型'; die(json_encode($result)); } if ($grade_id < 11 || $subject_id > 3 || !in_array($class_id, array(2, 3))) { $subject_type = '-1'; } // 范围知识点 $knowledge_ids = trim($this->input->post('knowledge_ids')); $knowledge_ids = explode(',', $knowledge_ids); $knowledge_id_arr = array(); foreach ($knowledge_ids as $id) { $id = intval($id); $id && array_push($knowledge_id_arr, $id); } if ($type > 0 && empty($knowledge_id_arr)) { $result['error'] = '请选择知识点范围'; die(json_encode($result)); } // 重点知识点 $rule_knowledge = intval($this->input->post('rule_knowledge')); $children_ids = array(); if ($type == 2) { if ($rule_knowledge) { $pid = KnowledgeModel::get_knowledge($rule_knowledge, 'pid'); if ($pid === false) { $rule_knowledge = 0; } else { if ($pid == 0) { // 一级知识点 $children = KnowledgeModel::get_knowledge_list(0, $rule_knowledge, 0); foreach ($knowledge_id_arr as $kid) { if (isset($children[$kid])) { $children_ids[] = $kid; } } } else { // 二级知识点 if (!in_array($rule_knowledge, $knowledge_id_arr)) { $rule_knowledge = 0; } } } } if (empty($rule_knowledge)) { $result['error'] = '请选择重点知识点'; die(json_encode($result)); } } $where = array(); $where[] = "q.is_delete<>1 AND q.parent_id=0"; $where[] = "q.subject_id={$subject_id}"; $where[] = "q.start_grade<={$grade_id} AND q.end_grade>={$grade_id}"; $where[] = "q.ques_id IN (SELECT distinct ques_id FROM {pre}relate_class \n\t\t WHERE grade_id={$grade_id} AND class_id={$class_id} AND subject_type={$subject_type})"; if ($is_original > 0) { $where[] = "q.is_original={$is_original}"; } //认知过程 $know_process = intval($this->input->post('know_process')); //die(json_encode( $know_process)); $know_process_sql = !$know_process ? '' : "and know_process={$know_process}"; if ($type) { // 范围知识点 $knowledge_id_arr // $except_ids = array(); // $query = $this->db->select('id')->get_where('knowledge', array('subject_id'=>$subject_id,'pid >'=>'0')); // foreach ($query->result_array() as $row) // { // if ( !in_array($row['id'], $knowledge_id_arr)) // $except_ids[] = $row['id']; // } if ($type == 2) { if ($children_ids) { $where[] = "q.ques_id IN (SELECT ques_id FROM {pre}relate_knowledge \n where knowledge_id IN(" . my_implode($children_ids) . ") {$know_process_sql} and is_child=0)"; } else { $where[] = "q.ques_id IN (SELECT ques_id FROM {pre}relate_knowledge \n where knowledge_id={$rule_knowledge} {$know_process_sql} and is_child=0)"; } } else { $where[] = "q.ques_id IN (SELECT ques_id FROM {pre}relate_knowledge \n where knowledge_id IN(" . implode(',', $knowledge_id_arr) . ") {$know_process_sql} and is_child=0)"; } // if ($except_ids) // { // $where[] = "q.ques_id NOT IN (SELECT ques_id FROM {pre}relate_knowledge // where knowledge_id IN(".implode(',', $except_ids).") {$know_process_sql} and is_child=0)"; // } } if ($type < 2) { // 总数量 $sql = "SELECT COUNT(ques_id) nums FROM {pre}question q WHERE " . implode(' AND ', $where); $query = $this->db->query($sql); $row = $query->row_array(); $result['count'][0] = $row['nums']; //--------------------------------------------// // 统计关联试题数 // = 无分组试题数 + 分组数量 //--------------------------------------------// $result['group_count'][0] = 0; // 独立试题数(无分组) $sql2 = "SELECT COUNT(q.ques_id) nums FROM {pre}question q \n WHERE " . implode(' AND ', $where) . " AND q.group_id=0"; $query = $this->db->query($sql2); foreach ($query->result_array() as $row) { $result['group_count'][0] = $row['nums']; } // 不同分组数 $sql2 = "SELECT COUNT(distinct q.group_id) nums FROM {pre}question q \n WHERE " . implode(' AND ', $where) . " AND q.group_id>0"; $query = $this->db->query($sql2); foreach ($query->result_array() as $row) { $result['group_count'][0] += $row['nums']; } die(json_encode($result)); } // 重点知识点统计:按题型、难易度区间分组 $areas = C('difficulty_area'); if ($subject_id == 3) { $result['count'] = array(0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0); $result['group_count'] = array(0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0); } else { $result['count'] = array(0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0); $result['group_count'] = array(0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0); } foreach ($areas as $k => $area) { $new_where = $where; $new_where[] = "qd.difficulty between {$area['0']} AND {$area['1']}"; $sql = "SELECT q.type, COUNT(q.ques_id) nums FROM {pre}question q \n LEFT JOIN {pre}relate_class qd ON q.ques_id=qd.ques_id AND qd.grade_id={$grade_id} AND qd.class_id={$class_id}\n WHERE " . implode(' AND ', $new_where) . " GROUP BY q.type"; //echo $sql ;die; $query = $this->db->query($sql); foreach ($query->result_array() as $row) { if ($row['type'] > 9) { continue; } $result['count'][$row['type'] * 3 + $k] = $row['nums']; } // 独立试题数 $sql2 = "SELECT q.type,COUNT(q.ques_id) nums FROM {pre}question q \n LEFT JOIN {pre}relate_class qd ON q.ques_id=qd.ques_id AND qd.grade_id={$grade_id} AND qd.class_id={$class_id}\n WHERE " . implode(' AND ', $new_where) . " AND q.group_id=0 GROUP BY q.type"; $query = $this->db->query($sql2); foreach ($query->result_array() as $row) { if ($row['type'] > 9) { continue; } $result['group_count'][$row['type'] * 3 + $k] = $row['nums']; } // 分组试题数 $sql2 = "SELECT q.type, COUNT(distinct q.group_id) nums FROM {pre}question q \n LEFT JOIN {pre}relate_class qd ON q.ques_id=qd.ques_id AND qd.grade_id={$grade_id} AND qd.class_id={$class_id}\n WHERE " . implode(' AND ', $new_where) . " AND q.group_id>0 GROUP BY q.type"; $query = $this->db->query($sql2); foreach ($query->result_array() as $row) { if ($row['type'] > 9) { continue; } $result['group_count'][$row['type'] * 3 + $k] += $row['nums']; } } // echo $this->db->last_query();die; die(json_encode($result)); }
private function _delete($id) { $id = intval($id); $item = KnowledgeModel::get_knowledge($id); if (empty($item)) { // 知识点不存在 return -1; } $query = $this->db->select('count(*) num')->get_where('knowledge', array('pid' => $id)); $row = $query->row_array(); if ($row['num']) { //该知识点还存在下级分类; return -2; } $query = $this->db->select('count(*) num')->get_where('relate_knowledge', array('knowledge_id' => $id, 'is_child' => 0)); $row = $query->row_array(); if ($row['num']) { //该知识点还存在关联试题; return -3; } /* if ( ! QuestionModel::check_subject_power($item['subject_id'], 'w', false)) { //没有权限 return -4; } */ try { $this->db->delete('knowledge', array('id' => $id)); admin_log('delete', 'knowledge', $id); } catch (Exception $e) { return FALSE; } return TRUE; }
/** * 生成试卷 * * @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 * array 试题信息 * @param * boolean 在试题不符合任何重点知识点规则的时候,是否强制加入 * @return boolean */ private static function reset_rule_ques_num(ExamPaperModelPrivateData &$this_data, $question, $force = FALSE) { $added = $force; // 修改待添加的重点知识点试题数量 $pids = array(); $offset = $question['type'] * 3 + ($question['difficulty'] <= 30 ? 0 : ($question['difficulty'] <= 60 ? 1 : 2)); if (!is_array($question['knowledge'])) { $question['knowledge'] = explode(',', trim($question['knowledge'], ',')); } foreach ($question['knowledge'] as $kid) { foreach ($this_data->sub_rules as &$val) { if ($val['knowledge_id'] == $kid && $val['nums'][$offset] > 0) { $val['nums'][$offset]--; $added = TRUE; } } // 如果存在一级重点知识点 $pid = KnowledgeModel::get_knowledge($kid, 'pid'); if (!isset($pids[$pid])) { foreach ($this_data->sub_rules as &$val) { if ($val['knowledge_id'] == $pid && $val['nums'][$offset] > 0) { $val['nums'][$offset]--; $pids[$pid] = $pid; $added = TRUE; } } } } if ($added) { self::insert_question($this_data, $question); } return $added; }
/** * 试卷试题列表未加入期次 * * @param int $paper_id 试卷id * @param int $qtype 题型 * @param int $method_tactic_id 方法策略 * @param int $kid 知识点 * @return void */ public function index3($paper_id = 0) { if (!$this->check_power('exam_list,exam_manage,paper_diy')) { return; } $paper_id = intval($paper_id); $paper = ExamPaperModel::get_paper($paper_id); if (!empty($paper['question_sort'])) { $paper = ExamPaperModel::detail_sg($paper_id, 1, 1); } $paper['ques_ids'] = json_decode($paper['question_sort'], true); $ques_ids_str = implode(',', $paper['ques_ids']); if (empty($paper)) { message('试卷不存在'); return; } /* * 考试期次 */ $exam = ExamModel::get_exam($paper['exam_id'], 'exam_pid,grade_id,class_id'); $search = $where = $param = array(); if (!empty($paper['question_sort'])) { $where[] = "1=1"; } $qtypes = C('qtype'); $qtype = $this->input->get('qtype'); if (strlen($qtype)) { $qtype = abs(intval($qtype)); $where['qtype'] = "q.type={$qtype}"; $param[] = "qtype={$qtype}"; } $search['qtype'] =& $qtype; /** is_original */ $is_original = $this->input->get('is_original'); if (in_array($is_original, array(1, 2))) { $where['is_original'] = "q.is_original={$is_original}"; $param[] = "is_original={$is_original}"; } $search['is_original'] =& $is_original; //方法逻辑 $method_tactic_id = intval($this->input->get('method_tactic_id')); if ($method_tactic_id) { $where['method_tactic_id'] = "q.ques_id IN (SELECT\n DISTINCT rmt.ques_id FROM {pre}relate_method_tactic rmt\n WHERE rmt.ques_id in({$ques_ids_str})\n AND rmt.method_tactic_id={$method_tactic_id})"; $param[] = "method_tactic_id={$method_tactic_id}"; } $search['method_tactic_id'] =& $method_tactic_id; //知识点 if ($kid = intval($this->input->get('kid'))) { $pkid = KnowledgeModel::get_knowledge($kid, 'pid'); if ($pkid !== false) { if ($pkid == 0) { // 一级知识点 $k_children = KnowledgeModel::get_knowledge_list(0, $kid, 0); $where['knowledge'] = "q.ques_id IN (\n SELECT DISTINCT rk.ques_id FROM {pre}relate_knowledge rk\n WHERE rk.ques_id in({$ques_ids_str}) AND rk.knowledge_id\n IN (" . my_implode(array_keys($k_children)) . ") AND rk.is_child=0)"; } else { // 二级知识点 if (!empty($paper['question_sort'])) { $where['knowledge'] = "q.ques_id IN (SELECT DISTINCT rk.ques_id FROM {pre}relate_knowledge\n rk WHERE rk.ques_id in({$ques_ids_str}) AND rk.knowledge_id={$kid} AND rk.is_child=0)"; } } $param[] = "kid={$kid}"; } } $search['kid'] =& $kid; /* 信息提取方式 */ if ($gid = intval($this->input->get('group_type_id'))) { $pgid = GroupTypeModel::get_group_type($gid, 'pid'); if ($pgid !== false) { if ($pgid == 0) { $g_children = GroupTypeModel::get_group_type_list($gid, 0); if (!empty($paper['question_sort'])) { $where['group_type'] = "q.ques_id IN ( SELECT DISTINCT\n rk.ques_id FROM {pre}relate_group_type rk WHERE\n rk.ques_id in({$ques_ids_str}) AND rk.group_type_id\n IN (" . my_implode(array_keys($g_children)) . ") AND rk.is_child=0)"; } } else { if (!empty($paper['question_sort'])) { $where['group_type'] = "q.ques_id IN (\n SELECT DISTINCT rk.ques_id FROM {pre}relate_group_type rk\n WHERE rk.ques_id in({$ques_ids_str})\n AND rk.group_type_id={$gid} AND rk.is_child=0)"; } } $param[] = "group_type_id={$gid}"; } } $search['group_type_id'] =& $gid; if (!empty($paper['question_sort'])) { $total = count($paper['question_sort']); } $size = 150; $page = isset($_GET['page']) && intval($_GET['page']) > 1 ? intval($_GET['page']) : 1; $offset = ($page - 1) * $size; $list = array(); if ($total) { $sql = "SELECT q.ques_id,q.title,q.type,q.group_id,q.addtime,\n (SELECT AVG(rc.difficulty) FROM {pre}relate_class rc where rc.ques_id=q.ques_id) AS difficulty\n FROM {pre}question q WHERE q.ques_id in({$ques_ids_str})\n AND " . implode(' AND ', $where) . " LIMIT {$offset},{$size}"; $res = $this->db->query($sql); foreach ($res->result_array() as $row) { $row['qtype'] = isset($qtypes[$row['type']]) ? $qtypes[$row['type']] : ''; $row['addtime'] = date('Y-m-d H:i', $row['addtime']); $row['has_edit_power'] = QuestionModel::check_question_power($row['ques_id'], 'w', false); $row['difficulty'] = round($row['difficulty'], 2); $list[] = $row; } } // 分页 $purl = site_url('admin/exam_question/index3/' . $paper_id . '/') . ($param ? '?' . implode('&', $param) : ''); $data['pagination'] = multipage($total, $size, $page, $purl); // 按题型分组统计数量 $qtype_nums = array(0, 0, 0, 0); foreach (explode(',', $paper['qtype_ques_num']) as $k => $v) { $qtype_nums[$k] = $v; } //判断该试题已经被考试过 或 正在被考 $paper['be_tested'] = false; if (!ExamModel::is_mini_test($exam['exam_pid'])) { $paper['be_tested'] = QuestionModel::paper_has_test_action($paper_id); } $data['search'] = $search; $data['qtypes'] = $qtypes; $data['paper'] = $paper; $data['list'] = $list; $data['qtype_nums'] = $qtype_nums; $data['priv_manage'] = $this->check_power('exam_manage', FALSE); /* 是否有权限查看试卷列表 */ $is_exam_paper_list = $this->check_power('exam_list', false); $data['is_exam_paper_list'] = $is_exam_paper_list; // 模版 $this->load->view('exam_question/index3', $data); }
public function edit($id = 0) { if (!$this->check_power('comparison_manage')) { return; } $id = intval($id); //$sql = "select * from rd_comparison_info where cmp_info_id=3"; //$res = mysql_query($sql, $this->db->conn_id); //pr(mysql_fetch_array($res)); $id && ($info_detail = ComparisonInfoModel::get_comparison_info_by_id($id)); if (empty($info_detail)) { message('信息不存在'); } $info_detail['cmp_extraction_ratio'] = json_decode($info_detail['cmp_extraction_ratio'], true); $type_detail = ComparisonTypeModel::get_comparison_type_by_id($info_detail['cmp_type_id']); //$this->load->library('Fn'); $db = Fn::db(); $res = $db->fetchCol('SELECT DISTINCT subject_id FROM rd_subject_category_subject'); $type_detail['subject_ids'] = $res; //$result = $this->db->query('SELECT group_concat(DISTINCT subject_id) as subject_ids FROM {pre}subject_category_subject')->row_array(); //$type_detail['subject_ids'] = explode(',', $result['subject_ids']); if (empty($type_detail)) { message('分类信息不存在'); } else { $type_detail['class_name'] = ClassModel::get_question_class_by_id($type_detail['class_id'], 'class_name'); $type_detail['grade_name'] = C('grades/' . $type_detail['grade_id']); $type_detail['subject_name'] = C('subject/' . $type_detail['subject_id']); } $items = ComparisonInfoModel::get_comparison_items($id, TRUE); $items2 = ComparisonInfoModel::get_comparison_items2($id, TRUE); //外部知识点与对比信息关系 $external_items = ComparisonInfoModel::get_comparison_items_external($id, TRUE); // 一级知识点 $knowledge_list = KnowledgeModel::get_knowledge_list($type_detail['subject_id'], 0, false); ksort($knowledge_list); //信息提取方式 $group_type_list = array(); if ($type_detail['subject_id'] == 3) { $group_type_list = GroupTypeModel::get_group_type_list(0, $type_detail['subject_id'], false); ksort($group_type_list); } //对比项《难易度》 $item_difficulties = ComparisonInfoModel::get_comparison_items_difficutly($id, TRUE); //对比项《外部题型 难易度》 $item_external_difficulties = ComparisonInfoModel::get_comparison_items_external_difficutly($id, TRUE); //方法策略 $method_tactic_list = SubjectCategoryModel::get_method_tactic_by_subject_id($type_detail['subject_id']); ksort($method_tactic_list); //对比项《方法策略》 $item_method_tactics = ComparisonInfoModel::get_comparison_items_method_tactic($id, TRUE); //对比项《外部方法策略》 $external_method_tactics = ComparisonInfoModel::get_comparison_items_external_method_tactic($id, TRUE); $data['act'] = 'edit'; $data['type_detail'] =& $type_detail; $data['info_detail'] =& $info_detail; $data['items'] =& $items; $data['items2'] =& $items2; $data['external_items'] =& $external_items; $data['knowledge_list'] =& $knowledge_list; $data['group_type_list'] =& $group_type_list; $data['item_difficulties'] =& $item_difficulties; $data['item_external_difficulties'] =& $item_external_difficulties; $data['method_tactic_list'] =& $method_tactic_list; $data['item_method_tactics'] =& $item_method_tactics; $data['external_method_tactics'] =& $external_method_tactics; $data['q_types'] = C('q_type'); //试题题型 $data['difficulty_types'] = array('2' => '高', '1' => '中', '0' => '低'); //试题题型 // 模版 $this->load->view('comparison_info/edit', $data); }