Add ability to choose how to deliver the certificate (#401)
This commit is contained in:
parent
ae2df6c9ed
commit
8446a2e10a
7 changed files with 53 additions and 22 deletions
|
@ -37,6 +37,16 @@ defined('MOODLE_INTERNAL') || die();
|
|||
*/
|
||||
class certificate {
|
||||
|
||||
/**
|
||||
* Send the file inline to the browser.
|
||||
*/
|
||||
const DELIVERY_OPTION_INLINE = 'I';
|
||||
|
||||
/**
|
||||
* Send to the browser and force a file download
|
||||
*/
|
||||
const DELIVERY_OPTION_DOWNLOAD = 'D';
|
||||
|
||||
/**
|
||||
* @var string the print protection variable
|
||||
*/
|
||||
|
|
|
@ -253,7 +253,7 @@ class template {
|
|||
* @param bool $return Do we want to return the contents of the PDF?
|
||||
* @return string|void Can return the PDF in string format if specified.
|
||||
*/
|
||||
public function generate_pdf($preview = false, $userid = null, $return = false) {
|
||||
public function generate_pdf(bool $preview = false, int $userid = null, bool $return = false) {
|
||||
global $CFG, $DB, $USER;
|
||||
|
||||
if (empty($userid)) {
|
||||
|
@ -269,12 +269,18 @@ class template {
|
|||
// Create the pdf object.
|
||||
$pdf = new \pdf();
|
||||
|
||||
$customcert = $DB->get_record('customcert', ['templateid' => $this->id]);
|
||||
|
||||
// If the template belongs to a certificate then we need to check what permissions we set for it.
|
||||
if ($protection = $DB->get_field('customcert', 'protection', array('templateid' => $this->id))) {
|
||||
$protection = $customcert->protection;
|
||||
if (!empty($protection)) {
|
||||
$protection = explode(', ', $protection);
|
||||
$pdf->SetProtection($protection);
|
||||
}
|
||||
|
||||
$deliveryoption = $customcert->deliveryoption;
|
||||
if (empty($deliveryoption)) {
|
||||
$deliveryoption = certificate::DELIVERY_OPTION_INLINE;
|
||||
}
|
||||
|
||||
$pdf->setPrintHeader(false);
|
||||
|
@ -320,7 +326,7 @@ class template {
|
|||
return $pdf->Output('', 'S');
|
||||
}
|
||||
|
||||
$pdf->Output($filename, 'I');
|
||||
$pdf->Output($filename, $deliveryoption);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -14,6 +14,7 @@
|
|||
<FIELD NAME="introformat" TYPE="int" LENGTH="4" NOTNULL="true" DEFAULT="0" SEQUENCE="false"/>
|
||||
<FIELD NAME="requiredtime" TYPE="int" LENGTH="10" NOTNULL="true" DEFAULT="0" SEQUENCE="false"/>
|
||||
<FIELD NAME="verifyany" TYPE="int" LENGTH="10" NOTNULL="true" DEFAULT="0" SEQUENCE="false"/>
|
||||
<FIELD NAME="deliveryoption" TYPE="char" LENGTH="255" NOTNULL="false" SEQUENCE="false"/>
|
||||
<FIELD NAME="emailstudents" TYPE="int" LENGTH="1" NOTNULL="true" DEFAULT="0" SEQUENCE="false"/>
|
||||
<FIELD NAME="emailteachers" TYPE="int" LENGTH="1" NOTNULL="true" DEFAULT="0" SEQUENCE="false"/>
|
||||
<FIELD NAME="emailothers" TYPE="text" NOTNULL="false" SEQUENCE="false"/>
|
||||
|
|
|
@ -166,5 +166,17 @@ function xmldb_customcert_upgrade($oldversion) {
|
|||
upgrade_mod_savepoint(true, 2019111803, 'customcert');
|
||||
}
|
||||
|
||||
if ($oldversion < 2020110901) {
|
||||
$table = new xmldb_table('customcert');
|
||||
$field = new xmldb_field('deliveryoption', XMLDB_TYPE_CHAR, '255', null, null, null, null, 'verifyany');
|
||||
|
||||
// Conditionally launch add field.
|
||||
if (!$dbman->field_exists($table, $field)) {
|
||||
$dbman->add_field($table, $field);
|
||||
}
|
||||
|
||||
upgrade_mod_savepoint(true, 2020110901, 'customcert');
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
|
|
@ -57,6 +57,9 @@ $string['deleteissueconfirm'] = 'Are you sure you want to delete this certificat
|
|||
$string['deleteissuedcertificates'] = 'Delete issued certificates';
|
||||
$string['deletepageconfirm'] = 'Are you sure you want to delete this certificate page?';
|
||||
$string['deletetemplateconfirm'] = 'Are you sure you want to delete this certificate template?';
|
||||
$string['deliveryoptiondownload'] = 'Send to the browser and force a file download';
|
||||
$string['deliveryoptioninline'] = 'Send the file inline to the browser';
|
||||
$string['deliveryoptions'] = 'Delivery options';
|
||||
$string['description'] = 'Description';
|
||||
$string['duplicate'] = 'Duplicate';
|
||||
$string['duplicateconfirm'] = 'Duplicate confirmation';
|
||||
|
|
27
mod_form.php
27
mod_form.php
|
@ -22,6 +22,8 @@
|
|||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
*/
|
||||
|
||||
use mod_customcert\certificate;
|
||||
|
||||
defined('MOODLE_INTERNAL') || die('Direct access to this script is forbidden.');
|
||||
|
||||
require_once($CFG->dirroot.'/course/moodleform_mod.php');
|
||||
|
@ -55,14 +57,20 @@ class mod_customcert_mod_form extends moodleform_mod {
|
|||
|
||||
$this->standard_intro_elements(get_string('description', 'customcert'));
|
||||
|
||||
$optionsheader = $mform->createElement('header', 'options', get_string('options', 'customcert'));
|
||||
$mform->addElement('header', 'options', get_string('options', 'customcert'));
|
||||
|
||||
$deliveryoptions = [
|
||||
certificate::DELIVERY_OPTION_INLINE => get_string('deliveryoptioninline', 'customcert'),
|
||||
certificate::DELIVERY_OPTION_DOWNLOAD => get_string('deliveryoptiondownload', 'customcert')
|
||||
];
|
||||
$mform->addElement('select', 'deliveryoption', get_string('deliveryoptions', 'customcert'), $deliveryoptions);
|
||||
$mform->setDefault('deliveryoption', certificate::DELIVERY_OPTION_INLINE);
|
||||
|
||||
if (has_capability('mod/customcert:manageemailstudents', $this->get_context())) {
|
||||
$mform->addElement('selectyesno', 'emailstudents', get_string('emailstudents', 'customcert'));
|
||||
$mform->setDefault('emailstudents', get_config('customcert', 'emailstudents'));
|
||||
$mform->addHelpButton('emailstudents', 'emailstudents', 'customcert');
|
||||
$mform->setType('emailstudents', PARAM_INT);
|
||||
$firstoption = 'emailstudents';
|
||||
}
|
||||
|
||||
if (has_capability('mod/customcert:manageemailteachers', $this->get_context())) {
|
||||
|
@ -70,7 +78,6 @@ class mod_customcert_mod_form extends moodleform_mod {
|
|||
$mform->setDefault('emailteachers', get_config('customcert', 'emailteachers'));
|
||||
$mform->addHelpButton('emailteachers', 'emailteachers', 'customcert');
|
||||
$mform->setType('emailteachers', PARAM_INT);
|
||||
$firstoption = empty($firstoption) ? 'emailteachers' : $firstoption;
|
||||
}
|
||||
|
||||
if (has_capability('mod/customcert:manageemailothers', $this->get_context())) {
|
||||
|
@ -78,7 +85,6 @@ class mod_customcert_mod_form extends moodleform_mod {
|
|||
$mform->addHelpButton('emailothers', 'emailothers', 'customcert');
|
||||
$mform->setDefault('emailothers', get_config('customcert', 'emailothers'));
|
||||
$mform->setType('emailothers', PARAM_TEXT);
|
||||
$firstoption = empty($firstoption) ? 'emailothers' : $firstoption;
|
||||
}
|
||||
|
||||
if (has_capability('mod/customcert:manageverifyany', $this->get_context())) {
|
||||
|
@ -86,7 +92,6 @@ class mod_customcert_mod_form extends moodleform_mod {
|
|||
$mform->addHelpButton('verifyany', 'verifycertificateanyone', 'customcert');
|
||||
$mform->setDefault('verifyany', get_config('customcert', 'verifyany'));
|
||||
$mform->setType('verifyany', PARAM_INT);
|
||||
$firstoption = empty($firstoption) ? 'verifyany' : $firstoption;
|
||||
}
|
||||
|
||||
if (has_capability('mod/customcert:managerequiredtime', $this->get_context())) {
|
||||
|
@ -94,7 +99,6 @@ class mod_customcert_mod_form extends moodleform_mod {
|
|||
$mform->addHelpButton('requiredtime', 'coursetimereq', 'customcert');
|
||||
$mform->setDefault('requiredtime', get_config('customcert', 'requiredtime'));
|
||||
$mform->setType('requiredtime', PARAM_INT);
|
||||
$firstoption = empty($firstoption) ? 'requiredtime' : $firstoption;
|
||||
}
|
||||
|
||||
if (has_capability('mod/customcert:manageprotection', $this->get_context())) {
|
||||
|
@ -106,11 +110,6 @@ class mod_customcert_mod_form extends moodleform_mod {
|
|||
$mform->setType('protection_print', PARAM_BOOL);
|
||||
$mform->setType('protection_modify', PARAM_BOOL);
|
||||
$mform->setType('protection_copy', PARAM_BOOL);
|
||||
$firstoption = empty($firstoption) ? 'protection_print' : $firstoption;
|
||||
}
|
||||
|
||||
if (!empty($firstoption)) {
|
||||
$mform->insertElementBefore($optionsheader, $firstoption);
|
||||
}
|
||||
|
||||
$this->standard_coursemodule_elements();
|
||||
|
@ -227,13 +226,13 @@ class mod_customcert_mod_form extends moodleform_mod {
|
|||
|
||||
$protection = explode(', ', $protection);
|
||||
|
||||
if (in_array(\mod_customcert\certificate::PROTECTION_PRINT, $protection)) {
|
||||
if (in_array(certificate::PROTECTION_PRINT, $protection)) {
|
||||
$data->protection_print = 1;
|
||||
}
|
||||
if (in_array(\mod_customcert\certificate::PROTECTION_MODIFY, $protection)) {
|
||||
if (in_array(certificate::PROTECTION_MODIFY, $protection)) {
|
||||
$data->protection_modify = 1;
|
||||
}
|
||||
if (in_array(\mod_customcert\certificate::PROTECTION_COPY, $protection)) {
|
||||
if (in_array(certificate::PROTECTION_COPY, $protection)) {
|
||||
$data->protection_copy = 1;
|
||||
}
|
||||
|
||||
|
|
|
@ -24,7 +24,7 @@
|
|||
|
||||
defined('MOODLE_INTERNAL') || die('Direct access to this script is forbidden.');
|
||||
|
||||
$plugin->version = 2020110900; // The current module version (Date: YYYYMMDDXX).
|
||||
$plugin->version = 2020110901; // The current module version (Date: YYYYMMDDXX).
|
||||
$plugin->requires = 2020110900; // Requires this Moodle version (3.10).
|
||||
$plugin->cron = 0; // Period for cron to check this module (secs).
|
||||
$plugin->component = 'mod_customcert';
|
||||
|
|
Loading…
Reference in a new issue