Fixed issue when no grade items present

This commit is contained in:
Mark Nelson 2015-03-13 00:09:36 -07:00
parent 0abc6a0f5c
commit 53cb267836

View file

@ -49,7 +49,11 @@ class customcert_element_gradeitemname extends customcert_element_base {
* @return string the text * @return string the text
*/ */
public function save_unique_data($data) { public function save_unique_data($data) {
return $data->gradeitem; if (!empty($data->gradeitem)) {
return $data->gradeitem;
}
return '';
} }
/** /**
@ -61,14 +65,17 @@ class customcert_element_gradeitemname extends customcert_element_base {
public function render($pdf, $preview) { public function render($pdf, $preview) {
global $DB; global $DB;
// Get the course module information. // Check that the grade item is not empty.
$cm = $DB->get_record('course_modules', array('id' => $this->element->data), '*', MUST_EXIST); if (!empty($this->element->data)) {
$module = $DB->get_record('modules', array('id' => $cm->module), '*', MUST_EXIST); // Get the course module information.
$cm = $DB->get_record('course_modules', array('id' => $this->element->data), '*', MUST_EXIST);
$module = $DB->get_record('modules', array('id' => $cm->module), '*', MUST_EXIST);
// Get the name of the item. // Get the name of the item.
$itemname = $DB->get_field($module->name, 'name', array('id' => $cm->instance), MUST_EXIST); $itemname = $DB->get_field($module->name, 'name', array('id' => $cm->instance), MUST_EXIST);
parent::render_content($pdf, $itemname); parent::render_content($pdf, $itemname);
}
} }
/** /**