diff --git a/grade/report/grader/lib.php b/grade/report/grader/lib.php index 8f0f549fe9a46..45c90d90b9ce2 100644 --- a/grade/report/grader/lib.php +++ b/grade/report/grader/lib.php @@ -243,24 +243,27 @@ public function process_data($data) { // Detect changes in exemption checkbox. if ($oldvalue->can_apply_penalty_to_overridden_mark()) { - $exemptionchanged = isset($data->exemption[$userid][$itemid]) != - !$oldvalue->is_penalty_applied_to_overridden_mark(); + if (!isset($data->exemption[$userid][$itemid])) { + $newvalue = format_float($postedvalue - $oldvalue->deductedmark, + $oldvalue->grade_item->get_decimals()); + } else { + $newvalue = $postedvalue; + } } else { - $exemptionchanged = false; + $newvalue = $postedvalue; } // If the grade item uses a custom scale if (!empty($oldvalue->grade_item->scaleid)) { - if ((int)$oldvalue->finalgrade === (int)$postedvalue && !$exemptionchanged) { + if ((int)$oldvalue->finalgrade === (int)$newvalue) { continue; } } else { // The grade item uses a numeric scale // Format the finalgrade from the DB so that it matches the grade from the client - if ($postedvalue === format_float($oldvalue->finalgrade, $oldvalue->grade_item->get_decimals()) - && !$exemptionchanged) { + if ($newvalue === format_float($oldvalue->finalgrade, $oldvalue->grade_item->get_decimals())) { continue; } } @@ -335,15 +338,17 @@ public function process_data($data) { } } + // Save final grade, without penalty. $gradeitem->update_final_grade($userid, $finalgrade, 'gradebook', false, FORMAT_MOODLE, null, null, true); - // Save overridden mark. + // Save overridden mark, without penalty. $gradeitem->update_overridden_mark($userid, $finalgrade); // Apply penalty. if ($oldvalue->can_apply_penalty_to_overridden_mark() && !isset($data->exemption[$userid][$itemid])) { - $gradeitem->update_final_grade($userid, $finalgrade - $oldvalue->deductedmark, 'gradepenalty', false, + // Apply penalty. + $gradeitem->update_final_grade($userid, $newvalue, 'gradepenalty', false, FORMAT_MOODLE, null, null, true); } } @@ -1168,12 +1173,19 @@ public function get_right_rows(bool $displayaverages): array { // Show option for user to apply penalty or not. if ($grade->can_apply_penalty_to_overridden_mark()) { $context->canapplypenalty = true; + if ($grade->is_penalty_applied_to_final_grade()) { + // We are editing the original grade value, ie, before applying penalty. + $context->value = format_float($gradeval + $grade->deductedmark, $decimalpoints); + } else { + $context->value = $value; + } + // Current grade. + $context->effectivegrade = $value; $context->deductedmark = format_float($grade->deductedmark, $decimalpoints); - $context->penaltyexempted = !$grade->is_penalty_applied_to_overridden_mark(); + $context->penaltyexempted = !$grade->is_penalty_applied_to_final_grade(); $context->exemptionid = 'exemption' . $userid . '_' . $item->id; $context->exemptionname = 'exemption[' . $userid . '][' . $item->id .']'; - $context->exemptionlabel = get_string('applypenaltytext', 'gradereport_grader'); - $context->exemptionarialabel = $gradelabel . ' ' . + $context->exemptionlabel = $gradelabel . ' ' . get_string('applypenaltytext', 'gradereport_grader'); $context->exemptiontooltip = get_string('applypenaltytooltip', 'gradereport_grader'); } diff --git a/grade/report/grader/templates/cell.mustache b/grade/report/grader/templates/cell.mustache index 293a709a4be7b..7dee1873929f0 100644 --- a/grade/report/grader/templates/cell.mustache +++ b/grade/report/grader/templates/cell.mustache @@ -41,22 +41,12 @@ {{>core_grades/grades/grader/scale}} {{/scale}} {{^scale}} -
-
- {{>core_grades/grades/grader/input}} -
- {{#canapplypenalty}} -
- - - {{{exemptionlabel}}} -
- {{/canapplypenalty}} -
+ {{#canapplypenalty}} + {{>core_grades/grades/grader/overriden_with_penalty}} + {{/canapplypenalty}} + {{^canapplypenalty}} + {{>core_grades/grades/grader/input}} + {{/canapplypenalty}} {{/scale}} {{/iseditable}} {{^iseditable}} diff --git a/grade/report/grader/tests/behat/grade_override_with_deduction.feature b/grade/report/grader/tests/behat/grade_override_with_deduction.feature index 034d6330a89da..6c1a51a9443f7 100644 --- a/grade/report/grader/tests/behat/grade_override_with_deduction.feature +++ b/grade/report/grader/tests/behat/grade_override_with_deduction.feature @@ -26,7 +26,7 @@ Feature: As a teacher, I want to override a grade with a deduction and check the @javascript Scenario: Override a grade with a deduction and check the gradebook - And I am on "Course 1" course homepage + Given I am on "Course 1" course homepage And I navigate to "View > Grader report" in the course gradebook And the following should exist in the "user-grades" table: | -1- | -2- | -3- | -4- | -5- | @@ -37,16 +37,16 @@ Feature: As a teacher, I want to override a grade with a deduction and check the | Student 1 Manual grade 01 Penalty exemption | 0 | | Student 1 Manual grade 02 Penalty exemption | 1 | And I click on "Save changes" "button" - And I turn editing mode off - And the following should exist in the "user-grades" table: + When I turn editing mode off + Then the following should exist in the "user-grades" table: | -1- | -2- | -3- | -4- | -5- | | Student 1 | student1@example.com | 70 | 80 | 150 | - And I turn editing mode on + When I turn editing mode on And I set the following fields to these values: | Student 1 Manual grade 02 grade | 100 | | Student 1 Manual grade 02 Penalty exemption | 1 | And I click on "Save changes" "button" And I turn editing mode off - And the following should exist in the "user-grades" table: + Then the following should exist in the "user-grades" table: | -1- | -2- | -3- | -4- | -5- | | Student 1 | student1@example.com | 70 | 100 | 170 | diff --git a/grade/templates/grades/grader/overriden_with_penalty.mustache b/grade/templates/grades/grader/overriden_with_penalty.mustache new file mode 100644 index 0000000000000..14c3ebdd121d7 --- /dev/null +++ b/grade/templates/grades/grader/overriden_with_penalty.mustache @@ -0,0 +1,49 @@ +{{! + This file is part of Moodle - http://moodle.org/ + + Moodle is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + Moodle is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with Moodle. If not, see . +}} +{{! + @template core_grades/grades/grader/overriden_with_penalty + + Input template for grader report cell. + + Example context (json): + { + "deductedmark": "30.00", + "exemptionid": "exemption3_2", + "exemptionlabel": "Exempt penalty", + "exemptionname": "exemption[3][2]", + "penaltyexempted": true, + } +}} + +
+
+
Original grade:
+ {{>core_grades/grades/grader/input}} +
+ +
+
Current grade: {{{effectivegrade}}}
+
+ +
+
Exempt penalty:
+ + +
+