]> git.mjollnir.org Git - moodle.git/commitdiff
Prevent duplicate users in list when user has both visible and hidden roles. MDL...
authorstronk7 <stronk7>
Sat, 15 Mar 2008 21:57:25 +0000 (21:57 +0000)
committerstronk7 <stronk7>
Sat, 15 Mar 2008 21:57:25 +0000 (21:57 +0000)
user/index.php

index 7a9aeca35df52280ddd614760ef02204ba1c02e2..3eace2f6109b6f128e994fb3ef5e29f89b04ee8a 100644 (file)
         $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);
             }
 
             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);
                 }
             } 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