--- group/assign.php Thu Jan 15 22:14:12 1970 +++ group/assign.php Thu Jan 15 22:14:12 1970 @@ -46,11 +46,13 @@ $potentialmembers = array(); if ($groups = get_records('groups', 'courseid', $courseid, 'name')) { + uasort($groups, 'object_name_sort_compare'); // Perform natural sort on groups if ($assignment = get_records('groupings_groups', 'groupingid', $grouping->id)) { foreach ($assignment as $ass) { $currentmembers[$ass->groupid] = $groups[$ass->groupid]; unset($groups[$ass->groupid]); } + uasort($currentmembers, 'object_name_sort_compare'); // Perform natural sort on assigned groups } $potentialmembers = $groups; } --- group/groupings.php Thu Jan 15 22:14:12 1970 +++ group/groupings.php Thu Jan 15 22:14:12 1970 @@ -41,11 +41,13 @@ $data = array(); if ($groupings = get_records('groupings', 'courseid', $course->id, 'name')) { + uasort($groupings, 'object_name_sort_compare'); // Perform natural sort on groupings foreach($groupings as $grouping) { $line = array(); $line[0] = format_string($grouping->name); if ($groups = groups_get_all_groups($courseid, 0, $grouping->id)) { + uasort($groups, 'object_name_sort_compare'); // Perform natural sort on groups $groupnames = array(); foreach ($groups as $group) { $groupnames[] = format_string($group->name); --- group/index.php Thu Jan 15 22:14:12 1970 +++ group/index.php Thu Jan 15 22:14:12 1970 @@ -183,6 +183,8 @@ echo ' onclick="window.status=this.selectedIndex==-1 ? \'\' : this.options[this.selectedIndex].title;" onmouseout="window.status=\'\';">'."\n"; $groups = groups_get_all_groups($courseid); +uasort($groups, 'object_name_sort_compare'); // Perform natural sort on groups + $selectedname = ' '; if ($groups) { --- group/lib.php Thu Jan 15 22:14:12 1970 +++ group/lib.php Thu Jan 15 22:14:12 1970 @@ -725,4 +725,15 @@ return $roles; } +/** + * Custom array sort function to do natural ordering on the "name" attribute + * of the member objects. Used on groups and groupings. + * + * @param object $a First object to compare + * @param object $b Second object to compare + * @return array As described in groups_get_members_by_role + */ +function object_name_sort_compare($a, $b) { + return strnatcasecmp($a->name, $b->name); +} ?> --- group/members.php Thu Jan 15 22:14:12 1970 +++ group/members.php Thu Jan 15 22:14:12 1970 @@ -115,6 +115,9 @@ $usergroups[$usergroup->userid][$usergroup->id] = $usergroup; } rs_close($rs); + foreach($usergroups as $uid=>$ugroups) { + uasort($usergroups[$uid], 'object_name_sort_compare'); // Perform natural sort on user's groups + } foreach($potentialmembersbyrole as $roleid=>$roledata) { $potentialmembersoptions .= ''; --- group/overview.php Thu Jan 15 22:14:12 1970 +++ group/overview.php Thu Jan 15 22:14:12 1970 @@ -46,6 +46,7 @@ if (!$groupings = get_records('groupings', 'courseid', $courseid, 'name')) { $groupings = array(); } + uasort($groupings, 'object_name_sort_compare'); // Perform natural sort on groupings $members = array(); foreach ($groupings as $grouping) { $members[$grouping->id] = array(); @@ -57,6 +58,7 @@ if (!$groups = get_records('groups', 'courseid', $courseid, 'name')) { $groups = array(); } +uasort($groups, 'object_name_sort_compare'); // Perform natural sort on groups if (empty($CFG->enablegroupings)) { $groupwhere = $groupid ? "AND g.id = $groupid" : ""; @@ -97,6 +99,25 @@ } } rs_close($rs); + + // Sort $members based on the already naturally-sorted $groups and $groupings + $groupKeys = array_flip(array_keys($groups)); + foreach ($members as $gpgid=>$groupdata) { + $tmpGroups = array(); + foreach ($groupKeys as $gpid=>$group) { + if (array_key_exists($gpid, $members[$gpgid])) { + $tmpGroups[$gpid]=$members[$gpgid][$gpid]; + } + } + $members[$gpgid] = $tmpGroups; + } + $tmpGroups = array(); + foreach ($groupKeys as $gpid=>$group) { + if (array_key_exists($gpid, $members[-1])) { + $tmpGroups[$gpid]=$members[-1][$gpid]; + } + } + $members[-1] = $tmpGroups; }