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);
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;
+}
+
?>
$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;