From e159a37e2aa1fc88bd540eee306c6feaf4472f08 Mon Sep 17 00:00:00 2001 From: Nathan Nguyen Date: Tue, 1 Apr 2025 15:09:26 +1100 Subject: [PATCH] MDL-85012 mod_assign: fix multiple attempt issue --- lib/grade/grade_item.php | 6 ++++-- mod/assign/locallib.php | 13 ++++++++++++- 2 files changed, 16 insertions(+), 3 deletions(-) diff --git a/lib/grade/grade_item.php b/lib/grade/grade_item.php index 6b050f5a4f4..a36f4e54f29 100644 --- a/lib/grade/grade_item.php +++ b/lib/grade/grade_item.php @@ -2086,8 +2086,10 @@ class grade_item extends grade_object { } // end of hack alert - // Default deduction is 0. - $grade->deductedmark = 0; + // Only reset the deducted mark if the grade has changed. + if ($grade->timemodified !== $oldgrade->timemodified) { + $grade->deductedmark = 0; + } $gradechanged = false; if (empty($grade->id)) { diff --git a/mod/assign/locallib.php b/mod/assign/locallib.php index 3458eeddd5c..5c3561de039 100644 --- a/mod/assign/locallib.php +++ b/mod/assign/locallib.php @@ -5423,7 +5423,15 @@ class assign { ); $gradefordisplay = $gradebookgrade->str_long_grade; } else { - $gradefordisplay = $this->display_grade($gradebookgrade->grade, false, 0, 0, $gradebookgrade->deductedmark); + // This grade info is the grade from gradebook. + // We need user id to determine if the grade is overridden or not. + $gradefordisplay = $this->display_grade( + $gradebookgrade->grade, + false, + $user->id, + 0, + $gradebookgrade->deductedmark + ); } $gradeddate = $gradebookgrade->dategraded; @@ -5630,6 +5638,8 @@ class assign { } } + // The assign grade for each attempt is not stored in the gradebook. + // We need to calculate them from assign_grade records. [$penalisedgrade, $deductedmark] = $this->calculate_penalised_grade($grade); // Now get the gradefordisplay. @@ -5641,6 +5651,7 @@ class assign { $penalisedgrade, $cangrade); } else { + // We do not need user id here as the overriden grade should not affect the previous attempts. $grade->gradefordisplay = $this->display_grade($penalisedgrade, false, 0, 0, $deductedmark); }