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:
parent
bb5ce9f4ac
commit
e811303e84
17 changed files with 29 additions and 20 deletions
6
edit.php
6
edit.php
|
@ -103,7 +103,7 @@ if ((!empty($moveup)) || (!empty($movedown))) {
|
||||||
$DB->set_field('customcert_elements', 'sequence', $movecertelement->sequence, array('id' => $swapcertelement->id));
|
$DB->set_field('customcert_elements', 'sequence', $movecertelement->sequence, array('id' => $swapcertelement->id));
|
||||||
}
|
}
|
||||||
} else if (!empty($deletepage)) { // Check if we are deleting a page.
|
} 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);
|
customcert_delete_page($deletepage);
|
||||||
} else {
|
} else {
|
||||||
// Set deletion flag to true.
|
// Set deletion flag to true.
|
||||||
|
@ -118,7 +118,7 @@ if ((!empty($moveup)) || (!empty($movedown))) {
|
||||||
'sesskey' => sesskey()));
|
'sesskey' => sesskey()));
|
||||||
}
|
}
|
||||||
} else if (!empty($deleteelement)) { // Check if we are deleting an element.
|
} 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.
|
// Ensure element exists and delete it.
|
||||||
$element = $DB->get_record('customcert_elements', array('id' => $deleteelement), '*', MUST_EXIST);
|
$element = $DB->get_record('customcert_elements', array('id' => $deleteelement), '*', MUST_EXIST);
|
||||||
// Get an instance of the element class.
|
// 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.
|
// Check if we want to preview this custom certificate.
|
||||||
if (!empty($data->previewbtn)) {
|
if (!empty($data->previewbtn)) {
|
||||||
customcert_generate_pdf($customcert);
|
customcert_generate_pdf($customcert, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Redirect to the editing page to show form with recent updates.
|
// Redirect to the editing page to show form with recent updates.
|
||||||
|
|
|
@ -32,8 +32,9 @@ class customcert_element_code extends customcert_element_base {
|
||||||
* Handles rendering the element on the pdf.
|
* Handles rendering the element on the pdf.
|
||||||
*
|
*
|
||||||
* @param pdf $pdf the pdf object
|
* @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;
|
global $DB, $USER;
|
||||||
|
|
||||||
// Get the page.
|
// Get the page.
|
||||||
|
|
|
@ -25,6 +25,6 @@
|
||||||
|
|
||||||
defined('MOODLE_INTERNAL') || die('Direct access to this script is forbidden.');
|
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->requires = 2013040500; // Requires this Moodle version.
|
||||||
$plugin->component = 'customcertelement_code';
|
$plugin->component = 'customcertelement_code';
|
||||||
|
|
|
@ -82,8 +82,9 @@ class customcert_element_date extends customcert_element_base {
|
||||||
* Handles rendering the element on the pdf.
|
* Handles rendering the element on the pdf.
|
||||||
*
|
*
|
||||||
* @param pdf $pdf the pdf object
|
* @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;
|
global $COURSE, $DB, $USER;
|
||||||
|
|
||||||
// If there is no element data, we have nothing to display.
|
// If there is no element data, we have nothing to display.
|
||||||
|
|
|
@ -25,6 +25,6 @@
|
||||||
|
|
||||||
defined('MOODLE_INTERNAL') || die('Direct access to this script is forbidden.');
|
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->requires = 2013040500; // Requires this Moodle version.
|
||||||
$plugin->component = 'customcertelement_date';
|
$plugin->component = 'customcertelement_date';
|
||||||
|
|
|
@ -172,8 +172,9 @@ abstract class customcert_element_base {
|
||||||
* Must be overridden.
|
* Must be overridden.
|
||||||
*
|
*
|
||||||
* @param pdf $pdf the pdf object
|
* @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.
|
// Must be overridden.
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -83,8 +83,9 @@ class customcert_element_grade extends customcert_element_base {
|
||||||
* Handles rendering the element on the pdf.
|
* Handles rendering the element on the pdf.
|
||||||
*
|
*
|
||||||
* @param pdf $pdf the pdf object
|
* @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;
|
global $USER;
|
||||||
|
|
||||||
// If there is no element data, we have nothing to display.
|
// If there is no element data, we have nothing to display.
|
||||||
|
|
|
@ -25,6 +25,6 @@
|
||||||
|
|
||||||
defined('MOODLE_INTERNAL') || die('Direct access to this script is forbidden.');
|
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->requires = 2013040500; // Requires this Moodle version.
|
||||||
$plugin->component = 'customcertelement_grade';
|
$plugin->component = 'customcertelement_grade';
|
||||||
|
|
|
@ -96,8 +96,9 @@ class customcert_element_image extends customcert_element_base {
|
||||||
* Handles rendering the element on the pdf.
|
* Handles rendering the element on the pdf.
|
||||||
*
|
*
|
||||||
* @param pdf $pdf the pdf object
|
* @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;
|
global $CFG;
|
||||||
|
|
||||||
// If there is no element data, we have nothing to display.
|
// If there is no element data, we have nothing to display.
|
||||||
|
|
|
@ -25,6 +25,6 @@
|
||||||
|
|
||||||
defined('MOODLE_INTERNAL') || die('Direct access to this script is forbidden.');
|
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->requires = 2013040500; // Requires this Moodle version.
|
||||||
$plugin->component = 'customcertelement_image';
|
$plugin->component = 'customcertelement_image';
|
||||||
|
|
|
@ -32,8 +32,9 @@ class customcert_element_studentname extends customcert_element_base {
|
||||||
* Handles rendering the element on the pdf.
|
* Handles rendering the element on the pdf.
|
||||||
*
|
*
|
||||||
* @param pdf $pdf the pdf object
|
* @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;
|
global $USER;
|
||||||
|
|
||||||
parent::render_content($pdf, fullname($USER));
|
parent::render_content($pdf, fullname($USER));
|
||||||
|
|
|
@ -25,6 +25,6 @@
|
||||||
|
|
||||||
defined('MOODLE_INTERNAL') || die('Direct access to this script is forbidden.');
|
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->requires = 2013040500; // Requires this Moodle version.
|
||||||
$plugin->component = 'customcertelement_studentname';
|
$plugin->component = 'customcertelement_studentname';
|
||||||
|
|
|
@ -56,8 +56,9 @@ class customcert_element_text extends customcert_element_base {
|
||||||
* Handles rendering the element on the pdf.
|
* Handles rendering the element on the pdf.
|
||||||
*
|
*
|
||||||
* @param pdf $pdf the pdf object
|
* @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);
|
parent::render_content($pdf, $this->element->data);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -25,6 +25,6 @@
|
||||||
|
|
||||||
defined('MOODLE_INTERNAL') || die('Direct access to this script is forbidden.');
|
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->requires = 2013040500; // Requires this Moodle version.
|
||||||
$plugin->component = 'customcertelement_text';
|
$plugin->component = 'customcertelement_text';
|
||||||
|
|
|
@ -62,8 +62,9 @@ class customcert_element_userfield extends customcert_element_base {
|
||||||
* Handles rendering the element on the pdf.
|
* Handles rendering the element on the pdf.
|
||||||
*
|
*
|
||||||
* @param pdf $pdf the pdf object
|
* @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;
|
global $DB, $USER;
|
||||||
|
|
||||||
// The user field to display.
|
// The user field to display.
|
||||||
|
|
|
@ -25,6 +25,6 @@
|
||||||
|
|
||||||
defined('MOODLE_INTERNAL') || die('Direct access to this script is forbidden.');
|
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->requires = 2013040500; // Requires this Moodle version.
|
||||||
$plugin->component = 'customcertelement_userfield';
|
$plugin->component = 'customcertelement_userfield';
|
||||||
|
|
5
lib.php
5
lib.php
|
@ -787,8 +787,9 @@ function customcert_generate_code() {
|
||||||
* Generate the PDF for the specified customcert and user.
|
* Generate the PDF for the specified customcert and user.
|
||||||
*
|
*
|
||||||
* @param stdClass $customcert
|
* @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;
|
global $CFG, $DB;
|
||||||
|
|
||||||
require_once($CFG->libdir . '/pdflib.php');
|
require_once($CFG->libdir . '/pdflib.php');
|
||||||
|
@ -817,7 +818,7 @@ function customcert_generate_pdf($customcert) {
|
||||||
foreach ($elements as $element) {
|
foreach ($elements as $element) {
|
||||||
// Get an instance of the element class.
|
// Get an instance of the element class.
|
||||||
if ($e = customcert_get_element_instance($element)) {
|
if ($e = customcert_get_element_instance($element)) {
|
||||||
$e->render($pdf);
|
$e->render($pdf, $preview);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue