diff --git a/grade/report/grader/lib.php b/grade/report/grader/lib.php index 09c6d7cedf3e4..6e39853c35976 100644 --- a/grade/report/grader/lib.php +++ b/grade/report/grader/lib.php @@ -1167,7 +1167,7 @@ public function get_right_rows(bool $displayaverages): array { $context->extraclasses = 'gradevalue ' . $hidden . $gradepass; $context->text = grade_format_gradevalue($gradeval, $item, true, - $gradedisplaytype, null); + $gradedisplaytype, null, 20); } } diff --git a/lib/gradelib.php b/lib/gradelib.php index 8af5c4f3516bd..b678235a5f54a 100644 --- a/lib/gradelib.php +++ b/lib/gradelib.php @@ -787,7 +787,9 @@ function grade_set_setting($courseid, $name, $value) { * @param int $decimals The number of decimal places when displaying float values * @return string */ -function grade_format_gradevalue(?float $value, &$grade_item, $localized=true, $displaytype=null, $decimals=null) { +function grade_format_gradevalue(?float $value, &$grade_item, $localized=true, $displaytype=null, $decimals=null, $penalty = 0.0) { + global $PAGE; + if ($grade_item->gradetype == GRADE_TYPE_NONE or $grade_item->gradetype == GRADE_TYPE_TEXT) { return ''; } @@ -812,40 +814,59 @@ function grade_format_gradevalue(?float $value, &$grade_item, $localized=true, $ switch ($displaytype) { case GRADE_DISPLAY_TYPE_REAL: - return grade_format_gradevalue_real($value, $grade_item, $decimals, $localized); + $gradetext = grade_format_gradevalue_real($value, $grade_item, $decimals, $localized); + break; case GRADE_DISPLAY_TYPE_PERCENTAGE: - return grade_format_gradevalue_percentage($value, $grade_item, $decimals, $localized); + $gradetext = grade_format_gradevalue_percentage($value, $grade_item, $decimals, $localized); + break; case GRADE_DISPLAY_TYPE_LETTER: - return grade_format_gradevalue_letter($value, $grade_item); + $gradetext = grade_format_gradevalue_letter($value, $grade_item); + break; case GRADE_DISPLAY_TYPE_REAL_PERCENTAGE: - return grade_format_gradevalue_real($value, $grade_item, $decimals, $localized) . ' (' . + $gradetext = grade_format_gradevalue_real($value, $grade_item, $decimals, $localized) . ' (' . grade_format_gradevalue_percentage($value, $grade_item, $decimals, $localized) . ')'; + break; case GRADE_DISPLAY_TYPE_REAL_LETTER: - return grade_format_gradevalue_real($value, $grade_item, $decimals, $localized) . ' (' . + $gradetext = grade_format_gradevalue_real($value, $grade_item, $decimals, $localized) . ' (' . grade_format_gradevalue_letter($value, $grade_item) . ')'; + break; case GRADE_DISPLAY_TYPE_PERCENTAGE_REAL: - return grade_format_gradevalue_percentage($value, $grade_item, $decimals, $localized) . ' (' . + $gradetext = grade_format_gradevalue_percentage($value, $grade_item, $decimals, $localized) . ' (' . grade_format_gradevalue_real($value, $grade_item, $decimals, $localized) . ')'; + break; case GRADE_DISPLAY_TYPE_LETTER_REAL: - return grade_format_gradevalue_letter($value, $grade_item) . ' (' . + $gradetext = grade_format_gradevalue_letter($value, $grade_item) . ' (' . grade_format_gradevalue_real($value, $grade_item, $decimals, $localized) . ')'; + break; case GRADE_DISPLAY_TYPE_LETTER_PERCENTAGE: - return grade_format_gradevalue_letter($value, $grade_item) . ' (' . + $gradetext = grade_format_gradevalue_letter($value, $grade_item) . ' (' . grade_format_gradevalue_percentage($value, $grade_item, $decimals, $localized) . ')'; + break; case GRADE_DISPLAY_TYPE_PERCENTAGE_LETTER: - return grade_format_gradevalue_percentage($value, $grade_item, $decimals, $localized) . ' (' . + $gradetext = grade_format_gradevalue_percentage($value, $grade_item, $decimals, $localized) . ' (' . grade_format_gradevalue_letter($value, $grade_item) . ')'; + break; + default: - return ''; + $gradetext = ''; } + + // Show penalty indicator if penalty is greater than 0.0. + if ($penalty > 0.0) { + $indicator = new \core_grades\output\penalty_indicator(2, $penalty); + $renderer = $PAGE->get_renderer('core_grades'); + $gradetext = $renderer->render_penalty_indicator($indicator) . $gradetext; + } + + return $gradetext; } /**