]> git.mjollnir.org Git - moodle.git/commitdiff
Cleaned up the Choice report - it's easier to make sense of now
authormartin <martin>
Sun, 18 Aug 2002 09:43:01 +0000 (09:43 +0000)
committermartin <martin>
Sun, 18 Aug 2002 09:43:01 +0000 (09:43 +0000)
mod/choice/lib.php
mod/choice/report.php

index 502187970459d30bb299fc71cff88e7d1cf3d2f6..cad24204fc599427b864e789dec110a13fec7d88 100644 (file)
@@ -91,7 +91,7 @@ function choice_get_answer($choice, $code) {
         case 2:
             return "$choice->answer2";
         default:
-            return get_string("undecided");
+            return get_string("notanswered", "choice");
     }
 }
 
index 42ff7710d8ce8796ad40c6d94750a522b2cb6cf9..10c8b935b9c8756ea65fd522f1bfc709b6fbbdf4 100644 (file)
                   <A HREF=view.php?id=$cm->id>$choice->name</A> -> $strresponses", "");
 
 
-    if (! $participants = get_records_sql("SELECT u.* FROM user u, user_students s, user_teachers t
-                                       WHERE (s.course = '$course->id' AND s.user = u.id) 
-                                          OR (t.course = '$course->id' AND t.user = u.id)
-                                       ORDER BY u.lastaccess DESC")) {
-
-        notify("No participants (strange)", "/course/view.php?id=$course->id");
-        die;
+    if (! $users = get_course_users($course->id)) {
+        error("No users found (very strange)");
     }
 
-    if ( $allanswers = get_records_sql("SELECT * FROM choice_answers WHERE choice='$choice->id'")) {
+    if ( $allanswers = get_records("choice_answers", "choice", $choice->id)) {
         foreach ($allanswers as $aa) {
             $answers[$aa->user] = $aa;
         }
     } else {
         $answers = array () ;
     }
-    
-
 
     $timenow = time();
 
-    echo "<TABLE BORDER=1 CELLSPACING=0 valign=top align=center cellpadding=10>";
-    foreach ($participants as $user) {
+    foreach ($users as $user) {
         $answer = $answers[$user->id];
+        $useranswer[(int)$answer->answer][] = $user;
+    }
+    ksort($useranswer);
 
-        echo "<TR>";
+    $tablewidth = (int) (100.0 / count($useranswer));
 
-        echo "<TD BGCOLOR=\"$THEME->body\" WIDTH=35 VALIGN=TOP>";
-        print_user_picture($user->id, $course->id, $user->picture);
-        echo "</TD>";
+    echo "<TABLE CELLPADDING=5 CELLSPACING=10 ALIGN=CENTER>";
+    echo "<TR>";
+    foreach ($useranswer as $key => $answer) {
+        if ($key) {
+            echo "<TH WIDTH=\"$tablewidth%\">";
+        } else {
+            echo "<TH BGCOLOR=\"$THEME->body\" WIDTH=\"$tablewidth%\">";
+        }
+        echo choice_get_answer($choice, $key);
+        echo "</TH>";
+    }
+    echo "</TR><TR>";
 
-        echo "<TD NOWRAP BGCOLOR=\"$THEME->cellheading\">$user->firstname $user->lastname</TD>";
-        echo "<TD><P>&nbsp;";
-        if ($answer->timemodified) {
-            echo userdate($answer->timemodified);
-        } 
-        
-        echo "</P> </TD>";
+    foreach ($useranswer as $key => $answer) {
+        if ($key) {
+            echo "<TD WIDTH=\"$tablewidth%\" VALIGN=TOP NOWRAP BGCOLOR=\"$THEME->cellcontent\">";
+        } else {
+            echo "<TD WIDTH=\"$tablewidth%\" VALIGN=TOP NOWRAP BGCOLOR=\"$THEME->body\">";
+        }
 
-        echo "<TD ALIGN=CENTER BGCOLOR=\"$THEME->cellcontent\"><P>";
-        echo choice_get_answer($choice, $answer->answer);
-        echo "</P></TD></TR>";
+        echo "<TABLE WIDTH=100%>";
+        foreach ($answer as $user) {
+            echo "<TR><TD WIDTH=10 NOWRAP>";
+            print_user_picture($user->id, $course->id, $user->picture);
+            echo "</TD><TD WIDTH=100% NOWRAP>";
+            echo "<P>$user->firstname $user->lastname</P>";
+            echo "</TD></TR>";
+        }
+        echo "</TABLE>";
+
+        echo "</TD>";
     }
-    echo "</TABLE>";
+    echo "</TR></TABLE>";
 
     print_footer($course);