本文整理汇总了PHP中Fn::factory方法的典型用法代码示例。如果您正苦于以下问题:PHP Fn::factory方法的具体用法?PHP Fn::factory怎么用?PHP Fn::factory使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Fn
的用法示例。
在下文中一共展示了Fn::factory方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: clean
/**
* 清除系统缓存
*/
public function clean()
{
$this->load->driver('cache');
$this->cache->file->clean();
Fn::factory('File')->clear('/zmexam/');
// $this->mc->flush();
message('清除成功');
}
示例2: update_questions_cache
/**
* 一键更新试题缓存
*
* @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);
//.........这里部分代码省略.........