Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

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

…OODLE_21_STABLE
  • Loading branch information...
commit 3cf17d040e1564e72e6afa7a61e2882196dc8fe0 2 parents d9e1178 + 45cadec
Aparup Banerjee authored May 16, 2012

Showing 1 changed file with 14 additions and 9 deletions. Show diff stats Hide diff stats

  1. 23  mod/quiz/locallib.php
23  mod/quiz/locallib.php
@@ -483,28 +483,33 @@ function quiz_set_grade($newgrade, $quiz) {
483 483
         return true;
484 484
     }
485 485
 
  486
+    $oldgrade = $quiz->grade;
  487
+    $quiz->grade = $newgrade;
  488
+
486 489
     // Use a transaction, so that on those databases that support it, this is safer.
487 490
     $transaction = $DB->start_delegated_transaction();
488 491
 
489 492
     // Update the quiz table.
490 493
     $DB->set_field('quiz', 'grade', $newgrade, array('id' => $quiz->instance));
491 494
 
492  
-    // Rescaling the other data is only possible if the old grade was non-zero.
493  
-    if ($quiz->grade > 1e-7) {
494  
-        global $CFG;
495  
-
496  
-        $factor = $newgrade/$quiz->grade;
497  
-        $quiz->grade = $newgrade;
  495
+    if ($oldgrade < 1) {
  496
+        // If the old grade was zero, we cannot rescale, we have to recompute.
  497
+        // We also recompute if the old grade was too small to avoid underflow problems.
  498
+        quiz_update_all_final_grades($quiz);
498 499
 
499  
-        // Update the quiz_grades table.
  500
+    } else {
  501
+        // We can rescale the grades efficiently.
500 502
         $timemodified = time();
501 503
         $DB->execute("
502 504
                 UPDATE {quiz_grades}
503 505
                 SET grade = ? * grade, timemodified = ?
504 506
                 WHERE quiz = ?
505  
-        ", array($factor, $timemodified, $quiz->id));
  507
+        ", array($newgrade/$oldgrade, $timemodified, $quiz->id));
  508
+    }
506 509
 
  510
+    if ($oldgrade > 1e-7) {
507 511
         // Update the quiz_feedback table.
  512
+        $factor = $newgrade/$oldgrade;
508 513
         $DB->execute("
509 514
                 UPDATE {quiz_feedback}
510 515
                 SET mingrade = ? * mingrade, maxgrade = ? * maxgrade
@@ -512,7 +517,7 @@ function quiz_set_grade($newgrade, $quiz) {
512 517
         ", array($factor, $factor, $quiz->id));
513 518
     }
514 519
 
515  
-    // update grade item and send all grades to gradebook
  520
+    // Update grade item and send all grades to gradebook.
516 521
     quiz_grade_item_update($quiz);
517 522
     quiz_update_grades($quiz);
518 523
 

0 notes on commit 3cf17d0

Please sign in to comment.
Something went wrong with that request. Please try again.