diff --git a/lib/accesslib.php b/lib/accesslib.php index fe55d4e85bc..520ec92eef8 100644 --- a/lib/accesslib.php +++ b/lib/accesslib.php @@ -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 * diff --git a/lib/deprecatedlib.php b/lib/deprecatedlib.php index 7b6bb02771f..975f2d353df 100644 --- a/lib/deprecatedlib.php +++ b/lib/deprecatedlib.php @@ -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; +} diff --git a/lib/upgrade.txt b/lib/upgrade.txt index 2257ef79e66..0a680c3cc91 100644 --- a/lib/upgrade.txt +++ b/lib/upgrade.txt @@ -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 ===