本文整理匯總了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;
}