MDL-41315 assign: Dont show users not in the current grouping
authorDamyon Wiese <damyon@moodle.com>
Fri, 23 Aug 2013 08:26:49 +0000 (16:26 +0800)
committerDamyon Wiese <damyon@moodle.com>
Fri, 13 Sep 2013 06:47:01 +0000 (14:47 +0800)
This is for separate groups mode. Note - this will be slower - but
this feature is experimental and groupslib does not provide a nicer api.

mod/assign/locallib.php

index 5941b34..9c87a52 100644 (file)
@@ -1260,12 +1260,21 @@ class assign {
      */
     public function list_participants($currentgroup, $idsonly) {
         if ($idsonly) {
-            return get_enrolled_users($this->context, 'mod/assign:submit', $currentgroup, 'u.id', null, null, null,
+            $users = get_enrolled_users($this->context, 'mod/assign:submit', $currentgroup, 'u.id', null, null, null,
                     $this->show_only_active_users());
         } else {
-            return get_enrolled_users($this->context, 'mod/assign:submit', $currentgroup, 'u.*', null, null, null,
+            $users = get_enrolled_users($this->context, 'mod/assign:submit', $currentgroup, 'u.*', null, null, null,
                     $this->show_only_active_users());
         }
+
+        $cm = $this->get_course_module();
+        foreach ($users as $userid => $user) {
+            if (!groups_course_module_visible($cm, $userid)) {
+                unset($users[$userid]);
+            }
+        }
+
+        return $users;
     }
 
     /**
@@ -1297,7 +1306,7 @@ class assign {
      * @return int number of matching users
      */
     public function count_participants($currentgroup) {
-        return count_enrolled_users($this->context, 'mod/assign:submit', $currentgroup, true);
+        return count($this->list_participants($currentgroup, true));
     }
 
     /**