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,30 +96,35 @@ class customcert_element_date extends customcert_element_base {
$dateitem = $dateinfo->dateitem;
$dateformat = $dateinfo->dateformat;
// Get the page.
$page = $DB->get_record('customcert_pages', array('id' => $this->element->pageid), '*', MUST_EXIST);
// Now we can get the issue for this user.
$issue = $DB->get_record('customcert_issues', array('userid' => $USER->id, 'customcertid' => $page->customcertid), '*', MUST_EXIST);
if ($dateitem == CUSTOMCERT_DATE_ISSUE) {
$date = $issue->timecreated;
} else if ($dateitem == CUSTOMCERT_DATE_COMPLETION) {
// Get the enrolment end date.
$sql = "SELECT MAX(c.timecompleted) as timecompleted
FROM {course_completions} c
WHERE c.userid = :userid
AND c.course = :courseid";
if ($timecompleted = $DB->get_record_sql($sql, array('userid' => $issue->userid, 'courseid' => $COURSE->id))) {
if (!empty($timecompleted->timecompleted)) {
$date = $timecompleted->timecompleted;
}
}
// If we are previewing this certificate then just show a demonstration date.
if ($preview) {
$date = time();
} else {
$gradeitem = new stdClass();
$gradeitem->gradeitem = $dateitem;
$gradeitem->gradeformat = GRADE_DISPLAY_TYPE_PERCENTAGE;
if ($modinfo = customcert_element_grade::get_grade($gradeitem, $issue->userid)) {
$date = $modinfo->dategraded;
// Get the page.
$page = $DB->get_record('customcert_pages', array('id' => $this->element->pageid), '*', MUST_EXIST);
// Now we can get the issue for this user.
$issue = $DB->get_record('customcert_issues', array('userid' => $USER->id, 'customcertid' => $page->customcertid), '*', MUST_EXIST);
if ($dateitem == CUSTOMCERT_DATE_ISSUE) {
$date = $issue->timecreated;
} else if ($dateitem == CUSTOMCERT_DATE_COMPLETION) {
// Get the enrolment end date.
$sql = "SELECT MAX(c.timecompleted) as timecompleted
FROM {course_completions} c
WHERE c.userid = :userid
AND c.course = :courseid";
if ($timecompleted = $DB->get_record_sql($sql, array('userid' => $issue->userid, 'courseid' => $COURSE->id))) {
if (!empty($timecompleted->timecompleted)) {
$date = $timecompleted->timecompleted;
}
}
} else {
$gradeitem = new stdClass();
$gradeitem->gradeitem = $dateitem;
$gradeitem->gradeformat = GRADE_DISPLAY_TYPE_PERCENTAGE;
if ($modinfo = customcert_element_grade::get_grade($gradeitem, $issue->userid)) {
$date = $modinfo->dategraded;
}
}
}

View file

@ -33,3 +33,4 @@ $string['gradepercent'] = 'Percentage Grade';
$string['gradepoints'] = 'Points Grade';
$string['gradeletter'] = 'Letter 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.
$gradeinfo = json_decode($this->element->data);
// Get the grade for the grade item.
$grade = self::get_grade($gradeinfo, $USER->id);
// 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.
$grade = self::get_grade($gradeinfo, $USER->id);
}
parent::render_content($pdf, $grade);
}