mirror of
https://github.com/moodle/moodle.git
synced 2025-01-17 21:49:15 +01:00
MDL-40467 Libraries: deprecated get_role_context_caps()
This commit is contained in:
parent
a439b2f9b4
commit
ae38dcb1dc
@ -7294,50 +7294,6 @@ function get_sorted_contexts($select, $params = array()) {
|
||||
", $params);
|
||||
}
|
||||
|
||||
/**
|
||||
* This is really slow!!! do not use above course context level
|
||||
*
|
||||
* @deprecated since 2.2
|
||||
* @param int $roleid
|
||||
* @param context $context
|
||||
* @return array
|
||||
*/
|
||||
function get_role_context_caps($roleid, context $context) {
|
||||
global $DB;
|
||||
|
||||
//this is really slow!!!! - do not use above course context level!
|
||||
$result = array();
|
||||
$result[$context->id] = array();
|
||||
|
||||
// first emulate the parent context capabilities merging into context
|
||||
$searchcontexts = array_reverse($context->get_parent_context_ids(true));
|
||||
foreach ($searchcontexts as $cid) {
|
||||
if ($capabilities = $DB->get_records('role_capabilities', array('roleid'=>$roleid, 'contextid'=>$cid))) {
|
||||
foreach ($capabilities as $cap) {
|
||||
if (!array_key_exists($cap->capability, $result[$context->id])) {
|
||||
$result[$context->id][$cap->capability] = 0;
|
||||
}
|
||||
$result[$context->id][$cap->capability] += $cap->permission;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// now go through the contexts below given context
|
||||
$searchcontexts = array_keys($context->get_child_contexts());
|
||||
foreach ($searchcontexts as $cid) {
|
||||
if ($capabilities = $DB->get_records('role_capabilities', array('roleid'=>$roleid, 'contextid'=>$cid))) {
|
||||
foreach ($capabilities as $cap) {
|
||||
if (!array_key_exists($cap->contextid, $result)) {
|
||||
$result[$cap->contextid] = array();
|
||||
}
|
||||
$result[$cap->contextid][$cap->capability] = $cap->permission;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return $result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets a string for sql calls, searching for stuff in this context or above
|
||||
*
|
||||
|
@ -4217,3 +4217,48 @@ function get_user_courses_bycap($userid, $cap, $accessdata_ignored, $doanything_
|
||||
|
||||
return $courses;
|
||||
}
|
||||
|
||||
/**
|
||||
* This is really slow!!! do not use above course context level
|
||||
*
|
||||
* @deprecated since Moodle 2.2
|
||||
* @param int $roleid
|
||||
* @param context $context
|
||||
* @return array
|
||||
*/
|
||||
function get_role_context_caps($roleid, context $context) {
|
||||
global $DB;
|
||||
debugging('get_role_context_caps() is deprecated, it is really slow. Don\'t use it.', DEBUG_DEVELOPER);
|
||||
|
||||
// This is really slow!!!! - do not use above course context level.
|
||||
$result = array();
|
||||
$result[$context->id] = array();
|
||||
|
||||
// First emulate the parent context capabilities merging into context.
|
||||
$searchcontexts = array_reverse($context->get_parent_context_ids(true));
|
||||
foreach ($searchcontexts as $cid) {
|
||||
if ($capabilities = $DB->get_records('role_capabilities', array('roleid'=>$roleid, 'contextid'=>$cid))) {
|
||||
foreach ($capabilities as $cap) {
|
||||
if (!array_key_exists($cap->capability, $result[$context->id])) {
|
||||
$result[$context->id][$cap->capability] = 0;
|
||||
}
|
||||
$result[$context->id][$cap->capability] += $cap->permission;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Now go through the contexts below given context.
|
||||
$searchcontexts = array_keys($context->get_child_contexts());
|
||||
foreach ($searchcontexts as $cid) {
|
||||
if ($capabilities = $DB->get_records('role_capabilities', array('roleid'=>$roleid, 'contextid'=>$cid))) {
|
||||
foreach ($capabilities as $cap) {
|
||||
if (!array_key_exists($cap->contextid, $result)) {
|
||||
$result[$cap->contextid] = array();
|
||||
}
|
||||
$result[$cap->contextid][$cap->capability] = $cap->permission;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return $result;
|
||||
}
|
||||
|
@ -28,6 +28,7 @@ information provided here is intended especially for developers.
|
||||
* get_context_url() is deprecated, please use $context->get_url().
|
||||
* get_course_context() is deprecated, please use $context->get_course_context().
|
||||
* get_user_courses_bycap() is deprecated, please use enrol_get_users_courses().
|
||||
* get_role_context_caps() is deprecated, it is really slow. Don't use it.
|
||||
|
||||
=== 2.5.1 ===
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user