Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

MDL-26275 grade: made some equality checks more strict and added some…

… explanatory comments
  • Loading branch information...
commit 1e2698f6fa4ad9c33ef11266c5dc05fbec6ad4a7 1 parent a740a0a
Andrew Davis andyjdavis authored

Showing 1 changed file with 23 additions and 8 deletions. Show diff stats Hide diff stats

  1. +23 8 grade/report/grader/lib.php
31 grade/report/grader/lib.php
@@ -200,17 +200,32 @@ public function process_data($data) {
200 200
201 201 // Was change requested?
202 202 $oldvalue = $this->grades[$userid][$itemid];
203   - if ($datatype == 'grade') {
204   - if ($oldvalue->finalgrade == $postedvalue) { // string comparison
205   - continue;
206   - }
207   - if ($oldvalue->finalgrade == null && $postedvalue == -1) {
  203 + if ($datatype === 'grade') {
  204 + // If there was no grade and there still isn't
  205 + if (is_null($oldvalue->finalgrade) && $postedvalue == -1) {
208 206 // -1 means no grade
209 207 continue;
210 208 }
  209 +
  210 + // If the grade item uses a custom scale
  211 + if (!empty($oldvalue->grade_item->scaleid)) {
  212 +
  213 + if ((int)$oldvalue->finalgrade === (int)$postedvalue) {
  214 + continue;
  215 + }
  216 + } else {
  217 + // The grade item uses a numeric scale
  218 +
  219 + // Format the finalgrade from the DB so that it matches the grade from the client
  220 + if ($postedvalue === format_float($oldvalue->finalgrade, $oldvalue->grade_item->get_decimals())) {
  221 + continue;
  222 + }
  223 + }
  224 +
211 225 $changedgrades = true;
212   - } else if ($datatype == 'feedback') {
213   - if ($oldvalue->feedback == $postedvalue) {
  226 +
  227 + } else if ($datatype === 'feedback') {
  228 + if ($oldvalue->feedback === $postedvalue) {
214 229 continue;
215 230 }
216 231 }
@@ -284,7 +299,7 @@ public function process_data($data) {
284 299 $gradeitem->update_final_grade($userid, $finalgrade, 'gradebook', $feedback, FORMAT_MOODLE);
285 300
286 301 // We can update feedback without reloading the grade item as it doesn't affect grade calculations
287   - if ($datatype == 'feedback') {
  302 + if ($datatype === 'feedback') {
288 303 $this->grades[$userid][$itemid]->feedback = $feedback;
289 304 }
290 305 }

0 comments on commit 1e2698f

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