Skip to content

Commit

Permalink
WIP
Browse files Browse the repository at this point in the history
  • Loading branch information
Nathan Nguyen committed Aug 15, 2024
1 parent e2314b7 commit 5010fa3
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 12 deletions.
2 changes: 1 addition & 1 deletion grade/report/grader/lib.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}

Expand Down
43 changes: 32 additions & 11 deletions lib/gradelib.php
Original file line number Diff line number Diff line change
Expand Up @@ -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 '';
}
Expand All @@ -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;
}

/**
Expand Down

0 comments on commit 5010fa3

Please sign in to comment.