本文整理汇总了PHP中context::get_parent_context_ids方法的典型用法代码示例。如果您正苦于以下问题:PHP context::get_parent_context_ids方法的具体用法?PHP context::get_parent_context_ids怎么用?PHP context::get_parent_context_ids使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类context
的用法示例。
在下文中一共展示了context::get_parent_context_ids方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: get_related_contexts_string
/**
* Gets a string for sql calls, searching for stuff in this context or above
*
* NOTE: use $DB->get_in_or_equal($context->get_parent_context_ids()...
*
* @deprecated since 2.2, $context->use get_parent_context_ids() instead
* @param context $context
* @return string
*/
function get_related_contexts_string(context $context)
{
if ($parents = $context->get_parent_context_ids()) {
return ' IN (' . $context->id . ',' . implode(',', $parents) . ')';
} else {
return ' =' . $context->id;
}
}
示例2: get_related_contexts_string
/**
* Gets a string for sql calls, searching for stuff in this context or above.
*
* @deprecated since 2.2
* @see context::get_parent_context_ids()
* @param context $context
* @return string
*/
function get_related_contexts_string(context $context)
{
debugging('get_related_contexts_string() is deprecated, please use $context->get_parent_context_ids(true) instead.', DEBUG_DEVELOPER);
if ($parents = $context->get_parent_context_ids()) {
return ' IN (' . $context->id . ',' . implode(',', $parents) . ')';
} else {
return ' =' . $context->id;
}
}
示例3: count_role_users
/**
* Counts all the users assigned this role in this context or higher
*
* @param int|array $roleid either int or an array of ints
* @param context $context
* @param bool $parent if true, get list of users assigned in higher context too
* @return int Returns the result count
*/
function count_role_users($roleid, context $context, $parent = false) {
global $DB;
if ($parent) {
if ($contexts = $context->get_parent_context_ids()) {
$parentcontexts = ' OR r.contextid IN ('.implode(',', $contexts).')';
} else {
$parentcontexts = '';
}
} else {
$parentcontexts = '';
}
if ($roleid) {
list($rids, $params) = $DB->get_in_or_equal($roleid, SQL_PARAMS_QM);
$roleselect = "AND r.roleid $rids";
} else {
$params = array();
$roleselect = '';
}
array_unshift($params, $context->id);
$sql = "SELECT COUNT(u.id)
FROM {role_assignments} r
JOIN {user} u ON u.id = r.userid
WHERE (r.contextid = ? $parentcontexts)
$roleselect
AND u.deleted = 0";
return $DB->count_records_sql($sql, $params);
}
示例4: meditraxcohort_can_view_cohort
/**
* Check if cohort exists and user is allowed to access it from the given context.
*
* @param stdClass|int $cohortorid cohort object or id
* @param context $currentcontext current context (course) where visibility is checked
* @return boolean
*/
function meditraxcohort_can_view_cohort($cohortorid, $currentcontext)
{
global $DB;
if (is_numeric($cohortorid)) {
$cohort = $DB->get_record('cohort', array('id' => $cohortorid), 'id, contextid, visible');
} else {
$cohort = $cohortorid;
}
if ($cohort && in_array($cohort->contextid, $currentcontext->get_parent_context_ids())) {
if ($cohort->visible) {
return true;
}
$cohortcontext = context::instance_by_id($cohort->contextid);
if (has_capability('moodle/cohort:view', $cohortcontext)) {
return true;
}
}
return false;
}