Teacher can now view student attempts
authormoodler <moodler>
Tue, 22 Oct 2002 04:25:58 +0000 (04:25 +0000)
committermoodler <moodler>
Tue, 22 Oct 2002 04:25:58 +0000 (04:25 +0000)
mod/quiz/lib.php
mod/quiz/report.php

index 4c9e048cab8a206106fae4e4933d73a4c63874bb..03aa70df086ac052e1a0e9befaf3928ae8384b81 100644 (file)
@@ -715,15 +715,15 @@ function quiz_get_user_attempts($quizid, $userid) {
 
 function quiz_get_user_attempts_string($quiz, $attempts, $bestgrade) {
 /// Returns a simple little comma-separated list of all attempts, 
-/// with the best grade bolded
+/// with each grade linked to the feedback report and with the best grade highlighted
 
     $bestgrade = format_float($bestgrade);
     foreach ($attempts as $attempt) {
         $attemptgrade = format_float(($attempt->sumgrades / $quiz->sumgrades) * $quiz->grade);
         if ($attemptgrade == $bestgrade) {
-            $userattempts[] = "<B>$attemptgrade</B>";
+            $userattempts[] = "<SPAN CLASS=highlight><A HREF=\"report.php?q=$quiz->id&attempt=$attempt->id\">$attemptgrade</A></SPAN>";
         } else {
-            $userattempts[] = "$attemptgrade";
+            $userattempts[] = "<A HREF=\"report.php?q=$quiz->id&attempt=$attempt->id\">$attemptgrade</A>";
         }
     }
     return implode(",", $userattempts);
@@ -1022,5 +1022,27 @@ function quiz_grade_attempt_results($quiz, $questions) {
 
     return $result;
 }
+
+
+function quiz_get_attempt_responses($attempt) {
+// Given an attempt object, this function gets all the 
+// stored responses and returns them in a format suitable
+// for regrading using quiz_grade_attempt_results()
+   
+    if (!$responses = get_records_sql("SELECT q.id, q.type, r.answer 
+                                        FROM quiz_responses r, quiz_questions q
+                                       WHERE r.attempt = '$attempt->id' 
+                                         AND q.id = r.question")) {
+        notify("Could not find any responses for that attempt!");
+        return false;
+    }
+
+    foreach ($responses as $key => $response) {
+        $responses[$key]->answer = explode(",",$response->answer);
+    }
+
+    return $responses;
+}
+
     
 ?>
index 0663559afbe96939d8f642289cb926c2c440b19f..7169b1b151bf0b6aca25132800c2d5def8b712b5 100644 (file)
     $strreport  = get_string("report", "quiz");
     $strname  = get_string("name");
     $strattempts  = get_string("attempts", "quiz");
+    $strscore  = get_string("score", "quiz");
     $strgrade  = get_string("grade");
+    $strtimetaken     = get_string("timetaken", "quiz");
+    $strtimecompleted = get_string("timecompleted", "quiz");
 
     print_header("$course->shortname: $quiz->name", "$course->fullname",
                  "$navigation <A HREF=index.php?id=$course->id>$strquizzes</A> 
 
     print_heading($quiz->name);
 
+    if ($attempt) {  // Show a particular attempt
+
+        if (! $attempt = get_record("quiz_attempts", "id", $attempt)) {
+            error("No such attempt ID exists");
+        }
+
+        if (! $questions = quiz_get_attempt_responses($attempt)) {
+            error("Could not reconstruct quiz results for attempt $attempt->id!");
+        }
+
+        if (!$result = quiz_grade_attempt_results($quiz, $questions)) {
+            error("Could not re-grade this quiz attempt!");
+        }
+
+        $table->align  = array("RIGHT", "LEFT");
+        $table->data[] = array("$strtimetaken:", format_time($attempt->timefinish - $attempt->timestart));
+        $table->data[] = array("$strtimecompleted:", userdate($attempt->timefinish));
+        $table->data[] = array("$strscore:", "$result->sumgrades/$quiz->sumgrades ($result->percentage %)");
+        $table->data[] = array("$strgrade:", "$result->grade/$quiz->grade");
+        print_table($table);
+
+        print_continue("report.php?q=$quiz->id");
+
+        $quiz->feedback = true;
+        $quiz->correctanswers = true;
+        quiz_print_quiz_questions($quiz, $result);
+
+        print_continue("report.php?q=$quiz->id");
+        print_footer($course);
+        exit;
+    }
+
     if (!$grades = quiz_get_grade_records($quiz)) {
         print_footer($course);
         exit;