$orderby = " ORDER BY $sort";
return groups_calculate_role_people(get_recordset_sql(
- $select.$from.$where.$orderby));
+ $select.$from.$where.$orderby),$context->id);
}
AND ra.contextid ".get_related_contexts_string($context)."
ORDER BY r.sortorder,$sort");
- return groups_calculate_role_people($rs);
+ return groups_calculate_role_people($rs,$context->id);
}
/**
* roles on a course.
*
* @param object $rs The record set (may be false)
+ * @param int $contextid ID of course context
* @return array As described in groups_get_members_by_role
*/
-function groups_calculate_role_people($rs) {
+function groups_calculate_role_people($rs,$contextid) {
global $CFG;
if(!$rs) {
return false;
}
+
+ // Get role aliases for course in array of roleid => obj->text
+ if(!($aliasnames=get_records('role_names','contextid',$contextid,'','roleid,text'))) {
+ $aliasnames=array();
+ }
// Array of all involved roles
$roles=array();
$roledata=new StdClass;
$roledata->id=$rec->roleid;
$roledata->shortname=$rec->roleshortname;
- $roledata->name=$rec->rolename;
+ if(array_key_exists($rec->roleid,$aliasnames)) {
+ $roledata->name=$aliasnames[$rec->roleid]->text;
+ } else {
+ $roledata->name=$rec->rolename;
+ }
$roledata->users=array();
$roles[$roledata->id]=$roledata;
}