Passed a new variable 'preview' to the render function

This variable determines whether we are viewing the custom certificate for a particular user, or if we are simply previewing it. This may be needed for some elements. For example, an element may retrieve the data for when the custom certificate was issued, but if the user has just set up the custom certificate and no issue has been created then this data is missing, so in this case we pass that the user is previewing the custom certificate so other data can be shown.
This commit is contained in:
Mark Nelson 2013-06-28 15:17:43 +08:00
parent bb5ce9f4ac
commit e811303e84
17 changed files with 29 additions and 20 deletions

View file

@ -103,7 +103,7 @@ if ((!empty($moveup)) || (!empty($movedown))) {
$DB->set_field('customcert_elements', 'sequence', $movecertelement->sequence, array('id' => $swapcertelement->id));
}
} else if (!empty($deletepage)) { // Check if we are deleting a page.
if (!empty($confirm)) { // Check they have confirmed the deletion
if (!empty($confirm)) { // Check they have confirmed the deletion.
customcert_delete_page($deletepage);
} else {
// Set deletion flag to true.
@ -118,7 +118,7 @@ if ((!empty($moveup)) || (!empty($movedown))) {
'sesskey' => sesskey()));
}
} else if (!empty($deleteelement)) { // Check if we are deleting an element.
if (!empty($confirm)) { // Check they have confirmed the deletion
if (!empty($confirm)) { // Check they have confirmed the deletion.
// Ensure element exists and delete it.
$element = $DB->get_record('customcert_elements', array('id' => $deleteelement), '*', MUST_EXIST);
// Get an instance of the element class.
@ -191,7 +191,7 @@ if ($data = $mform->get_data()) {
// Check if we want to preview this custom certificate.
if (!empty($data->previewbtn)) {
customcert_generate_pdf($customcert);
customcert_generate_pdf($customcert, true);
}
// Redirect to the editing page to show form with recent updates.

View file

@ -32,8 +32,9 @@ class customcert_element_code extends customcert_element_base {
* 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) {
public function render($pdf, $preview) {
global $DB, $USER;
// Get the page.

View file

@ -25,6 +25,6 @@
defined('MOODLE_INTERNAL') || die('Direct access to this script is forbidden.');
$plugin->version = 2013061200;
$plugin->version = 2013062800;
$plugin->requires = 2013040500; // Requires this Moodle version.
$plugin->component = 'customcertelement_code';

View file

@ -82,8 +82,9 @@ class customcert_element_date extends customcert_element_base {
* 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) {
public function render($pdf, $preview) {
global $COURSE, $DB, $USER;
// If there is no element data, we have nothing to display.

View file

@ -25,6 +25,6 @@
defined('MOODLE_INTERNAL') || die('Direct access to this script is forbidden.');
$plugin->version = 2013062500;
$plugin->version = 2013062800;
$plugin->requires = 2013040500; // Requires this Moodle version.
$plugin->component = 'customcertelement_date';

View file

@ -172,8 +172,9 @@ abstract class customcert_element_base {
* Must be overridden.
*
* @param pdf $pdf the pdf object
* @param bool $preview true if it is a preview, false otherwise
*/
public function render($pdf) {
public function render($pdf, $preview) {
// Must be overridden.
}

View file

@ -83,8 +83,9 @@ class customcert_element_grade extends customcert_element_base {
* 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) {
public function render($pdf, $preview) {
global $USER;
// If there is no element data, we have nothing to display.

View file

@ -25,6 +25,6 @@
defined('MOODLE_INTERNAL') || die('Direct access to this script is forbidden.');
$plugin->version = 2013062500;
$plugin->version = 2013062800;
$plugin->requires = 2013040500; // Requires this Moodle version.
$plugin->component = 'customcertelement_grade';

View file

@ -96,8 +96,9 @@ class customcert_element_image extends customcert_element_base {
* 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) {
public function render($pdf, $preview) {
global $CFG;
// If there is no element data, we have nothing to display.

View file

@ -25,6 +25,6 @@
defined('MOODLE_INTERNAL') || die('Direct access to this script is forbidden.');
$plugin->version = 2013062500;
$plugin->version = 2013062800;
$plugin->requires = 2013040500; // Requires this Moodle version.
$plugin->component = 'customcertelement_image';

View file

@ -32,8 +32,9 @@ class customcert_element_studentname extends customcert_element_base {
* 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) {
public function render($pdf, $preview) {
global $USER;
parent::render_content($pdf, fullname($USER));

View file

@ -25,6 +25,6 @@
defined('MOODLE_INTERNAL') || die('Direct access to this script is forbidden.');
$plugin->version = 2013061200;
$plugin->version = 2013062800;
$plugin->requires = 2013040500; // Requires this Moodle version.
$plugin->component = 'customcertelement_studentname';

View file

@ -56,8 +56,9 @@ class customcert_element_text extends customcert_element_base {
* 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) {
public function render($pdf, $preview) {
parent::render_content($pdf, $this->element->data);
}

View file

@ -25,6 +25,6 @@
defined('MOODLE_INTERNAL') || die('Direct access to this script is forbidden.');
$plugin->version = 2013062500;
$plugin->version = 2013062800;
$plugin->requires = 2013040500; // Requires this Moodle version.
$plugin->component = 'customcertelement_text';

View file

@ -62,8 +62,9 @@ class customcert_element_userfield extends customcert_element_base {
* 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) {
public function render($pdf, $preview) {
global $DB, $USER;
// The user field to display.

View file

@ -25,6 +25,6 @@
defined('MOODLE_INTERNAL') || die('Direct access to this script is forbidden.');
$plugin->version = 2013062500;
$plugin->version = 2013062800;
$plugin->requires = 2013040500; // Requires this Moodle version.
$plugin->component = 'customcertelement_userfield';

View file

@ -787,8 +787,9 @@ function customcert_generate_code() {
* Generate the PDF for the specified customcert and user.
*
* @param stdClass $customcert
* @param bool $preview true if it is a preview, false otherwise
*/
function customcert_generate_pdf($customcert) {
function customcert_generate_pdf($customcert, $preview = false) {
global $CFG, $DB;
require_once($CFG->libdir . '/pdflib.php');
@ -817,7 +818,7 @@ function customcert_generate_pdf($customcert) {
foreach ($elements as $element) {
// Get an instance of the element class.
if ($e = customcert_get_element_instance($element)) {
$e->render($pdf);
$e->render($pdf, $preview);
}
}
}