Example #1
0
 /**
  * 清除系统缓存
  */
 public function clean()
 {
     $this->load->driver('cache');
     $this->cache->file->clean();
     Fn::factory('File')->clear('/zmexam/');
     // $this->mc->flush();
     message('清除成功');
 }
Example #2
0
    /**
     * 一键更新试题缓存
     *
     * @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); */
    }