本文整理汇总了PHP中context::insert_context_record方法的典型用法代码示例。如果您正苦于以下问题:PHP context::insert_context_record方法的具体用法?PHP context::insert_context_record怎么用?PHP context::insert_context_record使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类context
的用法示例。
在下文中一共展示了context::insert_context_record方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: create_level_instances
/**
* Create missing context instances at block context level
* @static
*/
protected static function create_level_instances()
{
global $DB;
$sql = "SELECT " . CONTEXT_BLOCK . ", bi.id\n FROM {block_instances} bi\n WHERE NOT EXISTS (SELECT 'x'\n FROM {context} cx\n WHERE bi.id = cx.instanceid AND cx.contextlevel=" . CONTEXT_BLOCK . ")";
$contextdata = $DB->get_recordset_sql($sql);
foreach ($contextdata as $context) {
context::insert_context_record(CONTEXT_BLOCK, $context->id, null);
}
$contextdata->close();
}
示例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;
}