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);
* 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;
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.
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
*
return $groups;
}
+
+/**
+ * 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);
+}
- I set the field "<field_string>" to multiline
- I follow "<link_string>"" in the open menu
* Removed the lib/password_compat/lib/password.php file.
+* 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 ===