From 6d86b5dc163d6785fe576fe2b3512fb5af56a579 Mon Sep 17 00:00:00 2001 From: moodler Date: Tue, 22 Oct 2002 04:25:58 +0000 Subject: [PATCH] Teacher can now view student attempts --- mod/quiz/lib.php | 28 +++++++++++++++++++++++++--- mod/quiz/report.php | 35 +++++++++++++++++++++++++++++++++++ 2 files changed, 60 insertions(+), 3 deletions(-) diff --git a/mod/quiz/lib.php b/mod/quiz/lib.php index 4c9e048cab..03aa70df08 100644 --- a/mod/quiz/lib.php +++ b/mod/quiz/lib.php @@ -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[] = "$attemptgrade"; + $userattempts[] = "id&attempt=$attempt->id\">$attemptgrade"; } else { - $userattempts[] = "$attemptgrade"; + $userattempts[] = "id&attempt=$attempt->id\">$attemptgrade"; } } 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; +} + ?> diff --git a/mod/quiz/report.php b/mod/quiz/report.php index 0663559afb..7169b1b151 100644 --- a/mod/quiz/report.php +++ b/mod/quiz/report.php @@ -54,7 +54,10 @@ $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 id>$strquizzes @@ -63,6 +66,38 @@ 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; -- 2.39.5