本文整理汇总了PHP中context::cache_get方法的典型用法代码示例。如果您正苦于以下问题:PHP context::cache_get方法的具体用法?PHP context::cache_get怎么用?PHP context::cache_get使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类context
的用法示例。
在下文中一共展示了context::cache_get方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: get_from_record
public static function get_from_record($record)
{
if ($context = context::cache_get(CONTEXT_COURSE, $record->id)) {
return $context;
}
$context = new context_course($record);
context::cache_add($context);
return $context;
}
示例2: instance
/**
* Returns block context instance.
*
* @static
* @param int $instanceid
* @param int $strictness
* @return context_block context instance
*/
public static function instance($instanceid, $strictness = MUST_EXIST)
{
global $DB;
if ($context = context::cache_get(CONTEXT_BLOCK, $instanceid)) {
return $context;
}
if (!($record = $DB->get_record('context', array('contextlevel' => CONTEXT_BLOCK, 'instanceid' => $instanceid)))) {
if ($bi = $DB->get_record('block_instances', array('id' => $instanceid), 'id,parentcontextid', $strictness)) {
$parentcontext = context::instance_by_id($bi->parentcontextid);
$record = context::insert_context_record(CONTEXT_BLOCK, $bi->id, $parentcontext->path);
}
}
if ($record) {
$context = new context_block($record);
context::cache_add($context);
return $context;
}
return false;
}
示例3: instance
/**
* Returns costcenter context instance.
*
* @static
* @param int $instanceid
* @param int $strictness
* @return context_costcenter context instance
*/
public static function instance($instanceid, $strictness = MUST_EXIST) {
global $DB;
if ($context = context::cache_get(CONTEXT_COSTCENTER, $instanceid)) {
return $context;
}
if (!$record = $DB->get_record('context', array('contextlevel' => CONTEXT_COSTCENTER, 'instanceid' => $instanceid))) {
if ($costcenter = $DB->get_record('local_costcenter', array('id' => $instanceid), 'id,parentid', $strictness)) {
if ($costcenter->parentid) {
$parentcontext = context_costcenter::instance($costcenter->parentid);
$record = context::insert_context_record(CONTEXT_COSTCENTER, $costcenter->id, $parentcontext->path);
} else {
$record = context::insert_context_record(CONTEXT_COSTCENTER, $costcenter->id, '/' . SYSCONTEXTID, 0);
}
}
}
if ($record) {
$context = new context_costcenter($record);
context::cache_add($context);
return $context;
}
return false;
}