Merge branch 'MDL-62065-master' of git://github.com/cescobedo/moodle

This commit is contained in:
Eloy Lafuente (stronk7)
2018-08-07 15:51:34 +02:00
4 changed files with 43 additions and 36 deletions
@@ -147,8 +147,8 @@ class data_registry {
if ($contextcourse = $context->get_course_context(false)) {
// Below course level we look at module or block level roles + course-assigned roles.
$courseroles = get_roles_with_assignment_on_context($contextcourse);
$roles = $courseroles + get_roles_with_assignment_on_context($context);
$courseroles = get_roles_used_in_context($contextcourse, false);
$roles = $courseroles + get_roles_used_in_context($context, false);
} else {
// We list category + system for others (we don't work with user instances so no need to work about them).
$roles = get_roles_used_in_context($context);
+7 -34
View File
@@ -2548,12 +2548,17 @@ function get_profile_roles(context $context) {
* Gets the list of roles assigned to this context and up (parents)
*
* @param context $context
* @param boolean $includeparents, false means without parents.
* @return array
*/
function get_roles_used_in_context(context $context) {
function get_roles_used_in_context(context $context, $includeparents = true) {
global $DB;
list($contextlist, $params) = $DB->get_in_or_equal($context->get_parent_context_ids(true), SQL_PARAMS_NAMED, 'cl');
if ($includeparents === true) {
list($contextlist, $params) = $DB->get_in_or_equal($context->get_parent_context_ids(true), SQL_PARAMS_NAMED, 'cl');
} else {
list($contextlist, $params) = $DB->get_in_or_equal($context->id, SQL_PARAMS_NAMED, 'cl');
}
if ($coursecontext = $context->get_course_context(false)) {
$params['coursecontext'] = $coursecontext->id;
@@ -3988,22 +3993,6 @@ function get_user_capability_course($capability, $userid = null, $doanything = t
return empty($courses) ? false : $courses;
}
/**
* This function finds the roles assigned directly to this context only
* i.e. no roles in parent contexts
*
* @param context $context
* @return array
*/
function get_roles_on_exact_context(context $context) {
global $DB;
return $DB->get_records_sql("SELECT r.*
FROM {role_assignments} ra, {role} r
WHERE ra.roleid = r.id AND ra.contextid = ?",
array($context->id));
}
/**
* Switches the current user to another role for the current session and only
* in the given context.
@@ -4091,22 +4080,6 @@ function get_capabilities_from_role_on_context($role, context $context) {
array($context->id, $role->id));
}
/**
* Find out which roles has assignment on this context
*
* @param context $context
* @return array
*
*/
function get_roles_with_assignment_on_context(context $context) {
global $DB;
return $DB->get_records_sql("SELECT r.*
FROM {role_assignments} ra, {role} r
WHERE ra.roleid = r.id AND ra.contextid = ?",
array($context->id));
}
/**
* Find all user assignment of users for this role, on this context
*
+31
View File
@@ -3420,3 +3420,34 @@ function events_get_handlers($eventname) {
return $handlers[$eventname];
}
/**
* This function finds the roles assigned directly to this context only
* i.e. no roles in parent contexts
*
* @deprecated since Moodle 3.6. Please use the get_roles_used_in_context().
* @todo final deprecation. To be removed in Moodle 4.0
* @param context $context
* @return array
*/
function get_roles_on_exact_context(context $context) {
debugging('get_roles_on_exact_context() is deprecated, please use get_roles_used_in_context() instead.',
DEBUG_DEVELOPER);
return get_roles_used_in_context($context, false);
}
/**
* Find out which roles has assignment on this context
*
* @deprecated since Moodle 3.6. Please use the get_roles_used_in_context().
* @todo final deprecation. To be removed in Moodle 4.0
* @param context $context
* @return array
*/
function get_roles_with_assignment_on_context(context $context) {
debugging('get_roles_with_assignment_on_context() is deprecated, please use get_roles_used_in_context() instead.',
DEBUG_DEVELOPER);
return get_roles_used_in_context($context, false);
}
+3
View File
@@ -72,6 +72,9 @@ information provided here is intended especially for developers.
* The method message_sent::create_from_ids() parameter courseid is now required. A debugging
message was previously displayed, and the SITEID was used, when not provided.
* The method \core\message\manager::send_message() now only takes the object \core\message\message as the first parameter.
* Following functions have been deprecated, please use get_roles_used_in_context.
- get_roles_on_exact_context()
- get_roles_with_assignment_on_context()
=== 3.5 ===