Fixed issue when scales are used (#242)

The grade item's type was being hard-coded to
GRADE_TYPE_VALUE when this isn't always the
case.
This commit is contained in:
Mark Nelson 2018-12-19 12:08:27 +08:00
parent 32338c9aa7
commit 9e9192c7fc

View file

@ -542,31 +542,44 @@ class element_helper {
return false; return false;
} }
$gradeitem = grade_get_grades($cm->course, 'mod', $module->name, $cm->instance, $userid); $params = [
'itemtype' => 'mod',
'itemmodule' => $module->name,
'iteminstance' => $cm->instance,
'courseid' => $cm->course,
'itemnumber' => 0
];
$gradeitem = \grade_item::fetch($params);
if (empty($gradeitem)) { if (empty($gradeitem)) {
return false; return false;
} }
$item = new \grade_item(); $grade = grade_get_grades(
$item->gradetype = GRADE_TYPE_VALUE; $cm->course,
$item->courseid = $cm->course; 'mod',
$itemproperties = reset($gradeitem->items); $module->name,
foreach ($itemproperties as $key => $value) { $cm->instance,
$item->$key = $value; $userid
);
if (!isset($grade->items[0]->grades[$userid])) {
return false;
} }
$objgrade = $item->grades[$userid]; $gradebookgrade = $grade->items[0]->grades[$userid];
$dategraded = null; $dategraded = null;
if (!empty($objgrade->dategraded)) { if (!empty($gradebookgrade->dategraded)) {
$dategraded = $objgrade->dategraded; $dategraded = $gradebookgrade->dategraded;
} }
$displaygrade = grade_format_gradevalue($gradebookgrade->grade, $gradeitem, true, $gradeformat);
return new grade_information( return new grade_information(
$item->name, $gradeitem->get_name(),
$objgrade->grade, $gradebookgrade->grade,
grade_format_gradevalue($objgrade->grade, $item, true, $gradeformat), $displaygrade,
$dategraded $dategraded
); );
} }