Skip to content

Commit

Permalink
MDL-82126 core_grades: change overriden behavior
Browse files Browse the repository at this point in the history
  • Loading branch information
Nathan Nguyen committed Dec 16, 2024
1 parent a07074b commit 92aab45
Show file tree
Hide file tree
Showing 4 changed files with 86 additions and 35 deletions.
34 changes: 23 additions & 11 deletions grade/report/grader/lib.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}
Expand Down Expand Up @@ -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);
}
}
Expand Down Expand Up @@ -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');
}
Expand Down
22 changes: 6 additions & 16 deletions grade/report/grader/templates/cell.mustache
Original file line number Diff line number Diff line change
Expand Up @@ -41,22 +41,12 @@
{{>core_grades/grades/grader/scale}}
{{/scale}}
{{^scale}}
<div class="container">
<div class="row">
{{>core_grades/grades/grader/input}}
</div>
{{#canapplypenalty}}
<div class="row deductedmark">
<input type="checkbox" name="{{exemptionname}}"
value="{{deductedmark}}" id="{{exemptionid}}" class="ms-0"
{{#penaltyexempted}}checked{{/penaltyexempted}}>
<label for="{{exemptionid}}" class="form-check-label ml-1 accesshide" title="{{{exemptiontooltip}}}">
{{{exemptionarialabel}}}
</label>
<span class="form-check-label ml-1 ">{{{exemptionlabel}}}</span>
</div>
{{/canapplypenalty}}
</div>
{{#canapplypenalty}}
{{>core_grades/grades/grader/overriden_with_penalty}}
{{/canapplypenalty}}
{{^canapplypenalty}}
{{>core_grades/grades/grader/input}}
{{/canapplypenalty}}
{{/scale}}
{{/iseditable}}
{{^iseditable}}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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- |
Expand All @@ -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
| Student 1 | student1@example.com | 70 | 100 | 170 |
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 |
| Student 1 Manual grade 02 Penalty exemption | 0 |
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 |
| Student 1 | student1@example.com | 70 | 80 | 150 |
49 changes: 49 additions & 0 deletions grade/templates/grades/grader/overriden_with_penalty.mustache
Original file line number Diff line number Diff line change
@@ -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 <http://www.gnu.org/licenses/>.
}}
{{!
@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,
}
}}

<div class="container">
<div class="row">
<div class="mr-0">Original grade: </div>
{{>core_grades/grades/grader/input}}
</div>

<div class="row">
<div class="mr-0">Current grade: {{{effectivegrade}}}</div>
</div>

<div class="row">
<div class="mr-0" title="{{exemptiontooltip}}">Exempt penalty:</div>
<label for="{{exemptionid}}" class="accesshide">{{{exemptionlabel}}}</label>
<input type="checkbox" name="{{exemptionname}}"
value="{{deductedmark}}" id="{{exemptionid}}"
{{#penaltyexempted}}checked{{/penaltyexempted}}>
</div>
</div>

0 comments on commit 92aab45

Please sign in to comment.