From b0ad1ff25b7e6b4e09cd09db5d6c9540855d5d03 Mon Sep 17 00:00:00 2001 From: Mark Nelson Date: Fri, 28 Jun 2013 15:30:06 +0800 Subject: [PATCH] Set the code to a randomly generated one if we are previewing the custom certificate --- element/code/lib.php | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/element/code/lib.php b/element/code/lib.php index f8db4a3..f488dfa 100644 --- a/element/code/lib.php +++ b/element/code/lib.php @@ -37,11 +37,16 @@ class customcert_element_code extends customcert_element_base { public function render($pdf, $preview) { 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' => $USER->id, 'customcertid' => $page->customcertid), '*', MUST_EXIST); + if ($preview) { + $code = customcert_generate_code(); + } 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); + $code = $issue->code; + } - parent::render_content($pdf, $issue->code); + parent::render_content($pdf, $code); } }