From: stronk7 Date: Sat, 15 Mar 2008 21:57:25 +0000 (+0000) Subject: Prevent duplicate users in list when user has both visible and hidden roles. MDL... X-Git-Url: http://git.mjollnir.org/gw?a=commitdiff_plain;h=1f807bc46a2406f2c31fb3905d3e3a65bc81f2e0;p=moodle.git Prevent duplicate users in list when user has both visible and hidden roles. MDL-13935 ; merged from 19_STABLE --- diff --git a/user/index.php b/user/index.php index 7a9aeca35d..3eace2f610 100644 --- a/user/index.php +++ b/user/index.php @@ -448,10 +448,12 @@ $where .= ' AND '.$table->get_sql_where(); } + /// Always add r.hidden to sort in order to guarantee hiddens to "win" + /// in the resolution of duplicates later - MDL-13935 if ($table->get_sql_sort()) { - $sort = ' ORDER BY '.$table->get_sql_sort(); + $sort = ' ORDER BY '.$table->get_sql_sort() . ', r.hidden DESC'; } else { - $sort = ''; + $sort = ' r.hidden DESC'; } $matchcount = count_records_sql('SELECT COUNT(distinct u.id) '.$from.$where.$wheresearch); @@ -630,7 +632,13 @@ } if ($matchcount > 0) { + $usersprinted = array(); while ($user = rs_fetch_next_record($userlist)) { + if (in_array($user->id, $usersprinted)) { /// Prevent duplicates by r.hidden - MDL-13935 + continue; + } + $usersprinted[] = $user->id; /// Add new user to the array of users printed + $user = make_context_subobj($user); print_user($user, $course, $bulkoperations); } @@ -654,8 +662,14 @@ } else { $showenrolplugin = false; } - + + $usersprinted = array(); while ($user = rs_fetch_next_record($userlist)) { + if (in_array($user->id, $usersprinted)) { /// Prevent duplicates by r.hidden - MDL-13935 + continue; + } + $usersprinted[] = $user->id; /// Add new user to the array of users printed + $user = make_context_subobj($user); if ( !empty($user->hidden) ) { // if the assignment is hidden, display icon