From e4d86a6ec4e54a5b12f28611384a8d3352d71e87 Mon Sep 17 00:00:00 2001 From: Paul Holden Date: Wed, 27 Mar 2019 16:03:00 +0000 Subject: [PATCH] MDL-63387 access: add parameter to define how role names are returned. --- lib/accesslib.php | 12 ++++++++---- lib/upgrade.txt | 2 ++ 2 files changed, 10 insertions(+), 4 deletions(-) diff --git a/lib/accesslib.php b/lib/accesslib.php index 7e631557546..ab6f09eff00 100644 --- a/lib/accesslib.php +++ b/lib/accesslib.php @@ -3163,9 +3163,11 @@ function get_assignable_roles(context $context, $rolenamedisplay = ROLENAME_ALIA * test the moodle/role:switchroles to see if the user is allowed to switch in the first place. * * @param context $context a context. + * @param int $rolenamedisplay the type of role name to display. One of the + * ROLENAME_X constants. Default ROLENAME_ALIAS. * @return array an array $roleid => $rolename. */ -function get_switchable_roles(context $context) { +function get_switchable_roles(context $context, $rolenamedisplay = ROLENAME_ALIAS) { global $USER, $DB; // You can't switch roles without this capability. @@ -3208,7 +3210,7 @@ function get_switchable_roles(context $context) { ORDER BY r.sortorder"; $roles = $DB->get_records_sql($query, $params); - return role_fix_names($roles, $context, ROLENAME_ALIAS, true); + return role_fix_names($roles, $context, $rolenamedisplay, true); } /** @@ -3216,9 +3218,11 @@ function get_switchable_roles(context $context) { * * @param context $context a context. * @param int $userid id of user. + * @param int $rolenamedisplay the type of role name to display. One of the + * ROLENAME_X constants. Default ROLENAME_ALIAS. * @return array an array $roleid => $rolename. */ -function get_viewable_roles(context $context, $userid = null) { +function get_viewable_roles(context $context, $userid = null, $rolenamedisplay = ROLENAME_ALIAS) { global $USER, $DB; if ($userid == null) { @@ -3260,7 +3264,7 @@ function get_viewable_roles(context $context, $userid = null) { ORDER BY r.sortorder"; $roles = $DB->get_records_sql($query, $params); - return role_fix_names($roles, $context, ROLENAME_ALIAS, true); + return role_fix_names($roles, $context, $rolenamedisplay, true); } /** diff --git a/lib/upgrade.txt b/lib/upgrade.txt index 520f52734a7..0b349132483 100644 --- a/lib/upgrade.txt +++ b/lib/upgrade.txt @@ -31,6 +31,8 @@ information provided here is intended especially for developers. * The form element 'htmleditor', which was deprecated in 3.6, has been removed. * The `core_output_load_fontawesome_icon_map` web service has been deprecated and replaced by `core_output_load_fontawesome_icon_system_map` which takes the name of the theme to generate the icon system map for. +* A new parameter `$rolenamedisplay` has been added to `get_viewable_roles()` and `get_switchable_roles` to define how role names + should be returned. * The class coursecat_sortable_records has been removed. * Admin setting admin_setting_configselect now supports lazy-loading the options list by supplying a callback function instead of an array of options.