$string['regradecount'] = "\$a->changed out of \$a->attempt grades were changed";
$string['rename'] = "Rename";
$string['report'] = "Reports";
+$string['reportoverview'] = "Overview";
+$string['reportregrade'] = "Regrade attempts";
+$string['review'] = "Review";
$string['save'] = "Save";
$string['savegrades'] = "Save grades";
$string['savemyanswers'] = "Save my answers";
) TYPE=MyISAM COMMENT='Options for numerical questions'; ");
}
+ if ($oldversion < 2003072400) {
+ execute_sql(" INSERT INTO {$CFG->prefix}log_display VALUES ('quiz', 'review', 'quiz', 'name') ");
+ }
+
return true;
}
INSERT INTO prefix_log_display VALUES ('quiz', 'report', 'quiz', 'name');
INSERT INTO prefix_log_display VALUES ('quiz', 'attempt', 'quiz', 'name');
INSERT INTO prefix_log_display VALUES ('quiz', 'submit', 'quiz', 'name');
+INSERT INTO prefix_log_display VALUES ('quiz', 'review', 'quiz', 'name');
); ");
modify_database ("", "CREATE INDEX prefix_quiz_numerical_answer_idx ON prefix_quiz_numerical (answer);");
}
+
+ if ($oldversion < 2003072400) {
+ execute_sql(" INSERT INTO {$CFG->prefix}log_display VALUES ('quiz', 'review', 'quiz', 'name') ");
+ }
+
return true;
}
INSERT INTO prefix_log_display VALUES ('quiz', 'report', 'quiz', 'name');
INSERT INTO prefix_log_display VALUES ('quiz', 'attempt', 'quiz', 'name');
INSERT INTO prefix_log_display VALUES ('quiz', 'submit', 'quiz', 'name');
+INSERT INTO prefix_log_display VALUES ('quiz', 'review', 'quiz', 'name');
foreach ($attempts as $attempt) {
$attemptgrade = format_float(($attempt->sumgrades / $quiz->sumgrades) * $quiz->grade);
if ($attemptgrade == $bestgrade) {
- $userattempts[] = "<SPAN CLASS=highlight><A HREF=\"report.php?q=$quiz->id&attempt=$attempt->id\">$attemptgrade</A></SPAN>";
+ $userattempts[] = "<span class=highlight><a href=\"review.php?q=$quiz->id&attempt=$attempt->id\">$attemptgrade</a></span>";
} else {
- $userattempts[] = "<A HREF=\"report.php?q=$quiz->id&attempt=$attempt->id\">$attemptgrade</A>";
+ $userattempts[] = "<a href=\"review.php?q=$quiz->id&attempt=$attempt->id\">$attemptgrade</a>";
}
}
return implode(",", $userattempts);
}
+function quiz_remove_unwanted_questions(&$questions, $quiz) {
+/// Used by review.php
+
+ $quizquestions = array();
+ $quizids = explode(",", $quiz->questions);
+ foreach ($quizids as $quizid) {
+ $quizquestions[$quizid] = true;
+ }
+ foreach ($questions as $key => $question) {
+ if (!isset($quizquestions[$question->id])) {
+ unset($questions[$key]);
+ }
+ }
+}
+
?>
<?PHP // $Id$
-// This page prints a particular instance of quiz
+// This script uses installed report plugins to print quiz reports
require_once("../../config.php");
require_once("lib.php");
optional_variable($id); // Course Module ID, or
optional_variable($q); // quiz ID
- optional_variable($attempt); // A particular attempt ID
- optional_variable($review); // A particular attempt ID for review by student
- optional_variable($regrade); // Regrade all attempts
+ optional_variable($mode, "overview"); // Report mode
if ($id) {
if (! $cm = get_record("course_modules", "id", $id)) {
require_login($course->id);
-
if (!isteacher($course->id)) {
- if (!$quiz->review) {
- error(get_string("noreview", "quiz"));
- }
- if (time() < $quiz->timeclose) {
- error(get_string("noreviewuntil", "quiz", userdate($quiz->timeclose)));
- }
- if (empty($review)) {
- error("You are using this script wrongly.");
- }
- }
-
- if (!empty($review)) {
- $attempt = $review;
+ error("You are not allowed to use this script");
}
add_to_log($course->id, "quiz", "report", "report.php?id=$cm->id", "$quiz->id");
-// Print the page header
+/// Print the page header
if ($course->category) {
- $navigation = "<A HREF=\"../../course/view.php?id=$course->id\">$course->shortname</A> ->";
+ $navigation = "<a href=\"../../course/view.php?id=$course->id\">$course->shortname</a> ->";
}
$strquizzes = get_string("modulenameplural", "quiz");
$strquiz = get_string("modulename", "quiz");
$strreport = get_string("report", "quiz");
- $strname = get_string("name");
- $strattempts = get_string("attempts", "quiz");
- $strscore = get_string("score", "quiz");
- $strgrade = get_string("grade");
- $strbestgrade = get_string("bestgrade", "quiz");
- $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>
- -> <A HREF=\"view.php?id=$cm->id\">$quiz->name</A> -> $strreport",
+ -> <a href=\"view.php?id=$cm->id\">$quiz->name</a> -> $strreport",
"", "", true);
print_heading($quiz->name);
- if (!empty($attempt)) { // Show a particular attempt
-
- if (! $attempt = get_record("quiz_attempts", "id", $attempt)) {
- error("No such attempt ID exists");
- }
-
- if (!isteacher($course->id)) {
- if ($attempt->userid != $USER->id) {
- error("This is not your attempt!");
- }
- }
-
- if (! $questions = quiz_get_attempt_responses($attempt, $quiz)) {
- error("Could not reconstruct quiz results for attempt $attempt->id!");
- }
-
- quiz_remove_unwanted_questions($questions, $quiz);
-
- if (!$result = quiz_grade_attempt_results($quiz, $questions)) {
- error("Could not re-grade this quiz attempt!");
- }
-
- if ($timetaken = ($attempt->timefinish - $attempt->timestart)) {
- $timetaken = format_time($timetaken);
- } else {
- $timetaken = "-";
- }
-
- $table->align = array("RIGHT", "LEFT");
- $table->data[] = array("$strtimetaken:", $timetaken);
- $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);
-
- if (empty($review)) {
- print_continue("report.php?q=$quiz->id");
- } else {
- print_continue("view.php?q=$quiz->id");
- }
-
- $quiz->feedback = true;
- $quiz->correctanswers = true;
- $quiz->shuffleanswers = false;
- $quiz->shufflequestions = false;
- quiz_print_quiz_questions($quiz, $result, $questions);
+/// Print list of available quiz reports
- if (empty($review)) {
- print_continue("report.php?q=$quiz->id");
+ $reports = get_list_of_plugins("mod/quiz/report");
+ echo "<table cellpadding=10 align=center><tr>";
+ foreach ($reports as $report) {
+ $strreport = get_string("report$report", "quiz");
+ if ($report == $mode) {
+ echo "<td><u>$strreport</u></td>";
} else {
- print_continue("view.php?q=$quiz->id");
+ echo "<td><a href=\"report.php?id=$cm->id&mode=$report\">$strreport</a></td>";
}
- print_footer($course);
- exit;
}
+ echo "</tr></table><br /><br />";
- if (!empty($regrade)) {
- if (!$attempts = get_records("quiz_attempts", "quiz", $quiz->id)) {
- print_header(get_string("noattempts", "quiz"));
- print_continue("report.php?id=$cm->id");
- print_footer($course);
- exit;
- }
-
- $users = array();
- $count->attempt = 0;
- $count->changed = 0;
- foreach ($attempts as $attempt) {
-
- set_time_limit(120);
-
- if (!$attempt->timefinish) { // Skip incomplete attempts
- continue;
- }
-
- $count->attempt++;
-
- if (! $questions = quiz_get_attempt_responses($attempt, $quiz)) {
- error("Could not reconstruct quiz results for attempt $attempt->id!");
- }
- quiz_remove_unwanted_questions($questions, $quiz);
-
- if (!$result = quiz_grade_attempt_results($quiz, $questions)) {
- error("Could not re-grade this quiz attempt!");
- }
- if ($attempt->sumgrades != $result->sumgrades) {
- $attempt->sumgrades = $result->sumgrades;
- $count->changed++;
+/// Open the selected quiz report and display it
- if (! update_record("quiz_attempts", $attempt)) {
- notify("Could not regrade attempt $attempt->id");
- }
- }
-
- $users[$attempt->userid] = $attempt->userid;
- }
-
- if ($users) {
- foreach ($users as $userid) {
- if (! quiz_save_best_grade($quiz, $userid)) {
- notify("Could not save best grade for user $userid!");
- }
- }
- }
- print_heading(get_string("regradecomplete", "quiz"));
- print_heading(get_string("regradecount", "quiz", $count));
- print_continue("report.php?id=$cm->id");
- print_footer($course);
- exit;
+ if (! is_readable("report/$mode/report.php")) {
+ error("Report not known ($mode)");
}
- if (!$grades = quiz_get_grade_records($quiz)) {
- print_footer($course);
- exit;
- }
-
- $table->head = array(" ", $strname, $strattempts, "$strbestgrade /$quiz->grade");
- $table->align = array("CENTER", "LEFT", "LEFT", "CENTER");
- $table->width = array(10, "*", "*", 20);
-
- foreach ($grades as $grade) {
- $picture = print_user_picture($grade->userid, $course->id, $grade->picture, false, true);
+ include("report/default.php"); // Parent class
+ include("report/$mode/report.php");
- if ($attempts = quiz_get_user_attempts($quiz->id, $grade->userid)) {
- $userattempts = quiz_get_user_attempts_string($quiz, $attempts, $grade->grade);
- }
+ $report = new quiz_report();
- $table->data[] = array ($picture,
- "<A HREF=\"$CFG->wwwroot/user/view.php?id=$grade->userid&course=$course->id\">$grade->firstname $grade->lastname</A>",
- "$userattempts", round($grade->grade,0));
+ if (! $report->display($quiz, $cm, $course)) { // Do anything before that we need to
+ error("Error occurred during pre-processing!");
}
- print_table($table);
-
- echo "<CENTER><P>";
- $options["regrade"] = "true";
- $options["id"] = $cm->id;
- print_single_button("report.php", $options, get_string("regrade", "quiz"));
- echo "</P></CENTER>";
-
-// Finish the page
print_footer($course);
-
-function quiz_remove_unwanted_questions(&$questions, $quiz) {
-
- $quizquestions = array();
- $quizids = explode(",", $quiz->questions);
- foreach ($quizids as $quizid) {
- $quizquestions[$quizid] = true;
- }
- foreach ($questions as $key => $question) {
- if (!isset($quizquestions[$question->id])) {
- unset($questions[$key]);
- }
- }
-}
-
-
-
-
?>
--- /dev/null
+<?PHP // $Id$
+
+////////////////////////////////////////////////////////////////////
+/// Default class for report plugins
+///
+/// Doesn't do anything on it's own -- it needs to be extended.
+/// This class displays quiz reports. Because it is called from
+/// within /mod/quiz/report.php you can assume that the page header
+/// and footer are taken care of.
+///
+/// This file can refer to itself as report.php to pass variables
+/// to itself - all these will also be globally available. You must
+/// pass "id=$cm->id" or q=$quiz->id", and "mode=reportname".
+////////////////////////////////////////////////////////////////////
+
+// Included by ../report.php
+
+class quiz_default_report {
+
+ function display($cm, $course, $quiz) { /// This function just displays the report
+ return true;
+ }
+
+}
+
+?>
--- /dev/null
+<?PHP // $Id$
+
+/// Overview report just displays a big table of all the attempts
+
+class quiz_report extends quiz_default_report {
+
+ function display($quiz, $cm, $course) { /// This function just displays the report
+
+ global $CFG;
+
+ if (!$grades = quiz_get_grade_records($quiz)) {
+ return;
+ }
+
+ $strname = get_string("name");
+ $strattempts = get_string("attempts", "quiz");
+ $strbestgrade = get_string("bestgrade", "quiz");
+
+ $table->head = array(" ", $strname, $strattempts, "$strbestgrade /$quiz->grade");
+ $table->align = array("center", "left", "left", "center");
+ $table->width = array(10, "*", "*", 20);
+
+ foreach ($grades as $grade) {
+ $picture = print_user_picture($grade->userid, $course->id, $grade->picture, false, true);
+
+ if ($attempts = quiz_get_user_attempts($quiz->id, $grade->userid)) {
+ $userattempts = quiz_get_user_attempts_string($quiz, $attempts, $grade->grade);
+ }
+
+ $table->data[] = array ($picture,
+ "<a href=\"$CFG->wwwroot/user/view.php?id=$grade->userid&course=$course->id\">".
+ "$grade->firstname $grade->lastname</a>",
+ "$userattempts", round($grade->grade,0));
+ }
+
+ print_table($table);
+
+ return true;
+ }
+}
+
+?>
--- /dev/null
+<?PHP // $Id$
+
+/// Overview report just displays a big table of all the attempts
+
+class quiz_report extends quiz_default_report {
+
+ function display($quiz, $cm, $course) { /// This function just displays the report
+
+ global $CFG;
+
+ if (!$attempts = get_records("quiz_attempts", "quiz", $quiz->id)) {
+ print_header(get_string("noattempts", "quiz"));
+ print_continue("report.php?id=$cm->id");
+ print_footer($course);
+ exit;
+ }
+
+ $users = array();
+ $count->attempt = 0;
+ $count->changed = 0;
+
+ foreach ($attempts as $attempt) {
+
+ set_time_limit(120);
+
+ if (!$attempt->timefinish) { // Skip incomplete attempts
+ continue;
+ }
+
+ $count->attempt++;
+
+ if (! $questions = quiz_get_attempt_responses($attempt, $quiz)) {
+ error("Could not reconstruct quiz results for attempt $attempt->id!");
+ }
+ quiz_remove_unwanted_questions($questions, $quiz);
+
+ if (!$result = quiz_grade_attempt_results($quiz, $questions)) {
+ error("Could not re-grade this quiz attempt!");
+ }
+
+ if ($attempt->sumgrades != $result->sumgrades) {
+ $attempt->sumgrades = $result->sumgrades;
+ $count->changed++;
+
+ if (! update_record("quiz_attempts", $attempt)) {
+ notify("Could not regrade attempt $attempt->id");
+ }
+ }
+
+ $users[$attempt->userid] = $attempt->userid;
+ }
+
+ if ($users) {
+ foreach ($users as $userid) {
+ if (! quiz_save_best_grade($quiz, $userid)) {
+ notify("Could not save best grade for user $userid!");
+ }
+ }
+ }
+
+ print_heading(get_string("regradecomplete", "quiz"));
+ print_heading(get_string("regradecount", "quiz", $count));
+
+ return true;
+
+ }
+}
+
+?>
--- /dev/null
+<?PHP // $Id$
+
+// This page prints a review of a particular quiz attempt
+
+ require_once("../../config.php");
+ require_once("lib.php");
+
+ optional_variable($id); // Course Module ID, or
+ optional_variable($q); // quiz ID
+
+ require_variable($attempt); // A particular attempt ID for review
+
+ if ($id) {
+ if (! $cm = get_record("course_modules", "id", $id)) {
+ error("Course Module ID was incorrect");
+ }
+
+ if (! $course = get_record("course", "id", $cm->course)) {
+ error("Course is misconfigured");
+ }
+
+ if (! $quiz = get_record("quiz", "id", $cm->instance)) {
+ error("Course module is incorrect");
+ }
+
+ } else {
+ if (! $quiz = get_record("quiz", "id", $q)) {
+ error("Course module is incorrect");
+ }
+ if (! $course = get_record("course", "id", $quiz->course)) {
+ error("Course is misconfigured");
+ }
+ if (! $cm = get_coursemodule_from_instance("quiz", $quiz->id, $course->id)) {
+ error("Course Module ID was incorrect");
+ }
+ }
+
+ if (! $attempt = get_record("quiz_attempts", "id", $attempt)) {
+ error("No such attempt ID exists");
+ }
+
+
+ require_login($course->id);
+
+ if (!isteacher($course->id)) {
+ if (!$quiz->review) {
+ error(get_string("noreview", "quiz"));
+ }
+ if (time() < $quiz->timeclose) {
+ error(get_string("noreviewuntil", "quiz", userdate($quiz->timeclose)));
+ }
+ if ($attempt->userid != $USER->id) {
+ error("This is not your attempt!");
+ }
+ }
+
+ add_to_log($course->id, "quiz", "review", "review.php?id=$cm->id&attempt=$attempt->id", "$quiz->id");
+
+
+// Print the page header
+
+ if ($course->category) {
+ $navigation = "<A HREF=\"../../course/view.php?id=$course->id\">$course->shortname</A> ->";
+ }
+
+ $strquizzes = get_string("modulenameplural", "quiz");
+ $strquiz = get_string("modulename", "quiz");
+ $strreport = get_string("report", "quiz");
+ $strreview = get_string("review", "quiz");
+ $strname = get_string("name");
+ $strattempts = get_string("attempts", "quiz");
+ $strscore = get_string("score", "quiz");
+ $strgrade = get_string("grade");
+ $strbestgrade = get_string("bestgrade", "quiz");
+ $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>
+ -> <a href=\"view.php?id=$cm->id\">$quiz->name</a> -> $strreview",
+ "", "", true);
+
+ print_heading($quiz->name);
+
+
+ if (! $questions = quiz_get_attempt_responses($attempt, $quiz)) {
+ error("Could not reconstruct quiz results for attempt $attempt->id!");
+ }
+
+ quiz_remove_unwanted_questions($questions, $quiz);
+
+ if (!$result = quiz_grade_attempt_results($quiz, $questions)) {
+ error("Could not re-grade this quiz attempt!");
+ }
+
+ if ($timetaken = ($attempt->timefinish - $attempt->timestart)) {
+ $timetaken = format_time($timetaken);
+ } else {
+ $timetaken = "-";
+ }
+
+ $table->align = array("right", "left");
+ $table->data[] = array("$strtimetaken:", $timetaken);
+ $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);
+
+ if (isteacher($course->id)) {
+ print_continue("report.php?q=$quiz->id");
+ } else {
+ print_continue("view.php?q=$quiz->id");
+ }
+
+ $quiz->feedback = true;
+ $quiz->correctanswers = true;
+ $quiz->shuffleanswers = false;
+ $quiz->shufflequestions = false;
+ quiz_print_quiz_questions($quiz, $result, $questions);
+
+ if (isteacher($course->id)) {
+ print_continue("report.php?q=$quiz->id");
+ } else {
+ print_continue("view.php?q=$quiz->id");
+ }
+
+ print_footer($course);
+
+?>
// This fragment is called by moodle_needs_upgrading() and /admin/index.php
////////////////////////////////////////////////////////////////////////////////
-$module->version = 2003071001; // The (date) version of this module
+$module->version = 2003072400; // The (date) version of this module
$module->cron = 0; // How often should cron check this module (seconds)?
?>
} else {
$answercount = 0;
}
- echo "<P align=right><A HREF=\"report.php?id=$cm->id\">".get_string("viewallanswers","quiz",$answercount)."</A></P>";
+ echo "<p align=right><a href=\"report.php?id=$cm->id\">".get_string("viewallanswers","quiz",$answercount)."</a></p>";
} else if (!$cm->visible) {
notice(get_string("activityiscurrentlyhidden"));
}
if ($numattempts) {
$table->head = array($strattempt, $strtimetaken, $strtimecompleted, "$strgrade / $quiz->grade");
- $table->align = array("CENTER", "CENTER", "LEFT", "RIGHT");
+ $table->align = array("center", "center", "left", "right");
$table->width = array("", "", "", "");
foreach ($attempts as $attempt) {
if ($timetaken = ($attempt->timefinish - $attempt->timestart)) {
}
$attemptgrade = format_float(($attempt->sumgrades/$quiz->sumgrades)*$quiz->grade);
if ($attemptgrade == $mygrade) {
- $attemptgrade = "<SPAN class=highlight>$attemptgrade</SPAN>";
+ $attemptgrade = "<span class=highlight>$attemptgrade</span>";
}
if (!$available and $quiz->review) {
- $attemptgrade = "<A HREF=\"report.php?q=$quiz->id&review=$attempt->id\">$attemptgrade</A>";
+ $attemptgrade = "<a href=\"review.php?q=$quiz->id&attempt=$attempt->id\">$attemptgrade</a>";
}
$table->data[] = array( $attempt->attempt,
format_time($attempt->timefinish - $attempt->timestart),
}
if ($available) {
- echo "<P ALIGN=CENTER>".get_string("quizavailable", "quiz", userdate($quiz->timeclose));
+ echo "<p align=center>".get_string("quizavailable", "quiz", userdate($quiz->timeclose));
} else if ($timenow < $quiz->timeopen) {
- echo "<P ALIGN=CENTER>".get_string("quiznotavailable", "quiz", userdate($quiz->timeopen));
+ echo "<p align=center>".get_string("quiznotavailable", "quiz", userdate($quiz->timeopen));
} else {
- echo "<P ALIGN=CENTER>".get_string("quizclosed", "quiz", userdate($quiz->timeclose));
+ echo "<p align=center>".get_string("quizclosed", "quiz", userdate($quiz->timeclose));
}