Added the ability to specify the PDF protection
Note: I did not create a db/upgrade.php script to add the new database column as this module should not be currently used by anyone.
This commit is contained in:
parent
faedb6f7e0
commit
c0d081f849
4 changed files with 78 additions and 1 deletions
|
@ -12,6 +12,7 @@
|
|||
<FIELD NAME="intro" TYPE="text" LENGTH="small" NOTNULL="false" SEQUENCE="false" ENUM="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" ENUM="false"/>
|
||||
<FIELD NAME="protection" TYPE="char" LENGTH="255" NOTNULL="true" SEQUENCE="false" ENUM="false"/>
|
||||
<FIELD NAME="timecreated" TYPE="int" LENGTH="10" NOTNULL="true" DEFAULT="0" SEQUENCE="false" ENUM="false"/>
|
||||
<FIELD NAME="timemodified" TYPE="int" LENGTH="10" NOTNULL="true" DEFAULT="0" SEQUENCE="false" ENUM="false"/>
|
||||
</FIELDS>
|
||||
|
|
|
@ -25,6 +25,7 @@
|
|||
|
||||
$string['addcertpage'] = 'Add another certificate page';
|
||||
$string['addelement'] = 'Add element';
|
||||
$string['copy'] = 'Copy';
|
||||
$string['coursetimereq'] = 'Required minutes in course';
|
||||
$string['coursetimereq_help'] = 'Enter here the minimum amount of time, in minutes, that a student must be logged into the course before they will be able to receive the certificate.';
|
||||
$string['customcert:addinstance'] = 'Add a new custom certificate instance';
|
||||
|
@ -56,6 +57,7 @@ $string['landscape'] = 'Landscape';
|
|||
$string['load'] = 'Load';
|
||||
$string['loadtemplate'] = 'Load template';
|
||||
$string['loadtemplatemsg'] = 'Are you sure you wish to load this template? This will remove any existing pages and elements for this certificate.';
|
||||
$string['modify'] = 'Modify';
|
||||
$string['modulename'] = 'Custom Certificate';
|
||||
$string['modulenameplural'] = 'Custom Certificates';
|
||||
$string['name'] = 'Name';
|
||||
|
@ -66,6 +68,7 @@ $string['orientation_help'] = 'Choose whether you want your certificate orientat
|
|||
$string['page'] = 'Page {$a}';
|
||||
$string['pluginadministration'] = 'Custom Certificate administration';
|
||||
$string['pluginname'] = 'Custom Certificate';
|
||||
$string['print'] = 'Print';
|
||||
$string['portrait'] = 'Portrait';
|
||||
$string['posx'] = 'Position X';
|
||||
$string['posx_help'] = 'This is the position in pixels from the top left corner you wish the element to display in the x direction.';
|
||||
|
@ -73,6 +76,8 @@ $string['posy'] = 'Postion Y';
|
|||
$string['posy_help'] = 'This is the position in pixels from the top left corner you wish the element to display in the y direction.';
|
||||
$string['save'] = 'Save';
|
||||
$string['savetemplate'] = 'Save template';
|
||||
$string['setprotection'] = 'Set protection';
|
||||
$string['setprotection_help'] = 'Choose the actions you wish to prevent users from performing on this certificate.';
|
||||
$string['summaryofissue'] = 'Summary of issue';
|
||||
$string['templatename'] = 'Template name';
|
||||
$string['templatenameexists'] = 'That template name is currently in use, please choose another.';
|
||||
|
|
45
lib.php
45
lib.php
|
@ -25,6 +25,21 @@
|
|||
|
||||
defined('MOODLE_INTERNAL') || die('Direct access to this script is forbidden.');
|
||||
|
||||
/**
|
||||
* @var string the print protection variable
|
||||
*/
|
||||
define('PROTECTION_PRINT', 'print');
|
||||
|
||||
/**
|
||||
* @var string the modify protection variable
|
||||
*/
|
||||
define('PROTECTION_MODIFY', 'modify');
|
||||
|
||||
/**
|
||||
* @var string the copy protection variable
|
||||
*/
|
||||
define('PROTECTION_COPY', 'copy');
|
||||
|
||||
/**
|
||||
* Add customcert instance.
|
||||
*
|
||||
|
@ -35,6 +50,7 @@ defined('MOODLE_INTERNAL') || die('Direct access to this script is forbidden.');
|
|||
function customcert_add_instance($data, $mform) {
|
||||
global $DB;
|
||||
|
||||
$data->protection = customcert_set_protection($data);
|
||||
$data->timecreated = time();
|
||||
$data->timemodified = $data->timecreated;
|
||||
|
||||
|
@ -51,13 +67,36 @@ function customcert_add_instance($data, $mform) {
|
|||
function customcert_update_instance($data, $mform) {
|
||||
global $DB;
|
||||
|
||||
// Update the time modified.
|
||||
$data->protection = customcert_set_protection($data);
|
||||
$data->timemodified = time();
|
||||
$data->id = $data->instance;
|
||||
|
||||
return $DB->update_record('customcert', $data);
|
||||
}
|
||||
|
||||
/**
|
||||
* Handles setting the protection field for the customcert
|
||||
*
|
||||
* @param stdClass $data
|
||||
* @return string the value to insert into the protection field
|
||||
*/
|
||||
function customcert_set_protection($data) {
|
||||
$protection = array();
|
||||
|
||||
if (!empty($data->protection_print)) {
|
||||
$protection[] = PROTECTION_PRINT;
|
||||
}
|
||||
if (!empty($data->protection_modify)) {
|
||||
$protection[] = PROTECTION_MODIFY;
|
||||
}
|
||||
if (!empty($data->protection_copy)) {
|
||||
$protection[] = PROTECTION_COPY;
|
||||
}
|
||||
|
||||
// Return the protection string.
|
||||
return implode(', ', $protection);
|
||||
}
|
||||
|
||||
/**
|
||||
* Given an ID of an instance of this module,
|
||||
* this function will permanently delete the instance
|
||||
|
@ -773,6 +812,10 @@ function customcert_generate_pdf($customcert, $userid) {
|
|||
if ($pages = $DB->get_records('customcert_pages', array('customcertid' => $customcert->id), 'pagenumber ASC')) {
|
||||
// Create the pdf object.
|
||||
$pdf = new pdf();
|
||||
if (!empty($customcert->protection)) {
|
||||
$protection = explode(', ', $customcert->protection);
|
||||
$pdf->SetProtection($protection);
|
||||
}
|
||||
$pdf->setPrintHeader(false);
|
||||
$pdf->setPrintFooter(false);
|
||||
$pdf->SetTitle($customcert->name);
|
||||
|
|
28
mod_form.php
28
mod_form.php
|
@ -55,11 +55,39 @@ class mod_customcert_mod_form extends moodleform_mod {
|
|||
$mform->setType('requiredtime', PARAM_INT);
|
||||
$mform->addHelpButton('requiredtime', 'coursetimereq', 'customcert');
|
||||
|
||||
$mform->addElement('checkbox', 'protection_print', get_string('setprotection', 'customcert'), get_string('print', 'customcert'));
|
||||
$mform->addElement('checkbox', 'protection_modify', '', get_string('modify', 'customcert'));
|
||||
$mform->addElement('checkbox', 'protection_copy', '', get_string('copy', 'customcert'));
|
||||
$mform->addHelpButton('protection_print', 'setprotection', 'customcert');
|
||||
|
||||
$this->standard_coursemodule_elements();
|
||||
|
||||
$this->add_action_buttons();
|
||||
}
|
||||
|
||||
/**
|
||||
* Any data processing needed before the form is displayed.
|
||||
*
|
||||
* @param array $defaultvalues
|
||||
*/
|
||||
public function data_preprocessing(&$defaultvalues) {
|
||||
global $DB;
|
||||
|
||||
if (!empty($defaultvalues['protection'])) {
|
||||
$protection = explode(', ', $defaultvalues['protection']);
|
||||
// Set the values in the form to what has been set in database.
|
||||
if (in_array(PROTECTION_PRINT, $protection)) {
|
||||
$defaultvalues['protection_print'] = 1;
|
||||
}
|
||||
if (in_array(PROTECTION_MODIFY, $protection)) {
|
||||
$defaultvalues['protection_modify'] = 1;
|
||||
}
|
||||
if (in_array(PROTECTION_COPY, $protection)) {
|
||||
$defaultvalues['protection_copy'] = 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Some basic validation.
|
||||
*
|
||||
|
|
Loading…
Reference in a new issue