From 7749e7921276ff06d2b57f76da894b82d6785119 Mon Sep 17 00:00:00 2001 From: Nathan Nguyen Date: Wed, 2 Apr 2025 10:01:44 +1100 Subject: [PATCH] MDL-85012 mod_assign: reuse show_penalty_indicator --- mod/assign/locallib.php | 21 +++++++------------ mod/assign/tests/behat/display_grade.feature | 22 ++++++++++++++++++++ 2 files changed, 29 insertions(+), 14 deletions(-) diff --git a/mod/assign/locallib.php b/mod/assign/locallib.php index 5c3561de039..46d11c71528 100644 --- a/mod/assign/locallib.php +++ b/mod/assign/locallib.php @@ -2075,16 +2075,10 @@ class assign { // Add penalty indicator, icon only. $penaltyindicator = ''; if ($deductedmark > 0) { - $gradeitem = $this->get_grade_item(); - $ispenaltyapplied = $gradeitem && $gradeitem->get_grade($userid)->is_penalty_applied_to_final_grade(); - // If the user is set, we need to check if the penalty is applied to overridden grade. - if ($userid == 0 || $ispenaltyapplied) { - $usergrade = new \grade_grade(); - $usergrade->deductedmark = $deductedmark; - $indicator = new \core_grades\output\penalty_indicator(2, $usergrade); - $renderer = $PAGE->get_renderer('core_grades'); - $penaltyindicator = $renderer->render_penalty_indicator($indicator); - } + $gradegrade = new \grade_grade(); + $gradegrade->deductedmark = $deductedmark; + $gradegrade->overridden = $userid > 0 ? $this->get_grade_item()->get_grade($userid)->overridden : 0; + $penaltyindicator = \core_grades\penalty_manager::show_penalty_indicator($gradegrade); } return $penaltyindicator . $o; @@ -7891,12 +7885,11 @@ class assign { // Penalty indicator. $userassigngrade = $gradinginfo->items[0]->grades[$userid]; - if (isset($userassigngrade->grade) && $userassigngrade->deductedmark > 0) { + if (isset($userassigngrade->grade)) { $gradegrade = new \grade_grade(); $gradegrade->deductedmark = $userassigngrade->deductedmark; - $indicator = new \core_grades\output\penalty_indicator(2, $gradegrade); - $renderer = $PAGE->get_renderer('core_grades'); - $penaltyindicator = $renderer->render_penalty_indicator($indicator); + $gradegrade->overridden = $userassigngrade->overridden; + $penaltyindicator = \core_grades\penalty_manager::show_penalty_indicator($gradegrade); $gradestring = $penaltyindicator . $gradestring; } diff --git a/mod/assign/tests/behat/display_grade.feature b/mod/assign/tests/behat/display_grade.feature index f93dcae7fcd..c62aaa75890 100644 --- a/mod/assign/tests/behat/display_grade.feature +++ b/mod/assign/tests/behat/display_grade.feature @@ -108,7 +108,29 @@ Feature: Check that the assignment grade can be updated correctly And I set the field "Grade out of 100" to "100" And I set the field "Notify student" to "0" And I press "Save changes" + And the "title" attribute of ".penalty-indicator-icon" "css_element" should contain "Late penalty applied -10.00 marks" And I follow "View all submissions" And "Student 1" row "Grade" column of "generaltable" table should contain "100.00" And "Student 1" row "Final grade" column of "generaltable" table should contain "90.00" And the "title" attribute of ".penalty-indicator-icon" "css_element" should contain "Late penalty applied -10.00 marks" + # Override the grade. + When I am on "Course 1" course homepage + And I navigate to "View > Grader report" in the course gradebook + And I turn editing mode off + Then the following should exist in the "user-grades" table: + | -1- | -2- | -3- | -4- | + | Student 1 | student10@example.com | 90 | 90 | + And the "title" attribute of ".penalty-indicator-icon" "css_element" should contain "Late penalty applied -10.00 marks" + And I turn editing mode on + And I set the following fields to these values: + | Student 1 Test assignment name grade | 100 | + And I click on "Save changes" "button" + When I turn editing mode off + Then the following should exist in the "user-grades" table: + | -1- | -2- | -3- | -4- | + | Student 1 | student10@example.com | 100 | 100 | + And ".penalty-indicator-icon" "css_element" should not exist + When I go to "Student 1" "Test assignment name" activity advanced grading page + Then ".penalty-indicator-icon" "css_element" should not exist + And I follow "View all submissions" + Then ".penalty-indicator-icon" "css_element" should not exist