diff --git a/edit.php b/edit.php index 43f9f9c..cd06724 100644 --- a/edit.php +++ b/edit.php @@ -183,7 +183,7 @@ if ($data = $mform->get_data()) { // Check if we want to preview this custom certificate. if (!empty($data->previewbtn)) { - customcert_generate_pdf($customcert, $USER->id); + customcert_generate_pdf($customcert); } // Redirect to the editing page to show form with recent updates. diff --git a/elements/code/lib.php b/elements/code/lib.php index 51f849b..15c4b1c 100644 --- a/elements/code/lib.php +++ b/elements/code/lib.php @@ -33,15 +33,14 @@ class customcert_element_code extends customcert_element_base { * Handles rendering the element on the pdf. * * @param stdClass $pdf the pdf object - * @param int $userid */ - public function render($pdf, $userid) { - global $DB; + public function render($pdf) { + global $DB, $USER; // 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' => $userid, 'customcertid' => $page->customcertid), '*', MUST_EXIST); + $issue = $DB->get_record('customcert_issues', array('userid' => $USER->id, 'customcertid' => $page->customcertid), '*', MUST_EXIST); parent::render_content($pdf, $issue->code); } diff --git a/elements/date/lib.php b/elements/date/lib.php index 6514eb0..c405c29 100644 --- a/elements/date/lib.php +++ b/elements/date/lib.php @@ -91,9 +91,8 @@ class customcert_element_date extends customcert_element_base { * Handles rendering the element on the pdf. * * @param stdClass $pdf the pdf object - * @param int $userid */ - public function render($pdf, $userid) { + public function render($pdf) { // TO DO. } diff --git a/elements/element.class.php b/elements/element.class.php index f516d90..82f882a 100644 --- a/elements/element.class.php +++ b/elements/element.class.php @@ -169,9 +169,8 @@ class customcert_element_base { * Must be overridden. * * @param stdClass $pdf the pdf object - * @param int $userid */ - public function render($pdf, $userid) { + public function render($pdf) { // Must be overridden. } @@ -179,7 +178,7 @@ class customcert_element_base { * Common behaviour for rendering specified content on the pdf. * * @param stdClass $pdf the pdf object - * @param stdClass $content the content to render + * @param string $content the content to render */ public function render_content($pdf, $content) { $this->set_font($pdf); diff --git a/elements/grade/lib.php b/elements/grade/lib.php index 0847f6e..1294e36 100644 --- a/elements/grade/lib.php +++ b/elements/grade/lib.php @@ -103,9 +103,10 @@ class customcert_element_grade extends customcert_element_base { * Handles rendering the element on the pdf. * * @param stdClass $pdf the pdf object - * @param int $userid */ - public function render($pdf, $userid) { + public function render($pdf) { + global $USER; + // If there is no element data, we have nothing to display. if (empty($this->element->data)) { return; @@ -115,7 +116,7 @@ class customcert_element_grade extends customcert_element_base { $gradeinfo = json_decode($this->element->data); // Get the grade for the grade item. - $grade = customcert_element_grade::get_grade($gradeinfo, $userid); + $grade = customcert_element_grade::get_grade($gradeinfo, $USER->id); parent::render_content($pdf, $grade); } diff --git a/elements/image/lib.php b/elements/image/lib.php index 63ff6e6..7ed7eaf 100644 --- a/elements/image/lib.php +++ b/elements/image/lib.php @@ -144,9 +144,8 @@ class customcert_element_image extends customcert_element_base { * Handles rendering the element on the pdf. * * @param stdClass $pdf the pdf object - * @param int $userid */ - public function render($pdf, $userid) { + public function render($pdf) { global $CFG; // If there is no element data, we have nothing to display. diff --git a/elements/studentname/lib.php b/elements/studentname/lib.php index 3c380ac..7564b28 100644 --- a/elements/studentname/lib.php +++ b/elements/studentname/lib.php @@ -33,14 +33,10 @@ class customcert_element_studentname extends customcert_element_base { * Handles rendering the element on the pdf. * * @param stdClass $pdf the pdf object - * @param int $userid */ - public function render($pdf, $userid) { - global $DB; + public function render($pdf) { + global $USER; - $user = $DB->get_record('user', array('id' => $userid), 'id, firstname, lastname', MUST_EXIST); - $fullname = fullname($user); - - parent::render_content($pdf, $fullname); + parent::render_content($pdf, fullname($USER)); } } diff --git a/lib.php b/lib.php index 7156dee..4d577fc 100644 --- a/lib.php +++ b/lib.php @@ -817,9 +817,8 @@ function customcert_generate_code() { * Generate the PDF for the specified customcert and user. * * @param stdClass $customcert - * @param int $userid */ -function customcert_generate_pdf($customcert, $userid) { +function customcert_generate_pdf($customcert) { global $CFG, $DB; require_once($CFG->libdir . '/pdflib.php'); @@ -848,7 +847,7 @@ function customcert_generate_pdf($customcert, $userid) { foreach ($elements as $element) { // Get an instance of the element class. if ($e = customcert_get_element_instance($element)) { - $e->render($pdf, $userid); + $e->render($pdf); } } } diff --git a/view.php b/view.php index 76c4c56..bf125f1 100644 --- a/view.php +++ b/view.php @@ -120,5 +120,5 @@ if (empty($action)) { $DB->insert_record('customcert_issues', $customcertissue); } // Now we want to generate the PDF. - customcert_generate_pdf($customcert, $USER->id); + customcert_generate_pdf($customcert); }