$string['marks'] = "Marks";
$string['multichoice'] = "Multiple Choice";
$string['noanswers'] = "No answers were selected!";
+$string['noattempts'] = "No attempts have been made on this quiz";
$string['nomoreattempts'] = "No more attempts are allowed";
$string['noquestions'] = "No questions have been added yet";
$string['publish'] = "Publish";
$string['quizopen'] = "Open the quiz";
$string['quiznotavailable'] = "The quiz will not be available until: \$a";
$string['random'] = "Random set";
+$string['regrade'] = "Regrade all attempts";
+$string['regradecomplete'] = "All attempts have been regraded";
$string['rename'] = "Rename";
$string['report'] = "Reports";
$string['save'] = "Save";
exit;
}
- if (! quiz_save_best_grade($quiz, $USER)) {
+ if (! quiz_save_best_grade($quiz, $USER->id)) {
error("Sorry! Could not calculate your best grade!");
}
AND qg.user = u.id");
}
-function quiz_save_best_grade($quiz, $user) {
+function quiz_save_best_grade($quiz, $userid) {
/// Calculates the best grade out of all attempts at a quiz for a user,
/// and then saves that grade in the quiz_grades table.
- if (!$attempts = quiz_get_user_attempts($quiz->id, $user->id)) {
+ if (!$attempts = quiz_get_user_attempts($quiz->id, $userid)) {
notify("Could not find any user attempts");
return false;
}
$bestgrade = quiz_calculate_best_grade($quiz, $attempts);
$bestgrade = (($bestgrade / $quiz->sumgrades) * $quiz->grade);
- if ($grade = get_record_sql("SELECT * FROM quiz_grades WHERE quiz='$quiz->id' AND user='$user->id'")) {
+ if ($grade = get_record_sql("SELECT * FROM quiz_grades WHERE quiz='$quiz->id' AND user='$userid'")) {
$grade->grade = $bestgrade;
$grade->timemodified = time();
if (!update_record("quiz_grades", $grade)) {
}
} else {
$grade->quiz = $quiz->id;
- $grade->user = $user->id;
+ $grade->user = $userid;
$grade->grade = round($bestgrade, 2);
$grade->timemodified = time();
if (!insert_record("quiz_grades", $grade)) {
optional_variable($q); // quiz ID
optional_variable($attempt); // A particular attempt ID
+ optional_variable($regrade); // Regrade all attempts
if ($id) {
if (! $cm = get_record("course_modules", "id", $id)) {
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:", format_time($attempt->timefinish - $attempt->timestart));
+ $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");
exit;
}
+ if ($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();
+ foreach ($attempts as $attempt) {
+ 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!");
+ }
+
+ echo "<P ALIGN=center>$attempt->sumgrades --> $result->sumgrades</P>";
+ $attempt->sumgrades = $result->sumgrades;
+
+ if (! update_record("quiz_attempts", $attempt)) {
+ notify("Could not regrade attempt $attempt->id");
+ continue;
+ }
+
+ $users[$attempt->user] = $attempt->user;
+ }
+
+ 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_continue("report.php?id=$cm->id");
+ print_footer($course);
+ exit;
+ }
+
if (!$grades = quiz_get_grade_records($quiz)) {
print_footer($course);
exit;
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);
$table->align = array("CENTER", "CENTER", "LEFT", "RIGHT");
$table->width = array("", "", "", "");
foreach ($attempts as $attempt) {
+ if ($timetaken = ($attempt->timefinish - $attempt->timestart)) {
+ $timetaken = format_time($timetaken);
+ } else {
+ $timetaken = "-";
+ }
$table->data[] = array( $attempt->attempt,
format_time($attempt->timefinish - $attempt->timestart),
userdate($attempt->timefinish),