MDL-63387 access: add parameter to define how role names are returned.

This commit is contained in:
Paul Holden 2019-03-27 16:03:00 +00:00 committed by Paul Holden
parent 38abfb6a01
commit a9165e69b4
2 changed files with 10 additions and 4 deletions

View File

@ -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);
}
/**

View File

@ -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.