From 3540f2b35cf35a1301f91f275f8470bc70148470 Mon Sep 17 00:00:00 2001 From: sam_marshall Date: Fri, 18 Jan 2008 11:03:00 +0000 Subject: [PATCH] MDL-13045: Made groups UI use role name aliases --- group/lib.php | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) diff --git a/group/lib.php b/group/lib.php index a1ac96994cd..8f9d38311b7 100644 --- a/group/lib.php +++ b/group/lib.php @@ -344,7 +344,7 @@ function groups_get_users_not_in_group_by_role($courseid, $groupid, $searchtext= $orderby = " ORDER BY $sort"; return groups_calculate_role_people(get_recordset_sql( - $select.$from.$where.$orderby)); + $select.$from.$where.$orderby),$context->id); } @@ -540,7 +540,7 @@ function groups_get_members_by_role($groupid, $courseid, $fields='u.*', $sort='u 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); } /** @@ -549,13 +549,19 @@ function groups_get_members_by_role($groupid, $courseid, $fields='u.*', $sort='u * 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(); @@ -585,7 +591,11 @@ function groups_calculate_role_people($rs) { $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; }