]> git.mjollnir.org Git - moodle.git/commitdiff
allow selection of groups in reports
authorgbateson <gbateson>
Wed, 11 Oct 2006 01:30:27 +0000 (01:30 +0000)
committergbateson <gbateson>
Wed, 11 Oct 2006 01:30:27 +0000 (01:30 +0000)
mod/hotpot/report.php

index 4aa3644cd29b1a32590f9b6ba91b1118fa9603fa..c9deae55702b35d6d753ee472d80dfe7ed9450f5 100644 (file)
         hotpot_delete_selected_attempts($hotpot, $del);
     }
 
+    // check for groups
+    if (preg_match('/^group(\d*)$/', $formdata['reportusers'], $matches)) {
+        // validate groupid
+        if (is_numeric($matches[1]) && get_field('groups', 'courseid', 'id', $matches[1])===$course->id) {
+            $formdata['reportusers'] = 'group';
+            $formdata['reportgroupid'] = $matches[1];
+        } else {
+            $formdata['reportgroupid'] = 0; // groupid is invalid
+        }
+    }
+
     $user_ids = '';
     $users = array();
+
     switch ($formdata['reportusers']) {
+
         case 'allusers':
             // anyone who has ever attempted this hotpot
             if ($records = get_records_select('hotpot_attempts', "hotpot=$hotpot->id", '', 'id,userid')) {
             }
             break;
 
+        case 'group':
+            // group members
+            if ($records = get_records_select('groups_members', "groupid=".$formdata['reportgroupid'], '', 'id,userid')) {
+                foreach ($records as $record) {
+                    $users[$record->userid] = 1; // "1" signifies currently recognized participant
+                }
+            }
+            break;
+
         case 'allparticipants':
             // anyone currently allowed to attempt this HotPot
             if ($records = get_users_by_capability($modulecontext, 'mod/hotpot:attempt', 'u.id,u.id', 'u.id')) {
@@ -423,7 +445,17 @@ function hotpot_print_report_selector(&$course, &$hotpot, &$formdata) {
         }
     }
 
-    $menus['reportusers'] = array('allusers' => get_string('allusers', 'hotpot'));
+    $menus['reportusers'] = array(
+        'allusers' => get_string('allusers', 'hotpot'),
+        'allparticipants' => get_string('allparticipants')
+    );
+
+    // groups
+    if ($groups = get_records_select('groups', "courseid='$course->id'", '', 'id,name')) {
+        foreach ($groups as $group) {
+            $menus['reportusers']["group$group->id"] = get_string('group').': '.$group->name;
+        }
+    }
 
     // get users who have ever atetmpted this HotPot
     $users = get_records_sql("
@@ -446,29 +478,30 @@ function hotpot_print_report_selector(&$course, &$hotpot, &$formdata) {
     $teachers = get_users_by_capability($modulecontext, 'mod/hotpot:viewreport', 'u.id,u.firstname,u.lastname', 'u.lastname');
     $students = get_users_by_capability($modulecontext, 'mod/hotpot:attempt', 'u.id,u.firstname,u.lastname', 'u.lastname');
 
+    // current students
     if (!empty($students)) {
         $firsttime = true;
-        foreach ($students as $id=>$user) {
-            if (isset($users[$id]) && empty($teachers[$id])) {
+        foreach ($students as $user) {
+            if (isset($users[$user->id])) {
                 if ($firsttime) {
                     $firsttime = false; // so we only do this once
-                    $menus['reportusers']['allparticipants'] = get_string('allparticipants');
                     $menus['reportusers']['existingstudents'] = get_string('existingstudents');
                     $menus['reportusers'][] = '------';
                 }
-                $menus['reportusers']["$id"] = fullname($user);
-                unset($users[$id]);
+                $menus['reportusers']["$user->id"] = fullname($user);
+                unset($users[$user->id]);
             }
         }
     }
+    // others (former students, teachers, admins, course creators)
     if (!empty($users)) {
         $firsttime = true;
-        foreach ($users as $id=>$user) {
+        foreach ($users as $user) {
             if ($firsttime) {
                 $firsttime = false; // so we only do this once
                 $menus['reportusers'][] = '======';
             }
-            $menus['reportusers']["$id"] = fullname($user);
+            $menus['reportusers']["$user->id"] = fullname($user);
         }
     }