Set a date and grade to display when previewing a customcert

This commit is contained in:
Mark Nelson 2013-07-23 18:04:46 +08:00
parent 801f367616
commit ff1bdc42af
3 changed files with 37 additions and 25 deletions

View file

@ -96,6 +96,10 @@ class customcert_element_date extends customcert_element_base {
$dateitem = $dateinfo->dateitem; $dateitem = $dateinfo->dateitem;
$dateformat = $dateinfo->dateformat; $dateformat = $dateinfo->dateformat;
// If we are previewing this certificate then just show a demonstration date.
if ($preview) {
$date = time();
} else {
// Get the page. // Get the page.
$page = $DB->get_record('customcert_pages', array('id' => $this->element->pageid), '*', MUST_EXIST); $page = $DB->get_record('customcert_pages', array('id' => $this->element->pageid), '*', MUST_EXIST);
// Now we can get the issue for this user. // Now we can get the issue for this user.
@ -122,6 +126,7 @@ class customcert_element_date extends customcert_element_base {
$date = $modinfo->dategraded; $date = $modinfo->dategraded;
} }
} }
}
// Ensure that a date has been set. // Ensure that a date has been set.
if (!empty($date)) { if (!empty($date)) {

View file

@ -33,3 +33,4 @@ $string['gradepercent'] = 'Percentage Grade';
$string['gradepoints'] = 'Points Grade'; $string['gradepoints'] = 'Points Grade';
$string['gradeletter'] = 'Letter Grade'; $string['gradeletter'] = 'Letter Grade';
$string['pluginname'] = 'Grade'; $string['pluginname'] = 'Grade';
$string['previewgrade'] = 'Preview grade';

View file

@ -94,8 +94,14 @@ class customcert_element_grade extends customcert_element_base {
// Decode the information stored in the database. // Decode the information stored in the database.
$gradeinfo = json_decode($this->element->data); $gradeinfo = json_decode($this->element->data);
// If we are previewing this certificate then just show a demonstration grade.
if ($preview) {
$grade = get_string('previewgrade', 'customcertelement_grade') . ": 50%";
} else {
// Get the grade for the grade item. // Get the grade for the grade item.
$grade = self::get_grade($gradeinfo, $USER->id); $grade = self::get_grade($gradeinfo, $USER->id);
}
parent::render_content($pdf, $grade); parent::render_content($pdf, $grade);
} }