Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Merge branch 'MDL-32633_22' of git://github.com/timhunt/moodle into M…

…OODLE_22_STABLE
  • Loading branch information...
commit 5a6042c9be015fa5e722ee42150165b0c2974ccc 2 parents e8cc542 + fd32dbf
@nebgor nebgor authored
Showing with 14 additions and 9 deletions.
  1. +14 −9 mod/quiz/locallib.php
View
23 mod/quiz/locallib.php
@@ -461,28 +461,33 @@ function quiz_set_grade($newgrade, $quiz) {
return true;
}
+ $oldgrade = $quiz->grade;
+ $quiz->grade = $newgrade;
+
// Use a transaction, so that on those databases that support it, this is safer.
$transaction = $DB->start_delegated_transaction();
// Update the quiz table.
$DB->set_field('quiz', 'grade', $newgrade, array('id' => $quiz->instance));
- // Rescaling the other data is only possible if the old grade was non-zero.
- if ($quiz->grade > 1e-7) {
- global $CFG;
-
- $factor = $newgrade/$quiz->grade;
- $quiz->grade = $newgrade;
+ if ($oldgrade < 1) {
+ // If the old grade was zero, we cannot rescale, we have to recompute.
+ // We also recompute if the old grade was too small to avoid underflow problems.
+ quiz_update_all_final_grades($quiz);
- // Update the quiz_grades table.
+ } else {
+ // We can rescale the grades efficiently.
$timemodified = time();
$DB->execute("
UPDATE {quiz_grades}
SET grade = ? * grade, timemodified = ?
WHERE quiz = ?
- ", array($factor, $timemodified, $quiz->id));
+ ", array($newgrade/$oldgrade, $timemodified, $quiz->id));
+ }
+ if ($oldgrade > 1e-7) {
// Update the quiz_feedback table.
+ $factor = $newgrade/$oldgrade;
$DB->execute("
UPDATE {quiz_feedback}
SET mingrade = ? * mingrade, maxgrade = ? * maxgrade
@@ -490,7 +495,7 @@ function quiz_set_grade($newgrade, $quiz) {
", array($factor, $factor, $quiz->id));
}
- // update grade item and send all grades to gradebook
+ // Update grade item and send all grades to gradebook.
quiz_grade_item_update($quiz);
quiz_update_grades($quiz);
Please sign in to comment.
Something went wrong with that request. Please try again.