本文整理汇总了PHP中context::get_parent_context方法的典型用法代码示例。如果您正苦于以下问题:PHP context::get_parent_context方法的具体用法?PHP context::get_parent_context怎么用?PHP context::get_parent_context使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类context
的用法示例。
在下文中一共展示了context::get_parent_context方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: core_role_get_potential_user_selector
/**
* Get the potential assignees selector for a given context.
*
* If this context is a course context, or inside a course context (module or
* some blocks) then return a core_role_potential_assignees_below_course object. Otherwise
* return a core_role_potential_assignees_course_and_above.
*
* @param context $context a context.
* @param string $name passed to user selector constructor.
* @param array $options to user selector constructor.
* @return user_selector_base an appropriate user selector.
*/
function core_role_get_potential_user_selector(context $context, $name, $options)
{
$blockinsidecourse = false;
if ($context->contextlevel == CONTEXT_BLOCK) {
$parentcontext = $context->get_parent_context();
$blockinsidecourse = in_array($parentcontext->contextlevel, array(CONTEXT_MODULE, CONTEXT_COURSE));
}
if (($context->contextlevel == CONTEXT_MODULE || $blockinsidecourse) && !is_inside_frontpage($context)) {
$potentialuserselector = new core_role_potential_assignees_below_course('addselect', $options);
} else {
$potentialuserselector = new core_role_potential_assignees_course_and_above('addselect', $options);
}
return $potentialuserselector;
}
示例2: get_parent_contextid
/**
* Return the id of the parent of this context, or false if there is no parent (only happens if this
* is the site context.)
*
* @deprecated since 2.2, use $context->get_parent_context() instead
* @param context $context
* @return integer the id of the parent context.
*/
function get_parent_contextid(context $context)
{
if ($parent = $context->get_parent_context()) {
return $parent->id;
} else {
return false;
}
}
示例3:
/**
* Constructor
* @param context $context The context used for the capability check
* @param string $capability The required capability
* @param string $errormessage The error message to show the user
* @param string $stringfile
*/
function __construct($context, $capability, $errormessage, $stringfile)
{
$capabilityname = get_capability_string($capability);
if ($context->contextlevel == CONTEXT_MODULE and preg_match('/:view$/', $capability)) {
// we can not go to mod/xx/view.php because we most probably do not have cap to view it, let's go to course instead
$parentcontext = $context->get_parent_context();
$link = $parentcontext->get_url();
} else {
$link = $context->get_url();
}
parent::__construct($errormessage, $stringfile, $link, $capabilityname);
}
示例4: set_context
/**
* Set the main context to which this page belongs.
*
* @param context $context a context object. You normally get this with context_xxxx::instance().
*/
public function set_context($context)
{
if ($context === null) {
// Extremely ugly hack which sets context to some value in order to prevent warnings,
// use only for core error handling!!!!
if (!$this->_context) {
$this->_context = context_system::instance();
}
return;
}
// Ideally we should set context only once.
if (isset($this->_context) && $context->id !== $this->_context->id) {
$current = $this->_context->contextlevel;
if ($current == CONTEXT_SYSTEM or $current == CONTEXT_COURSE) {
// Hmm - not ideal, but it might produce too many warnings due to the design of require_login.
} else {
if ($current == CONTEXT_MODULE and $parentcontext = $context->get_parent_context() and $this->_context->id == $parentcontext->id) {
// Hmm - most probably somebody did require_login() and after that set the block context.
} else {
// We do not want devs to do weird switching of context levels on the fly because we might have used
// the context already such as in text filter in page title.
// This is explicitly allowed for webservices though which may
// call "external_api::validate_context on many contexts in a single request.
if (!WS_SERVER) {
debugging("Coding problem: unsupported modification of PAGE->context from {$current} to {$context->contextlevel}");
}
}
}
}
$this->_context = $context;
}
示例5: get_parent_contextid
/**
* Return the id of the parent of this context, or false if there is no parent (only happens if this
* is the site context.)
*
* @deprecated since Moodle 2.2
* @see context::get_parent_context()
* @param context $context
* @return integer the id of the parent context.
*/
function get_parent_contextid(context $context)
{
debugging('get_parent_contextid() is deprecated, please use $context->get_parent_context() instead.', DEBUG_DEVELOPER);
if ($parent = $context->get_parent_context()) {
return $parent->id;
} else {
return false;
}
}