/** * Handles rendering the element on the pdf. * * @param pdf $pdf the pdf object * @param bool $preview true if it is a preview, false otherwise */ public function render($pdf, $preview) { global $COURSE, $DB, $USER; // If there is no element data, we have nothing to display. if (empty($this->element->data)) { return; } // Decode the information stored in the database. $dateinfo = json_decode($this->element->data); $dateitem = $dateinfo->dateitem; $dateformat = $dateinfo->dateformat; // If we are previewing this certificate then just show a demonstration date. if ($preview) { $date = time(); } else { // 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\n FROM {course_completions} c\n WHERE c.userid = :userid\n 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; } } } } // Ensure that a date has been set. if (!empty($date)) { switch ($dateformat) { case 1: $certificatedate = userdate($date, '%B %d, %Y'); break; case 2: $suffix = $this->get_ordinal_number_suffix(userdate($date, '%d')); $certificatedate = userdate($date, '%B %d' . $suffix . ', %Y'); break; case 3: $certificatedate = userdate($date, '%d %B %Y'); break; case 4: $certificatedate = userdate($date, '%B %Y'); break; default: $certificatedate = userdate($date, get_string('strftimedate', 'langconfig')); } parent::render_content($pdf, $certificatedate); } }
/** * This function renders the form elements when adding a customcert element. * * @param mod_customcert_edit_element_form $mform the edit_form instance */ public function render_form_elements($mform) { $mform->addElement('select', 'gradeitem', get_string('gradeitem', 'customcertelement_gradeitemname'), customcert_element_grade::get_grade_items()); $mform->addHelpButton('gradeitem', 'gradeitem', 'customcertelement_gradeitemname'); parent::render_form_elements($mform); }