本文整理汇总了PHP中external_api::contextrestriction方法的典型用法代码示例。如果您正苦于以下问题:PHP external_api::contextrestriction方法的具体用法?PHP external_api::contextrestriction怎么用?PHP external_api::contextrestriction使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类external_api
的用法示例。
在下文中一共展示了external_api::contextrestriction方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: validate_context
/**
* Makes sure user may execute functions in this context.
* @param object $context
* @return void
*/
protected static function validate_context($context)
{
global $CFG;
if (empty($context)) {
throw new invalid_parameter_exception('Context does not exist');
}
if (empty(self::$contextrestriction)) {
self::$contextrestriction = get_context_instance(CONTEXT_SYSTEM);
}
$rcontext = self::$contextrestriction;
if ($rcontext->contextlevel == $context->contextlevel) {
if ($rcontext->id != $context->id) {
throw new restricted_context_exception();
}
} else {
if ($rcontext->contextlevel > $context->contextlevel) {
throw new restricted_context_exception();
} else {
$parents = get_parent_contexts($context);
if (!in_array($rcontext->id, $parents)) {
throw new restricted_context_exception();
}
}
}
if ($context->contextlevel >= CONTEXT_COURSE) {
list($context, $course, $cm) = get_context_info_array($context->id);
require_login($course, false, $cm, false, true);
}
}
示例2: validate_context
/**
* Makes sure user may execute functions in this context.
*
* @param stdClass $context
* @since Moodle 2.0
*/
public static function validate_context($context)
{
global $CFG, $PAGE;
if (empty($context)) {
throw new invalid_parameter_exception('Context does not exist');
}
if (empty(self::$contextrestriction)) {
self::$contextrestriction = context_system::instance();
}
$rcontext = self::$contextrestriction;
if ($rcontext->contextlevel == $context->contextlevel) {
if ($rcontext->id != $context->id) {
throw new restricted_context_exception();
}
} else {
if ($rcontext->contextlevel > $context->contextlevel) {
throw new restricted_context_exception();
} else {
$parents = $context->get_parent_context_ids();
if (!in_array($rcontext->id, $parents)) {
throw new restricted_context_exception();
}
}
}
$PAGE->reset_theme_and_output();
list($unused, $course, $cm) = get_context_info_array($context->id);
require_login($course, false, $cm, false, true);
$PAGE->set_context($context);
}
示例3: set_context_restriction
/**
* Set context restriction for all following subsequent function calls.
* @param stdClass $contex
* @return void
*/
public static function set_context_restriction($context)
{
self::$contextrestriction = $context;
}