#78 Add setting to allow anyone to verify certificates

This commit is contained in:
Mark Nelson 2017-05-06 19:14:15 +08:00
parent bb918a02d6
commit 3d722a49f7
6 changed files with 34 additions and 8 deletions

View file

@ -1,5 +1,5 @@
<?xml version="1.0" encoding="UTF-8" ?> <?xml version="1.0" encoding="UTF-8" ?>
<XMLDB PATH="mod/customcert/db" VERSION="20150311" COMMENT="XMLDB file for Moodle mod/customcert" <XMLDB PATH="mod/customcert/db" VERSION="20170530" COMMENT="XMLDB file for Moodle mod/customcert"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="../../../lib/xmldb/xmldb.xsd" xsi:noNamespaceSchemaLocation="../../../lib/xmldb/xmldb.xsd"
> >
@ -13,6 +13,7 @@
<FIELD NAME="intro" TYPE="text" LENGTH="small" NOTNULL="false" SEQUENCE="false"/> <FIELD NAME="intro" TYPE="text" LENGTH="small" NOTNULL="false" SEQUENCE="false"/>
<FIELD NAME="introformat" TYPE="int" LENGTH="4" NOTNULL="true" DEFAULT="0" SEQUENCE="false"/> <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="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="emailstudents" TYPE="int" LENGTH="1" NOTNULL="true" DEFAULT="0" 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="emailteachers" TYPE="int" LENGTH="1" NOTNULL="true" DEFAULT="0" SEQUENCE="false"/>
<FIELD NAME="emailothers" TYPE="text" NOTNULL="false" SEQUENCE="false"/> <FIELD NAME="emailothers" TYPE="text" NOTNULL="false" SEQUENCE="false"/>

View file

@ -106,5 +106,20 @@ function xmldb_customcert_upgrade($oldversion) {
upgrade_mod_savepoint(true, 2016120507, 'customcert'); upgrade_mod_savepoint(true, 2016120507, 'customcert');
} }
if ($oldversion < 2016120508) {
// Add column for new 'verifycertificateanyone' setting.
$table = new xmldb_table('customcert');
$field = new xmldb_field('verifyany', XMLDB_TYPE_INTEGER, '1', null, XMLDB_NOTNULL, null, '0',
'requiredtime');
// Conditionally launch add field.
if (!$dbman->field_exists($table, $field)) {
$dbman->add_field($table, $field);
}
// Savepoint reached.
upgrade_mod_savepoint(true, 2016120508, 'customcert');
}
return true; return true;
} }

View file

@ -154,6 +154,8 @@ this method will be available throughout your site to all users who are able to
$string['verified'] = 'Verified'; $string['verified'] = 'Verified';
$string['verify'] = 'Verify'; $string['verify'] = 'Verify';
$string['verifycertificate'] = 'Verify certificate'; $string['verifycertificate'] = 'Verify certificate';
$string['verifycertificateanyone'] = 'Allow anyone to verify a certificate';
$string['verifycertificateanyone_help'] = 'This setting enables anyone with the certificate verification link (including users not logged in) to verify a certificate.';
$string['viewcustomcertissues'] = 'View {$a} issued custom certificates'; $string['viewcustomcertissues'] = 'View {$a} issued custom certificates';
$string['width'] = 'Width'; $string['width'] = 'Width';
$string['width_help'] = 'This is the width of the certificate PDF in mm. For reference an A4 piece of paper is 210mm wide and a letter is 216mm wide.'; $string['width_help'] = 'This is the width of the certificate PDF in mm. For reference an A4 piece of paper is 210mm wide and a letter is 216mm wide.';

View file

@ -69,6 +69,10 @@ class mod_customcert_mod_form extends moodleform_mod {
$mform->setType('emailothers', PARAM_TEXT); $mform->setType('emailothers', PARAM_TEXT);
$mform->addHelpButton('emailothers', 'emailothers', 'customcert'); $mform->addHelpButton('emailothers', 'emailothers', 'customcert');
$mform->addElement('selectyesno', 'verifyany', get_string('verifycertificateanyone', 'customcert'));
$mform->setType('verifyany', 0);
$mform->addHelpButton('verifyany', 'verifycertificateanyone', 'customcert');
$mform->addElement('text', 'requiredtime', get_string('coursetimereq', 'customcert'), array('size' => '3')); $mform->addElement('text', 'requiredtime', get_string('coursetimereq', 'customcert'), array('size' => '3'));
$mform->setType('requiredtime', PARAM_INT); $mform->setType('requiredtime', PARAM_INT);
$mform->addHelpButton('requiredtime', 'coursetimereq', 'customcert'); $mform->addHelpButton('requiredtime', 'coursetimereq', 'customcert');

View file

@ -33,11 +33,15 @@ $cm = get_coursemodule_from_id('customcert', $context->instanceid, 0, false, MUS
$course = $DB->get_record('course', array('id' => $cm->course), '*', MUST_EXIST); $course = $DB->get_record('course', array('id' => $cm->course), '*', MUST_EXIST);
$customcert = $DB->get_record('customcert', array('id' => $cm->instance), '*', MUST_EXIST); $customcert = $DB->get_record('customcert', array('id' => $cm->instance), '*', MUST_EXIST);
// Need to be logged in. // Check if we are allowing anyone to verify, if so, no need to check login, or permissions.
require_login($course, false, $cm); if (!$customcert->verifyany) {
// Need to be logged in.
// Ok, now check the user has the ability to verify certificates. require_login($course, false, $cm);
require_capability('mod/customcert:verifycertificate', $context); // Ok, now check the user has the ability to verify certificates.
require_capability('mod/customcert:verifycertificate', $context);
} else {
$PAGE->set_cm($cm, $course);
}
// Set up the page. // Set up the page.
$pageurl = new moodle_url('/mod/customcert/verify_certificate.php', array('contextid' => $contextid)); $pageurl = new moodle_url('/mod/customcert/verify_certificate.php', array('contextid' => $contextid));

View file

@ -24,10 +24,10 @@
defined('MOODLE_INTERNAL') || die('Direct access to this script is forbidden.'); defined('MOODLE_INTERNAL') || die('Direct access to this script is forbidden.');
$plugin->version = 2016120507; // The current module version (Date: YYYYMMDDXX). $plugin->version = 2016120508; // The current module version (Date: YYYYMMDDXX).
$plugin->requires = 2016120500; // Requires this Moodle version (3.2). $plugin->requires = 2016120500; // Requires this Moodle version (3.2).
$plugin->cron = 0; // Period for cron to check this module (secs). $plugin->cron = 0; // Period for cron to check this module (secs).
$plugin->component = 'mod_customcert'; $plugin->component = 'mod_customcert';
$plugin->maturity = MATURITY_STABLE; $plugin->maturity = MATURITY_STABLE;
$plugin->release = "3.2 release (Build: 2016120507)"; // User-friendly version number. $plugin->release = "3.2 release (Build: 2016120508)"; // User-friendly version number.