Teacher can now regrade (recalculate grades) of all quiz attempts

(in case the quiz changed somehow)
This commit is contained in:
moodler
2002-10-22 06:52:23 +00:00
parent 5ecb135644
commit e331eb06fd
5 changed files with 69 additions and 6 deletions
+3
View File
@@ -56,6 +56,7 @@ $string['introduction'] = "Introduction";
$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";
@@ -69,6 +70,8 @@ $string['quizclosed'] = "This quiz closed on \$a";
$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";
+1 -1
View File
@@ -120,7 +120,7 @@
exit;
}
if (! quiz_save_best_grade($quiz, $USER)) {
if (! quiz_save_best_grade($quiz, $USER->id)) {
error("Sorry! Could not calculate your best grade!");
}
+4 -4
View File
@@ -748,11 +748,11 @@ function quiz_get_grade_records($quiz) {
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;
}
@@ -760,7 +760,7 @@ function quiz_save_best_grade($quiz, $user) {
$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)) {
@@ -769,7 +769,7 @@ function quiz_save_best_grade($quiz, $user) {
}
} 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)) {
+56 -1
View File
@@ -9,6 +9,7 @@
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)) {
@@ -80,8 +81,14 @@
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");
@@ -98,6 +105,48 @@
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;
@@ -121,6 +170,12 @@
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);
+5
View File
@@ -101,6 +101,11 @@
$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),