]> git.mjollnir.org Git - moodle.git/commitdiff
Group support for Quiz reports. :-)
authormoodler <moodler>
Sat, 14 Feb 2004 16:52:55 +0000 (16:52 +0000)
committermoodler <moodler>
Sat, 14 Feb 2004 16:52:55 +0000 (16:52 +0000)
... except detailed stats.

mod/quiz/report/overview/report.php
mod/quiz/report/simplestat/report.php

index 2bc1c9ef174d5841a1e444317ad7217d20125c46..79e0652ff7b94c8f4ad9b487e55190abbdeb2ab1 100644 (file)
@@ -67,6 +67,41 @@ class quiz_report extends quiz_default_report {
             return true;
         }
 
+    /// Check to see if groups are being used in this quiz
+    /// and if so, set $currentgroup to reflect the current group
+
+        $groupmode = groupmode($course, $cm);   // Groups are being used
+        $currentgroup = get_and_set_current_group($course, $groupmode, $_GET['group']);
+
+        if ($groupmode and !$currentgroup and !isteacheredit($course->id)) {
+            print_heading("Sorry, but you can't see this group");
+            print_footer();
+            exit;
+        }
+
+        if ($groupmode == VISIBLEGROUPS or ($groupmode and isteacheredit($course->id))) {
+            if ($groups = get_records_menu("groups", "courseid", $course->id, "name ASC", "id,name")) {
+                echo '<table align="center"><tr><td>';
+                if ($groupmode == VISIBLEGROUPS) {
+                    print_string('groupsvisible');
+                } else {
+                    print_string('groupsseparate');
+                }
+                echo ':';
+                echo '</td><td nowrap="nowrap" align="left" width="50%">';
+                popup_form("report.php?id=$cm->id&mode=overview&group=", 
+                           $groups, 'selectgroup', $currentgroup, "", "", "", false, "self");
+                echo '</tr></table>';
+            }
+        }
+
+
+    /// Get all teachers and students
+        if ($currentgroup) {
+            $users = get_users_in_group($currentgroup);
+        }
+
+
         $table->head = array("&nbsp;", $strname, $strattempts, "$strbestgrade /$quiz->grade");
         $table->align = array("center", "left", "left", "center");
         $table->wrap = array("nowrap", "nowrap", "nowrap", "nowrap");
@@ -74,6 +109,11 @@ class quiz_report extends quiz_default_report {
         $table->size = array(10, "*", "80%", "*");
 
         foreach ($grades as $grade) {
+            if ($currentgroup) {
+                if (empty($users[$grade->userid])) {       /// Using groups, but this user not in group
+                    continue;
+                }
+            }
             $picture = print_user_picture($grade->userid, $course->id, $grade->picture, false, true);
 
             if ($attempts = quiz_get_user_attempts($quiz->id, $grade->userid)) {
index acbf0e4d5559b041514bd6a78fbaebcee18a37a7..2d2c5b997b3424e34ac649b1d9ecf690c2ed587c 100644 (file)
@@ -11,12 +11,47 @@ class quiz_report extends quiz_default_report {
 
         optional_variable($download, "");
 
+    /// Check to see if groups are being used in this quiz
+    /// and if so, set $currentgroup to reflect the current group
+
+        $groupmode = groupmode($course, $cm);   // Groups are being used
+        $currentgroup = get_and_set_current_group($course, $groupmode, $_GET['group']);
+
+        if ($groupmode and !$currentgroup and !isteacheredit($course->id)) {
+            print_heading("Sorry, but you can't see this group");
+            print_footer();
+            exit;
+        }
+
+        if ($groupmode == VISIBLEGROUPS or ($groupmode and isteacheredit($course->id))) {
+            if ($groups = get_records_menu("groups", "courseid", $course->id, "name ASC", "id,name")) {
+                echo '<table align="center"><tr><td>';
+                if ($groupmode == VISIBLEGROUPS) {
+                    print_string('groupsvisible');
+                } else {
+                    print_string('groupsseparate');
+                }
+                echo ':';
+                echo '</td><td nowrap="nowrap" align="left" width="50%">';
+                popup_form("report.php?id=$cm->id&mode=simplestat&group=", 
+                           $groups, 'selectgroup', $currentgroup, "", "", "", false, "self");
+                echo '</tr></table>';
+            }
+        }
+
+
+        if ($currentgroup) {
+            $users = get_users_in_group($currentgroup, "u.lastname ASC");
+        } else {
+            $users = get_course_students($course->id, "u.lastname ASC");
+        }
+
         $data = array();
         $questionorder = explode(',', $quiz->questions);
 
-        /// For each person in the class, get their best attempt
-        /// and create a table listing results for each person
-        if ($users = get_course_students($course->id, "u.lastname ASC")) {
+    /// For each person in the class, get their best attempt
+    /// and create a table listing results for each person
+        if ($users) {
             foreach ($users as $user) {
 
                 $data[$user->id]->firstname = $user->firstname;
@@ -199,7 +234,11 @@ class quiz_report extends quiz_default_report {
             echo "<td><b>$datum->firstname $datum->lastname</b></td>";
             if ($datum->grades) {
                 foreach ($datum->grades as $key => $grade) {
-                    echo "<td>$grade</td>";
+                    if (isset($grade)) {
+                        echo "<td>$grade</td>";
+                    } else {
+                        echo "<td>&nbsp;</td>";
+                    }
                 }
             }
             echo "</tr>";