The Grade item name element works with all grade items (#346)

This commit is contained in:
Mark Nelson 2020-05-08 17:20:12 +02:00
parent 9badf60f91
commit 42645287d7

View file

@ -117,13 +117,33 @@ class element extends \mod_customcert\element {
protected function get_grade_item_name() : string { protected function get_grade_item_name() : string {
global $DB; global $DB;
// Get the course module information. $gradeitem = $this->get_data();
$cm = $DB->get_record('course_modules', array('id' => $this->get_data()), '*', MUST_EXIST);
$module = $DB->get_record('modules', array('id' => $cm->module), '*', MUST_EXIST);
// Get the name of the item. if (strpos($gradeitem, 'gradeitem:') === 0) {
$itemname = $DB->get_field($module->name, 'name', array('id' => $cm->instance), MUST_EXIST); $gradeitemid = substr($gradeitem, 10);
$gradeitem = \grade_item::fetch(['id' => $gradeitemid]);
return format_string($itemname, true, ['context' => \mod_customcert\element_helper::get_context($this->get_id())]); return $gradeitem->get_name();
} else {
if (!$cm = $DB->get_record('course_modules', array('id' => $gradeitem))) {
return '';
}
if (!$module = $DB->get_record('modules', array('id' => $cm->module))) {
return '';
}
$params = [
'itemtype' => 'mod',
'itemmodule' => $module->name,
'iteminstance' => $cm->instance,
'courseid' => $cm->course,
'itemnumber' => 0
];
$gradeitem = \grade_item::fetch($params);
return $gradeitem->get_name();
}
} }
} }