Compare commits
70 commits
MOODLE_311
...
MOODLE_32_
Author | SHA1 | Date | |
---|---|---|---|
|
6c21cd41cb | ||
|
234b36f0c0 | ||
|
e8046b60bc | ||
|
9f760a1a6b | ||
|
2ab29492b7 | ||
|
ae94419e55 | ||
|
b811656ef3 | ||
|
c0e15cbb88 | ||
|
ef239e178e | ||
|
1c141bdebc | ||
|
ead842abdd | ||
|
ad82da2de8 | ||
|
62a7491c99 | ||
|
c6d6394b0d | ||
|
0ba790b08b | ||
|
289742da00 | ||
|
0051a25cc4 | ||
|
8823a90ddb | ||
|
fdf71fac98 | ||
|
1f2a34a92f | ||
|
6e27421982 | ||
|
45409dfe1c | ||
|
d6c4843acf | ||
|
2a7b02527e | ||
|
f963358ddf | ||
|
6d02679ad2 | ||
|
e6d9b708ed | ||
|
5d7921f23f | ||
|
6afd9555c4 | ||
|
4232b1da86 | ||
|
a7b14ab48d | ||
|
e087567b03 | ||
|
309815eb7c | ||
|
762e56b680 | ||
|
e406bb48c7 | ||
|
be25ea3637 | ||
|
24974bc5af | ||
|
327750bb38 | ||
|
ae90c7ee4a | ||
|
24f57a7dbc | ||
|
47b7ec2577 | ||
|
4a3e2d217d | ||
|
61608c56fa | ||
|
1edab7a384 | ||
|
9606e9003d | ||
|
4c26f6c2c3 | ||
|
533d128be7 | ||
|
72de06f17f | ||
|
11495411e2 | ||
|
edd8734711 | ||
|
822b46bf5a | ||
|
d70a693137 | ||
|
e7dba867ec | ||
|
e41880730a | ||
|
b8bb672d85 | ||
|
b85d982674 | ||
|
03d6b12628 | ||
|
c90a3445e5 | ||
|
3a142506c7 | ||
|
744ac1b42b | ||
|
b2b820cc9a | ||
|
07f506293d | ||
|
d05258131f | ||
|
7e9c790dac | ||
|
bd6f2d77e1 | ||
|
397c5bf73b | ||
|
3d722a49f7 | ||
|
bb918a02d6 | ||
|
e5d6115c2a | ||
|
4d21173247 |
70 changed files with 3343 additions and 639 deletions
|
@ -8,7 +8,7 @@ cache:
|
|||
|
||||
php:
|
||||
- 5.6
|
||||
- 7.0
|
||||
- 7.1
|
||||
|
||||
env:
|
||||
global:
|
||||
|
@ -29,7 +29,6 @@ install:
|
|||
|
||||
script:
|
||||
- moodle-plugin-ci phplint
|
||||
- moodle-plugin-ci phpcpd
|
||||
- moodle-plugin-ci codechecker
|
||||
- moodle-plugin-ci csslint
|
||||
- moodle-plugin-ci shifter
|
||||
|
|
65
CHANGES.md
Normal file
65
CHANGES.md
Normal file
|
@ -0,0 +1,65 @@
|
|||
# Changelog
|
||||
|
||||
All notable changes to this project will be documented in this file.
|
||||
|
||||
Note - All hash comments refer to the issue number. Eg. #169 refers to https://github.com/markn86/moodle-mod_customcert/issues/169.
|
||||
|
||||
## [3.2.16] - 2018-05-17
|
||||
### Fixed
|
||||
- Race condition on certificate issues in scheduled task (#173).
|
||||
- Ensure we backup the 'verifyany' setting (#169).
|
||||
- Fixed encoding content links used by restore (#166).
|
||||
|
||||
## [3.2.15] - 2017-11-13
|
||||
### Added
|
||||
- Added capability ```mod/customcert:verifyallcertificates``` that provides a user with the ability to verify any certificate
|
||||
on the site by simply visiting the ```mod/customcert/verify_certificate.php``` page, rather than having to go to the
|
||||
verification link for each certificate.
|
||||
- Added site setting ```customcert/verifyallcertificates``` which when enabled allows any person (including users not logged in)
|
||||
to be able to verify any certificate on the site, rather than having to go to the verification link for each certificate.
|
||||
However, this only applies to certificates where ```Allow anyone to verify a certificate``` has been set to ```Yes``` in the
|
||||
certificate settings.
|
||||
- You can now display the grade and date of all grade items, not just the course and course activities.
|
||||
- Text has been added above the ```My certificates``` list to explain that it contains certificates that have been issued to
|
||||
avoid confusion as to why certificates may not be appearing.
|
||||
|
||||
### Changed
|
||||
- The course full name is now used in emails.
|
||||
|
||||
### Fixed
|
||||
- Added missing string used in course reset.
|
||||
|
||||
## [3.2.14] - 2017-09-04
|
||||
### Added
|
||||
- New digital signature element (uses existing functionality in the TCPDF library).
|
||||
- Ability to duplicate site templates via the manage templates page.
|
||||
- Ability to delete issued certificates for individual users on the course report page.
|
||||
|
||||
### Changed
|
||||
- Removed usage of magic getter and abuse of ```$this->element```. The variable ```$this->element``` will still be
|
||||
accessible by any third-party element plugins, though this is discouraged and the appropriate ```get_xxx()```
|
||||
method should be used instead. Using ```$this->element``` in ```definition_after_data()``` will no longer work.
|
||||
Please explicitly set the value of any custom fields you have in the form.
|
||||
|
||||
### Fixed
|
||||
- Added missing ```confirm_sesskey()``` checks.
|
||||
- Minor bug fixes.
|
||||
|
||||
## [3.2.13] - 2017-08-11
|
||||
### Added
|
||||
- Added much needed Behat test coverage.
|
||||
|
||||
### Changed
|
||||
- Minor language string changes.
|
||||
- Made changes to the UI when editing a certificate.
|
||||
- Moved the 'Add element' submit button below the list of elements.
|
||||
- Added icon next to the 'Delete page' link.
|
||||
- Changed the 'Add page' button to a link, added an icon and moved it's location to the right.
|
||||
- Do not make all submit buttons primary. MDL-59740 needs to be applied to your Moodle install in order to notice the change.
|
||||
|
||||
### Fixed
|
||||
- Issue where the date an activity was graded was not displaying at all.
|
||||
|
||||
## [3.2.12] - 2017-08-05
|
||||
### Changed
|
||||
- Renamed the column 'size' in the table 'customcert_elements' to 'fontsize' due to 'size' being a reserved word in Oracle.
|
2
amd/build/rearrange-area.min.js
vendored
2
amd/build/rearrange-area.min.js
vendored
|
@ -1 +1 @@
|
|||
define(["jquery","core/yui","core/fragment","mod_customcert/dialogue","core/notification","core/str","core/templates","core/ajax"],function(a,b,c,d,e,f,g,h){var i=function(b){this._node=a(b),this._setEvents()};return i.prototype.CUSTOMCERT_REF_POINT_TOPLEFT=0,i.prototype.CUSTOMCERT_REF_POINT_TOPCENTER=1,i.prototype.CUSTOMCERT_REF_POINT_TOPRIGHT=2,i.prototype.PIXELSINMM=3.779527559055,i.prototype._setEvents=function(){this._node.on("click",".element",this._editElement.bind(this))},i.prototype._editElement=function(a){var g=a.currentTarget.id.substr(8),h=this._node.attr("data-contextid"),i={elementid:g};c.loadFragment("mod_customcert","editelement",h,i).done(function(a,c){f.get_string("editelement","mod_customcert").done(function(e){b.use("moodle-core-formchangechecker",function(){new d(e,"<div id='elementcontent'></div>",this._editElementDialogueConfig.bind(this,g,a,c),(void 0),(!0))}.bind(this))}.bind(this))}.bind(this)).fail(e.exception)},i.prototype._editElementDialogueConfig=function(b,c,d,e){g.replaceNode("#elementcontent",c,d),this._setPositionInForm(b);var f=a(e.getContent());f.on("click","#id_submitbutton",function(c){M.core_formchangechecker.reset_form_dirty_state(),this._saveElement(b).then(function(){this._getElementHTML(b).done(function(c){var d=this._node.find("#element-"+b),f=parseInt(a("#id_refpoint").val()),g="";f==this.CUSTOMCERT_REF_POINT_TOPLEFT?g="refpoint-left":f==this.CUSTOMCERT_REF_POINT_TOPCENTER?g="refpoint-center":f==this.CUSTOMCERT_REF_POINT_TOPRIGHT&&(g="refpoint-right"),d.empty().append(c),d.removeClass(),d.addClass("element "+g),d.attr("data-refpoint",f);var h=a("#editelementform #id_posx").val(),i=a("#editelementform #id_posy").val();this._setPosition(b,f,h,i),e.close()}.bind(this))}.bind(this)),c.preventDefault()}.bind(this)),f.on("click","#id_cancel",function(a){e.close(),a.preventDefault()})},i.prototype._setPosition=function(a,c,d,e){var f=b.one("#element-"+a);d=b.one("#pdf").getX()+d*this.PIXELSINMM,e=b.one("#pdf").getY()+e*this.PIXELSINMM;var g=parseFloat(f.getComputedStyle("width")),h=f.width*this.PIXELSINMM;switch(h&&g>h&&(g=h),c){case this.CUSTOMCERT_REF_POINT_TOPCENTER:d-=g/2;break;case this.CUSTOMCERT_REF_POINT_TOPRIGHT:d=d-g+2}f.setX(d),f.setY(e)},i.prototype._setPositionInForm=function(c){var d=a("#editelementform #id_posx"),e=a("#editelementform #id_posy");if(d.length&&e.length){var f=b.one("#element-"+c),g=f.getX()-b.one("#pdf").getX(),h=f.getY()-b.one("#pdf").getY(),i=parseInt(f.getData("refpoint")),j=parseFloat(f.getComputedStyle("width"));switch(i){case this.CUSTOMCERT_REF_POINT_TOPCENTER:g+=j/2;break;case this.CUSTOMCERT_REF_POINT_TOPRIGHT:g+=j}g=Math.round(parseFloat(g/this.PIXELSINMM)),h=Math.round(parseFloat(h/this.PIXELSINMM)),d.val(g),e.val(h)}},i.prototype._getElementHTML=function(a){var b=this._node.attr("data-templateid"),c=h.call([{methodname:"mod_customcert_get_element_html",args:{templateid:b,elementid:a}}]);return c[0]},i.prototype._saveElement=function(b){var c=this._node.attr("data-templateid"),d=a("#editelementform").serializeArray(),e=h.call([{methodname:"mod_customcert_save_element",args:{templateid:c,elementid:b,values:d}}]);return e[0]},{init:function(a){new i(a)}}});
|
||||
define(["jquery","core/yui","core/fragment","mod_customcert/dialogue","core/notification","core/str","core/templates","core/ajax"],function(a,b,c,d,e,f,g,h){var i=function(b){this._node=a(b),this._setEvents()};return i.prototype.CUSTOMCERT_REF_POINT_TOPLEFT=0,i.prototype.CUSTOMCERT_REF_POINT_TOPCENTER=1,i.prototype.CUSTOMCERT_REF_POINT_TOPRIGHT=2,i.prototype.PIXELSINMM=3.779527559055,i.prototype._setEvents=function(){this._node.on("click",".element",this._editElement.bind(this))},i.prototype._editElement=function(a){var g=a.currentTarget.id.substr(8),h=this._node.attr("data-contextid"),i={elementid:g};c.loadFragment("mod_customcert","editelement",h,i).done(function(a,c){f.get_string("editelement","mod_customcert").done(function(e){b.use("moodle-core-formchangechecker",function(){new d(e,"<div id='elementcontent'></div>",this._editElementDialogueConfig.bind(this,g,a,c),(void 0),(!0))}.bind(this))}.bind(this))}.bind(this)).fail(e.exception)},i.prototype._editElementDialogueConfig=function(b,c,d,f){g.replaceNode("#elementcontent",c,d),this._setPositionInForm(b);var h=a(f.getContent());h.on("click","#id_submitbutton",function(c){M.core_formchangechecker.reset_form_dirty_state(),this._saveElement(b).then(function(){this._getElementHTML(b).done(function(c){var d=this._node.find("#element-"+b),e=parseInt(a("#id_refpoint").val()),g="";e==this.CUSTOMCERT_REF_POINT_TOPLEFT?g="refpoint-left":e==this.CUSTOMCERT_REF_POINT_TOPCENTER?g="refpoint-center":e==this.CUSTOMCERT_REF_POINT_TOPRIGHT&&(g="refpoint-right"),d.empty().append(c),d.removeClass(),d.addClass("element "+g),d.attr("data-refpoint",e);var h=a("#editelementform #id_posx").val(),i=a("#editelementform #id_posy").val();this._setPosition(b,e,h,i),f.close()}.bind(this))}.bind(this)).fail(e.exception),c.preventDefault()}.bind(this)),h.on("click","#id_cancel",function(a){f.close(),a.preventDefault()})},i.prototype._setPosition=function(a,c,d,e){var f=b.one("#element-"+a);d=b.one("#pdf").getX()+d*this.PIXELSINMM,e=b.one("#pdf").getY()+e*this.PIXELSINMM;var g=parseFloat(f.getComputedStyle("width")),h=f.width*this.PIXELSINMM;switch(h&&g>h&&(g=h),c){case this.CUSTOMCERT_REF_POINT_TOPCENTER:d-=g/2;break;case this.CUSTOMCERT_REF_POINT_TOPRIGHT:d=d-g+2}f.setX(d),f.setY(e)},i.prototype._setPositionInForm=function(c){var d=a("#editelementform #id_posx"),e=a("#editelementform #id_posy");if(d.length&&e.length){var f=b.one("#element-"+c),g=f.getX()-b.one("#pdf").getX(),h=f.getY()-b.one("#pdf").getY(),i=parseInt(f.getData("refpoint")),j=parseFloat(f.getComputedStyle("width"));switch(i){case this.CUSTOMCERT_REF_POINT_TOPCENTER:g+=j/2;break;case this.CUSTOMCERT_REF_POINT_TOPRIGHT:g+=j}g=Math.round(parseFloat(g/this.PIXELSINMM)),h=Math.round(parseFloat(h/this.PIXELSINMM)),d.val(g),e.val(h)}},i.prototype._getElementHTML=function(a){var b=this._node.attr("data-templateid"),c=h.call([{methodname:"mod_customcert_get_element_html",args:{templateid:b,elementid:a}}]);return c[0]},i.prototype._saveElement=function(b){var c=this._node.attr("data-templateid"),d=a("#editelementform").serializeArray(),e=h.call([{methodname:"mod_customcert_save_element",args:{templateid:c,elementid:b,values:d}}]);return e[0]},{init:function(a){new i(a)}}});
|
|
@ -105,7 +105,7 @@ define(['jquery', 'core/yui', 'core/fragment', 'mod_customcert/dialogue', 'core/
|
|||
// All done.
|
||||
popup.close();
|
||||
}.bind(this));
|
||||
}.bind(this));
|
||||
}.bind(this)).fail(notification.exception);
|
||||
e.preventDefault();
|
||||
}.bind(this));
|
||||
|
||||
|
|
|
@ -63,11 +63,11 @@ class backup_customcert_activity_task extends backup_activity_task {
|
|||
|
||||
// Link to the list of customcerts.
|
||||
$search = "/(".$base."\/mod\/customcert\/index.php\?id\=)([0-9]+)/";
|
||||
$content = preg_replace($search, '$@customcertINDEX*$2@$', $content);
|
||||
$content = preg_replace($search, '$@CUSTOMCERTINDEX*$2@$', $content);
|
||||
|
||||
// Link to customcert view by moduleid.
|
||||
$search = "/(".$base."\/mod\/customcert\/view.php\?id\=)([0-9]+)/";
|
||||
$content = preg_replace($search, '$@customcertVIEWBYID*$2@$', $content);
|
||||
$content = preg_replace($search, '$@CUSTOMCERTVIEWBYID*$2@$', $content);
|
||||
|
||||
return $content;
|
||||
}
|
||||
|
|
|
@ -42,7 +42,7 @@ class backup_customcert_activity_structure_step extends backup_activity_structur
|
|||
|
||||
// The instance.
|
||||
$customcert = new backup_nested_element('customcert', array('id'), array(
|
||||
'templateid', 'name', 'intro', 'introformat', 'requiredtime', 'emailstudents',
|
||||
'templateid', 'name', 'intro', 'introformat', 'requiredtime', 'verifyany', 'emailstudents',
|
||||
'emailteachers', 'emailothers', 'protection', 'timecreated', 'timemodified'));
|
||||
|
||||
// The template.
|
||||
|
@ -57,7 +57,7 @@ class backup_customcert_activity_structure_step extends backup_activity_structur
|
|||
|
||||
// The elements.
|
||||
$element = new backup_nested_element('element', array('id'), array(
|
||||
'pageid', 'name', 'element', 'data', 'font', 'size',
|
||||
'pageid', 'name', 'element', 'data', 'font', 'fontsize',
|
||||
'colour', 'posx', 'posy', 'width', 'refpoint', 'sequence',
|
||||
'timecreated', 'timemodified'));
|
||||
|
||||
|
|
|
@ -112,7 +112,7 @@ class restore_customcert_activity_task extends restore_activity_task {
|
|||
// Go through the elements for the certificate.
|
||||
foreach ($elements as $e) {
|
||||
// Get an instance of the element class.
|
||||
if ($e = \mod_customcert\element::instance($e)) {
|
||||
if ($e = \mod_customcert\element_factory::get_element_instance($e)) {
|
||||
$e->after_restore($this);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -86,13 +86,14 @@ class certificate {
|
|||
*
|
||||
* @param int $draftitemid the draft area containing the files
|
||||
* @param int $contextid the context we are storing this image in
|
||||
* @param string $filearea indentifies the file area.
|
||||
*/
|
||||
public static function upload_imagefiles($draftitemid, $contextid) {
|
||||
public static function upload_files($draftitemid, $contextid, $filearea = 'image') {
|
||||
global $CFG;
|
||||
|
||||
// Save the file if it exists that is currently in the draft area.
|
||||
require_once($CFG->dirroot . '/lib/filelib.php');
|
||||
file_save_draft_area_files($draftitemid, $contextid, 'mod_customcert', 'image', 0);
|
||||
file_save_draft_area_files($draftitemid, $contextid, 'mod_customcert', $filearea, 0);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -154,7 +155,7 @@ class certificate {
|
|||
// Array to store the sizes.
|
||||
$sizes = array();
|
||||
|
||||
for ($i = 1; $i <= 60; $i++) {
|
||||
for ($i = 1; $i <= 200; $i++) {
|
||||
$sizes[$i] = $i;
|
||||
}
|
||||
|
||||
|
@ -246,7 +247,7 @@ class certificate {
|
|||
* @param int $limitfrom
|
||||
* @param int $limitnum
|
||||
* @param string $sort
|
||||
* @return \stdClass the users
|
||||
* @return array the users
|
||||
*/
|
||||
public static function get_issues($customcertid, $groupmode, $cm, $limitfrom, $limitnum, $sort = '') {
|
||||
global $DB;
|
||||
|
@ -264,7 +265,7 @@ class certificate {
|
|||
|
||||
// Return the issues.
|
||||
$ufields = \user_picture::fields('u');
|
||||
$sql = "SELECT $ufields, ci.code, ci.timecreated
|
||||
$sql = "SELECT $ufields, ci.id as issueid, ci.code, ci.timecreated
|
||||
FROM {user} u
|
||||
INNER JOIN {customcert_issues} ci
|
||||
ON u.id = ci.userid
|
||||
|
@ -420,6 +421,27 @@ class certificate {
|
|||
return $DB->get_records_sql($sql, array('userid' => $userid), $limitfrom, $limitnum);
|
||||
}
|
||||
|
||||
/**
|
||||
* Issues a certificate to a user.
|
||||
*
|
||||
* @param int $certificateid The ID of the certificate
|
||||
* @param int $userid The ID of the user to issue the certificate to
|
||||
* @return int The ID of the issue
|
||||
*/
|
||||
public static function issue_certificate($certificateid, $userid) {
|
||||
global $DB;
|
||||
|
||||
$issue = new \stdClass();
|
||||
$issue->userid = $userid;
|
||||
$issue->customcertid = $certificateid;
|
||||
$issue->code = self::generate_code();
|
||||
$issue->emailed = 0;
|
||||
$issue->timecreated = time();
|
||||
|
||||
// Insert the record into the database.
|
||||
return $DB->insert_record('customcert_issues', $issue);
|
||||
}
|
||||
|
||||
/**
|
||||
* Generates a 10-digit code of random letters and numbers.
|
||||
*
|
||||
|
|
|
@ -63,7 +63,7 @@ class edit_element_form extends \moodleform {
|
|||
$mform->addRule('name', get_string('required'), 'required', null, 'client');
|
||||
$mform->addHelpButton('name', 'elementname', 'customcert');
|
||||
|
||||
$this->element = \mod_customcert\element::instance($element);
|
||||
$this->element = \mod_customcert\element_factory::get_element_instance($element);
|
||||
$this->element->render_form_elements($mform);
|
||||
|
||||
$this->add_action_buttons(true);
|
||||
|
|
|
@ -55,7 +55,7 @@ class edit_form extends \moodleform {
|
|||
* Form definition.
|
||||
*/
|
||||
public function definition() {
|
||||
global $DB;
|
||||
global $DB, $OUTPUT;
|
||||
|
||||
$mform =& $this->_form;
|
||||
|
||||
|
@ -80,16 +80,23 @@ class edit_form extends \moodleform {
|
|||
$this->add_customcert_page_elements($page);
|
||||
}
|
||||
|
||||
$mform->closeHeaderBefore('addcertpage');
|
||||
|
||||
$mform->addElement('submit', 'addcertpage', get_string('addcertpage', 'customcert'));
|
||||
|
||||
$mform->closeHeaderBefore('submitbtn');
|
||||
// Link to add another page.
|
||||
$addpagelink = new \moodle_url('/mod/customcert/edit.php',
|
||||
array(
|
||||
'tid' => $this->tid,
|
||||
'aid' => 1,
|
||||
'action' => 'addpage',
|
||||
'sesskey' => sesskey()
|
||||
)
|
||||
);
|
||||
$icon = $OUTPUT->pix_icon('t/switch_plus', get_string('addcertpage', 'customcert'));
|
||||
$addpagehtml = \html_writer::link($addpagelink, $icon . get_string('addcertpage', 'customcert'));
|
||||
$mform->addElement('html', \html_writer::tag('div', $addpagehtml, array('class' => 'addpage')));
|
||||
|
||||
// Add the submit buttons.
|
||||
$group = array();
|
||||
$group[] = $mform->createElement('submit', 'submitbtn', get_string('savechanges'));
|
||||
$group[] = $mform->createElement('submit', 'previewbtn', get_string('savechangespreview', 'customcert'));
|
||||
$group[] = $mform->createElement('submit', 'previewbtn', get_string('savechangespreview', 'customcert'), array(), false);
|
||||
$mform->addElement('group', 'submitbtngroup', '', $group, '', false);
|
||||
|
||||
$mform->addElement('hidden', 'tid');
|
||||
|
@ -193,9 +200,9 @@ class edit_form extends \moodleform {
|
|||
}
|
||||
|
||||
$editlink = '/mod/customcert/edit.php';
|
||||
$editlinkparams = array('tid' => $this->tid);
|
||||
$editlinkparams = array('tid' => $this->tid, 'sesskey' => sesskey());
|
||||
$editelementlink = '/mod/customcert/edit_element.php';
|
||||
$editelementlinkparams = array('tid' => $this->tid);
|
||||
$editelementlinkparams = array('tid' => $this->tid, 'sesskey' => sesskey());
|
||||
|
||||
// Place the ordering arrows.
|
||||
// Only display the move up arrow if it is not the first.
|
||||
|
@ -231,17 +238,13 @@ class edit_form extends \moodleform {
|
|||
$mform->setDefault('pagerightmargin_' . $page->id, 0);
|
||||
$mform->addHelpButton('pagerightmargin_' . $page->id, 'rightmargin', 'customcert');
|
||||
|
||||
$group = array();
|
||||
$group[] = $mform->createElement('select', 'element_' . $page->id, '', element::get_available_types());
|
||||
$group[] = $mform->createElement('submit', 'addelement_' . $page->id, get_string('addelement', 'customcert'));
|
||||
$mform->addElement('group', 'elementgroup', '', $group, '', false);
|
||||
|
||||
// Check if there are elements to add.
|
||||
if ($elements = $DB->get_records('customcert_elements', array('pageid' => $page->id), 'sequence ASC')) {
|
||||
// Get the total number of elements.
|
||||
$numelements = count($elements);
|
||||
// Create a table to display these elements.
|
||||
$table = new \html_table();
|
||||
$table->attributes = array('class' => 'generaltable elementstable');
|
||||
$table->head = array(get_string('name', 'customcert'), get_string('type', 'customcert'), '');
|
||||
$table->align = array('left', 'left', 'left');
|
||||
// Loop through and add the elements to the table.
|
||||
|
@ -255,11 +258,13 @@ class edit_form extends \moodleform {
|
|||
// Link to edit this element.
|
||||
$link = new \moodle_url($editelementlink, $editelementlinkparams + array('id' => $element->id,
|
||||
'action' => 'edit'));
|
||||
$icons = $OUTPUT->action_icon($link, new \pix_icon('t/edit', get_string('edit')));
|
||||
$icons = $OUTPUT->action_icon($link, new \pix_icon('t/edit', get_string('edit')), null,
|
||||
array('class' => 'action-icon edit-icon'));
|
||||
// Link to delete the element.
|
||||
$link = new \moodle_url($editlink, $editlinkparams + array('action' => 'deleteelement',
|
||||
'aid' => $element->id));
|
||||
$icons .= $OUTPUT->action_icon($link, new \pix_icon('t/delete', get_string('delete')));
|
||||
$icons .= $OUTPUT->action_icon($link, new \pix_icon('t/delete', get_string('delete')), null,
|
||||
array('class' => 'action-icon delete-icon'));
|
||||
// Now display any moving arrows if they are needed.
|
||||
if ($numelements > 1) {
|
||||
// Only display the move up arrow if it is not the first.
|
||||
|
@ -285,17 +290,23 @@ class edit_form extends \moodleform {
|
|||
get_string('rearrangeelements', 'customcert'));
|
||||
// Add the table to the form.
|
||||
$mform->addElement('static', 'elements_' . $page->id, get_string('elements', 'customcert'), \html_writer::table($table)
|
||||
. \html_writer::tag( 'div', $link, array('style' => 'text-align:right')));
|
||||
. \html_writer::tag( 'div', $link));
|
||||
$mform->addHelpButton('elements_' . $page->id, 'elements', 'customcert');
|
||||
}
|
||||
|
||||
$group = array();
|
||||
$group[] = $mform->createElement('select', 'element_' . $page->id, '', element_helper::get_available_element_types());
|
||||
$group[] = $mform->createElement('submit', 'addelement_' . $page->id, get_string('addelement', 'customcert'),
|
||||
array(), false);
|
||||
$mform->addElement('group', 'elementgroup', '', $group, '', false);
|
||||
|
||||
// Add option to delete this page if there is more than one page.
|
||||
if ($this->numpages > 1) {
|
||||
// Link to delete the element.
|
||||
// Link to delete the page.
|
||||
$deletelink = new \moodle_url($editlink, $editlinkparams + array('action' => 'deletepage', 'aid' => $page->id));
|
||||
$deletelink = \html_writer::tag('a', get_string('deletecertpage', 'customcert'),
|
||||
array('href' => $deletelink->out(false), 'class' => 'deletebutton'));
|
||||
$mform->addElement('html', \html_writer::tag('div', $deletelink, array('class' => 'deletebutton')));
|
||||
$icon = $OUTPUT->pix_icon('t/delete', get_string('deletecertpage', 'customcert'));
|
||||
$deletepagehtml = \html_writer::link($deletelink, $icon . get_string('deletecertpage', 'customcert'));
|
||||
$mform->addElement('html', \html_writer::tag('div', $deletepagehtml, array('class' => 'deletebutton')));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -38,14 +38,69 @@ defined('MOODLE_INTERNAL') || die();
|
|||
abstract class element {
|
||||
|
||||
/**
|
||||
* @var \stdClass $element The data for the element we are adding.
|
||||
* @var \stdClass $element The data for the element we are adding - do not use, kept for legacy reasons.
|
||||
*/
|
||||
public $element;
|
||||
protected $element;
|
||||
|
||||
/**
|
||||
* @var int The id.
|
||||
*/
|
||||
protected $id;
|
||||
|
||||
/**
|
||||
* @var int The page id.
|
||||
*/
|
||||
protected $pageid;
|
||||
|
||||
/**
|
||||
* @var string The name.
|
||||
*/
|
||||
protected $name;
|
||||
|
||||
/**
|
||||
* @var mixed The data.
|
||||
*/
|
||||
protected $data;
|
||||
|
||||
/**
|
||||
* @var string The font name.
|
||||
*/
|
||||
protected $font;
|
||||
|
||||
/**
|
||||
* @var int The font size.
|
||||
*/
|
||||
protected $fontsize;
|
||||
|
||||
/**
|
||||
* @var string The font colour.
|
||||
*/
|
||||
protected $colour;
|
||||
|
||||
/**
|
||||
* @var int The position x.
|
||||
*/
|
||||
protected $posx;
|
||||
|
||||
/**
|
||||
* @var int The position y.
|
||||
*/
|
||||
protected $posy;
|
||||
|
||||
/**
|
||||
* @var int The width.
|
||||
*/
|
||||
protected $width;
|
||||
|
||||
/**
|
||||
* @var int The refpoint.
|
||||
*/
|
||||
protected $refpoint;
|
||||
|
||||
/**
|
||||
* @var bool $showposxy Show position XY form elements?
|
||||
*/
|
||||
public $showposxy;
|
||||
protected $showposxy;
|
||||
|
||||
/**
|
||||
* Constructor.
|
||||
|
@ -55,10 +110,122 @@ abstract class element {
|
|||
public function __construct($element) {
|
||||
$showposxy = get_config('customcert', 'showposxy');
|
||||
|
||||
// Keeping this for legacy reasons so we do not break third-party elements.
|
||||
$this->element = clone($element);
|
||||
|
||||
$this->id = $element->id;
|
||||
$this->pageid = $element->pageid;
|
||||
$this->name = $element->name;
|
||||
$this->data = $element->data;
|
||||
$this->font = $element->font;
|
||||
$this->fontsize = $element->fontsize;
|
||||
$this->colour = $element->colour;
|
||||
$this->posx = $element->posx;
|
||||
$this->posy = $element->posy;
|
||||
$this->width = $element->width;
|
||||
$this->refpoint = $element->refpoint;
|
||||
$this->showposxy = isset($showposxy) && $showposxy;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the id.
|
||||
*
|
||||
* @return int
|
||||
*/
|
||||
public function get_id() {
|
||||
return $this->id;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the page id.
|
||||
*
|
||||
* @return int
|
||||
*/
|
||||
public function get_pageid() {
|
||||
return $this->pageid;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the name.
|
||||
*
|
||||
* @return int
|
||||
*/
|
||||
public function get_name() {
|
||||
return $this->name;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the data.
|
||||
*
|
||||
* @return mixed
|
||||
*/
|
||||
public function get_data() {
|
||||
return $this->data;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the font name.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function get_font() {
|
||||
return $this->font;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the font size.
|
||||
*
|
||||
* @return int
|
||||
*/
|
||||
public function get_fontsize() {
|
||||
return $this->fontsize;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the font colour.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function get_colour() {
|
||||
return $this->colour;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the position x.
|
||||
*
|
||||
* @return int
|
||||
*/
|
||||
public function get_posx() {
|
||||
return $this->posx;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the position y.
|
||||
*
|
||||
* @return int
|
||||
*/
|
||||
public function get_posy() {
|
||||
return $this->posy;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the width.
|
||||
*
|
||||
* @return int
|
||||
*/
|
||||
public function get_width() {
|
||||
return $this->width;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the refpoint.
|
||||
*
|
||||
* @return int
|
||||
*/
|
||||
public function get_refpoint() {
|
||||
return $this->refpoint;
|
||||
}
|
||||
|
||||
/**
|
||||
* This function renders the form elements when adding a customcert element.
|
||||
* Can be overridden if more functionality is needed.
|
||||
|
@ -84,8 +251,18 @@ abstract class element {
|
|||
public function definition_after_data($mform) {
|
||||
// Loop through the properties of the element and set the values
|
||||
// of the corresponding form element, if it exists.
|
||||
foreach ($this->element as $property => $value) {
|
||||
if ($mform->elementExists($property)) {
|
||||
$properties = [
|
||||
'name' => $this->name,
|
||||
'font' => $this->font,
|
||||
'fontsize' => $this->fontsize,
|
||||
'colour' => $this->colour,
|
||||
'posx' => $this->posx,
|
||||
'posy' => $this->posy,
|
||||
'width' => $this->width,
|
||||
'refpoint' => $this->refpoint
|
||||
];
|
||||
foreach ($properties as $property => $value) {
|
||||
if (!is_null($value) && $mform->elementExists($property)) {
|
||||
$element = $mform->getElement($property);
|
||||
$element->setValue($value);
|
||||
}
|
||||
|
@ -129,7 +306,7 @@ abstract class element {
|
|||
$element->name = $data->name;
|
||||
$element->data = $this->save_unique_data($data);
|
||||
$element->font = (isset($data->font)) ? $data->font : null;
|
||||
$element->size = (isset($data->size)) ? $data->size : null;
|
||||
$element->fontsize = (isset($data->fontsize)) ? $data->fontsize : null;
|
||||
$element->colour = (isset($data->colour)) ? $data->colour : null;
|
||||
if ($this->showposxy) {
|
||||
$element->posx = (isset($data->posx)) ? $data->posx : null;
|
||||
|
@ -140,8 +317,8 @@ abstract class element {
|
|||
$element->timemodified = time();
|
||||
|
||||
// Check if we are updating, or inserting a new element.
|
||||
if (!empty($this->element->id)) { // Must be updating a record in the database.
|
||||
$element->id = $this->element->id;
|
||||
if (!empty($this->id)) { // Must be updating a record in the database.
|
||||
$element->id = $this->id;
|
||||
return $DB->update_record('customcert_elements', $element);
|
||||
} else { // Must be adding a new one.
|
||||
$element->element = $data->element;
|
||||
|
@ -198,7 +375,6 @@ abstract class element {
|
|||
*/
|
||||
public abstract function render_html();
|
||||
|
||||
|
||||
/**
|
||||
* Handles deleting any data this element may have introduced.
|
||||
* Can be overridden if more functionality is needed.
|
||||
|
@ -208,7 +384,7 @@ abstract class element {
|
|||
public function delete() {
|
||||
global $DB;
|
||||
|
||||
return $DB->delete_records('customcert_elements', array('id' => $this->element->id));
|
||||
return $DB->delete_records('customcert_elements', array('id' => $this->id));
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -230,66 +406,9 @@ abstract class element {
|
|||
* @param string $name
|
||||
*/
|
||||
public function __get($name) {
|
||||
debugging('Please call the appropriate get_* function instead of relying on magic getters', DEBUG_DEVELOPER);
|
||||
if (property_exists($this->element, $name)) {
|
||||
return $this->element->$name;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns an instance of the element class.
|
||||
*
|
||||
* @param \stdClass $element the element
|
||||
* @return \mod_customcert\element|bool returns the instance of the element class, or false if element
|
||||
* class does not exists.
|
||||
*/
|
||||
public static function instance($element) {
|
||||
// Get the class name.
|
||||
$classname = '\\customcertelement_' . $element->element . '\\element';
|
||||
|
||||
// Ensure the necessary class exists.
|
||||
if (class_exists($classname)) {
|
||||
return new $classname($element);
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the list of possible elements to add.
|
||||
*
|
||||
* @return array the list of element types that can be used.
|
||||
*/
|
||||
public static function get_available_types() {
|
||||
global $CFG;
|
||||
|
||||
// Array to store the element types.
|
||||
$options = array();
|
||||
|
||||
// Check that the directory exists.
|
||||
$elementdir = "$CFG->dirroot/mod/customcert/element";
|
||||
if (file_exists($elementdir)) {
|
||||
// Get directory contents.
|
||||
$elementfolders = new \DirectoryIterator($elementdir);
|
||||
// Loop through the elements folder.
|
||||
foreach ($elementfolders as $elementfolder) {
|
||||
// If it is not a directory or it is '.' or '..', skip it.
|
||||
if (!$elementfolder->isDir() || $elementfolder->isDot()) {
|
||||
continue;
|
||||
}
|
||||
// Check that the standard class exists, if not we do
|
||||
// not want to display it as an option as it will not work.
|
||||
$foldername = $elementfolder->getFilename();
|
||||
// Get the class name.
|
||||
$classname = '\\customcertelement_' . $foldername . '\\element';
|
||||
// Ensure the necessary class exists.
|
||||
if (class_exists($classname)) {
|
||||
$component = "customcertelement_{$foldername}";
|
||||
$options[$foldername] = get_string('pluginname', $component);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
\core_collator::asort($options);
|
||||
return $options;
|
||||
}
|
||||
}
|
||||
|
|
70
classes/element_factory.php
Normal file
70
classes/element_factory.php
Normal file
|
@ -0,0 +1,70 @@
|
|||
<?php
|
||||
// This file is part of the customcert module for Moodle - http://moodle.org/
|
||||
//
|
||||
// Moodle is free software: you can redistribute it and/or modify
|
||||
// it under the terms of the GNU General Public License as published by
|
||||
// the Free Software Foundation, either version 3 of the License, or
|
||||
// (at your option) any later version.
|
||||
//
|
||||
// Moodle is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
/**
|
||||
* Contains the factory class responsible for creating custom certificate instances.
|
||||
*
|
||||
* @package mod_customcert
|
||||
* @copyright 2017 Mark Nelson <markn@moodle.com>
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
*/
|
||||
|
||||
namespace mod_customcert;
|
||||
|
||||
defined('MOODLE_INTERNAL') || die();
|
||||
|
||||
/**
|
||||
* The factory class responsible for creating custom certificate instances.
|
||||
*
|
||||
* @package mod_customcert
|
||||
* @copyright 2017 Mark Nelson <markn@moodle.com>
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
*/
|
||||
class element_factory {
|
||||
|
||||
/**
|
||||
* Returns an instance of the element class.
|
||||
*
|
||||
* @param \stdClass $element the element
|
||||
* @return \mod_customcert\element|bool returns the instance of the element class, or false if element
|
||||
* class does not exists.
|
||||
*/
|
||||
public static function get_element_instance($element) {
|
||||
// Get the class name.
|
||||
$classname = '\\customcertelement_' . $element->element . '\\element';
|
||||
|
||||
$data = new \stdClass();
|
||||
$data->id = isset($element->id) ? $element->id : null;
|
||||
$data->pageid = isset($element->pageid) ? $element->pageid : null;
|
||||
$data->name = isset($element->name) ? $element->name : get_string('pluginname', 'customcertelement_' . $element->element);
|
||||
$data->element = $element->element;
|
||||
$data->data = isset($element->data) ? $element->data : null;
|
||||
$data->font = isset($element->font) ? $element->font : null;
|
||||
$data->fontsize = isset($element->fontsize) ? $element->fontsize : null;
|
||||
$data->colour = isset($element->colour) ? $element->colour : null;
|
||||
$data->posx = isset($element->posx) ? $element->posx : null;
|
||||
$data->posy = isset($element->posy) ? $element->posy : null;
|
||||
$data->width = isset($element->width) ? $element->width : null;
|
||||
$data->refpoint = isset($element->refpoint) ? $element->refpoint : null;
|
||||
|
||||
// Ensure the necessary class exists.
|
||||
if (class_exists($classname)) {
|
||||
return new $classname($data);
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
}
|
|
@ -26,13 +26,17 @@ namespace mod_customcert;
|
|||
|
||||
defined('MOODLE_INTERNAL') || die();
|
||||
|
||||
require_once($CFG->libdir . '/grade/constants.php');
|
||||
require_once($CFG->dirroot . '/grade/lib.php');
|
||||
require_once($CFG->dirroot . '/grade/querylib.php');
|
||||
|
||||
/**
|
||||
* Class helper.
|
||||
*
|
||||
* Provides useful functions related to elements.
|
||||
*
|
||||
* @package mod_customcert
|
||||
* @copyright 2013 Mark Nelson <markn@moodle.com>
|
||||
* @copyright 2016 Mark Nelson <markn@moodle.com>
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
*/
|
||||
class element_helper {
|
||||
|
@ -61,14 +65,14 @@ class element_helper {
|
|||
*/
|
||||
public static function render_content($pdf, $element, $content) {
|
||||
list($font, $attr) = self::get_font($element);
|
||||
$pdf->setFont($font, $attr, $element->size);
|
||||
$fontcolour = \TCPDF_COLORS::convertHTMLColorToDec($element->colour, $fontcolour);
|
||||
$pdf->setFont($font, $attr, $element->get_fontsize());
|
||||
$fontcolour = \TCPDF_COLORS::convertHTMLColorToDec($element->get_colour(), $fontcolour);
|
||||
$pdf->SetTextColor($fontcolour['R'], $fontcolour['G'], $fontcolour['B']);
|
||||
|
||||
$x = $element->posx;
|
||||
$y = $element->posy;
|
||||
$w = $element->width;
|
||||
$refpoint = $element->refpoint;
|
||||
$x = $element->get_posx();
|
||||
$y = $element->get_posy();
|
||||
$w = $element->get_width();
|
||||
$refpoint = $element->get_refpoint();
|
||||
$actualwidth = $pdf->GetStringWidth($content);
|
||||
|
||||
if ($w and $w < $actualwidth) {
|
||||
|
@ -77,19 +81,19 @@ class element_helper {
|
|||
|
||||
switch ($refpoint) {
|
||||
case self::CUSTOMCERT_REF_POINT_TOPRIGHT:
|
||||
$x = $element->posx - $actualwidth;
|
||||
$x = $element->get_posx() - $actualwidth;
|
||||
if ($x < 0) {
|
||||
$x = 0;
|
||||
$w = $element->posx;
|
||||
$w = $element->get_posx();
|
||||
} else {
|
||||
$w = $actualwidth;
|
||||
}
|
||||
break;
|
||||
case self::CUSTOMCERT_REF_POINT_TOPCENTER:
|
||||
$x = $element->posx - $actualwidth / 2;
|
||||
$x = $element->get_posx() - $actualwidth / 2;
|
||||
if ($x < 0) {
|
||||
$x = 0;
|
||||
$w = $element->posx * 2;
|
||||
$w = $element->get_posx() * 2;
|
||||
} else {
|
||||
$w = $actualwidth;
|
||||
}
|
||||
|
@ -120,9 +124,9 @@ class element_helper {
|
|||
$fontstyle .= '; font-style: italic';
|
||||
}
|
||||
|
||||
$style = $fontstyle . '; color: ' . $element->colour . '; font-size: ' . $element->size . 'pt;';
|
||||
if ($element->width) {
|
||||
$style .= ' width: ' . $element->width . 'mm';
|
||||
$style = $fontstyle . '; color: ' . $element->get_colour() . '; font-size: ' . $element->get_fontsize() . 'pt;';
|
||||
if ($element->get_width()) {
|
||||
$style .= ' width: ' . $element->get_width() . 'mm';
|
||||
}
|
||||
return \html_writer::div($content, '', array('style' => $style));
|
||||
}
|
||||
|
@ -137,10 +141,11 @@ class element_helper {
|
|||
$mform->setType('font', PARAM_TEXT);
|
||||
$mform->setDefault('font', 'times');
|
||||
$mform->addHelpButton('font', 'font', 'customcert');
|
||||
$mform->addElement('select', 'size', get_string('fontsize', 'customcert'), \mod_customcert\certificate::get_font_sizes());
|
||||
$mform->setType('size', PARAM_INT);
|
||||
$mform->setDefault('size', 12);
|
||||
$mform->addHelpButton('size', 'fontsize', 'customcert');
|
||||
$mform->addElement('select', 'fontsize', get_string('fontsize', 'customcert'),
|
||||
\mod_customcert\certificate::get_font_sizes());
|
||||
$mform->setType('fontsize', PARAM_INT);
|
||||
$mform->setDefault('fontsize', 12);
|
||||
$mform->addHelpButton('fontsize', 'fontsize', 'customcert');
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -252,7 +257,7 @@ class element_helper {
|
|||
*/
|
||||
public static function get_font($element) {
|
||||
// Variable for the font.
|
||||
$font = $element->font;
|
||||
$font = $element->get_font();
|
||||
// Get the last two characters of the font name.
|
||||
$fontlength = strlen($font);
|
||||
$lastchar = $font[$fontlength - 1];
|
||||
|
@ -352,4 +357,255 @@ class element_helper {
|
|||
|
||||
return $sequence;
|
||||
}
|
||||
|
||||
/**
|
||||
* Helper function that returns the course id for this element.
|
||||
*
|
||||
* @param int $elementid The element id
|
||||
* @return int The course id
|
||||
*/
|
||||
public static function get_courseid($elementid) {
|
||||
global $DB, $SITE;
|
||||
|
||||
$sql = "SELECT course
|
||||
FROM {customcert} c
|
||||
INNER JOIN {customcert_pages} cp
|
||||
ON c.templateid = cp.templateid
|
||||
INNER JOIN {customcert_elements} ce
|
||||
ON cp.id = ce.pageid
|
||||
WHERE ce.id = :elementid";
|
||||
|
||||
// Check if there is a course associated with this element.
|
||||
if ($course = $DB->get_record_sql($sql, array('elementid' => $elementid))) {
|
||||
return $course->course;
|
||||
} else { // Must be in a site template.
|
||||
return $SITE->id;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the list of possible elements to add.
|
||||
*
|
||||
* @return array the list of element types that can be used.
|
||||
*/
|
||||
public static function get_available_element_types() {
|
||||
global $CFG;
|
||||
|
||||
// Array to store the element types.
|
||||
$options = array();
|
||||
|
||||
// Check that the directory exists.
|
||||
$elementdir = "$CFG->dirroot/mod/customcert/element";
|
||||
if (file_exists($elementdir)) {
|
||||
// Get directory contents.
|
||||
$elementfolders = new \DirectoryIterator($elementdir);
|
||||
// Loop through the elements folder.
|
||||
foreach ($elementfolders as $elementfolder) {
|
||||
// If it is not a directory or it is '.' or '..', skip it.
|
||||
if (!$elementfolder->isDir() || $elementfolder->isDot()) {
|
||||
continue;
|
||||
}
|
||||
// Check that the standard class exists, if not we do
|
||||
// not want to display it as an option as it will not work.
|
||||
$foldername = $elementfolder->getFilename();
|
||||
// Get the class name.
|
||||
$classname = '\\customcertelement_' . $foldername . '\\element';
|
||||
// Ensure the necessary class exists.
|
||||
if (class_exists($classname)) {
|
||||
$component = "customcertelement_{$foldername}";
|
||||
$options[$foldername] = get_string('pluginname', $component);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
\core_collator::asort($options);
|
||||
return $options;
|
||||
}
|
||||
|
||||
/**
|
||||
* Helper function to return all the grades items for a given course.
|
||||
*
|
||||
* @param \stdClass $course The course we want to return the grade items for
|
||||
* @return array the array of gradeable items in the course
|
||||
*/
|
||||
public static function get_grade_items($course) {
|
||||
global $DB;
|
||||
|
||||
// Array to store the grade items.
|
||||
$modules = array();
|
||||
|
||||
// Collect course modules data.
|
||||
$modinfo = get_fast_modinfo($course);
|
||||
$mods = $modinfo->get_cms();
|
||||
$sections = $modinfo->get_section_info_all();
|
||||
|
||||
// Create the section label depending on course format.
|
||||
$sectionlabel = get_string('section');
|
||||
if ($course->format == 'topics') {
|
||||
$sectionlabel = get_string('topic');
|
||||
} else if ($course->format == 'weeks') {
|
||||
$sectionlabel = get_string('week');
|
||||
}
|
||||
|
||||
// Loop through each course section.
|
||||
for ($i = 0; $i <= count($sections) - 1; $i++) {
|
||||
// Confirm the index exists, should always be true.
|
||||
if (isset($sections[$i])) {
|
||||
// Get the individual section.
|
||||
$section = $sections[$i];
|
||||
// Get the mods for this section.
|
||||
$sectionmods = explode(",", $section->sequence);
|
||||
// Loop through the section mods.
|
||||
foreach ($sectionmods as $sectionmod) {
|
||||
// Should never happen unless DB is borked.
|
||||
if (empty($mods[$sectionmod])) {
|
||||
continue;
|
||||
}
|
||||
$mod = $mods[$sectionmod];
|
||||
$instance = $DB->get_record($mod->modname, array('id' => $mod->instance));
|
||||
// Get the grade items for this activity.
|
||||
if ($gradeitems = grade_get_grade_items_for_activity($mod)) {
|
||||
$moditem = grade_get_grades($course->id, 'mod', $mod->modname, $mod->instance);
|
||||
$gradeitem = reset($moditem->items);
|
||||
if (isset($gradeitem->grademax)) {
|
||||
$modules[$mod->id] = $sectionlabel . ' ' . $section->section . ' : ' . $instance->name;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if ($gradeitems = \grade_item::fetch_all(['courseid' => $course->id])) {
|
||||
$arrgradeitems = [];
|
||||
foreach ($gradeitems as $gi) {
|
||||
// Skip the course and mod items since we already have them.
|
||||
if ($gi->itemtype == 'mod' || $gi->itemtype == 'course') {
|
||||
continue;
|
||||
}
|
||||
$arrgradeitems['gradeitem:' . $gi->id] = get_string('gradeitem', 'grades') . ' : ' . $gi->get_name(true);
|
||||
}
|
||||
|
||||
// Alphabetise this.
|
||||
asort($arrgradeitems);
|
||||
|
||||
// Merge results.
|
||||
$modules = $modules + $arrgradeitems;
|
||||
}
|
||||
|
||||
return $modules;
|
||||
}
|
||||
|
||||
/**
|
||||
* Helper function to return the grade information for a course for a specified user.
|
||||
*
|
||||
* @param int $courseid
|
||||
* @param int $gradeformat
|
||||
* @param int $userid
|
||||
* @return grade_information|bool the grade information, or false if there is none.
|
||||
*/
|
||||
public static function get_course_grade_info($courseid, $gradeformat, $userid) {
|
||||
$courseitem = \grade_item::fetch_course_item($courseid);
|
||||
|
||||
if (!$courseitem) {
|
||||
return false;
|
||||
}
|
||||
|
||||
// Define how many decimals to display.
|
||||
$decimals = 2;
|
||||
if ($gradeformat == GRADE_DISPLAY_TYPE_PERCENTAGE) {
|
||||
$decimals = 0;
|
||||
}
|
||||
|
||||
$grade = new \grade_grade(array('itemid' => $courseitem->id, 'userid' => $userid));
|
||||
|
||||
return new grade_information(
|
||||
$courseitem->get_name(),
|
||||
$grade->finalgrade,
|
||||
grade_format_gradevalue($grade->finalgrade, $courseitem, true, $gradeformat, $decimals),
|
||||
$grade->get_dategraded()
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Helper function to return the grade information for a module for a specified user.
|
||||
*
|
||||
* @param int $cmid
|
||||
* @param int $gradeformat
|
||||
* @param int $userid
|
||||
* @return grade_information|bool the grade information, or false if there is none.
|
||||
*/
|
||||
public static function get_mod_grade_info($cmid, $gradeformat, $userid) {
|
||||
global $DB;
|
||||
|
||||
if (!$cm = $DB->get_record('course_modules', array('id' => $cmid))) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!$module = $DB->get_record('modules', array('id' => $cm->module))) {
|
||||
return false;
|
||||
}
|
||||
|
||||
$gradeitem = grade_get_grades($cm->course, 'mod', $module->name, $cm->instance, $userid);
|
||||
|
||||
if (empty($gradeitem)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
// Define how many decimals to display.
|
||||
$decimals = 2;
|
||||
if ($gradeformat == GRADE_DISPLAY_TYPE_PERCENTAGE) {
|
||||
$decimals = 0;
|
||||
}
|
||||
|
||||
$item = new \grade_item();
|
||||
$item->gradetype = GRADE_TYPE_VALUE;
|
||||
$item->courseid = $cm->course;
|
||||
$itemproperties = reset($gradeitem->items);
|
||||
foreach ($itemproperties as $key => $value) {
|
||||
$item->$key = $value;
|
||||
}
|
||||
|
||||
$objgrade = $item->grades[$userid];
|
||||
|
||||
$dategraded = null;
|
||||
if (!empty($objgrade->dategraded)) {
|
||||
$dategraded = $objgrade->dategraded;
|
||||
}
|
||||
|
||||
return new grade_information(
|
||||
$item->name,
|
||||
$objgrade->grade,
|
||||
grade_format_gradevalue($objgrade->grade, $item, true, $gradeformat, $decimals),
|
||||
$dategraded
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Helper function to return the grade information for a grade item for a specified user.
|
||||
*
|
||||
* @param int $gradeitemid
|
||||
* @param int $gradeformat
|
||||
* @param int $userid
|
||||
* @return grade_information|bool the grade information, or false if there is none.
|
||||
*/
|
||||
public static function get_grade_item_info($gradeitemid, $gradeformat, $userid) {
|
||||
if (!$gradeitem = \grade_item::fetch(['id' => $gradeitemid])) {
|
||||
return false;
|
||||
}
|
||||
|
||||
// Define how many decimals to display.
|
||||
$decimals = 2;
|
||||
if ($gradeformat == GRADE_DISPLAY_TYPE_PERCENTAGE) {
|
||||
$decimals = 0;
|
||||
}
|
||||
|
||||
$grade = new \grade_grade(array('itemid' => $gradeitem->id, 'userid' => $userid));
|
||||
|
||||
return new grade_information(
|
||||
$gradeitem->get_name(),
|
||||
$grade->finalgrade,
|
||||
grade_format_gradevalue($grade->finalgrade, $gradeitem, true, $gradeformat, $decimals),
|
||||
$grade->get_dategraded()
|
||||
);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -99,7 +99,7 @@ class external extends \external_api {
|
|||
}
|
||||
|
||||
// Get an instance of the element class.
|
||||
if ($e = \mod_customcert\element::instance($element)) {
|
||||
if ($e = \mod_customcert\element_factory::get_element_instance($element)) {
|
||||
return $e->save_form_elements($data);
|
||||
}
|
||||
|
||||
|
@ -159,7 +159,7 @@ class external extends \external_api {
|
|||
}
|
||||
|
||||
// Get an instance of the element class.
|
||||
if ($e = \mod_customcert\element::instance($element)) {
|
||||
if ($e = \mod_customcert\element_factory::get_element_instance($element)) {
|
||||
return $e->render_html();
|
||||
}
|
||||
|
||||
|
|
108
classes/grade_information.php
Normal file
108
classes/grade_information.php
Normal file
|
@ -0,0 +1,108 @@
|
|||
<?php
|
||||
// This file is part of the customcert module for Moodle - http://moodle.org/
|
||||
//
|
||||
// Moodle is free software: you can redistribute it and/or modify
|
||||
// it under the terms of the GNU General Public License as published by
|
||||
// the Free Software Foundation, either version 3 of the License, or
|
||||
// (at your option) any later version.
|
||||
//
|
||||
// Moodle is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
/**
|
||||
* Contains the class that provides a grade object to be used by elements for display purposes.
|
||||
*
|
||||
* @package mod_customcert
|
||||
* @copyright 2017 Mark Nelson <markn@moodle.com>
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
*/
|
||||
|
||||
namespace mod_customcert;
|
||||
|
||||
defined('MOODLE_INTERNAL') || die();
|
||||
|
||||
/**
|
||||
* The class that provides a grade object to be used by elements for display purposes.
|
||||
*
|
||||
* @package mod_customcert
|
||||
* @copyright 2017 Mark Nelson <markn@moodle.com>
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
*/
|
||||
class grade_information {
|
||||
|
||||
/**
|
||||
* @var string The grade name.
|
||||
*/
|
||||
protected $name;
|
||||
|
||||
/**
|
||||
* @var float The raw grade.
|
||||
*/
|
||||
protected $grade;
|
||||
|
||||
/**
|
||||
* @var string The grade to display
|
||||
*/
|
||||
protected $displaygrade;
|
||||
|
||||
/**
|
||||
* @var int The date it was graded.
|
||||
*/
|
||||
protected $dategraded;
|
||||
|
||||
/**
|
||||
* The constructor.
|
||||
*
|
||||
* @param string $name
|
||||
* @param float $grade
|
||||
* @param string $displaygrade
|
||||
* @param int $dategraded
|
||||
*/
|
||||
public function __construct($name, $grade, $displaygrade, $dategraded) {
|
||||
$this->name = $name;
|
||||
$this->grade = $grade;
|
||||
$this->displaygrade = $displaygrade;
|
||||
$this->dategraded = $dategraded;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the name.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function get_name() {
|
||||
return $this->name;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the raw grade.
|
||||
*
|
||||
* @return float
|
||||
*/
|
||||
public function get_grade() {
|
||||
return $this->grade;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the display grade.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function get_displaygrade() {
|
||||
return $this->displaygrade;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the date it was graded.
|
||||
*
|
||||
* @return int
|
||||
*/
|
||||
public function get_dategraded() {
|
||||
return $this->dategraded;
|
||||
}
|
||||
}
|
142
classes/manage_templates_table.php
Normal file
142
classes/manage_templates_table.php
Normal file
|
@ -0,0 +1,142 @@
|
|||
<?php
|
||||
// This file is part of Moodle - http://moodle.org/
|
||||
//
|
||||
// Moodle is free software: you can redistribute it and/or modify
|
||||
// it under the terms of the GNU General Public License as published by
|
||||
// the Free Software Foundation, either version 3 of the License, or
|
||||
// (at your option) any later version.
|
||||
//
|
||||
// Moodle is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
/**
|
||||
* The table that displays the templates in a given context.
|
||||
*
|
||||
* @package mod_customcert
|
||||
* @copyright 2017 Mark Nelson <markn@moodle.com>
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
*/
|
||||
|
||||
namespace mod_customcert;
|
||||
|
||||
defined('MOODLE_INTERNAL') || die;
|
||||
|
||||
global $CFG;
|
||||
|
||||
require_once($CFG->libdir . '/tablelib.php');
|
||||
|
||||
/**
|
||||
* Class for the table that displays the templates in a given context.
|
||||
*
|
||||
* @package mod_customcert
|
||||
* @copyright 2017 Mark Nelson <markn@moodle.com>
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
*/
|
||||
class manage_templates_table extends \table_sql {
|
||||
|
||||
/**
|
||||
* @var \context $context
|
||||
*/
|
||||
protected $context;
|
||||
|
||||
/**
|
||||
* Sets up the table.
|
||||
*
|
||||
* @param \context $context
|
||||
*/
|
||||
public function __construct($context) {
|
||||
parent::__construct('mod_customcert_manage_templates_table');
|
||||
|
||||
$columns = [
|
||||
'name',
|
||||
'actions'
|
||||
];
|
||||
|
||||
$headers = [
|
||||
get_string('name'),
|
||||
''
|
||||
];
|
||||
|
||||
$this->define_columns($columns);
|
||||
$this->define_headers($headers);
|
||||
$this->collapsible(false);
|
||||
$this->sortable(true);
|
||||
|
||||
$this->context = $context;
|
||||
}
|
||||
|
||||
/**
|
||||
* Generate the name column.
|
||||
*
|
||||
* @param \stdClass $template
|
||||
* @return string
|
||||
*/
|
||||
public function col_name($template) {
|
||||
return $template->name;
|
||||
}
|
||||
|
||||
/**
|
||||
* Generate the actions column.
|
||||
*
|
||||
* @param \stdClass $template
|
||||
* @return string
|
||||
*/
|
||||
public function col_actions($template) {
|
||||
global $OUTPUT;
|
||||
|
||||
// Link to edit the template.
|
||||
$editlink = new \moodle_url('/mod/customcert/edit.php', array('tid' => $template->id));
|
||||
$editicon = $OUTPUT->action_icon($editlink, new \pix_icon('t/edit', get_string('edit')));
|
||||
|
||||
// Link to duplicate the template.
|
||||
$duplicatelink = new \moodle_url('/mod/customcert/manage_templates.php',
|
||||
array(
|
||||
'tid' => $template->id,
|
||||
'action' => 'duplicate',
|
||||
'sesskey' => sesskey()
|
||||
)
|
||||
);
|
||||
$duplicateicon = $OUTPUT->action_icon($duplicatelink, new \pix_icon('t/copy', get_string('duplicate')), null,
|
||||
array('class' => 'action-icon duplicate-icon'));
|
||||
|
||||
// Link to delete the template.
|
||||
$deletelink = new \moodle_url('/mod/customcert/manage_templates.php',
|
||||
array(
|
||||
'tid' => $template->id,
|
||||
'action' => 'delete',
|
||||
'sesskey' => sesskey()
|
||||
)
|
||||
);
|
||||
$deleteicon = $OUTPUT->action_icon($deletelink, new \pix_icon('t/delete', get_string('delete')), null,
|
||||
array('class' => 'action-icon delete-icon'));
|
||||
|
||||
return $editicon . $duplicateicon . $deleteicon;
|
||||
}
|
||||
|
||||
/**
|
||||
* Query the reader.
|
||||
*
|
||||
* @param int $pagesize size of page for paginated displayed table.
|
||||
* @param bool $useinitialsbar do you want to use the initials bar.
|
||||
*/
|
||||
public function query_db($pagesize, $useinitialsbar = true) {
|
||||
global $DB;
|
||||
|
||||
$total = $DB->count_records('customcert_templates', array('contextid' => $this->context->id));
|
||||
|
||||
$this->pagesize($pagesize, $total);
|
||||
|
||||
$this->rawdata = $DB->get_records('customcert_templates', array('contextid' => $this->context->id),
|
||||
$this->get_sql_sort(), '*', $this->get_page_start(), $this->get_page_size());
|
||||
|
||||
// Set initial bars.
|
||||
if ($useinitialsbar) {
|
||||
$this->initialbars($total > $pagesize);
|
||||
}
|
||||
}
|
||||
}
|
|
@ -44,6 +44,11 @@ class email_certificate implements \renderable, \templatable {
|
|||
*/
|
||||
public $userfullname;
|
||||
|
||||
/**
|
||||
* @var string The course short name.
|
||||
*/
|
||||
public $courseshortname;
|
||||
|
||||
/**
|
||||
* @var string The course full name.
|
||||
*/
|
||||
|
@ -64,13 +69,15 @@ class email_certificate implements \renderable, \templatable {
|
|||
*
|
||||
* @param bool $isstudent Are we emailing the student?
|
||||
* @param string $userfullname The name of the user who owns the certificate.
|
||||
* @param string $coursefullname The name of the course.
|
||||
* @param string $courseshortname The short name of the course.
|
||||
* @param string $coursefullname The full name of the course.
|
||||
* @param string $certificatename The name of the certificate.
|
||||
* @param string $cmid The course module id.
|
||||
*/
|
||||
public function __construct($isstudent, $userfullname, $coursefullname, $certificatename, $cmid) {
|
||||
public function __construct($isstudent, $userfullname, $courseshortname, $coursefullname, $certificatename, $cmid) {
|
||||
$this->isstudent = $isstudent;
|
||||
$this->userfullname = $userfullname;
|
||||
$this->courseshortname = $courseshortname;
|
||||
$this->coursefullname = $coursefullname;
|
||||
$this->certificatename = $certificatename;
|
||||
$this->cmid = $cmid;
|
||||
|
@ -89,6 +96,7 @@ class email_certificate implements \renderable, \templatable {
|
|||
$info = new \stdClass();
|
||||
$info->userfullname = $this->userfullname;
|
||||
$info->certificatename = $this->certificatename;
|
||||
$info->courseshortname = $this->courseshortname;
|
||||
$info->coursefullname = $this->coursefullname;
|
||||
|
||||
if ($this->isstudent) {
|
||||
|
|
|
@ -86,6 +86,11 @@ class report_table extends \table_sql {
|
|||
$headers[] = get_string('file');
|
||||
}
|
||||
|
||||
if (!$this->is_downloading() && has_capability('mod/customcert:manage', \context_module::instance($cm->id))) {
|
||||
$columns[] = 'actions';
|
||||
$headers[] = '';
|
||||
}
|
||||
|
||||
$this->define_columns($columns);
|
||||
$this->define_headers($headers);
|
||||
$this->collapsible(false);
|
||||
|
@ -108,7 +113,11 @@ class report_table extends \table_sql {
|
|||
public function col_fullname($user) {
|
||||
global $OUTPUT;
|
||||
|
||||
return $OUTPUT->user_picture($user) . ' ' . fullname($user);
|
||||
if (!$this->is_downloading()) {
|
||||
return $OUTPUT->user_picture($user) . ' ' . fullname($user);
|
||||
} else {
|
||||
return fullname($user);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -149,6 +158,27 @@ class report_table extends \table_sql {
|
|||
return $OUTPUT->action_link($link, '', null, null, $icon);
|
||||
}
|
||||
|
||||
/**
|
||||
* Generate the actions column.
|
||||
*
|
||||
* @param \stdClass $user
|
||||
* @return string
|
||||
*/
|
||||
public function col_actions($user) {
|
||||
global $OUTPUT;
|
||||
|
||||
$icon = new \pix_icon('i/delete', get_string('delete'));
|
||||
$link = new \moodle_url('/mod/customcert/report.php',
|
||||
[
|
||||
'id' => $this->cm->id,
|
||||
'deleteissue' => $user->issueid,
|
||||
'sesskey' => sesskey()
|
||||
]
|
||||
);
|
||||
|
||||
return $OUTPUT->action_icon($link, $icon, null, ['class' => 'action-icon delete-icon']);
|
||||
}
|
||||
|
||||
/**
|
||||
* Query the reader.
|
||||
*
|
||||
|
|
|
@ -51,7 +51,7 @@ class email_certificate_task extends \core\task\scheduled_task {
|
|||
|
||||
// Get all the certificates that have requested someone get emailed.
|
||||
$sql = "SELECT c.*, ct.id as templateid, ct.name as templatename, ct.contextid, co.id as courseid,
|
||||
co.shortname as coursename
|
||||
co.fullname as coursefullname, co.shortname as courseshortname
|
||||
FROM {customcert} c
|
||||
JOIN {customcert_templates} ct
|
||||
ON c.templateid = ct.id
|
||||
|
@ -78,24 +78,25 @@ class email_certificate_task extends \core\task\scheduled_task {
|
|||
$userfrom = get_admin();
|
||||
}
|
||||
|
||||
$coursename = format_string($customcert->coursename, true, array('context' => $context));
|
||||
$courseshortname = format_string($customcert->courseshortname, true, array('context' => $context));
|
||||
$coursefullname = format_string($customcert->coursefullname, true, array('context' => $context));
|
||||
$certificatename = format_string($customcert->name, true, array('context' => $context));
|
||||
|
||||
// Used to create the email subject.
|
||||
$info = new \stdClass;
|
||||
$info->coursename = $coursename;
|
||||
$info->coursename = $courseshortname; // Added for BC, so users who have edited the string don't lose this value.
|
||||
$info->courseshortname = $courseshortname;
|
||||
$info->coursefullname = $coursefullname;
|
||||
$info->certificatename = $certificatename;
|
||||
|
||||
// Get a list of issues that have not yet been emailed.
|
||||
// Get a list of all the issues.
|
||||
$userfields = get_all_user_name_fields(true, 'u');
|
||||
$sql = "SELECT u.id, u.username, $userfields, u.email, ci.id as issueid
|
||||
$sql = "SELECT u.id, u.username, $userfields, u.email, ci.id as issueid, ci.emailed
|
||||
FROM {customcert_issues} ci
|
||||
JOIN {user} u
|
||||
ON ci.userid = u.id
|
||||
WHERE ci.customcertid = :customcertid
|
||||
AND emailed = :emailed";
|
||||
$issuedusers = $DB->get_records_sql($sql, array('customcertid' => $customcert->id,
|
||||
'emailed' => 0));
|
||||
WHERE ci.customcertid = :customcertid";
|
||||
$issuedusers = $DB->get_records_sql($sql, array('customcertid' => $customcert->id));
|
||||
|
||||
// Now, get a list of users who can access the certificate but have not yet.
|
||||
$enrolledusers = get_enrolled_users(\context_course::instance($customcert->courseid), 'mod/customcert:view');
|
||||
|
@ -124,22 +125,27 @@ class email_certificate_task extends \core\task\scheduled_task {
|
|||
}
|
||||
}
|
||||
|
||||
// Ok, issue them the certificate.
|
||||
$customcertissue = new \stdClass();
|
||||
$customcertissue->customcertid = $customcert->id;
|
||||
$customcertissue->userid = $enroluser->id;
|
||||
$customcertissue->code = \mod_customcert\certificate::generate_code();
|
||||
$customcertissue->emailed = 0;
|
||||
$customcertissue->timecreated = time();
|
||||
|
||||
// Insert the record into the database.
|
||||
$issueid = $DB->insert_record('customcert_issues', $customcertissue);
|
||||
// Ensure the cert hasn't already been issued, e.g via the UI (view.php) - a race condition.
|
||||
$issueid = $DB->get_field('customcert_issues', 'id',
|
||||
array('userid' => $enroluser->id, 'customcertid' => $customcert->id));
|
||||
if (empty($issueid)) {
|
||||
// Ok, issue them the certificate.
|
||||
$issueid = \mod_customcert\certificate::issue_certificate($customcert->id, $enroluser->id);
|
||||
}
|
||||
|
||||
// Add them to the array so we email them.
|
||||
$enroluser->issueid = $issueid;
|
||||
$enroluser->emailed = 0;
|
||||
$issuedusers[] = $enroluser;
|
||||
}
|
||||
|
||||
// Remove all the users who have already been emailed.
|
||||
foreach ($issuedusers as $key => $issueduser) {
|
||||
if ($issueduser->emailed) {
|
||||
unset($issuedusers[$key]);
|
||||
}
|
||||
}
|
||||
|
||||
// Now, email the people we need to.
|
||||
if ($issuedusers) {
|
||||
foreach ($issuedusers as $user) {
|
||||
|
@ -160,7 +166,7 @@ class email_certificate_task extends \core\task\scheduled_task {
|
|||
$filecontents = $template->generate_pdf(false, $user->id, true);
|
||||
|
||||
// Set the name of the file we are going to send.
|
||||
$filename = $coursename . '_' . $certificatename;
|
||||
$filename = $courseshortname . '_' . $certificatename;
|
||||
$filename = \core_text::entities_to_utf8($filename);
|
||||
$filename = strip_tags($filename);
|
||||
$filename = rtrim($filename, '.');
|
||||
|
@ -171,8 +177,8 @@ class email_certificate_task extends \core\task\scheduled_task {
|
|||
file_put_contents($tempfile, $filecontents);
|
||||
|
||||
if ($customcert->emailstudents) {
|
||||
$renderable = new \mod_customcert\output\email_certificate(true, $userfullname, $coursename,
|
||||
$certificatename, $customcert->contextid);
|
||||
$renderable = new \mod_customcert\output\email_certificate(true, $userfullname, $courseshortname,
|
||||
$coursefullname, $certificatename, $customcert->contextid);
|
||||
|
||||
$subject = get_string('emailstudentsubject', 'customcert', $info);
|
||||
$message = $textrenderer->render($renderable);
|
||||
|
@ -181,8 +187,8 @@ class email_certificate_task extends \core\task\scheduled_task {
|
|||
}
|
||||
|
||||
if ($customcert->emailteachers) {
|
||||
$renderable = new \mod_customcert\output\email_certificate(false, $userfullname, $coursename,
|
||||
$certificatename, $customcert->contextid);
|
||||
$renderable = new \mod_customcert\output\email_certificate(false, $userfullname, $courseshortname,
|
||||
$coursefullname, $certificatename, $customcert->contextid);
|
||||
|
||||
$subject = get_string('emailnonstudentsubject', 'customcert', $info);
|
||||
$message = $textrenderer->render($renderable);
|
||||
|
@ -198,8 +204,8 @@ class email_certificate_task extends \core\task\scheduled_task {
|
|||
foreach ($others as $email) {
|
||||
$email = trim($email);
|
||||
if (validate_email($email)) {
|
||||
$renderable = new \mod_customcert\output\email_certificate(false, $userfullname, $coursename,
|
||||
$certificatename, $customcert->contextid);
|
||||
$renderable = new \mod_customcert\output\email_certificate(false, $userfullname,
|
||||
$courseshortname, $coursefullname, $certificatename, $customcert->contextid);
|
||||
|
||||
$subject = get_string('emailnonstudentsubject', 'customcert', $info);
|
||||
$message = $textrenderer->render($renderable);
|
||||
|
|
|
@ -18,7 +18,7 @@
|
|||
* Class represents a customcert template.
|
||||
*
|
||||
* @package mod_customcert
|
||||
* @copyright 2015 Mark Nelson <markn@moodle.com>
|
||||
* @copyright 2016 Mark Nelson <markn@moodle.com>
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
*/
|
||||
|
||||
|
@ -159,7 +159,7 @@ class template {
|
|||
if ($elements = $DB->get_records_sql($sql, array('templateid' => $this->id))) {
|
||||
foreach ($elements as $element) {
|
||||
// Get an instance of the element class.
|
||||
if ($e = \mod_customcert\element::instance($element)) {
|
||||
if ($e = \mod_customcert\element_factory::get_element_instance($element)) {
|
||||
$e->delete();
|
||||
} else {
|
||||
// The plugin files are missing, so just remove the entry from the DB.
|
||||
|
@ -199,7 +199,7 @@ class template {
|
|||
if ($elements = $DB->get_records('customcert_elements', array('pageid' => $page->id))) {
|
||||
foreach ($elements as $element) {
|
||||
// Get an instance of the element class.
|
||||
if ($e = \mod_customcert\element::instance($element)) {
|
||||
if ($e = \mod_customcert\element_factory::get_element_instance($element)) {
|
||||
$e->delete();
|
||||
} else {
|
||||
// The plugin files are missing, so just remove the entry from the DB.
|
||||
|
@ -229,7 +229,7 @@ class template {
|
|||
$element = $DB->get_record('customcert_elements', array('id' => $elementid), '*', MUST_EXIST);
|
||||
|
||||
// Get an instance of the element class.
|
||||
if ($e = \mod_customcert\element::instance($element)) {
|
||||
if ($e = \mod_customcert\element_factory::get_element_instance($element)) {
|
||||
$e->delete();
|
||||
} else {
|
||||
// The plugin files are missing, so just remove the entry from the DB.
|
||||
|
@ -299,7 +299,7 @@ class template {
|
|||
// Loop through and display.
|
||||
foreach ($elements as $element) {
|
||||
// Get an instance of the element class.
|
||||
if ($e = \mod_customcert\element::instance($element)) {
|
||||
if ($e = \mod_customcert\element_factory::get_element_instance($element)) {
|
||||
$e->render($pdf, $preview, $user);
|
||||
}
|
||||
}
|
||||
|
@ -312,6 +312,46 @@ class template {
|
|||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Handles copying this template into another.
|
||||
*
|
||||
* @param int $copytotemplateid The template id to copy to
|
||||
*/
|
||||
public function copy_to_template($copytotemplateid) {
|
||||
global $DB;
|
||||
|
||||
// Get the pages for the template, there should always be at least one page for each template.
|
||||
if ($templatepages = $DB->get_records('customcert_pages', array('templateid' => $this->id))) {
|
||||
// Loop through the pages.
|
||||
foreach ($templatepages as $templatepage) {
|
||||
$page = clone($templatepage);
|
||||
$page->templateid = $copytotemplateid;
|
||||
$page->timecreated = time();
|
||||
$page->timemodified = $page->timecreated;
|
||||
// Insert into the database.
|
||||
$page->id = $DB->insert_record('customcert_pages', $page);
|
||||
// Now go through the elements we want to load.
|
||||
if ($templateelements = $DB->get_records('customcert_elements', array('pageid' => $templatepage->id))) {
|
||||
foreach ($templateelements as $templateelement) {
|
||||
$element = clone($templateelement);
|
||||
$element->pageid = $page->id;
|
||||
$element->timecreated = time();
|
||||
$element->timemodified = $element->timecreated;
|
||||
// Ok, now we want to insert this into the database.
|
||||
$element->id = $DB->insert_record('customcert_elements', $element);
|
||||
// Load any other information the element may need to for the template.
|
||||
if ($e = \mod_customcert\element_factory::get_element_instance($element)) {
|
||||
if (!$e->copy_element($templateelement)) {
|
||||
// Failed to copy - delete the element.
|
||||
$e->delete();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Handles moving an item on a template.
|
||||
*
|
||||
|
|
|
@ -60,6 +60,17 @@ $capabilities = array(
|
|||
)
|
||||
),
|
||||
|
||||
'mod/customcert:viewreport' => array(
|
||||
|
||||
'captype' => 'read',
|
||||
'contextlevel' => CONTEXT_MODULE,
|
||||
'archetypes' => array(
|
||||
'teacher' => CAP_ALLOW,
|
||||
'editingteacher' => CAP_ALLOW,
|
||||
'manager' => CAP_ALLOW
|
||||
)
|
||||
),
|
||||
|
||||
'mod/customcert:viewallcertificates' => array(
|
||||
'captype' => 'read',
|
||||
'contextlevel' => CONTEXT_SYSTEM,
|
||||
|
@ -77,4 +88,12 @@ $capabilities = array(
|
|||
'manager' => CAP_ALLOW
|
||||
)
|
||||
),
|
||||
|
||||
'mod/customcert:verifyallcertificates' => array(
|
||||
'captype' => 'read',
|
||||
'contextlevel' => CONTEXT_SYSTEM,
|
||||
'archetypes' => array(
|
||||
'manager' => CAP_ALLOW
|
||||
)
|
||||
),
|
||||
);
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
<?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"
|
||||
xsi:noNamespaceSchemaLocation="../../../lib/xmldb/xmldb.xsd"
|
||||
>
|
||||
|
@ -13,6 +13,7 @@
|
|||
<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="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="emailteachers" TYPE="int" LENGTH="1" NOTNULL="true" DEFAULT="0" SEQUENCE="false"/>
|
||||
<FIELD NAME="emailothers" TYPE="text" NOTNULL="false" SEQUENCE="false"/>
|
||||
|
@ -77,7 +78,7 @@
|
|||
<FIELD NAME="element" TYPE="text" LENGTH="big" NOTNULL="true" SEQUENCE="false"/>
|
||||
<FIELD NAME="data" TYPE="text" LENGTH="big" NOTNULL="false" SEQUENCE="false"/>
|
||||
<FIELD NAME="font" TYPE="char" LENGTH="255" NOTNULL="false" SEQUENCE="false"/>
|
||||
<FIELD NAME="size" TYPE="int" LENGTH="10" NOTNULL="false" SEQUENCE="false"/>
|
||||
<FIELD NAME="fontsize" TYPE="int" LENGTH="10" NOTNULL="false" SEQUENCE="false"/>
|
||||
<FIELD NAME="colour" TYPE="char" LENGTH="50" NOTNULL="false" SEQUENCE="false"/>
|
||||
<FIELD NAME="posx" TYPE="int" LENGTH="10" NOTNULL="false" SEQUENCE="false"/>
|
||||
<FIELD NAME="posy" TYPE="int" LENGTH="10" NOTNULL="false" SEQUENCE="false"/>
|
||||
|
|
|
@ -80,5 +80,60 @@ function xmldb_customcert_upgrade($oldversion) {
|
|||
upgrade_mod_savepoint(true, 2016120505, 'customcert');
|
||||
}
|
||||
|
||||
if ($oldversion < 2016120507) {
|
||||
// Remove any duplicate rows from customcert issue table.
|
||||
// This SQL fetches the id of those records which have duplicate customcert issues.
|
||||
// This doesn't return the first issue.
|
||||
$fromclause = "FROM (
|
||||
SELECT min(id) AS minid, userid, customcertid
|
||||
FROM {customcert_issues}
|
||||
GROUP BY userid, customcertid
|
||||
) minid
|
||||
JOIN {customcert_issues} ci
|
||||
ON ci.userid = minid.userid
|
||||
AND ci.customcertid = minid.customcertid
|
||||
AND ci.id > minid.minid";
|
||||
|
||||
// Get the records themselves.
|
||||
$getduplicatessql = "SELECT ci.id $fromclause ORDER BY minid";
|
||||
if ($records = $DB->get_records_sql($getduplicatessql)) {
|
||||
// Delete them.
|
||||
$ids = implode(',', array_keys($records));
|
||||
$DB->delete_records_select('customcert_issues', "id IN ($ids)");
|
||||
}
|
||||
|
||||
// Savepoint reached.
|
||||
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');
|
||||
}
|
||||
|
||||
if ($oldversion < 2016120512) {
|
||||
$table = new xmldb_table('customcert_elements');
|
||||
$field = new xmldb_field('size');
|
||||
|
||||
// Rename column as it is a reserved word in Oracle.
|
||||
if ($dbman->field_exists($table, $field)) {
|
||||
$field->set_attributes(XMLDB_TYPE_INTEGER, '10', null, null, null, null, 'font');
|
||||
$dbman->rename_field($table, $field, 'fontsize');
|
||||
}
|
||||
|
||||
// Savepoint reached.
|
||||
upgrade_mod_savepoint(true, 2016120512, 'customcert');
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
|
123
edit.php
123
edit.php
|
@ -66,58 +66,74 @@ if ($context->contextlevel == CONTEXT_SYSTEM) {
|
|||
$PAGE->navbar->add(get_string('editcustomcert', 'customcert'));
|
||||
}
|
||||
|
||||
|
||||
// Flag to determine if we are deleting anything.
|
||||
$deleting = false;
|
||||
|
||||
if ($tid) {
|
||||
switch ($action) {
|
||||
case 'pmoveup' :
|
||||
$template->move_item('page', $actionid, 'up');
|
||||
break;
|
||||
case 'pmovedown' :
|
||||
$template->move_item('page', $actionid, 'down');
|
||||
break;
|
||||
case 'emoveup' :
|
||||
$template->move_item('element', $actionid, 'up');
|
||||
break;
|
||||
case 'emovedown' :
|
||||
$template->move_item('element', $actionid, 'down');
|
||||
break;
|
||||
case 'deletepage' :
|
||||
if (!empty($confirm)) { // Check they have confirmed the deletion.
|
||||
$template->delete_page($actionid);
|
||||
} else {
|
||||
// Set deletion flag to true.
|
||||
$deleting = true;
|
||||
// Create the message.
|
||||
$message = get_string('deletepageconfirm', 'customcert');
|
||||
// Create the link options.
|
||||
$nourl = new moodle_url('/mod/customcert/edit.php', array('tid' => $tid));
|
||||
$yesurl = new moodle_url('/mod/customcert/edit.php', array('tid' => $tid,
|
||||
'action' => 'deletepage',
|
||||
'aid' => $actionid,
|
||||
'confirm' => 1,
|
||||
'sesskey' => sesskey()));
|
||||
}
|
||||
break;
|
||||
case 'deleteelement' :
|
||||
if (!empty($confirm)) { // Check they have confirmed the deletion.
|
||||
$template->delete_element($actionid);
|
||||
} else {
|
||||
// Set deletion flag to true.
|
||||
$deleting = true;
|
||||
// Create the message.
|
||||
$message = get_string('deleteelementconfirm', 'customcert');
|
||||
// Create the link options.
|
||||
$nourl = new moodle_url('/mod/customcert/edit.php', array('tid' => $tid));
|
||||
$yesurl = new moodle_url('/mod/customcert/edit.php', array('tid' => $tid,
|
||||
'action' => 'deleteelement',
|
||||
'aid' => $actionid,
|
||||
'confirm' => 1,
|
||||
'sesskey' => sesskey()));
|
||||
}
|
||||
break;
|
||||
if ($action && confirm_sesskey()) {
|
||||
switch ($action) {
|
||||
case 'pmoveup' :
|
||||
$template->move_item('page', $actionid, 'up');
|
||||
break;
|
||||
case 'pmovedown' :
|
||||
$template->move_item('page', $actionid, 'down');
|
||||
break;
|
||||
case 'emoveup' :
|
||||
$template->move_item('element', $actionid, 'up');
|
||||
break;
|
||||
case 'emovedown' :
|
||||
$template->move_item('element', $actionid, 'down');
|
||||
break;
|
||||
case 'addpage' :
|
||||
$template->add_page();
|
||||
$url = new \moodle_url('/mod/customcert/edit.php', array('tid' => $tid));
|
||||
redirect($url);
|
||||
break;
|
||||
case 'deletepage' :
|
||||
if (!empty($confirm)) { // Check they have confirmed the deletion.
|
||||
$template->delete_page($actionid);
|
||||
$url = new \moodle_url('/mod/customcert/edit.php', array('tid' => $tid));
|
||||
redirect($url);
|
||||
} else {
|
||||
// Set deletion flag to true.
|
||||
$deleting = true;
|
||||
// Create the message.
|
||||
$message = get_string('deletepageconfirm', 'customcert');
|
||||
// Create the link options.
|
||||
$nourl = new moodle_url('/mod/customcert/edit.php', array('tid' => $tid));
|
||||
$yesurl = new moodle_url('/mod/customcert/edit.php',
|
||||
array(
|
||||
'tid' => $tid,
|
||||
'action' => 'deletepage',
|
||||
'aid' => $actionid,
|
||||
'confirm' => 1,
|
||||
'sesskey' => sesskey()
|
||||
)
|
||||
);
|
||||
}
|
||||
break;
|
||||
case 'deleteelement' :
|
||||
if (!empty($confirm)) { // Check they have confirmed the deletion.
|
||||
$template->delete_element($actionid);
|
||||
} else {
|
||||
// Set deletion flag to true.
|
||||
$deleting = true;
|
||||
// Create the message.
|
||||
$message = get_string('deleteelementconfirm', 'customcert');
|
||||
// Create the link options.
|
||||
$nourl = new moodle_url('/mod/customcert/edit.php', array('tid' => $tid));
|
||||
$yesurl = new moodle_url('/mod/customcert/edit.php',
|
||||
array(
|
||||
'tid' => $tid,
|
||||
'action' => 'deleteelement',
|
||||
'aid' => $actionid,
|
||||
'confirm' => 1,
|
||||
'sesskey' => sesskey()
|
||||
)
|
||||
);
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -182,11 +198,6 @@ if ($data = $mform->get_data()) {
|
|||
// Save any page data.
|
||||
$template->save_page($data);
|
||||
|
||||
// Check if we are adding a page.
|
||||
if (!empty($data->addcertpage)) {
|
||||
$template->add_page();
|
||||
}
|
||||
|
||||
// Loop through the data.
|
||||
foreach ($data as $key => $value) {
|
||||
// Check if they chose to add an element to a page.
|
||||
|
@ -210,6 +221,7 @@ if ($data = $mform->get_data()) {
|
|||
// Check if we want to preview this custom certificate.
|
||||
if (!empty($data->previewbtn)) {
|
||||
$template->generate_pdf(true);
|
||||
exit();
|
||||
}
|
||||
|
||||
// Redirect to the editing page to show form with recent updates.
|
||||
|
@ -220,9 +232,10 @@ if ($data = $mform->get_data()) {
|
|||
echo $OUTPUT->header();
|
||||
echo $OUTPUT->heading(get_string('editcustomcert', 'customcert'));
|
||||
$mform->display();
|
||||
if ($tid) {
|
||||
if ($tid && $context->contextlevel == CONTEXT_MODULE) {
|
||||
$loadtemplateurl = new moodle_url('/mod/customcert/load_template.php', array('tid' => $tid));
|
||||
$loadtemplateform = new \mod_customcert\load_template_form($loadtemplateurl, array('context' => $context));
|
||||
$loadtemplateform = new \mod_customcert\load_template_form($loadtemplateurl, array('context' => $context), 'post',
|
||||
'', array('id' => 'loadtemplateform'));
|
||||
$loadtemplateform->display();
|
||||
}
|
||||
echo $OUTPUT->footer();
|
||||
|
|
|
@ -86,7 +86,7 @@ if ($data = $mform->get_data()) {
|
|||
// Set the element variable.
|
||||
$data->element = $element->element;
|
||||
// Get an instance of the element class.
|
||||
if ($e = \mod_customcert\element::instance($data)) {
|
||||
if ($e = \mod_customcert\element_factory::get_element_instance($data)) {
|
||||
$e->save_form_elements($data);
|
||||
}
|
||||
|
||||
|
|
|
@ -67,7 +67,14 @@ class element extends \customcertelement_image\element {
|
|||
*/
|
||||
public function render($pdf, $preview, $user) {
|
||||
// If there is no element data, we have nothing to display.
|
||||
if (empty($this->element->data)) {
|
||||
if (empty($this->get_data())) {
|
||||
return;
|
||||
}
|
||||
|
||||
$imageinfo = json_decode($this->get_data());
|
||||
|
||||
// If there is no file, we have nothing to display.
|
||||
if (empty($imageinfo->filename)) {
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -97,7 +104,14 @@ class element extends \customcertelement_image\element {
|
|||
global $DB;
|
||||
|
||||
// If there is no element data, we have nothing to display.
|
||||
if (empty($this->element->data)) {
|
||||
if (empty($this->get_data())) {
|
||||
return '';
|
||||
}
|
||||
|
||||
$imageinfo = json_decode($this->get_data());
|
||||
|
||||
// If there is no file, we have nothing to display.
|
||||
if (empty($imageinfo->filename)) {
|
||||
return '';
|
||||
}
|
||||
|
||||
|
@ -105,7 +119,7 @@ class element extends \customcertelement_image\element {
|
|||
$url = \moodle_url::make_pluginfile_url($file->get_contextid(), 'mod_customcert', 'image', $file->get_itemid(),
|
||||
$file->get_filepath(), $file->get_filename());
|
||||
// Get the page we are rendering this on.
|
||||
$page = $DB->get_record('customcert_pages', array('id' => $this->element->pageid), '*', MUST_EXIST);
|
||||
$page = $DB->get_record('customcert_pages', array('id' => $this->get_pageid()), '*', MUST_EXIST);
|
||||
|
||||
// Set the image to the size of the page.
|
||||
$style = 'width: ' . $page->width . 'mm; height: ' . $page->height . 'mm';
|
||||
|
|
|
@ -58,8 +58,8 @@ class element extends \mod_customcert\element {
|
|||
* @param \stdClass $user the user we are rendering this for
|
||||
*/
|
||||
public function render($pdf, $preview, $user) {
|
||||
$colour = \TCPDF_COLORS::convertHTMLColorToDec($this->element->colour, $colour);
|
||||
$pdf->SetLineStyle(array('width' => $this->element->data, 'color' => $colour));
|
||||
$colour = \TCPDF_COLORS::convertHTMLColorToDec($this->get_colour(), $colour);
|
||||
$pdf->SetLineStyle(array('width' => $this->get_data(), 'color' => $colour));
|
||||
$pdf->Line(0, 0, $pdf->getPageWidth(), 0);
|
||||
$pdf->Line($pdf->getPageWidth(), 0, $pdf->getPageWidth(), $pdf->getPageHeight());
|
||||
$pdf->Line(0, $pdf->getPageHeight(), $pdf->getPageWidth(), $pdf->getPageHeight());
|
||||
|
@ -106,8 +106,9 @@ class element extends \mod_customcert\element {
|
|||
* @param \mod_customcert\edit_element_form $mform the edit_form instance
|
||||
*/
|
||||
public function definition_after_data($mform) {
|
||||
if (!empty($this->element->data)) {
|
||||
$this->element->width = $this->element->data;
|
||||
if (!empty($this->get_data())) {
|
||||
$element = $mform->getElement('width');
|
||||
$element->setValue($this->get_data());
|
||||
}
|
||||
parent::definition_after_data($mform);
|
||||
}
|
||||
|
|
|
@ -43,7 +43,7 @@ class element extends \mod_customcert\element {
|
|||
* @param \stdClass $user the user we are rendering this for
|
||||
*/
|
||||
public function render($pdf, $preview, $user) {
|
||||
\mod_customcert\element_helper::render_content($pdf, $this, self::get_category_name());
|
||||
\mod_customcert\element_helper::render_content($pdf, $this, self::get_category_name($this->get_id()));
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -55,22 +55,28 @@ class element extends \mod_customcert\element {
|
|||
* @return string the html
|
||||
*/
|
||||
public function render_html() {
|
||||
return \mod_customcert\element_helper::render_html_content($this, self::get_category_name());
|
||||
global $COURSE;
|
||||
|
||||
return \mod_customcert\element_helper::render_html_content($this, $COURSE->fullname);
|
||||
}
|
||||
|
||||
/**
|
||||
* Helper function that returns the category name.
|
||||
*
|
||||
* @param int $elementid
|
||||
* @return string
|
||||
*/
|
||||
protected static function get_category_name() {
|
||||
global $DB, $COURSE;
|
||||
protected static function get_category_name($elementid) {
|
||||
global $DB, $SITE;
|
||||
|
||||
$courseid = \mod_customcert\element_helper::get_courseid($elementid);
|
||||
$course = get_course($courseid);
|
||||
|
||||
// Check that there is a course category available.
|
||||
if (!empty($COURSE->category)) {
|
||||
return $DB->get_field('course_categories', 'name', array('id' => $COURSE->category), MUST_EXIST);
|
||||
if (!empty($course->category)) {
|
||||
return $DB->get_field('course_categories', 'name', array('id' => $course->category), MUST_EXIST);
|
||||
} else { // Must be in a site template.
|
||||
return $COURSE->fullname;
|
||||
return $SITE->fullname;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -49,7 +49,7 @@ class element extends \mod_customcert\element {
|
|||
$code = \mod_customcert\certificate::generate_code();
|
||||
} else {
|
||||
// Get the page.
|
||||
$page = $DB->get_record('customcert_pages', array('id' => $this->element->pageid), '*', MUST_EXIST);
|
||||
$page = $DB->get_record('customcert_pages', array('id' => $this->get_pageid()), '*', MUST_EXIST);
|
||||
// Get the customcert this page belongs to.
|
||||
$customcert = $DB->get_record('customcert', array('templateid' => $page->templateid), '*', MUST_EXIST);
|
||||
// Now we can get the issue for this user.
|
||||
|
|
|
@ -43,9 +43,10 @@ class element extends \mod_customcert\element {
|
|||
* @param \stdClass $user the user we are rendering this for
|
||||
*/
|
||||
public function render($pdf, $preview, $user) {
|
||||
global $COURSE;
|
||||
$courseid = \mod_customcert\element_helper::get_courseid($this->get_id());
|
||||
$course = get_course($courseid);
|
||||
|
||||
\mod_customcert\element_helper::render_content($pdf, $this, $COURSE->fullname);
|
||||
\mod_customcert\element_helper::render_content($pdf, $this, $course->fullname);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -26,6 +26,11 @@ namespace customcertelement_date;
|
|||
|
||||
defined('MOODLE_INTERNAL') || die();
|
||||
|
||||
/**
|
||||
* Date - Course grade date
|
||||
*/
|
||||
define('CUSTOMCERT_DATE_COURSE_GRADE', '0');
|
||||
|
||||
/**
|
||||
* Date - Issue
|
||||
*/
|
||||
|
@ -36,6 +41,16 @@ define('CUSTOMCERT_DATE_ISSUE', '-1');
|
|||
*/
|
||||
define('CUSTOMCERT_DATE_COMPLETION', '-2');
|
||||
|
||||
/**
|
||||
* Date - Course start
|
||||
*/
|
||||
define('CUSTOMCERT_DATE_COURSE_START', '-3');
|
||||
|
||||
/**
|
||||
* Date - Course end
|
||||
*/
|
||||
define('CUSTOMCERT_DATE_COURSE_END', '-4');
|
||||
|
||||
require_once($CFG->dirroot . '/lib/grade/constants.php');
|
||||
|
||||
/**
|
||||
|
@ -53,11 +68,16 @@ class element extends \mod_customcert\element {
|
|||
* @param \mod_customcert\edit_element_form $mform the edit_form instance
|
||||
*/
|
||||
public function render_form_elements($mform) {
|
||||
global $COURSE;
|
||||
|
||||
// Get the possible date options.
|
||||
$dateoptions = array();
|
||||
$dateoptions[CUSTOMCERT_DATE_ISSUE] = get_string('issueddate', 'customcertelement_date');
|
||||
$dateoptions[CUSTOMCERT_DATE_COMPLETION] = get_string('completiondate', 'customcertelement_date');
|
||||
$dateoptions = $dateoptions + \customcertelement_grade\element::get_grade_items();;
|
||||
$dateoptions[CUSTOMCERT_DATE_COURSE_START] = get_string('coursestartdate', 'customcertelement_date');
|
||||
$dateoptions[CUSTOMCERT_DATE_COURSE_END] = get_string('courseenddate', 'customcertelement_date');
|
||||
$dateoptions[CUSTOMCERT_DATE_COURSE_GRADE] = get_string('coursegradedate', 'customcertelement_date');
|
||||
$dateoptions = $dateoptions + \mod_customcert\element_helper::get_grade_items($COURSE);
|
||||
|
||||
$mform->addElement('select', 'dateitem', get_string('dateitem', 'customcertelement_date'), $dateoptions);
|
||||
$mform->addHelpButton('dateitem', 'dateitem', 'customcertelement_date');
|
||||
|
@ -94,15 +114,17 @@ class element extends \mod_customcert\element {
|
|||
* @param \stdClass $user the user we are rendering this for
|
||||
*/
|
||||
public function render($pdf, $preview, $user) {
|
||||
global $COURSE, $DB;
|
||||
global $DB;
|
||||
|
||||
// If there is no element data, we have nothing to display.
|
||||
if (empty($this->element->data)) {
|
||||
if (empty($this->get_data())) {
|
||||
return;
|
||||
}
|
||||
|
||||
$courseid = \mod_customcert\element_helper::get_courseid($this->id);
|
||||
|
||||
// Decode the information stored in the database.
|
||||
$dateinfo = json_decode($this->element->data);
|
||||
$dateinfo = json_decode($this->get_data());
|
||||
$dateitem = $dateinfo->dateitem;
|
||||
$dateformat = $dateinfo->dateformat;
|
||||
|
||||
|
@ -111,7 +133,7 @@ class element extends \mod_customcert\element {
|
|||
$date = time();
|
||||
} else {
|
||||
// Get the page.
|
||||
$page = $DB->get_record('customcert_pages', array('id' => $this->element->pageid), '*', MUST_EXIST);
|
||||
$page = $DB->get_record('customcert_pages', array('id' => $this->get_pageid()), '*', MUST_EXIST);
|
||||
// Get the customcert this page belongs to.
|
||||
$customcert = $DB->get_record('customcert', array('templateid' => $page->templateid), '*', MUST_EXIST);
|
||||
// Now we can get the issue for this user.
|
||||
|
@ -121,24 +143,44 @@ class element extends \mod_customcert\element {
|
|||
if ($dateitem == CUSTOMCERT_DATE_ISSUE) {
|
||||
$date = $issue->timecreated;
|
||||
} else if ($dateitem == CUSTOMCERT_DATE_COMPLETION) {
|
||||
// Get the enrolment end date.
|
||||
// Get the last completion date.
|
||||
$sql = "SELECT MAX(c.timecompleted) as timecompleted
|
||||
FROM {course_completions} c
|
||||
WHERE c.userid = :userid
|
||||
AND c.course = :courseid";
|
||||
if ($timecompleted = $DB->get_record_sql($sql, array('userid' => $issue->userid, 'courseid' => $COURSE->id))) {
|
||||
if ($timecompleted = $DB->get_record_sql($sql, array('userid' => $issue->userid, 'courseid' => $courseid))) {
|
||||
if (!empty($timecompleted->timecompleted)) {
|
||||
$date = $timecompleted->timecompleted;
|
||||
}
|
||||
}
|
||||
} else if ($dateitem == CUSTOMCERT_DATE_COURSE_START) {
|
||||
$date = $DB->get_field('course', 'startdate', array('id' => $courseid));
|
||||
} else if ($dateitem == CUSTOMCERT_DATE_COURSE_END) {
|
||||
$date = $DB->get_field('course', 'enddate', array('id' => $courseid));
|
||||
} else {
|
||||
$gradeitem = new \stdClass();
|
||||
$gradeitem->gradeitem = $dateitem;
|
||||
$gradeitem->gradeformat = GRADE_DISPLAY_TYPE_PERCENTAGE;
|
||||
if ($modinfo = \customcertelement_grade\element::get_grade($gradeitem, $issue->userid)) {
|
||||
if (!empty($modinfo->dategraded)) {
|
||||
$date = $modinfo->dategraded;
|
||||
}
|
||||
if ($dateitem == CUSTOMCERT_DATE_COURSE_GRADE) {
|
||||
$grade = \mod_customcert\element_helper::get_course_grade_info(
|
||||
$courseid,
|
||||
GRADE_DISPLAY_TYPE_DEFAULT,
|
||||
$user->id
|
||||
);
|
||||
} else if (strpos($dateitem, 'gradeitem:') === 0) {
|
||||
$gradeitemid = substr($dateitem, 10);
|
||||
$grade = \mod_customcert\element_helper::get_grade_item_info(
|
||||
$gradeitemid,
|
||||
$dateitem,
|
||||
$user->id
|
||||
);
|
||||
} else {
|
||||
$grade = \mod_customcert\element_helper::get_mod_grade_info(
|
||||
$dateitem,
|
||||
GRADE_DISPLAY_TYPE_DEFAULT,
|
||||
$user->id
|
||||
);
|
||||
}
|
||||
|
||||
if ($grade && !empty($grade->get_dategraded())) {
|
||||
$date = $grade->get_dategraded();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -159,12 +201,12 @@ class element extends \mod_customcert\element {
|
|||
*/
|
||||
public function render_html() {
|
||||
// If there is no element data, we have nothing to display.
|
||||
if (empty($this->element->data)) {
|
||||
if (empty($this->get_data())) {
|
||||
return;
|
||||
}
|
||||
|
||||
// Decode the information stored in the database.
|
||||
$dateinfo = json_decode($this->element->data);
|
||||
$dateinfo = json_decode($this->get_data());
|
||||
$dateformat = $dateinfo->dateformat;
|
||||
|
||||
return \mod_customcert\element_helper::render_html_content($this, $this->get_date_format_string(time(), $dateformat));
|
||||
|
@ -177,10 +219,14 @@ class element extends \mod_customcert\element {
|
|||
*/
|
||||
public function definition_after_data($mform) {
|
||||
// Set the item and format for this element.
|
||||
if (!empty($this->element->data)) {
|
||||
$dateinfo = json_decode($this->element->data);
|
||||
$this->element->dateitem = $dateinfo->dateitem;
|
||||
$this->element->dateformat = $dateinfo->dateformat;
|
||||
if (!empty($this->get_data())) {
|
||||
$dateinfo = json_decode($this->get_data());
|
||||
|
||||
$element = $mform->getElement('dateitem');
|
||||
$element->setValue($dateinfo->dateitem);
|
||||
|
||||
$element = $mform->getElement('dateformat');
|
||||
$element->setValue($dateinfo->dateformat);
|
||||
}
|
||||
|
||||
parent::definition_after_data($mform);
|
||||
|
@ -197,10 +243,10 @@ class element extends \mod_customcert\element {
|
|||
public function after_restore($restore) {
|
||||
global $DB;
|
||||
|
||||
$dateinfo = json_decode($this->element->data);
|
||||
$dateinfo = json_decode($this->get_data());
|
||||
if ($newitem = \restore_dbops::get_backup_ids_record($restore->get_restoreid(), 'course_module', $dateinfo->dateitem)) {
|
||||
$dateinfo->dateitem = $newitem->newitemid;
|
||||
$DB->set_field('customcert_elements', 'data', self::save_unique_data($dateinfo), array('id' => $this->element->id));
|
||||
$DB->set_field('customcert_elements', 'data', $this->save_unique_data($dateinfo), array('id' => $this->get_id()));
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -210,12 +256,27 @@ class element extends \mod_customcert\element {
|
|||
* @return array the list of date formats
|
||||
*/
|
||||
public static function get_date_formats() {
|
||||
$dateformats = array();
|
||||
$dateformats[1] = 'January 1, 2000';
|
||||
$dateformats[2] = 'January 1st, 2000';
|
||||
$dateformats[3] = '1 January 2000';
|
||||
$dateformats[4] = 'January 2000';
|
||||
$dateformats[5] = get_string('userdateformat', 'customcertelement_date');
|
||||
$date = time();
|
||||
|
||||
$suffix = self::get_ordinal_number_suffix(userdate($date, '%d'));
|
||||
|
||||
$dateformats = array(
|
||||
1 => userdate($date, '%B %d, %Y'),
|
||||
2 => userdate($date, '%B %d' . $suffix . ', %Y'),
|
||||
'strftimedate' => userdate($date, get_string('strftimedate', 'langconfig')),
|
||||
'strftimedatefullshort' => userdate($date, get_string('strftimedatefullshort', 'langconfig')),
|
||||
'strftimedateshort' => userdate($date, get_string('strftimedateshort', 'langconfig')),
|
||||
'strftimedatetime' => userdate($date, get_string('strftimedatetime', 'langconfig')),
|
||||
'strftimedatetimeshort' => userdate($date, get_string('strftimedatetimeshort', 'langconfig')),
|
||||
'strftimedaydate' => userdate($date, get_string('strftimedaydate', 'langconfig')),
|
||||
'strftimedaydatetime' => userdate($date, get_string('strftimedaydatetime', 'langconfig')),
|
||||
'strftimedayshort' => userdate($date, get_string('strftimedayshort', 'langconfig')),
|
||||
'strftimedaytime' => userdate($date, get_string('strftimedaytime', 'langconfig')),
|
||||
'strftimemonthyear' => userdate($date, get_string('strftimemonthyear', 'langconfig')),
|
||||
'strftimerecent' => userdate($date, get_string('strftimerecent', 'langconfig')),
|
||||
'strftimerecentfull' => userdate($date, get_string('strftimerecentfull', 'langconfig')),
|
||||
'strftimetime' => userdate($date, get_string('strftimetime', 'langconfig'))
|
||||
);
|
||||
|
||||
return $dateformats;
|
||||
}
|
||||
|
@ -228,22 +289,30 @@ class element extends \mod_customcert\element {
|
|||
* @return string
|
||||
*/
|
||||
protected function get_date_format_string($date, $dateformat) {
|
||||
switch ($dateformat) {
|
||||
case 1:
|
||||
$certificatedate = userdate($date, '%B %d, %Y');
|
||||
break;
|
||||
case 2:
|
||||
$suffix = $this->get_ordinal_number_suffix(userdate($date, '%d'));
|
||||
$certificatedate = userdate($date, '%B %d' . $suffix . ', %Y');
|
||||
break;
|
||||
case 3:
|
||||
$certificatedate = userdate($date, '%d %B %Y');
|
||||
break;
|
||||
case 4:
|
||||
$certificatedate = userdate($date, '%B %Y');
|
||||
break;
|
||||
default:
|
||||
$certificatedate = userdate($date, get_string('strftimedate', 'langconfig'));
|
||||
// Keeping for backwards compatibility.
|
||||
if (is_number($dateformat)) {
|
||||
switch ($dateformat) {
|
||||
case 1:
|
||||
$certificatedate = userdate($date, '%B %d, %Y');
|
||||
break;
|
||||
case 2:
|
||||
$suffix = self::get_ordinal_number_suffix(userdate($date, '%d'));
|
||||
$certificatedate = userdate($date, '%B %d' . $suffix . ', %Y');
|
||||
break;
|
||||
case 3:
|
||||
$certificatedate = userdate($date, '%d %B %Y');
|
||||
break;
|
||||
case 4:
|
||||
$certificatedate = userdate($date, '%B %Y');
|
||||
break;
|
||||
default:
|
||||
$certificatedate = userdate($date, get_string('strftimedate', 'langconfig'));
|
||||
}
|
||||
}
|
||||
|
||||
// Ok, so we must have been passed the actual format in the lang file.
|
||||
if (!isset($certificatedate)) {
|
||||
$certificatedate = userdate($date, get_string($dateformat, 'langconfig'));
|
||||
}
|
||||
|
||||
return $certificatedate;
|
||||
|
@ -256,7 +325,7 @@ class element extends \mod_customcert\element {
|
|||
* @param int $day the day of the month
|
||||
* @return string the suffix.
|
||||
*/
|
||||
protected function get_ordinal_number_suffix($day) {
|
||||
protected static function get_ordinal_number_suffix($day) {
|
||||
if (!in_array(($day % 100), array(11, 12, 13))) {
|
||||
switch ($day % 10) {
|
||||
// Handle 1st, 2nd, 3rd.
|
||||
|
|
|
@ -23,6 +23,9 @@
|
|||
*/
|
||||
|
||||
$string['completiondate'] = 'Completion date';
|
||||
$string['courseenddate'] = 'Course end date';
|
||||
$string['coursegradedate'] = 'Course grade date';
|
||||
$string['coursestartdate'] = 'Course start date';
|
||||
$string['dateformat'] = 'Date format';
|
||||
$string['dateformat_help'] = 'This is the format of the date that will be displayed';
|
||||
$string['dateitem'] = 'Date item';
|
||||
|
|
338
element/digitalsignature/classes/element.php
Normal file
338
element/digitalsignature/classes/element.php
Normal file
|
@ -0,0 +1,338 @@
|
|||
<?php
|
||||
// This file is part of the customcert module for Moodle - http://moodle.org/
|
||||
//
|
||||
// Moodle is free software: you can redistribute it and/or modify
|
||||
// it under the terms of the GNU General Public License as published by
|
||||
// the Free Software Foundation, either version 3 of the License, or
|
||||
// (at your option) any later version.
|
||||
//
|
||||
// Moodle is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
/**
|
||||
* This file contains the customcert element digitial signature's core interaction API.
|
||||
*
|
||||
* @package customcertelement_digitalsignature
|
||||
* @copyright 2017 Mark Nelson <markn@moodle.com>
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
*/
|
||||
|
||||
namespace customcertelement_digitalsignature;
|
||||
|
||||
defined('MOODLE_INTERNAL') || die();
|
||||
|
||||
/**
|
||||
* The customcert element digital signature's core interaction API.
|
||||
*
|
||||
* @package customcertelement_digitalsignature
|
||||
* @copyright 2017 Mark Nelson <markn@moodle.com>
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
*/
|
||||
class element extends \customcertelement_image\element {
|
||||
|
||||
/**
|
||||
* @var array The file manager options for the certificate.
|
||||
*/
|
||||
protected $signaturefilemanageroptions = array();
|
||||
|
||||
/**
|
||||
* Constructor.
|
||||
*
|
||||
* @param \stdClass $element the element data
|
||||
*/
|
||||
public function __construct($element) {
|
||||
global $COURSE;
|
||||
|
||||
$this->signaturefilemanageroptions = [
|
||||
'maxbytes' => $COURSE->maxbytes,
|
||||
'subdirs' => 1,
|
||||
'accepted_types' => ['.crt']
|
||||
];
|
||||
|
||||
parent::__construct($element);
|
||||
}
|
||||
|
||||
/**
|
||||
* This function renders the form elements when adding a customcert element.
|
||||
*
|
||||
* @param \mod_customcert\edit_element_form $mform the edit_form instance
|
||||
*/
|
||||
public function render_form_elements($mform) {
|
||||
$mform->addElement('select', 'fileid', get_string('image', 'customcertelement_image'), self::get_images());
|
||||
|
||||
$mform->addElement('select', 'signaturefileid', get_string('digitalsignature', 'customcertelement_digitalsignature'),
|
||||
self::get_signatures());
|
||||
|
||||
$mform->addElement('text', 'signaturename', get_string('signaturename', 'customcertelement_digitalsignature'));
|
||||
$mform->setType('signaturename', PARAM_TEXT);
|
||||
$mform->setDefault('signaturename', '');
|
||||
|
||||
$mform->addElement('passwordunmask', 'signaturepassword',
|
||||
get_string('signaturepassword', 'customcertelement_digitalsignature'));
|
||||
$mform->setType('signaturepassword', PARAM_TEXT);
|
||||
$mform->setDefault('signaturepassword', '');
|
||||
|
||||
$mform->addElement('text', 'signaturelocation', get_string('signaturelocation', 'customcertelement_digitalsignature'));
|
||||
$mform->setType('signaturelocation', PARAM_TEXT);
|
||||
$mform->setDefault('signaturelocation', '');
|
||||
|
||||
$mform->addElement('text', 'signaturereason', get_string('signaturereason', 'customcertelement_digitalsignature'));
|
||||
$mform->setType('signaturereason', PARAM_TEXT);
|
||||
$mform->setDefault('signaturereason', '');
|
||||
|
||||
$mform->addElement('text', 'signaturecontactinfo',
|
||||
get_string('signaturecontactinfo', 'customcertelement_digitalsignature'));
|
||||
$mform->setType('signaturecontactinfo', PARAM_TEXT);
|
||||
$mform->setDefault('signaturecontactinfo', '');
|
||||
|
||||
$mform->addElement('text', 'width', get_string('width', 'customcertelement_image'), array('size' => 10));
|
||||
$mform->setType('width', PARAM_INT);
|
||||
$mform->setDefault('width', 0);
|
||||
$mform->addHelpButton('width', 'width', 'customcertelement_image');
|
||||
|
||||
$mform->addElement('text', 'height', get_string('height', 'customcertelement_image'), array('size' => 10));
|
||||
$mform->setType('height', PARAM_INT);
|
||||
$mform->setDefault('height', 0);
|
||||
$mform->addHelpButton('height', 'height', 'customcertelement_image');
|
||||
|
||||
if (get_config('customcert', 'showposxy')) {
|
||||
\mod_customcert\element_helper::render_form_element_position($mform);
|
||||
}
|
||||
|
||||
$mform->addElement('filemanager', 'customcertimage', get_string('uploadimage', 'customcert'), '',
|
||||
$this->filemanageroptions);
|
||||
|
||||
$mform->addElement('filemanager', 'digitalsignature',
|
||||
get_string('uploaddigitalsignature', 'customcertelement_digitalsignature'), '',
|
||||
$this->signaturefilemanageroptions);
|
||||
}
|
||||
|
||||
/**
|
||||
* Handles saving the form elements created by this element.
|
||||
* Can be overridden if more functionality is needed.
|
||||
*
|
||||
* @param \stdClass $data the form data
|
||||
* @return bool true of success, false otherwise.
|
||||
*/
|
||||
public function save_form_elements($data) {
|
||||
global $COURSE, $SITE;
|
||||
|
||||
// Set the context.
|
||||
if ($COURSE->id == $SITE->id) {
|
||||
$context = \context_system::instance();
|
||||
} else {
|
||||
$context = \context_course::instance($COURSE->id);
|
||||
}
|
||||
|
||||
// Handle file uploads.
|
||||
\mod_customcert\certificate::upload_files($data->customcertimage, $context->id);
|
||||
|
||||
// Handle file certificate uploads.
|
||||
\mod_customcert\certificate::upload_files($data->digitalsignature, $context->id, 'signature');
|
||||
|
||||
return parent::save_form_elements($data);
|
||||
}
|
||||
|
||||
/**
|
||||
* This will handle how form data will be saved into the data column in the
|
||||
* customcert_elements table.
|
||||
*
|
||||
* @param \stdClass $data the form data
|
||||
* @return string the json encoded array
|
||||
*/
|
||||
public function save_unique_data($data) {
|
||||
$arrtostore = [
|
||||
'signaturename' => $data->signaturename,
|
||||
'signaturepassword' => $data->signaturepassword,
|
||||
'signaturelocation' => $data->signaturelocation,
|
||||
'signaturereason' => $data->signaturereason,
|
||||
'signaturecontactinfo' => $data->signaturecontactinfo,
|
||||
'width' => !empty($data->width) ? (int) $data->width : 0,
|
||||
'height' => !empty($data->height) ? (int) $data->height : 0
|
||||
];
|
||||
|
||||
// Array of data we will be storing in the database.
|
||||
$fs = get_file_storage();
|
||||
|
||||
if (!empty($data->fileid)) {
|
||||
if ($file = $fs->get_file_by_id($data->fileid)) {
|
||||
$arrtostore += [
|
||||
'contextid' => $file->get_contextid(),
|
||||
'filearea' => $file->get_filearea(),
|
||||
'itemid' => $file->get_itemid(),
|
||||
'filepath' => $file->get_filepath(),
|
||||
'filename' => $file->get_filename(),
|
||||
];
|
||||
}
|
||||
}
|
||||
|
||||
if (!empty($data->signaturefileid)) {
|
||||
if ($signaturefile = $fs->get_file_by_id($data->signaturefileid)) {
|
||||
$arrtostore += [
|
||||
'signaturecontextid' => $signaturefile->get_contextid(),
|
||||
'signaturefilearea' => $signaturefile->get_filearea(),
|
||||
'signatureitemid' => $signaturefile->get_itemid(),
|
||||
'signaturefilepath' => $signaturefile->get_filepath(),
|
||||
'signaturefilename' => $signaturefile->get_filename()
|
||||
];
|
||||
}
|
||||
}
|
||||
|
||||
return json_encode($arrtostore);
|
||||
}
|
||||
|
||||
/**
|
||||
* Handles rendering the element on the pdf.
|
||||
*
|
||||
* @param \pdf $pdf the pdf object
|
||||
* @param bool $preview true if it is a preview, false otherwise
|
||||
* @param \stdClass $user the user we are rendering this for
|
||||
*/
|
||||
public function render($pdf, $preview, $user) {
|
||||
// If there is no element data, we have nothing to display.
|
||||
if (empty($this->get_data())) {
|
||||
return;
|
||||
}
|
||||
|
||||
$imageinfo = json_decode($this->get_data());
|
||||
|
||||
// If there is no file, we have nothing to display.
|
||||
if (empty($imageinfo->filename)) {
|
||||
return;
|
||||
}
|
||||
|
||||
// If there is no signature file, we have nothing to display.
|
||||
if (empty($imageinfo->signaturefilename)) {
|
||||
return;
|
||||
}
|
||||
|
||||
if ($file = $this->get_file()) {
|
||||
$location = make_request_directory() . '/target';
|
||||
$file->copy_content_to($location);
|
||||
|
||||
$mimetype = $file->get_mimetype();
|
||||
if ($mimetype == 'image/svg+xml') {
|
||||
$pdf->ImageSVG($location, $this->get_posx(), $this->get_posy(), $imageinfo->width, $imageinfo->height);
|
||||
} else {
|
||||
$pdf->Image($location, $this->get_posx(), $this->get_posy(), $imageinfo->width, $imageinfo->height);
|
||||
}
|
||||
}
|
||||
|
||||
if ($signaturefile = $this->get_signature_file()) {
|
||||
$location = make_request_directory() . '/target';
|
||||
$signaturefile->copy_content_to($location);
|
||||
$info = [
|
||||
'Name' => $imageinfo->signaturename,
|
||||
'Location' => $imageinfo->signaturelocation,
|
||||
'Reason' => $imageinfo->signaturereason,
|
||||
'ContactInfo' => $imageinfo->signaturecontactinfo
|
||||
];
|
||||
$pdf->setSignature('file://' . $location, '', $imageinfo->signaturepassword, '', 2, $info);
|
||||
$pdf->setSignatureAppearance($this->get_posx(), $this->get_posy(), $imageinfo->width, $imageinfo->height);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the data on the form when editing an element.
|
||||
*
|
||||
* @param \mod_customcert\edit_element_form $mform the edit_form instance
|
||||
*/
|
||||
public function definition_after_data($mform) {
|
||||
global $COURSE, $SITE;
|
||||
|
||||
// Set the context.
|
||||
if ($COURSE->id == $SITE->id) {
|
||||
$context = \context_system::instance();
|
||||
} else {
|
||||
$context = \context_course::instance($COURSE->id);
|
||||
}
|
||||
|
||||
if (!empty($this->get_data())) {
|
||||
$imageinfo = json_decode($this->get_data());
|
||||
|
||||
$element = $mform->getElement('signaturename');
|
||||
$element->setValue($imageinfo->signaturename);
|
||||
|
||||
$element = $mform->getElement('signaturepassword');
|
||||
$element->setValue($imageinfo->signaturepassword);
|
||||
|
||||
$element = $mform->getElement('signaturelocation');
|
||||
$element->setValue($imageinfo->signaturelocation);
|
||||
|
||||
$element = $mform->getElement('signaturereason');
|
||||
$element->setValue($imageinfo->signaturereason);
|
||||
|
||||
$element = $mform->getElement('signaturecontactinfo');
|
||||
$element->setValue($imageinfo->signaturecontactinfo);
|
||||
|
||||
if (!empty($imageinfo->signaturefilename)) {
|
||||
if ($signaturefile = $this->get_signature_file()) {
|
||||
$element = $mform->getElement('signaturefileid');
|
||||
$element->setValue($signaturefile->get_id());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Editing existing instance - copy existing files into draft area.
|
||||
$draftitemid = file_get_submitted_draft_itemid('digitalsignature');
|
||||
file_prepare_draft_area($draftitemid, $context->id, 'mod_customcert', 'signature', 0,
|
||||
$this->signaturefilemanageroptions);
|
||||
$element = $mform->getElement('digitalsignature');
|
||||
$element->setValue($draftitemid);
|
||||
|
||||
parent::definition_after_data($mform);
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the list of possible images to use.
|
||||
*
|
||||
* @return array the list of images that can be used
|
||||
*/
|
||||
public static function get_signatures() {
|
||||
global $COURSE;
|
||||
|
||||
// Create file storage object.
|
||||
$fs = get_file_storage();
|
||||
|
||||
// The array used to store the digital signatures.
|
||||
$arrfiles = array();
|
||||
// Loop through the files uploaded in the system context.
|
||||
if ($files = $fs->get_area_files(\context_system::instance()->id, 'mod_customcert', 'signature', false,
|
||||
'filename', false)) {
|
||||
foreach ($files as $hash => $file) {
|
||||
$arrfiles[$file->get_id()] = $file->get_filename();
|
||||
}
|
||||
}
|
||||
// Loop through the files uploaded in the course context.
|
||||
if ($files = $fs->get_area_files(\context_course::instance($COURSE->id)->id, 'mod_customcert', 'signature', false,
|
||||
'filename', false)) {
|
||||
foreach ($files as $hash => $file) {
|
||||
$arrfiles[$file->get_id()] = $file->get_filename();
|
||||
}
|
||||
}
|
||||
|
||||
\core_collator::asort($arrfiles);
|
||||
$arrfiles = array('0' => get_string('nosignature', 'customcertelement_digitalsignature')) + $arrfiles;
|
||||
|
||||
return $arrfiles;
|
||||
}
|
||||
|
||||
/**
|
||||
* Fetch stored file.
|
||||
*
|
||||
* @return \stored_file|bool stored_file instance if exists, false if not
|
||||
*/
|
||||
public function get_signature_file() {
|
||||
$imageinfo = json_decode($this->get_data());
|
||||
|
||||
$fs = get_file_storage();
|
||||
|
||||
return $fs->get_file($imageinfo->signaturecontextid, 'mod_customcert', $imageinfo->signaturefilearea,
|
||||
$imageinfo->signatureitemid, $imageinfo->signaturefilepath, $imageinfo->signaturefilename);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,33 @@
|
|||
<?php
|
||||
// This file is part of the customcert module for Moodle - http://moodle.org/
|
||||
//
|
||||
// Moodle is free software: you can redistribute it and/or modify
|
||||
// it under the terms of the GNU General Public License as published by
|
||||
// the Free Software Foundation, either version 3 of the License, or
|
||||
// (at your option) any later version.
|
||||
//
|
||||
// Moodle is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
/**
|
||||
* Strings for component 'customcertelement_digitalsignature', language 'en'.
|
||||
*
|
||||
* @package customcertelement_digitalsignature
|
||||
* @copyright 2017 Mark Nelson <markn@moodle.com>
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
*/
|
||||
|
||||
$string['digitalsignature'] = 'Digital signature';
|
||||
$string['nosignature'] = 'No signature';
|
||||
$string['pluginname'] = 'Digital signature';
|
||||
$string['signaturename'] = 'Signature name';
|
||||
$string['signaturepassword'] = 'Signature password';
|
||||
$string['signaturelocation'] = 'Signature location';
|
||||
$string['signaturereason'] = 'Signature reason';
|
||||
$string['signaturecontactinfo'] = 'Signature contact info';
|
||||
$string['uploaddigitalsignature'] = 'Upload digital signature';
|
29
element/digitalsignature/version.php
Normal file
29
element/digitalsignature/version.php
Normal file
|
@ -0,0 +1,29 @@
|
|||
<?php
|
||||
// This file is part of the customcert module for Moodle - http://moodle.org/
|
||||
//
|
||||
// Moodle is free software: you can redistribute it and/or modify
|
||||
// it under the terms of the GNU General Public License as published by
|
||||
// the Free Software Foundation, either version 3 of the License, or
|
||||
// (at your option) any later version.
|
||||
//
|
||||
// Moodle is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
/**
|
||||
* This file contains the version information for the digital signature plugin.
|
||||
*
|
||||
* @package customcertelement_digitalsignature
|
||||
* @copyright 2017 Mark Nelson <markn@moodle.com>
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
*/
|
||||
|
||||
defined('MOODLE_INTERNAL') || die('Direct access to this script is forbidden.');
|
||||
|
||||
$plugin->version = 2016120500; // The current module version (Date: YYYYMMDDXX).
|
||||
$plugin->requires = 2016120500; // Requires this Moodle version (3.2).
|
||||
$plugin->component = 'customcertelement_digitalsignature';
|
|
@ -26,10 +26,6 @@ namespace customcertelement_grade;
|
|||
|
||||
defined('MOODLE_INTERNAL') || die();
|
||||
|
||||
require_once($CFG->libdir . '/grade/constants.php');
|
||||
require_once($CFG->dirroot . '/grade/lib.php');
|
||||
require_once($CFG->dirroot . '/grade/querylib.php');
|
||||
|
||||
/**
|
||||
* Grade - Course
|
||||
*/
|
||||
|
@ -50,14 +46,15 @@ class element extends \mod_customcert\element {
|
|||
* @param \mod_customcert\edit_element_form $mform the edit_form instance
|
||||
*/
|
||||
public function render_form_elements($mform) {
|
||||
global $COURSE;
|
||||
|
||||
// Get the grade items we can display.
|
||||
$gradeitems = array();
|
||||
$gradeitems[CUSTOMCERT_GRADE_COURSE] = get_string('coursegrade', 'customcertelement_grade');
|
||||
$gradeitems = $gradeitems + self::get_grade_items();
|
||||
$gradeitems = $gradeitems + \mod_customcert\element_helper::get_grade_items($COURSE);
|
||||
|
||||
// The grade items.
|
||||
$mform->addElement('select', 'gradeitem', get_string('gradeitem', 'customcertelement_grade'), $gradeitems);
|
||||
$mform->setType('gradeitem', PARAM_INT);
|
||||
$mform->addHelpButton('gradeitem', 'gradeitem', 'customcertelement_grade');
|
||||
|
||||
// The grade format.
|
||||
|
@ -95,23 +92,53 @@ class element extends \mod_customcert\element {
|
|||
* @param \stdClass $user the user we are rendering this for
|
||||
*/
|
||||
public function render($pdf, $preview, $user) {
|
||||
global $COURSE;
|
||||
|
||||
// If there is no element data, we have nothing to display.
|
||||
if (empty($this->element->data)) {
|
||||
if (empty($this->get_data())) {
|
||||
return;
|
||||
}
|
||||
|
||||
$courseid = \mod_customcert\element_helper::get_courseid($this->id);
|
||||
|
||||
// Decode the information stored in the database.
|
||||
$gradeinfo = json_decode($this->element->data);
|
||||
$gradeinfo = json_decode($this->get_data());
|
||||
$gradeitem = $gradeinfo->gradeitem;
|
||||
$gradeformat = $gradeinfo->gradeformat;
|
||||
|
||||
// If we are previewing this certificate then just show a demonstration grade.
|
||||
if ($preview) {
|
||||
$courseitem = \grade_item::fetch_course_item($COURSE->id);
|
||||
$grade = grade_format_gradevalue('100', $courseitem, true, $gradeinfo->gradeformat, 2);
|
||||
// Define how many decimals to display.
|
||||
$decimals = 2;
|
||||
if ($gradeinfo->gradeformat == GRADE_DISPLAY_TYPE_PERCENTAGE) {
|
||||
$decimals = 0;
|
||||
}
|
||||
|
||||
$courseitem = \grade_item::fetch_course_item($courseid);
|
||||
$grade = grade_format_gradevalue('100', $courseitem, true, $gradeinfo->gradeformat, $decimals);
|
||||
} else {
|
||||
// Get the grade for the grade item.
|
||||
$grade = self::get_grade($gradeinfo, $user->id);
|
||||
if ($gradeitem == CUSTOMCERT_GRADE_COURSE) {
|
||||
$grade = \mod_customcert\element_helper::get_course_grade_info(
|
||||
$courseid,
|
||||
$gradeformat,
|
||||
$user->id
|
||||
);
|
||||
} else if (strpos($gradeitem, 'gradeitem:') === 0) {
|
||||
$gradeitemid = substr($gradeitem, 10);
|
||||
$grade = \mod_customcert\element_helper::get_grade_item_info(
|
||||
$gradeitemid,
|
||||
$gradeformat,
|
||||
$user->id
|
||||
);
|
||||
} else {
|
||||
$grade = \mod_customcert\element_helper::get_mod_grade_info(
|
||||
$gradeitem,
|
||||
$gradeformat,
|
||||
$user->id
|
||||
);
|
||||
}
|
||||
|
||||
if ($grade) {
|
||||
$grade = $grade->get_displaygrade();
|
||||
}
|
||||
}
|
||||
|
||||
\mod_customcert\element_helper::render_content($pdf, $this, $grade);
|
||||
|
@ -129,19 +156,21 @@ class element extends \mod_customcert\element {
|
|||
global $COURSE;
|
||||
|
||||
// If there is no element data, we have nothing to display.
|
||||
if (empty($this->element->data)) {
|
||||
if (empty($this->get_data())) {
|
||||
return;
|
||||
}
|
||||
|
||||
// Decode the information stored in the database.
|
||||
$gradeinfo = json_decode($this->element->data);
|
||||
$gradeinfo = json_decode($this->get_data());
|
||||
|
||||
$courseitem = \grade_item::fetch_course_item($COURSE->id);
|
||||
|
||||
// Define how many decimals to display.
|
||||
$decimals = 2;
|
||||
if ($gradeinfo->gradeformat == GRADE_DISPLAY_TYPE_PERCENTAGE) {
|
||||
$decimals = 0;
|
||||
}
|
||||
|
||||
$grade = grade_format_gradevalue('100', $courseitem, true, $gradeinfo->gradeformat, $decimals);
|
||||
|
||||
return \mod_customcert\element_helper::render_html_content($this, $grade);
|
||||
|
@ -154,10 +183,14 @@ class element extends \mod_customcert\element {
|
|||
*/
|
||||
public function definition_after_data($mform) {
|
||||
// Set the item and format for this element.
|
||||
if (!empty($this->element->data)) {
|
||||
$gradeinfo = json_decode($this->element->data);
|
||||
$this->element->gradeitem = $gradeinfo->gradeitem;
|
||||
$this->element->gradeformat = $gradeinfo->gradeformat;
|
||||
if (!empty($this->get_data())) {
|
||||
$gradeinfo = json_decode($this->get_data());
|
||||
|
||||
$element = $mform->getElement('gradeitem');
|
||||
$element->setValue($gradeinfo->gradeitem);
|
||||
|
||||
$element = $mform->getElement('gradeformat');
|
||||
$element->setValue($gradeinfo->gradeformat);
|
||||
}
|
||||
|
||||
parent::definition_after_data($mform);
|
||||
|
@ -174,73 +207,13 @@ class element extends \mod_customcert\element {
|
|||
public function after_restore($restore) {
|
||||
global $DB;
|
||||
|
||||
$gradeinfo = json_decode($this->element->data);
|
||||
$gradeinfo = json_decode($this->get_data());
|
||||
if ($newitem = \restore_dbops::get_backup_ids_record($restore->get_restoreid(), 'course_module', $gradeinfo->gradeitem)) {
|
||||
$gradeinfo->gradeitem = $newitem->newitemid;
|
||||
$DB->set_field('customcert_elements', 'data', self::save_unique_data($gradeinfo), array('id' => $this->element->id));
|
||||
$DB->set_field('customcert_elements', 'data', $this->save_unique_data($gradeinfo), array('id' => $this->get_id()));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Helper function to return all the grades items for this course.
|
||||
*
|
||||
* @return array the array of gradeable items in the course
|
||||
*/
|
||||
public static function get_grade_items() {
|
||||
global $COURSE, $DB;
|
||||
|
||||
// Array to store the grade items.
|
||||
$modules = array();
|
||||
|
||||
// Collect course modules data.
|
||||
$modinfo = get_fast_modinfo($COURSE);
|
||||
$mods = $modinfo->get_cms();
|
||||
$sections = $modinfo->get_section_info_all();
|
||||
|
||||
// Create the section label depending on course format.
|
||||
switch ($COURSE->format) {
|
||||
case 'topics':
|
||||
$sectionlabel = get_string('topic');
|
||||
break;
|
||||
case 'weeks':
|
||||
$sectionlabel = get_string('week');
|
||||
break;
|
||||
default:
|
||||
$sectionlabel = get_string('section');
|
||||
break;
|
||||
}
|
||||
|
||||
// Loop through each course section.
|
||||
for ($i = 0; $i <= count($sections) - 1; $i++) {
|
||||
// Confirm the index exists, should always be true.
|
||||
if (isset($sections[$i])) {
|
||||
// Get the individual section.
|
||||
$section = $sections[$i];
|
||||
// Get the mods for this section.
|
||||
$sectionmods = explode(",", $section->sequence);
|
||||
// Loop through the section mods.
|
||||
foreach ($sectionmods as $sectionmod) {
|
||||
// Should never happen unless DB is borked.
|
||||
if (empty($mods[$sectionmod])) {
|
||||
continue;
|
||||
}
|
||||
$mod = $mods[$sectionmod];
|
||||
$instance = $DB->get_record($mod->modname, array('id' => $mod->instance));
|
||||
// Get the grade items for this activity.
|
||||
if ($gradeitems = grade_get_grade_items_for_activity($mod)) {
|
||||
$moditem = grade_get_grades($COURSE->id, 'mod', $mod->modname, $mod->instance);
|
||||
$gradeitem = reset($moditem->items);
|
||||
if (isset($gradeitem->grademax)) {
|
||||
$modules[$mod->id] = $sectionlabel . ' ' . $section->section . ' : ' . $instance->name;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return $modules;
|
||||
}
|
||||
|
||||
/**
|
||||
* Helper function to return all the possible grade formats.
|
||||
*
|
||||
|
@ -254,89 +227,4 @@ class element extends \mod_customcert\element {
|
|||
|
||||
return $gradeformat;
|
||||
}
|
||||
|
||||
/**
|
||||
* Helper function to return the grade to display.
|
||||
*
|
||||
* @param \stdClass $gradeinfo
|
||||
* @param int $userid
|
||||
* @return string the grade result
|
||||
*/
|
||||
public static function get_grade($gradeinfo, $userid) {
|
||||
global $COURSE;
|
||||
|
||||
// Get the grade information.
|
||||
$gradeitem = $gradeinfo->gradeitem;
|
||||
$gradeformat = $gradeinfo->gradeformat;
|
||||
|
||||
// Check if we are displaying the course grade.
|
||||
if ($gradeitem == CUSTOMCERT_GRADE_COURSE) {
|
||||
if ($courseitem = \grade_item::fetch_course_item($COURSE->id)) {
|
||||
// Set the grade type we want.
|
||||
$courseitem->gradetype = GRADE_TYPE_VALUE;
|
||||
$grade = new \grade_grade(array('itemid' => $courseitem->id, 'userid' => $userid));
|
||||
$coursegrade = grade_format_gradevalue($grade->finalgrade, $courseitem, true, $gradeformat, 2);
|
||||
return $coursegrade;
|
||||
}
|
||||
} else { // Get the module grade.
|
||||
if ($modinfo = self::get_mod_grade($gradeitem, $gradeformat, $userid)) {
|
||||
return $modinfo->gradetodisplay;
|
||||
}
|
||||
}
|
||||
|
||||
// Only gets here if no grade was retrieved from the DB.
|
||||
return '';
|
||||
}
|
||||
|
||||
/**
|
||||
* Helper function to return the grade the user achieved for a specified module.
|
||||
*
|
||||
* @param int $moduleid
|
||||
* @param int $gradeformat
|
||||
* @param int $userid
|
||||
* @return \stdClass|bool the grade information, or false if there is none.
|
||||
*/
|
||||
public static function get_mod_grade($moduleid, $gradeformat, $userid) {
|
||||
global $DB;
|
||||
|
||||
if (!$cm = $DB->get_record('course_modules', array('id' => $moduleid))) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!$module = $DB->get_record('modules', array('id' => $cm->module))) {
|
||||
return false;
|
||||
}
|
||||
|
||||
$gradeitem = grade_get_grades($cm->course, 'mod', $module->name, $cm->instance, $userid);
|
||||
if (!empty($gradeitem)) {
|
||||
$item = new \grade_item();
|
||||
$item->gradetype = GRADE_TYPE_VALUE;
|
||||
$item->courseid = $cm->course;
|
||||
$itemproperties = reset($gradeitem->items);
|
||||
foreach ($itemproperties as $key => $value) {
|
||||
$item->$key = $value;
|
||||
}
|
||||
// Grade for the user.
|
||||
$grade = $item->grades[$userid]->grade;
|
||||
// Define how many decimals to display.
|
||||
$decimals = 2;
|
||||
if ($gradeformat == GRADE_DISPLAY_TYPE_PERCENTAGE) {
|
||||
$decimals = 0;
|
||||
}
|
||||
|
||||
// Create the object we will be returning.
|
||||
$modinfo = new \stdClass;
|
||||
$modinfo->name = $DB->get_field($module->name, 'name', array('id' => $cm->instance));
|
||||
$modinfo->gradetodisplay = grade_format_gradevalue($grade, $item, true, $gradeformat, $decimals);
|
||||
|
||||
if ($grade) {
|
||||
$modinfo->dategraded = $item->grades[$userid]->dategraded;
|
||||
} else {
|
||||
$modinfo->dategraded = time();
|
||||
}
|
||||
return $modinfo;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -28,8 +28,8 @@ $string['gradeitem_help'] = 'The grade item you wish to display the grade of.';
|
|||
$string['gradeformat'] = 'Grade format';
|
||||
$string['gradeformat_help'] = 'The format you wish to use when displaying the grade.';
|
||||
$string['gradeitem'] = 'Grade item';
|
||||
$string['gradepercent'] = 'Percentage Grade';
|
||||
$string['gradepoints'] = 'Points Grade';
|
||||
$string['gradeletter'] = 'Letter Grade';
|
||||
$string['gradepercent'] = 'Percentage';
|
||||
$string['gradepoints'] = 'Points';
|
||||
$string['gradeletter'] = 'Letter';
|
||||
$string['pluginname'] = 'Grade';
|
||||
$string['previewgrade'] = 'Preview grade';
|
||||
|
|
|
@ -41,8 +41,10 @@ class element extends \mod_customcert\element {
|
|||
* @param \mod_customcert\edit_element_form $mform the edit_form instance
|
||||
*/
|
||||
public function render_form_elements($mform) {
|
||||
global $COURSE;
|
||||
|
||||
$mform->addElement('select', 'gradeitem', get_string('gradeitem', 'customcertelement_gradeitemname'),
|
||||
\customcertelement_grade\element::get_grade_items());
|
||||
\mod_customcert\element_helper::get_grade_items($COURSE));
|
||||
$mform->addHelpButton('gradeitem', 'gradeitem', 'customcertelement_gradeitemname');
|
||||
|
||||
parent::render_form_elements($mform);
|
||||
|
@ -74,9 +76,9 @@ class element extends \mod_customcert\element {
|
|||
global $DB;
|
||||
|
||||
// Check that the grade item is not empty.
|
||||
if (!empty($this->element->data)) {
|
||||
if (!empty($this->get_data())) {
|
||||
// Get the course module information.
|
||||
$cm = $DB->get_record('course_modules', array('id' => $this->element->data), '*', MUST_EXIST);
|
||||
$cm = $DB->get_record('course_modules', array('id' => $this->get_data()), '*', MUST_EXIST);
|
||||
$module = $DB->get_record('modules', array('id' => $cm->module), '*', MUST_EXIST);
|
||||
|
||||
// Get the name of the item.
|
||||
|
@ -98,9 +100,9 @@ class element extends \mod_customcert\element {
|
|||
global $DB;
|
||||
|
||||
// Check that the grade item is not empty.
|
||||
if (!empty($this->element->data)) {
|
||||
if (!empty($this->get_data())) {
|
||||
// Get the course module information.
|
||||
$cm = $DB->get_record('course_modules', array('id' => $this->element->data), '*', MUST_EXIST);
|
||||
$cm = $DB->get_record('course_modules', array('id' => $this->get_data()), '*', MUST_EXIST);
|
||||
$module = $DB->get_record('modules', array('id' => $cm->module), '*', MUST_EXIST);
|
||||
|
||||
// Get the name of the item.
|
||||
|
@ -118,8 +120,9 @@ class element extends \mod_customcert\element {
|
|||
* @param \mod_customcert\edit_element_form $mform the edit_form instance
|
||||
*/
|
||||
public function definition_after_data($mform) {
|
||||
if (!empty($this->element->data)) {
|
||||
$this->element->gradeitem = $this->element->data;
|
||||
if (!empty($this->get_data())) {
|
||||
$element = $mform->getElement('gradeitem');
|
||||
$element->setValue($this->get_data());
|
||||
}
|
||||
parent::definition_after_data($mform);
|
||||
}
|
||||
|
|
|
@ -130,7 +130,7 @@ class element extends \mod_customcert\element {
|
|||
}
|
||||
|
||||
// Handle file uploads.
|
||||
\mod_customcert\certificate::upload_imagefiles($data->customcertimage, $context->id);
|
||||
\mod_customcert\certificate::upload_files($data->customcertimage, $context->id);
|
||||
|
||||
return parent::save_form_elements($data);
|
||||
}
|
||||
|
@ -143,18 +143,24 @@ class element extends \mod_customcert\element {
|
|||
* @return string the json encoded array
|
||||
*/
|
||||
public function save_unique_data($data) {
|
||||
// Array of data we will be storing in the database.
|
||||
$fs = get_file_storage();
|
||||
$file = $fs->get_file_by_id($data->fileid);
|
||||
$arrtostore = array(
|
||||
'contextid' => $file->get_contextid(),
|
||||
'filearea' => $file->get_filearea(),
|
||||
'itemid' => $file->get_itemid(),
|
||||
'filepath' => $file->get_filepath(),
|
||||
'filename' => $file->get_filename(),
|
||||
$arrtostore = [
|
||||
'width' => !empty($data->width) ? (int) $data->width : 0,
|
||||
'height' => !empty($data->height) ? (int) $data->height : 0
|
||||
);
|
||||
];
|
||||
|
||||
if (!empty($data->fileid)) {
|
||||
// Array of data we will be storing in the database.
|
||||
$fs = get_file_storage();
|
||||
if ($file = $fs->get_file_by_id($data->fileid)) {
|
||||
$arrtostore += [
|
||||
'contextid' => $file->get_contextid(),
|
||||
'filearea' => $file->get_filearea(),
|
||||
'itemid' => $file->get_itemid(),
|
||||
'filepath' => $file->get_filepath(),
|
||||
'filename' => $file->get_filename(),
|
||||
];
|
||||
}
|
||||
}
|
||||
|
||||
return json_encode($arrtostore);
|
||||
}
|
||||
|
@ -168,11 +174,16 @@ class element extends \mod_customcert\element {
|
|||
*/
|
||||
public function render($pdf, $preview, $user) {
|
||||
// If there is no element data, we have nothing to display.
|
||||
if (empty($this->element->data)) {
|
||||
if (empty($this->get_data())) {
|
||||
return;
|
||||
}
|
||||
|
||||
$imageinfo = json_decode($this->element->data);
|
||||
$imageinfo = json_decode($this->get_data());
|
||||
|
||||
// If there is no file, we have nothing to display.
|
||||
if (empty($imageinfo->filename)) {
|
||||
return;
|
||||
}
|
||||
|
||||
if ($file = $this->get_file()) {
|
||||
$location = make_request_directory() . '/target';
|
||||
|
@ -180,9 +191,9 @@ class element extends \mod_customcert\element {
|
|||
|
||||
$mimetype = $file->get_mimetype();
|
||||
if ($mimetype == 'image/svg+xml') {
|
||||
$pdf->ImageSVG($location, $this->element->posx, $this->element->posy, $imageinfo->width, $imageinfo->height);
|
||||
$pdf->ImageSVG($location, $this->get_posx(), $this->get_posy(), $imageinfo->width, $imageinfo->height);
|
||||
} else {
|
||||
$pdf->Image($location, $this->element->posx, $this->element->posy, $imageinfo->width, $imageinfo->height);
|
||||
$pdf->Image($location, $this->get_posx(), $this->get_posy(), $imageinfo->width, $imageinfo->height);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -197,11 +208,16 @@ class element extends \mod_customcert\element {
|
|||
*/
|
||||
public function render_html() {
|
||||
// If there is no element data, we have nothing to display.
|
||||
if (empty($this->element->data)) {
|
||||
if (empty($this->get_data())) {
|
||||
return '';
|
||||
}
|
||||
|
||||
$imageinfo = json_decode($this->element->data);
|
||||
$imageinfo = json_decode($this->get_data());
|
||||
|
||||
// If there is no file, we have nothing to display.
|
||||
if (empty($imageinfo->filename)) {
|
||||
return '';
|
||||
}
|
||||
|
||||
// Get the image.
|
||||
$fs = get_file_storage();
|
||||
|
@ -242,12 +258,23 @@ class element extends \mod_customcert\element {
|
|||
global $COURSE, $SITE;
|
||||
|
||||
// Set the image, width and height for this element.
|
||||
if (!empty($this->element->data)) {
|
||||
$imageinfo = json_decode($this->element->data);
|
||||
if ($file = $this->get_file()) {
|
||||
$this->element->fileid = $file->get_id();
|
||||
$this->element->width = $imageinfo->width;
|
||||
$this->element->height = $imageinfo->height;
|
||||
if (!empty($this->get_data())) {
|
||||
$imageinfo = json_decode($this->get_data());
|
||||
if (!empty($imageinfo->filename)) {
|
||||
if ($file = $this->get_file()) {
|
||||
$element = $mform->getElement('fileid');
|
||||
$element->setValue($file->get_id());
|
||||
}
|
||||
}
|
||||
|
||||
if (isset($imageinfo->width) && $mform->elementExists('width')) {
|
||||
$element = $mform->getElement('width');
|
||||
$element->setValue($imageinfo->width);
|
||||
}
|
||||
|
||||
if (isset($imageinfo->height) && $mform->elementExists('height')) {
|
||||
$element = $mform->getElement('height');
|
||||
$element->setValue($imageinfo->height);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -278,7 +305,7 @@ class element extends \mod_customcert\element {
|
|||
global $DB;
|
||||
|
||||
// Get the current data we have stored for this element.
|
||||
$elementinfo = json_decode($this->element->data);
|
||||
$elementinfo = json_decode($this->get_data());
|
||||
|
||||
// Update the context.
|
||||
$elementinfo->contextid = \context_course::instance($restore->get_courseid())->id;
|
||||
|
@ -287,7 +314,7 @@ class element extends \mod_customcert\element {
|
|||
$elementinfo = json_encode($elementinfo);
|
||||
|
||||
// Perform the update.
|
||||
$DB->set_field('customcert_elements', 'data', $elementinfo, array('id' => $this->element->id));
|
||||
$DB->set_field('customcert_elements', 'data', $elementinfo, array('id' => $this->get_id()));
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -296,7 +323,7 @@ class element extends \mod_customcert\element {
|
|||
* @return \stored_file|bool stored_file instance if exists, false if not
|
||||
*/
|
||||
public function get_file() {
|
||||
$imageinfo = json_decode($this->element->data);
|
||||
$imageinfo = json_decode($this->get_data());
|
||||
|
||||
$fs = get_file_storage();
|
||||
|
||||
|
|
|
@ -71,7 +71,7 @@ class element extends \mod_customcert\element {
|
|||
public function render($pdf, $preview, $user) {
|
||||
global $DB;
|
||||
|
||||
$teacher = $DB->get_record('user', array('id' => $this->element->data));
|
||||
$teacher = $DB->get_record('user', array('id' => $this->get_data()));
|
||||
$teachername = fullname($teacher);
|
||||
|
||||
\mod_customcert\element_helper::render_content($pdf, $this, $teachername);
|
||||
|
@ -88,7 +88,7 @@ class element extends \mod_customcert\element {
|
|||
public function render_html() {
|
||||
global $DB;
|
||||
|
||||
$teacher = $DB->get_record('user', array('id' => $this->element->data));
|
||||
$teacher = $DB->get_record('user', array('id' => $this->get_data()));
|
||||
$teachername = fullname($teacher);
|
||||
|
||||
return \mod_customcert\element_helper::render_html_content($this, $teachername);
|
||||
|
@ -121,8 +121,9 @@ class element extends \mod_customcert\element {
|
|||
* @param \mod_customcert\edit_element_form $mform the edit_form instance
|
||||
*/
|
||||
public function definition_after_data($mform) {
|
||||
if (!empty($this->element->data)) {
|
||||
$this->element->teacher = $this->element->data;
|
||||
if (!empty($this->get_data())) {
|
||||
$element = $mform->getElement('teacher');
|
||||
$element->setValue($this->get_data());
|
||||
}
|
||||
parent::definition_after_data($mform);
|
||||
}
|
||||
|
|
|
@ -67,7 +67,7 @@ class element extends \mod_customcert\element {
|
|||
* @param \stdClass $user the user we are rendering this for
|
||||
*/
|
||||
public function render($pdf, $preview, $user) {
|
||||
\mod_customcert\element_helper::render_content($pdf, $this, $this->element->data);
|
||||
\mod_customcert\element_helper::render_content($pdf, $this, $this->get_data());
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -79,7 +79,7 @@ class element extends \mod_customcert\element {
|
|||
* @return string the html
|
||||
*/
|
||||
public function render_html() {
|
||||
return \mod_customcert\element_helper::render_html_content($this, $this->element->data);
|
||||
return \mod_customcert\element_helper::render_html_content($this, $this->get_data());
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -88,8 +88,9 @@ class element extends \mod_customcert\element {
|
|||
* @param \mod_customcert\edit_element_form $mform the edit_form instance
|
||||
*/
|
||||
public function definition_after_data($mform) {
|
||||
if (!empty($this->element->data)) {
|
||||
$this->element->text = $this->element->data;
|
||||
if (!empty($this->get_data())) {
|
||||
$element = $mform->getElement('text');
|
||||
$element->setValue($this->get_data());
|
||||
}
|
||||
parent::definition_after_data($mform);
|
||||
}
|
||||
|
|
|
@ -101,7 +101,7 @@ class element extends \mod_customcert\element {
|
|||
global $CFG, $DB;
|
||||
|
||||
// The user field to display.
|
||||
$field = $this->element->data;
|
||||
$field = $this->get_data();
|
||||
// The value to display on the PDF.
|
||||
$value = '';
|
||||
if (is_number($field)) { // Must be a custom user profile field.
|
||||
|
@ -132,7 +132,7 @@ class element extends \mod_customcert\element {
|
|||
global $CFG, $DB, $USER;
|
||||
|
||||
// The user field to display.
|
||||
$field = $this->element->data;
|
||||
$field = $this->get_data();
|
||||
// The value to display - we always want to show a value here so it can be repositioned.
|
||||
$value = $field;
|
||||
if (is_number($field)) { // Must be a custom user profile field.
|
||||
|
@ -164,8 +164,9 @@ class element extends \mod_customcert\element {
|
|||
* @param \mod_customcert\edit_element_form $mform the edit_form instance
|
||||
*/
|
||||
public function definition_after_data($mform) {
|
||||
if (!empty($this->element->data)) {
|
||||
$this->element->userfield = $this->element->data;
|
||||
if (!empty($this->get_data())) {
|
||||
$element = $mform->getElement('userfield');
|
||||
$element->setValue($this->get_data());
|
||||
}
|
||||
parent::definition_after_data($mform);
|
||||
}
|
||||
|
|
|
@ -113,11 +113,11 @@ class element extends \mod_customcert\element {
|
|||
global $CFG;
|
||||
|
||||
// If there is no element data, we have nothing to display.
|
||||
if (empty($this->element->data)) {
|
||||
if (empty($this->get_data())) {
|
||||
return;
|
||||
}
|
||||
|
||||
$imageinfo = json_decode($this->element->data);
|
||||
$imageinfo = json_decode($this->get_data());
|
||||
|
||||
$context = \context_user::instance($user->id);
|
||||
|
||||
|
@ -138,10 +138,10 @@ class element extends \mod_customcert\element {
|
|||
if ($file) {
|
||||
$location = make_request_directory() . '/target';
|
||||
$file->copy_content_to($location);
|
||||
$pdf->Image($location, $this->element->posx, $this->element->posy, $imageinfo->width, $imageinfo->height);
|
||||
$pdf->Image($location, $this->get_posx(), $this->get_posy(), $imageinfo->width, $imageinfo->height);
|
||||
} else if ($preview) { // Can't find an image, but we are in preview mode then display default pic.
|
||||
$location = $CFG->dirroot . '/pix/u/f1.png';
|
||||
$pdf->Image($location, $this->element->posx, $this->element->posy, $imageinfo->width, $imageinfo->height);
|
||||
$pdf->Image($location, $this->get_posx(), $this->get_posy(), $imageinfo->width, $imageinfo->height);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -157,11 +157,11 @@ class element extends \mod_customcert\element {
|
|||
global $PAGE, $USER;
|
||||
|
||||
// If there is no element data, we have nothing to display.
|
||||
if (empty($this->element->data)) {
|
||||
if (empty($this->get_data())) {
|
||||
return '';
|
||||
}
|
||||
|
||||
$imageinfo = json_decode($this->element->data);
|
||||
$imageinfo = json_decode($this->get_data());
|
||||
|
||||
// Get the image.
|
||||
$userpicture = new \user_picture($USER);
|
||||
|
@ -194,10 +194,14 @@ class element extends \mod_customcert\element {
|
|||
*/
|
||||
public function definition_after_data($mform) {
|
||||
// Set the image, width and height for this element.
|
||||
if (!empty($this->element->data)) {
|
||||
$imageinfo = json_decode($this->element->data);
|
||||
$this->element->width = $imageinfo->width;
|
||||
$this->element->height = $imageinfo->height;
|
||||
if (!empty($this->get_data())) {
|
||||
$imageinfo = json_decode($this->get_data());
|
||||
|
||||
$element = $mform->getElement('width');
|
||||
$element->setValue($imageinfo->width);
|
||||
|
||||
$element = $mform->getElement('height');
|
||||
$element->setValue($imageinfo->height);
|
||||
}
|
||||
|
||||
parent::definition_after_data($mform);
|
||||
|
|
|
@ -22,9 +22,10 @@
|
|||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
*/
|
||||
|
||||
$string['addcertpage'] = 'Add another certificate page';
|
||||
$string['addcertpage'] = 'Add page';
|
||||
$string['addelement'] = 'Add element';
|
||||
$string['awardedto'] = 'Awarded to';
|
||||
$string['cannotverifyallcertificates'] = 'You do not have the permission to verify all certificates on the site.';
|
||||
$string['certificate'] = 'Certificate';
|
||||
$string['code'] = 'Code';
|
||||
$string['copy'] = 'Copy';
|
||||
|
@ -36,21 +37,27 @@ $string['customcertreport'] = 'Custom certificate report';
|
|||
$string['customcert:addinstance'] = 'Add a new custom certificate instance';
|
||||
$string['customcert:manage'] = 'Manage a custom certificate';
|
||||
$string['customcert:view'] = 'View a custom certificate';
|
||||
$string['customcert:viewreport'] = 'View course report';
|
||||
$string['customcert:viewallcertificates'] = 'View all certificates';
|
||||
$string['customcert:verifyallcertificates'] = 'Verify all certificates on the site';
|
||||
$string['customcert:verifycertificate'] = 'Verify a certificate';
|
||||
$string['deletecertpage'] = 'Delete certificate page';
|
||||
$string['deletecertpage'] = 'Delete page';
|
||||
$string['deleteconfirm'] = 'Delete confirmation';
|
||||
$string['deleteelement'] = 'Delete element';
|
||||
$string['deleteelementconfirm'] = 'Are you sure you want to delete this element?';
|
||||
$string['deleteissueconfirm'] = 'Are you sure you want to delete this certificate issue?';
|
||||
$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['description'] = 'Description';
|
||||
$string['editcustomcert'] = 'Edit custom certificate';
|
||||
$string['duplicate'] = 'Duplicate';
|
||||
$string['duplicateconfirm'] = 'Duplicate confirmation';
|
||||
$string['duplicatetemplateconfirm'] = 'Are you sure you want to duplicate this certificate template?';
|
||||
$string['editcustomcert'] = 'Edit certificate';
|
||||
$string['editelement'] = 'Edit element';
|
||||
$string['edittemplate'] = 'Edit template';
|
||||
$string['elementname'] = 'Element name';
|
||||
$string['elementname_help'] = 'This will be the name used to identify this element when editing a custom certificate. For example, you may have multiple images on a
|
||||
page and will want to distinguish between them quickly when editing the certificate. Note: this will not displayed on the PDF.';
|
||||
$string['elementname_help'] = 'This will be the name used to identify this element when editing a certificate. Note: this will not displayed on the PDF.';
|
||||
$string['elements'] = 'Elements';
|
||||
$string['elements_help'] = 'This is the list of elements that will be displayed on the certificate.
|
||||
|
||||
|
@ -60,11 +67,11 @@ $string['elementwidth_help'] = 'Specify the width of the element - \'0\' means t
|
|||
$string['emailnonstudentbody'] = 'Attached is the certificate \'{$a->certificatename}\' for \'{$a->userfullname}\' for the course \'{$a->coursefullname}\'.';
|
||||
$string['emailnonstudentcertificatelinktext'] = 'View certificate report';
|
||||
$string['emailnonstudentgreeting'] = 'Hi';
|
||||
$string['emailnonstudentsubject'] = '{$a->coursename}: {$a->certificatename}';
|
||||
$string['emailnonstudentsubject'] = '{$a->coursefullname}: {$a->certificatename}';
|
||||
$string['emailstudentbody'] = 'Attached is your certificate \'{$a->certificatename}\' for the course \'{$a->coursefullname}\'.';
|
||||
$string['emailstudentcertificatelinktext'] = 'View certificate';
|
||||
$string['emailstudentgreeting'] = 'Dear {$a}';
|
||||
$string['emailstudentsubject'] = '{$a->coursename}: {$a->certificatename}';
|
||||
$string['emailstudentsubject'] = '{$a->coursefullname}: {$a->certificatename}';
|
||||
$string['emailstudents'] = 'Email students';
|
||||
$string['emailstudents_help'] = 'If set this will email the students a copy of the certificate when it becomes available.';
|
||||
$string['emailteachers'] = 'Email teachers';
|
||||
|
@ -95,16 +102,17 @@ $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['managetemplates'] = 'Manage templates';
|
||||
$string['managetemplatesdesc'] = 'This link will take you to a new screen where you will be able to manage templates used by customcert activities in courses.';
|
||||
$string['managetemplatesdesc'] = 'This link will take you to a new screen where you will be able to manage templates used by Custom certificate activities in courses.';
|
||||
$string['modify'] = 'Modify';
|
||||
$string['modulename'] = 'Custom certificate';
|
||||
$string['modulenameplural'] = 'Custom certificates';
|
||||
$string['modulename_help'] = 'This module allows for the dynamic generation of PDF certificates.';
|
||||
$string['modulename_link'] = 'Custom_certificate_module';
|
||||
$string['mycertificates'] = 'My certificates';
|
||||
$string['mycertificatesdescription'] = 'These are the certificates you have been issued by either email or downloading manually.';
|
||||
$string['name'] = 'Name';
|
||||
$string['nametoolong'] = 'You have exceeded the maximum length allowed for the name';
|
||||
$string['nocustomcerts'] = 'There are no custom certificates for this course';
|
||||
$string['nocustomcerts'] = 'There are no certificates for this course';
|
||||
$string['noimage'] = 'No image';
|
||||
$string['notemplates'] = 'No templates';
|
||||
$string['notissued'] = 'Not issued';
|
||||
|
@ -150,10 +158,16 @@ $string['topright'] = 'Top right';
|
|||
$string['type'] = 'Type';
|
||||
$string['uploadimage'] = 'Upload image';
|
||||
$string['uploadimagedesc'] = 'This link will take you to a new screen where you will be able to upload images. Images uploaded using
|
||||
this method will be available throughout your site to all users who are able to create a custom certificate.';
|
||||
this method will be available throughout your site to all users who are able to create a certificate.';
|
||||
$string['verified'] = 'Verified';
|
||||
$string['verify'] = 'Verify';
|
||||
$string['verifyallcertificates'] = 'Allow verification of all certificates';
|
||||
$string['verifyallcertificates_desc'] = 'When this setting is enabled any person (including users not logged in) can visit the link \'{$a}\' in order to verify any certificate on the site, rather than having to go to the verification link for each certificate.
|
||||
|
||||
Note - this only applies to certificates where \'Allow anyone to verify a certificate\' has been set to \'Yes\' in the certificate settings.';
|
||||
$string['verifycertificate'] = 'Verify certificate';
|
||||
$string['viewcustomcertissues'] = 'View {$a} issued custom certificates';
|
||||
$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 certificates';
|
||||
$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.';
|
||||
|
|
5
lib.php
5
lib.php
|
@ -132,7 +132,8 @@ function customcert_reset_userdata($data) {
|
|||
FROM {customcert} cert
|
||||
WHERE cert.course = :courseid";
|
||||
$DB->delete_records_select('customcert_issues', "customcertid IN ($sql)", array('courseid' => $data->courseid));
|
||||
$status[] = array('component' => $componentstr, 'item' => get_string('customcertremoved', 'customcert'), 'error' => false);
|
||||
$status[] = array('component' => $componentstr, 'item' => get_string('deleteissuedcertificates', 'customcert'),
|
||||
'error' => false);
|
||||
}
|
||||
|
||||
// Updating dates - shift may be negative too.
|
||||
|
@ -152,7 +153,7 @@ function customcert_reset_userdata($data) {
|
|||
*/
|
||||
function customcert_reset_course_form_definition(&$mform) {
|
||||
$mform->addElement('header', 'customcertheader', get_string('modulenameplural', 'customcert'));
|
||||
$mform->addElement('advcheckbox', 'reset_customcert', get_string('deletissuedcustomcerts', 'customcert'));
|
||||
$mform->addElement('advcheckbox', 'reset_customcert', get_string('deleteissuedcertificates', 'customcert'));
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -42,7 +42,7 @@ if ($cm = $template->get_cm()) {
|
|||
$template->require_manage();
|
||||
|
||||
// Check that they have confirmed they wish to load the template.
|
||||
if ($confirm) {
|
||||
if ($confirm && confirm_sesskey()) {
|
||||
// First, remove all the existing elements and pages.
|
||||
$sql = "SELECT e.*
|
||||
FROM {customcert_elements} e
|
||||
|
@ -52,7 +52,7 @@ if ($confirm) {
|
|||
if ($elements = $DB->get_records_sql($sql, array('templateid' => $template->get_id()))) {
|
||||
foreach ($elements as $element) {
|
||||
// Get an instance of the element class.
|
||||
if ($e = \mod_customcert\element::instance($element)) {
|
||||
if ($e = \mod_customcert\element_factory::get_element_instance($element)) {
|
||||
$e->delete();
|
||||
}
|
||||
}
|
||||
|
@ -61,39 +61,8 @@ if ($confirm) {
|
|||
// Delete the pages.
|
||||
$DB->delete_records('customcert_pages', array('templateid' => $template->get_id()));
|
||||
|
||||
// Store the current time in a variable.
|
||||
$time = time();
|
||||
|
||||
// Now, get the template data we want to load.
|
||||
if ($templatepages = $DB->get_records('customcert_pages', array('templateid' => $ltid))) {
|
||||
// Loop through the pages.
|
||||
foreach ($templatepages as $templatepage) {
|
||||
$page = clone($templatepage);
|
||||
$page->templateid = $tid;
|
||||
$page->timecreated = $time;
|
||||
$page->timemodified = $time;
|
||||
// Insert into the database.
|
||||
$page->id = $DB->insert_record('customcert_pages', $page);
|
||||
// Now go through the elements we want to load.
|
||||
if ($templateelements = $DB->get_records('customcert_elements', array('pageid' => $templatepage->id))) {
|
||||
foreach ($templateelements as $templateelement) {
|
||||
$element = clone($templateelement);
|
||||
$element->pageid = $page->id;
|
||||
$element->timecreated = $time;
|
||||
$element->timemodified = $time;
|
||||
// Ok, now we want to insert this into the database.
|
||||
$element->id = $DB->insert_record('customcert_elements', $element);
|
||||
// Load any other information the element may need to for the template.
|
||||
if ($e = \mod_customcert\element::instance($element)) {
|
||||
if (!$e->copy_element($templateelement)) {
|
||||
// Failed to copy - delete the element.
|
||||
$e->delete();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
// Copy the items across.
|
||||
$loadtemplate->copy_to_template($template->get_id());
|
||||
|
||||
// Redirect.
|
||||
$url = new moodle_url('/mod/customcert/edit.php', array('tid' => $tid));
|
||||
|
@ -104,7 +73,8 @@ if ($confirm) {
|
|||
$nourl = new moodle_url('/mod/customcert/edit.php', array('tid' => $tid));
|
||||
$yesurl = new moodle_url('/mod/customcert/load_template.php', array('tid' => $tid,
|
||||
'ltid' => $ltid,
|
||||
'confirm' => 1));
|
||||
'confirm' => 1,
|
||||
'sesskey' => sesskey()));
|
||||
|
||||
$pageurl = new moodle_url('/mod/customcert/load_template.php', array('tid' => $tid, 'ltid' => $ltid));
|
||||
\mod_customcert\page_helper::page_setup($pageurl, $template->get_context(), get_string('loadtemplate', 'customcert'));
|
||||
|
|
|
@ -27,6 +27,8 @@ require_once('../../config.php');
|
|||
$contextid = optional_param('contextid', context_system::instance()->id, PARAM_INT);
|
||||
$action = optional_param('action', '', PARAM_ALPHA);
|
||||
$confirm = optional_param('confirm', 0, PARAM_INT);
|
||||
$page = optional_param('page', 0, PARAM_INT);
|
||||
$perpage = optional_param('perpage', 10, PARAM_INT);
|
||||
|
||||
if ($action) {
|
||||
$tid = required_param('tid', PARAM_INT);
|
||||
|
@ -51,65 +53,74 @@ $pageurl = new moodle_url('/mod/customcert/manage_templates.php');
|
|||
// Additional page setup.
|
||||
$PAGE->navbar->add(get_string('managetemplates', 'customcert'));
|
||||
|
||||
// Check if we are deleting a template.
|
||||
if ($tid) {
|
||||
if ($action == 'delete') {
|
||||
if (!$confirm) {
|
||||
$nourl = new moodle_url('/mod/customcert/manage_templates.php');
|
||||
$yesurl = new moodle_url('/mod/customcert/manage_templates.php', array('tid' => $tid,
|
||||
'action' => 'delete',
|
||||
if ($action && confirm_sesskey()) {
|
||||
$nourl = new moodle_url('/mod/customcert/manage_templates.php');
|
||||
$yesurl = new moodle_url('/mod/customcert/manage_templates.php',
|
||||
array(
|
||||
'tid' => $tid,
|
||||
'action' => $action,
|
||||
'confirm' => 1,
|
||||
'sesskey' => sesskey()));
|
||||
'sesskey' => sesskey()
|
||||
)
|
||||
);
|
||||
|
||||
// Show a confirmation page.
|
||||
$strheading = get_string('deleteconfirm', 'customcert');
|
||||
$PAGE->navbar->add($strheading);
|
||||
$PAGE->set_title($strheading);
|
||||
$message = get_string('deletetemplateconfirm', 'customcert');
|
||||
echo $OUTPUT->header();
|
||||
echo $OUTPUT->heading($strheading);
|
||||
echo $OUTPUT->confirm($message, $yesurl, $nourl);
|
||||
echo $OUTPUT->footer();
|
||||
exit();
|
||||
// Check if we are deleting a template.
|
||||
if ($action == 'delete') {
|
||||
if (!$confirm) {
|
||||
// Show a confirmation page.
|
||||
$strheading = get_string('deleteconfirm', 'customcert');
|
||||
$PAGE->navbar->add($strheading);
|
||||
$PAGE->set_title($strheading);
|
||||
$message = get_string('deletetemplateconfirm', 'customcert');
|
||||
echo $OUTPUT->header();
|
||||
echo $OUTPUT->heading($strheading);
|
||||
echo $OUTPUT->confirm($message, $yesurl, $nourl);
|
||||
echo $OUTPUT->footer();
|
||||
exit();
|
||||
}
|
||||
|
||||
// Delete the template.
|
||||
$template->delete();
|
||||
|
||||
// Redirect back to the manage templates page.
|
||||
redirect(new moodle_url('/mod/customcert/manage_templates.php'));
|
||||
} else if ($action == 'duplicate') {
|
||||
if (!$confirm) {
|
||||
// Show a confirmation page.
|
||||
$strheading = get_string('duplicateconfirm', 'customcert');
|
||||
$PAGE->navbar->add($strheading);
|
||||
$PAGE->set_title($strheading);
|
||||
$message = get_string('duplicatetemplateconfirm', 'customcert');
|
||||
echo $OUTPUT->header();
|
||||
echo $OUTPUT->heading($strheading);
|
||||
echo $OUTPUT->confirm($message, $yesurl, $nourl);
|
||||
echo $OUTPUT->footer();
|
||||
exit();
|
||||
}
|
||||
|
||||
// Create another template to copy the data to.
|
||||
$newtemplate = new \stdClass();
|
||||
$newtemplate->name = $template->get_name() . ' (' . strtolower(get_string('duplicate', 'customcert')) . ')';
|
||||
$newtemplate->contextid = $template->get_contextid();
|
||||
$newtemplate->timecreated = time();
|
||||
$newtemplate->timemodified = $newtemplate->timecreated;
|
||||
$newtemplateid = $DB->insert_record('customcert_templates', $newtemplate);
|
||||
|
||||
// Copy the data to the new template.
|
||||
$template->copy_to_template($newtemplateid);
|
||||
|
||||
// Redirect back to the manage templates page.
|
||||
redirect(new moodle_url('/mod/customcert/manage_templates.php'));
|
||||
}
|
||||
|
||||
// Delete the template.
|
||||
$template->delete();
|
||||
|
||||
// Redirect back to the manage templates page.
|
||||
redirect(new moodle_url('/mod/customcert/manage_templates.php'));
|
||||
}
|
||||
}
|
||||
// Get all the templates that are available.
|
||||
if ($templates = $DB->get_records('customcert_templates', array('contextid' => $contextid), 'timecreated DESC')) {
|
||||
// Create a table to display these elements.
|
||||
$table = new html_table();
|
||||
$table->head = array(get_string('name', 'customcert'), '');
|
||||
$table->align = array('left', 'center');
|
||||
|
||||
foreach ($templates as $template) {
|
||||
// Link to edit the element.
|
||||
$editlink = new \moodle_url('/mod/customcert/edit.php', array('tid' => $template->id));
|
||||
$editicon = $OUTPUT->action_icon($editlink, new \pix_icon('t/edit', get_string('edit')));
|
||||
|
||||
// Link to delete the element.
|
||||
$deletelink = new \moodle_url('/mod/customcert/manage_templates.php', array('tid' => $template->id,
|
||||
'action' => 'delete'));
|
||||
$deleteicon = $OUTPUT->action_icon($deletelink, new \pix_icon('t/delete', get_string('delete')));
|
||||
|
||||
$row = new html_table_row();
|
||||
$row->cells[] = $template->name;
|
||||
$row->cells[] = $editicon . $deleteicon;
|
||||
$table->data[] = $row;
|
||||
}
|
||||
}
|
||||
$table = new \mod_customcert\manage_templates_table($context);
|
||||
$table->define_baseurl($pageurl);
|
||||
|
||||
echo $OUTPUT->header();
|
||||
if (isset($table)) {
|
||||
echo html_writer::table($table);
|
||||
} else {
|
||||
echo html_writer::tag('div', get_string('notemplates', 'customcert'), array('class' => 'alert'));
|
||||
}
|
||||
$table->out($perpage, false);
|
||||
$url = new moodle_url('/mod/customcert/edit.php?contextid=' . $contextid);
|
||||
echo $OUTPUT->single_button($url, get_string('createtemplate', 'customcert'), 'get');
|
||||
echo $OUTPUT->footer();
|
||||
|
|
|
@ -69,6 +69,10 @@ class mod_customcert_mod_form extends moodleform_mod {
|
|||
$mform->setType('emailothers', PARAM_TEXT);
|
||||
$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->setType('requiredtime', PARAM_INT);
|
||||
$mform->addHelpButton('requiredtime', 'coursetimereq', 'customcert');
|
||||
|
|
|
@ -75,5 +75,6 @@ $PAGE->navbar->add(get_string('mycertificates', 'customcert'));
|
|||
|
||||
echo $OUTPUT->header();
|
||||
echo $OUTPUT->heading(get_string('mycertificates', 'customcert'));
|
||||
echo html_writer::div(get_string('mycertificatesdescription', 'customcert'));
|
||||
$table->out($perpage, false);
|
||||
echo $OUTPUT->footer();
|
||||
|
|
|
@ -91,7 +91,7 @@ if ($page->leftmargin) {
|
|||
if ($elements) {
|
||||
foreach ($elements as $element) {
|
||||
// Get an instance of the element class.
|
||||
if ($e = \mod_customcert\element::instance($element)) {
|
||||
if ($e = \mod_customcert\element_factory::get_element_instance($element)) {
|
||||
switch ($element->refpoint) {
|
||||
case \mod_customcert\element_helper::CUSTOMCERT_REF_POINT_TOPRIGHT:
|
||||
$class = 'element refpoint-right';
|
||||
|
|
38
report.php
38
report.php
|
@ -27,6 +27,8 @@ require_once('../../config.php');
|
|||
$id = required_param('id', PARAM_INT);
|
||||
$download = optional_param('download', null, PARAM_ALPHA);
|
||||
$downloadcert = optional_param('downloadcert', '', PARAM_BOOL);
|
||||
$deleteissue = optional_param('deleteissue', 0, PARAM_INT);
|
||||
$confirm = optional_param('confirm', 0, PARAM_BOOL);
|
||||
if ($downloadcert) {
|
||||
$userid = required_param('userid', PARAM_INT);
|
||||
}
|
||||
|
@ -44,7 +46,41 @@ require_login($course, false, $cm);
|
|||
|
||||
// Check capabilities.
|
||||
$context = context_module::instance($cm->id);
|
||||
require_capability('mod/customcert:manage', $context);
|
||||
require_capability('mod/customcert:viewreport', $context);
|
||||
|
||||
if ($deleteissue && confirm_sesskey()) {
|
||||
require_capability('mod/customcert:manage', $context);
|
||||
|
||||
if (!$confirm) {
|
||||
$nourl = new moodle_url('/mod/customcert/report.php', ['id' => $id]);
|
||||
$yesurl = new moodle_url('/mod/customcert/report.php',
|
||||
[
|
||||
'id' => $id,
|
||||
'deleteissue' => $deleteissue,
|
||||
'confirm' => 1,
|
||||
'sesskey' => sesskey()
|
||||
]
|
||||
);
|
||||
|
||||
// Show a confirmation page.
|
||||
$strheading = get_string('deleteconfirm', 'customcert');
|
||||
$PAGE->navbar->add($strheading);
|
||||
$PAGE->set_title($strheading);
|
||||
$PAGE->set_url($url);
|
||||
$message = get_string('deleteissueconfirm', 'customcert');
|
||||
echo $OUTPUT->header();
|
||||
echo $OUTPUT->heading($strheading);
|
||||
echo $OUTPUT->confirm($message, $yesurl, $nourl);
|
||||
echo $OUTPUT->footer();
|
||||
exit();
|
||||
}
|
||||
|
||||
// Delete the issue.
|
||||
$DB->delete_records('customcert_issues', array('id' => $deleteissue, 'customcertid' => $customcert->id));
|
||||
|
||||
// Redirect back to the manage templates page.
|
||||
redirect(new moodle_url('/mod/customcert/report.php', array('id' => $id)));
|
||||
}
|
||||
|
||||
// Check if we requested to download another user's certificate.
|
||||
if ($downloadcert) {
|
||||
|
|
|
@ -24,6 +24,12 @@
|
|||
|
||||
defined('MOODLE_INTERNAL') || die;
|
||||
|
||||
$url = $CFG->wwwroot . '/mod/customcert/verify_certificate.php';
|
||||
$settings->add(new admin_setting_configcheckbox('customcert/verifyallcertificates',
|
||||
get_string('verifyallcertificates', 'customcert'),
|
||||
get_string('verifyallcertificates_desc', 'customcert', $url),
|
||||
0));
|
||||
|
||||
$settings->add(new admin_setting_configcheckbox('customcert/showposxy',
|
||||
get_string('showposxy', 'customcert'),
|
||||
get_string('showposxy_desc', 'customcert'),
|
||||
|
|
|
@ -2,6 +2,11 @@
|
|||
text-align: right;
|
||||
}
|
||||
|
||||
#page-mod-customcert-edit .addpage {
|
||||
border-top: 1px solid #f4f4f4;
|
||||
text-align: right;
|
||||
}
|
||||
|
||||
#page-mod-customcert-edit #id_replace {
|
||||
margin-left: 10px;
|
||||
}
|
||||
|
|
|
@ -15,7 +15,7 @@
|
|||
along with Moodle. If not, see <http://www.gnu.org/licenses/>.
|
||||
}}
|
||||
{{!
|
||||
@template mod_customcert/email_certificate_html
|
||||
@template mod_customcert/email_certificate_text
|
||||
|
||||
The certificate verification result
|
||||
|
||||
|
|
150
tests/behat/behat_mod_customcert.php
Normal file
150
tests/behat/behat_mod_customcert.php
Normal file
|
@ -0,0 +1,150 @@
|
|||
<?php
|
||||
// This file is part of Moodle - http://moodle.org/
|
||||
//
|
||||
// Moodle is free software: you can redistribute it and/or modify
|
||||
// it under the terms of the GNU General Public License as published by
|
||||
// the Free Software Foundation, either version 3 of the License, or
|
||||
// (at your option) any later version.
|
||||
//
|
||||
// Moodle is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
/**
|
||||
* Contains the class responsible for step definitions related to mod_customcert.
|
||||
*
|
||||
* @package mod_customcert
|
||||
* @category test
|
||||
* @copyright 2017 Mark Nelson <markn@moodle.com>
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
*/
|
||||
|
||||
// NOTE: no MOODLE_INTERNAL test here, this file may be required by behat before including /config.php.
|
||||
|
||||
require_once(__DIR__ . '/../../../../lib/behat/behat_base.php');
|
||||
|
||||
/**
|
||||
* The class responsible for step definitions related to mod_customcert.
|
||||
*
|
||||
* @package mod_customcert
|
||||
* @category test
|
||||
* @copyright 2017 Mark Nelson <markn@moodle.com>
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
*/
|
||||
class behat_mod_customcert extends behat_base {
|
||||
|
||||
/**
|
||||
* Adds an element to the specified page of a template.
|
||||
*
|
||||
* @codingStandardsIgnoreLine
|
||||
* @Given /^I add the element "(?P<element_name>(?:[^"]|\\")*)" to page "(?P<page_number>\d+)" of the "(?P<template_name>(?:[^"]|\\")*)" certificate template$/
|
||||
* @param string $elementname
|
||||
* @param int $pagenum
|
||||
* @param string $templatename
|
||||
*/
|
||||
public function i_add_the_element_to_the_certificate_template_page($elementname, $pagenum, $templatename) {
|
||||
global $DB;
|
||||
|
||||
$template = $DB->get_record('customcert_templates', array('name' => $templatename), '*', MUST_EXIST);
|
||||
$page = $DB->get_record('customcert_pages', array('templateid' => $template->id, 'sequence' => $pagenum),
|
||||
'*', MUST_EXIST);
|
||||
|
||||
$this->execute('behat_forms::i_set_the_field_to', array($this->escape('element_' . $page->id),
|
||||
$this->escape($elementname)));
|
||||
$this->execute('behat_forms::press_button', get_string('addelement', 'customcert'));
|
||||
}
|
||||
|
||||
/**
|
||||
* Deletes an element from a specified page of a template.
|
||||
*
|
||||
* @Given /^I delete page "(?P<page_number>\d+)" of the "(?P<template_name>(?:[^"]|\\")*)" certificate template$/
|
||||
* @param int $pagenum
|
||||
* @param string $templatename
|
||||
*/
|
||||
public function i_delete_the_certificate_page($pagenum, $templatename) {
|
||||
global $DB;
|
||||
|
||||
$template = $DB->get_record('customcert_templates', array('name' => $templatename), '*', MUST_EXIST);
|
||||
$page = $DB->get_record('customcert_pages', array('templateid' => $template->id, 'sequence' => $pagenum),
|
||||
'*', MUST_EXIST);
|
||||
|
||||
$this->execute('behat_general::i_click_on_in_the', array('Delete page', 'link',
|
||||
$this->escape('#id_page_' . $page->id), 'css_element'));
|
||||
$this->execute('behat_forms::press_button', get_string('continue'));
|
||||
}
|
||||
|
||||
/**
|
||||
* Verifies the certificate code for a user.
|
||||
*
|
||||
* @Given /^I verify the "(?P<certificate_name>(?:[^"]|\\")*)" certificate for the user "(?P<user_name>(?:[^"]|\\")*)"$/
|
||||
* @param string $certificatename
|
||||
* @param string $username
|
||||
*/
|
||||
public function i_verify_the_custom_certificate_for_user($certificatename, $username) {
|
||||
global $DB;
|
||||
|
||||
$certificate = $DB->get_record('customcert', array('name' => $certificatename), '*', MUST_EXIST);
|
||||
$user = $DB->get_record('user', array('username' => $username), '*', MUST_EXIST);
|
||||
$issue = $DB->get_record('customcert_issues', array('userid' => $user->id, 'customcertid' => $certificate->id),
|
||||
'*', MUST_EXIST);
|
||||
|
||||
$this->execute('behat_forms::i_set_the_field_to', array(get_string('code', 'customcert'), $issue->code));
|
||||
$this->execute('behat_forms::press_button', get_string('verify', 'customcert'));
|
||||
$this->execute('behat_general::assert_page_contains_text', get_string('verified', 'customcert'));
|
||||
$this->execute('behat_general::assert_page_not_contains_text', get_string('notverified', 'customcert'));
|
||||
}
|
||||
|
||||
/**
|
||||
* Verifies the certificate code for a user.
|
||||
*
|
||||
* @Given /^I can not verify the "(?P<certificate_name>(?:[^"]|\\")*)" certificate for the user "(?P<user_name>(?:[^"]|\\")*)"$/
|
||||
* @param string $certificatename
|
||||
* @param string $username
|
||||
*/
|
||||
public function i_can_not_verify_the_custom_certificate_for_user($certificatename, $username) {
|
||||
global $DB;
|
||||
|
||||
$certificate = $DB->get_record('customcert', array('name' => $certificatename), '*', MUST_EXIST);
|
||||
$user = $DB->get_record('user', array('username' => $username), '*', MUST_EXIST);
|
||||
$issue = $DB->get_record('customcert_issues', array('userid' => $user->id, 'customcertid' => $certificate->id),
|
||||
'*', MUST_EXIST);
|
||||
|
||||
$this->execute('behat_forms::i_set_the_field_to', array(get_string('code', 'customcert'), $issue->code));
|
||||
$this->execute('behat_forms::press_button', get_string('verify', 'customcert'));
|
||||
$this->execute('behat_general::assert_page_contains_text', get_string('notverified', 'customcert'));
|
||||
$this->execute('behat_general::assert_page_not_contains_text', get_string('verified', 'customcert'));
|
||||
}
|
||||
|
||||
/**
|
||||
* Directs the user to the URL for verifying a certificate.
|
||||
*
|
||||
* This has been created as we allow non-users to verify certificates and they can not navigate to
|
||||
* the page like a conventional user.
|
||||
*
|
||||
* @Given /^I visit the verification url for the "(?P<certificate_name>(?:[^"]|\\")*)" certificate$/
|
||||
* @param string $certificatename
|
||||
*/
|
||||
public function i_visit_the_verification_url_for_custom_certificate($certificatename) {
|
||||
global $DB;
|
||||
|
||||
$certificate = $DB->get_record('customcert', array('name' => $certificatename), '*', MUST_EXIST);
|
||||
$template = $DB->get_record('customcert_templates', array('id' => $certificate->templateid), '*', MUST_EXIST);
|
||||
|
||||
$url = new moodle_url('/mod/customcert/verify_certificate.php', array('contextid' => $template->contextid));
|
||||
$this->getSession()->visit($this->locate_path($url->out_as_local_url()));
|
||||
}
|
||||
|
||||
/**
|
||||
* Directs the user to the URL for verifying all certificates on the site.
|
||||
*
|
||||
* @Given /^I visit the verification url for the site$/
|
||||
*/
|
||||
public function i_visit_the_verification_url_for_the_site() {
|
||||
$url = new moodle_url('/mod/customcert/verify_certificate.php');
|
||||
$this->getSession()->visit($this->locate_path($url->out_as_local_url()));
|
||||
}
|
||||
}
|
307
tests/behat/managing_elements.feature
Normal file
307
tests/behat/managing_elements.feature
Normal file
|
@ -0,0 +1,307 @@
|
|||
@mod @mod_customcert
|
||||
Feature: Being able to manage elements in a certificate template
|
||||
In order to ensure managing elements in a certificate template works as expected
|
||||
As a teacher
|
||||
I need to manage elements in a certificate template
|
||||
|
||||
Background:
|
||||
Given the following "courses" exist:
|
||||
| fullname | shortname | category |
|
||||
| Course 1 | C1 | 0 |
|
||||
And the following "users" exist:
|
||||
| username | firstname | lastname | email |
|
||||
| teacher1 | Teacher | 1 | teacher1@example.com |
|
||||
| teacher2 | Teacher | 2 | teacher2@example.com |
|
||||
And the following "course enrolments" exist:
|
||||
| user | course | role |
|
||||
| teacher1 | C1 | editingteacher |
|
||||
| teacher2 | C1 | editingteacher |
|
||||
And the following "activities" exist:
|
||||
| activity | name | intro | course | idnumber |
|
||||
| assign | Assignment 1 | Assignment 1 intro | C1 | assign1 |
|
||||
| assign | Assignment 2 | Assignment 2 intro | C1 | assign2 |
|
||||
| customcert | Custom certificate 1 | Custom certificate 1 intro | C1 | customcert1 |
|
||||
And I log in as "teacher1"
|
||||
And I am on "Course 1" course homepage
|
||||
And I follow "Custom certificate 1"
|
||||
And I navigate to "Edit certificate" in current page administration
|
||||
|
||||
Scenario: Add and edit elements in a certificate template
|
||||
# Background image.
|
||||
And I add the element "Background image" to page "1" of the "Custom certificate 1" certificate template
|
||||
And I press "Save changes"
|
||||
And I should see "Background image" in the "elementstable" "table"
|
||||
# Border.
|
||||
And I add the element "Border" to page "1" of the "Custom certificate 1" certificate template
|
||||
And I set the following fields to these values:
|
||||
| Width | 2 |
|
||||
| Colour | #045ECD |
|
||||
And I press "Save changes"
|
||||
And I should see "Border" in the "elementstable" "table"
|
||||
And I click on ".edit-icon" "css_element" in the "Border" "table_row"
|
||||
And the following fields match these values:
|
||||
| Width | 2 |
|
||||
| Colour | #045ECD |
|
||||
And I press "Save changes"
|
||||
# Category name.
|
||||
And I add the element "Category name" to page "1" of the "Custom certificate 1" certificate template
|
||||
And I set the following fields to these values:
|
||||
| Font | Helvetica |
|
||||
| Size | 20 |
|
||||
| Colour | #045ECD |
|
||||
| Width | 20 |
|
||||
| Reference point location | Top left |
|
||||
And I press "Save changes"
|
||||
And I should see "Category name" in the "elementstable" "table"
|
||||
And I click on ".edit-icon" "css_element" in the "Category name" "table_row"
|
||||
And the following fields match these values:
|
||||
| Font | Helvetica |
|
||||
| Size | 20 |
|
||||
| Colour | #045ECD |
|
||||
| Width | 20 |
|
||||
| Reference point location | Top left |
|
||||
And I press "Save changes"
|
||||
# Code.
|
||||
And I add the element "Code" to page "1" of the "Custom certificate 1" certificate template
|
||||
And I set the following fields to these values:
|
||||
| Font | Helvetica |
|
||||
| Size | 20 |
|
||||
| Colour | #045ECD |
|
||||
| Width | 20 |
|
||||
| Reference point location | Top left |
|
||||
And I press "Save changes"
|
||||
And I should see "Code" in the "elementstable" "table"
|
||||
And I click on ".edit-icon" "css_element" in the "Code" "table_row"
|
||||
And the following fields match these values:
|
||||
| Font | Helvetica |
|
||||
| Size | 20 |
|
||||
| Colour | #045ECD |
|
||||
| Width | 20 |
|
||||
| Reference point location | Top left |
|
||||
And I press "Save changes"
|
||||
# Course name.
|
||||
And I add the element "Course name" to page "1" of the "Custom certificate 1" certificate template
|
||||
And I set the following fields to these values:
|
||||
| Font | Helvetica |
|
||||
| Size | 20 |
|
||||
| Colour | #045ECD |
|
||||
| Width | 20 |
|
||||
| Reference point location | Top left |
|
||||
And I press "Save changes"
|
||||
And I should see "Course name" in the "elementstable" "table"
|
||||
And I click on ".edit-icon" "css_element" in the "Course name" "table_row"
|
||||
And the following fields match these values:
|
||||
| Font | Helvetica |
|
||||
| Size | 20 |
|
||||
| Colour | #045ECD |
|
||||
| Width | 20 |
|
||||
| Reference point location | Top left |
|
||||
And I press "Save changes"
|
||||
# Date.
|
||||
And I add the element "Date" to page "1" of the "Custom certificate 1" certificate template
|
||||
And I set the following fields to these values:
|
||||
| Date item | Course start date |
|
||||
| Date format | 2 |
|
||||
| Font | Helvetica |
|
||||
| Size | 20 |
|
||||
| Colour | #045ECD |
|
||||
| Width | 20 |
|
||||
| Reference point location | Top left |
|
||||
And I press "Save changes"
|
||||
And I should see "Date" in the "elementstable" "table"
|
||||
And I click on ".edit-icon" "css_element" in the "Date" "table_row"
|
||||
And the following fields match these values:
|
||||
| Date item | Course start date |
|
||||
| Date format | 2 |
|
||||
| Font | Helvetica |
|
||||
| Size | 20 |
|
||||
| Colour | #045ECD |
|
||||
| Width | 20 |
|
||||
| Reference point location | Top left |
|
||||
And I press "Save changes"
|
||||
# Digital signature.
|
||||
And I add the element "Digital signature" to page "1" of the "Custom certificate 1" certificate template
|
||||
And I set the following fields to these values:
|
||||
| Signature name | This is the signature name |
|
||||
| Signature password | Some awesome password |
|
||||
| Signature location | Mordor |
|
||||
| Signature reason | Meh, felt like it. |
|
||||
| Signature contact info | Sauron |
|
||||
| Width | 25 |
|
||||
| Height | 15 |
|
||||
And I press "Save changes"
|
||||
And I should see "Digital signature" in the "elementstable" "table"
|
||||
And I click on ".edit-icon" "css_element" in the "Digital signature" "table_row"
|
||||
And the following fields match these values:
|
||||
| Signature name | This is the signature name |
|
||||
| Signature password | Some awesome password |
|
||||
| Signature location | Mordor |
|
||||
| Signature reason | Meh, felt like it. |
|
||||
| Signature contact info | Sauron |
|
||||
| Width | 25 |
|
||||
| Height | 15 |
|
||||
And I press "Save changes"
|
||||
# Grade.
|
||||
And I add the element "Grade" to page "1" of the "Custom certificate 1" certificate template
|
||||
And I set the following fields to these values:
|
||||
| Grade item | Topic 0 : Assignment 1 |
|
||||
| Grade format | Percentage |
|
||||
| Font | Helvetica |
|
||||
| Size | 20 |
|
||||
| Colour | #045ECD |
|
||||
| Width | 20 |
|
||||
| Reference point location | Top left |
|
||||
And I press "Save changes"
|
||||
And I should see "Grade" in the "elementstable" "table"
|
||||
And I click on ".edit-icon" "css_element" in the "Grade" "table_row"
|
||||
And the following fields match these values:
|
||||
| Grade item | Topic 0 : Assignment 1 |
|
||||
| Grade format | Percentage |
|
||||
| Font | Helvetica |
|
||||
| Size | 20 |
|
||||
| Colour | #045ECD |
|
||||
| Width | 20 |
|
||||
| Reference point location | Top left |
|
||||
And I press "Save changes"
|
||||
# Grade item name.
|
||||
And I add the element "Grade item name" to page "1" of the "Custom certificate 1" certificate template
|
||||
And I set the following fields to these values:
|
||||
| Grade item | Topic 0 : Assignment 2 |
|
||||
| Font | Helvetica |
|
||||
| Size | 20 |
|
||||
| Colour | #045ECD |
|
||||
| Width | 20 |
|
||||
| Reference point location | Top left |
|
||||
And I press "Save changes"
|
||||
And I should see "Grade item name" in the "elementstable" "table"
|
||||
And I click on ".edit-icon" "css_element" in the "Grade item name" "table_row"
|
||||
And the following fields match these values:
|
||||
| Grade item | Topic 0 : Assignment 2 |
|
||||
| Font | Helvetica |
|
||||
| Size | 20 |
|
||||
| Colour | #045ECD |
|
||||
| Width | 20 |
|
||||
| Reference point location | Top left |
|
||||
And I press "Save changes"
|
||||
# Image.
|
||||
And I add the element "Image" to page "1" of the "Custom certificate 1" certificate template
|
||||
And I set the following fields to these values:
|
||||
| Width | 25 |
|
||||
| Height | 15 |
|
||||
And I press "Save changes"
|
||||
And I should see "Image" in the "elementstable" "table"
|
||||
And I click on ".edit-icon" "css_element" in the "Image" "table_row"
|
||||
And the following fields match these values:
|
||||
| Width | 25 |
|
||||
| Height | 15 |
|
||||
And I press "Save changes"
|
||||
# Student name.
|
||||
And I add the element "Student name" to page "1" of the "Custom certificate 1" certificate template
|
||||
And I set the following fields to these values:
|
||||
| Font | Helvetica |
|
||||
| Size | 20 |
|
||||
| Colour | #045ECD |
|
||||
| Width | 20 |
|
||||
| Reference point location | Top left |
|
||||
And I press "Save changes"
|
||||
And I should see "Student name" in the "elementstable" "table"
|
||||
And I click on ".edit-icon" "css_element" in the "Student name" "table_row"
|
||||
And the following fields match these values:
|
||||
| Font | Helvetica |
|
||||
| Size | 20 |
|
||||
| Colour | #045ECD |
|
||||
| Width | 20 |
|
||||
| Reference point location | Top left |
|
||||
And I press "Save changes"
|
||||
# Teacher name.
|
||||
And I add the element "Teacher name" to page "1" of the "Custom certificate 1" certificate template
|
||||
And I set the following fields to these values:
|
||||
| Teacher | Teacher 2 |
|
||||
| Font | Helvetica |
|
||||
| Size | 20 |
|
||||
| Colour | #045ECD |
|
||||
| Width | 20 |
|
||||
| Reference point location | Top left |
|
||||
And I press "Save changes"
|
||||
And I should see "Teacher name" in the "elementstable" "table"
|
||||
And I click on ".edit-icon" "css_element" in the "Teacher name" "table_row"
|
||||
And the following fields match these values:
|
||||
| Teacher | Teacher 2 |
|
||||
| Font | Helvetica |
|
||||
| Size | 20 |
|
||||
| Colour | #045ECD |
|
||||
| Width | 20 |
|
||||
| Reference point location | Top left |
|
||||
And I press "Save changes"
|
||||
# Text.
|
||||
And I add the element "Text" to page "1" of the "Custom certificate 1" certificate template
|
||||
And I set the following fields to these values:
|
||||
| Text | Test this |
|
||||
| Font | Helvetica |
|
||||
| Size | 20 |
|
||||
| Colour | #045ECD |
|
||||
| Width | 20 |
|
||||
| Reference point location | Top left |
|
||||
And I press "Save changes"
|
||||
And I should see "Text" in the "elementstable" "table"
|
||||
And I click on ".edit-icon" "css_element" in the "Text" "table_row"
|
||||
And the following fields match these values:
|
||||
| Text | Test this |
|
||||
| Font | Helvetica |
|
||||
| Size | 20 |
|
||||
| Colour | #045ECD |
|
||||
| Width | 20 |
|
||||
| Reference point location | Top left |
|
||||
And I press "Save changes"
|
||||
# User field.
|
||||
And I add the element "User field" to page "1" of the "Custom certificate 1" certificate template
|
||||
And I set the following fields to these values:
|
||||
| User field | Country |
|
||||
| Font | Helvetica |
|
||||
| Size | 20 |
|
||||
| Colour | #045ECD |
|
||||
| Width | 20 |
|
||||
| Reference point location | Top left |
|
||||
And I press "Save changes"
|
||||
And I should see "User field" in the "elementstable" "table"
|
||||
And I click on ".edit-icon" "css_element" in the "User field" "table_row"
|
||||
And the following fields match these values:
|
||||
| User field | Country |
|
||||
| Font | Helvetica |
|
||||
| Size | 20 |
|
||||
| Colour | #045ECD |
|
||||
| Width | 20 |
|
||||
| Reference point location | Top left |
|
||||
And I press "Save changes"
|
||||
# User picture.
|
||||
And I add the element "User picture" to page "1" of the "Custom certificate 1" certificate template
|
||||
And I set the following fields to these values:
|
||||
| Width | 10 |
|
||||
| Height | 10 |
|
||||
And I press "Save changes"
|
||||
And I should see "User picture" in the "elementstable" "table"
|
||||
And I click on ".edit-icon" "css_element" in the "User picture" "table_row"
|
||||
And the following fields match these values:
|
||||
| Width | 10 |
|
||||
| Height | 10 |
|
||||
And I press "Save changes"
|
||||
# Just to test there are no exceptions being thrown.
|
||||
And I follow "Reposition elements"
|
||||
And I press "Save and close"
|
||||
And I press "Save changes and preview"
|
||||
|
||||
Scenario: Delete an element from a certificate template
|
||||
And I add the element "Background image" to page "1" of the "Custom certificate 1" certificate template
|
||||
And I press "Save changes"
|
||||
And I should see "Background image" in the "elementstable" "table"
|
||||
And I add the element "Student name" to page "1" of the "Custom certificate 1" certificate template
|
||||
And I press "Save changes"
|
||||
And I should see "Student name" in the "elementstable" "table"
|
||||
And I click on ".delete-icon" "css_element" in the "Student name" "table_row"
|
||||
And I press "Cancel"
|
||||
And I should see "Background image" in the "elementstable" "table"
|
||||
And I should see "Student name" in the "elementstable" "table"
|
||||
And I click on ".delete-icon" "css_element" in the "Student name" "table_row"
|
||||
And I press "Continue"
|
||||
And I should see "Background image" in the "elementstable" "table"
|
||||
And I should not see "Student name" in the "elementstable" "table"
|
42
tests/behat/managing_pages.feature
Normal file
42
tests/behat/managing_pages.feature
Normal file
|
@ -0,0 +1,42 @@
|
|||
@mod @mod_customcert
|
||||
Feature: Being able to manage pages in a certificate template
|
||||
In order to ensure managing pages in a certificate template works as expected
|
||||
As a teacher
|
||||
I need to manage pages in a certificate template
|
||||
|
||||
Background:
|
||||
Given the following "courses" exist:
|
||||
| fullname | shortname | category |
|
||||
| Course 1 | C1 | 0 |
|
||||
And the following "users" exist:
|
||||
| username | firstname | lastname | email |
|
||||
| teacher1 | Teacher | 1 | teacher1@example.com |
|
||||
And the following "course enrolments" exist:
|
||||
| user | course | role |
|
||||
| teacher1 | C1 | editingteacher |
|
||||
And the following "activities" exist:
|
||||
| activity | name | intro | course | idnumber |
|
||||
| customcert | Custom certificate 1 | Custom certificate 1 intro | C1 | customcert1 |
|
||||
And I log in as "teacher1"
|
||||
And I am on "Course 1" course homepage
|
||||
And I follow "Custom certificate 1"
|
||||
And I navigate to "Edit certificate" in current page administration
|
||||
|
||||
Scenario: Adding a page to a certificate template
|
||||
And I follow "Add page"
|
||||
And I should see "Page 1"
|
||||
And I should see "Page 2"
|
||||
|
||||
Scenario: Deleting a page from a certificate template
|
||||
And I add the element "Background image" to page "1" of the "Custom certificate 1" certificate template
|
||||
And I press "Save changes"
|
||||
And I add the element "Student name" to page "1" of the "Custom certificate 1" certificate template
|
||||
And I press "Save changes"
|
||||
And I follow "Add page"
|
||||
And I should see "Page 1"
|
||||
And I should see "Page 2"
|
||||
And I delete page "2" of the "Custom certificate 1" certificate template
|
||||
And I should see "Background image" in the "elementstable" "table"
|
||||
And I should see "Student name" in the "elementstable" "table"
|
||||
And I should not see "Page 1"
|
||||
And I should not see "Page 2"
|
102
tests/behat/managing_templates.feature
Normal file
102
tests/behat/managing_templates.feature
Normal file
|
@ -0,0 +1,102 @@
|
|||
@mod @mod_customcert
|
||||
Feature: Being able to manage site templates
|
||||
In order to ensure managing site templates works as expected
|
||||
As an admin
|
||||
I need to manage and load site templates
|
||||
|
||||
Background:
|
||||
Given the following "courses" exist:
|
||||
| fullname | shortname | category |
|
||||
| Course 1 | C1 | 0 |
|
||||
And the following "users" exist:
|
||||
| username | firstname | lastname | email |
|
||||
| teacher1 | Teacher | 1 | teacher1@example.com |
|
||||
And the following "course enrolments" exist:
|
||||
| user | course | role |
|
||||
| teacher1 | C1 | editingteacher |
|
||||
And the following "activities" exist:
|
||||
| activity | name | intro | course | idnumber |
|
||||
| customcert | Custom certificate 1 | Custom certificate 1 intro | C1 | customcert1 |
|
||||
And I log in as "admin"
|
||||
|
||||
Scenario: Adding a site template and loading it into a course certificate
|
||||
And I navigate to "Plugins" in site administration
|
||||
And I follow "Manage activities"
|
||||
And I click on "Settings" "link" in the "Custom certificate" "table_row"
|
||||
And I follow "Manage templates"
|
||||
And I press "Create template"
|
||||
And I set the field "Name" to "Site template"
|
||||
And I press "Save changes"
|
||||
And I add the element "Border" to page "1" of the "Site template" certificate template
|
||||
And I set the following fields to these values:
|
||||
| Width | 5 |
|
||||
| Colour | #045ECD |
|
||||
And I press "Save changes"
|
||||
And I add the element "Category name" to page "1" of the "Site template" certificate template
|
||||
And I set the following fields to these values:
|
||||
| Font | Helvetica |
|
||||
| Size | 20 |
|
||||
| Colour | #045ECD |
|
||||
| Width | 20 |
|
||||
| Reference point location | Top left |
|
||||
And I press "Save changes"
|
||||
And I am on "Course 1" course homepage
|
||||
And I follow "Custom certificate 1"
|
||||
And I navigate to "Edit certificate" in current page administration
|
||||
And I set the field "ltid" to "Site template"
|
||||
And I click on "Load" "button" in the "#loadtemplateform" "css_element"
|
||||
And I should see "Are you sure you wish to load this template"
|
||||
And I press "Cancel"
|
||||
And "elementstable" "table" should not exist
|
||||
And I set the field "ltid" to "Site template"
|
||||
And I click on "Load" "button" in the "#loadtemplateform" "css_element"
|
||||
And I should see "Are you sure you wish to load this template"
|
||||
And I press "Continue"
|
||||
And I should see "Border" in the "elementstable" "table"
|
||||
And I should see "Category name" in the "elementstable" "table"
|
||||
And I click on ".edit-icon" "css_element" in the "Border" "table_row"
|
||||
And the following fields match these values:
|
||||
| Width | 5 |
|
||||
| Colour | #045ECD |
|
||||
And I press "Save changes"
|
||||
And I click on ".edit-icon" "css_element" in the "Category name" "table_row"
|
||||
And the following fields match these values:
|
||||
| Font | Helvetica |
|
||||
| Size | 20 |
|
||||
| Colour | #045ECD |
|
||||
| Width | 20 |
|
||||
| Reference point location | Top left |
|
||||
|
||||
Scenario: Deleting a site template
|
||||
And I navigate to "Plugins" in site administration
|
||||
And I follow "Manage activities"
|
||||
And I click on "Settings" "link" in the "Custom certificate" "table_row"
|
||||
And I follow "Manage templates"
|
||||
And I press "Create template"
|
||||
And I set the field "Name" to "Site template"
|
||||
And I press "Save changes"
|
||||
And I follow "Manage templates"
|
||||
And I click on ".delete-icon" "css_element" in the "Site template" "table_row"
|
||||
And I press "Cancel"
|
||||
And I should see "Site template"
|
||||
And I click on ".delete-icon" "css_element" in the "Site template" "table_row"
|
||||
And I press "Continue"
|
||||
And I should not see "Site template"
|
||||
|
||||
Scenario: Duplicating a site template
|
||||
And I navigate to "Plugins" in site administration
|
||||
And I follow "Manage activities"
|
||||
And I click on "Settings" "link" in the "Custom certificate" "table_row"
|
||||
And I follow "Manage templates"
|
||||
And I press "Create template"
|
||||
And I set the field "Name" to "Site template"
|
||||
And I press "Save changes"
|
||||
And I follow "Manage templates"
|
||||
And I click on ".duplicate-icon" "css_element" in the "Site template" "table_row"
|
||||
And I press "Cancel"
|
||||
And I should see "Site template"
|
||||
And I should not see "Site template (duplicate)"
|
||||
And I click on ".duplicate-icon" "css_element" in the "Site template" "table_row"
|
||||
And I press "Continue"
|
||||
And I should see "Site template"
|
||||
And I should see "Site template (duplicate)"
|
39
tests/behat/my_certificates.feature
Normal file
39
tests/behat/my_certificates.feature
Normal file
|
@ -0,0 +1,39 @@
|
|||
@mod @mod_customcert
|
||||
Feature: Being able to view the certificates you have been issued
|
||||
In order to ensure that a user can view the certificates they have been issued
|
||||
As a student
|
||||
I need to view the certificates I have been issued
|
||||
|
||||
Background:
|
||||
Given the following "courses" exist:
|
||||
| fullname | shortname | category |
|
||||
| Course 1 | C1 | 0 |
|
||||
| Course 2 | C2 | 0 |
|
||||
And the following "users" exist:
|
||||
| username | firstname | lastname | email |
|
||||
| student1 | Student | 1 | student1@example.com |
|
||||
And the following "course enrolments" exist:
|
||||
| user | course | role |
|
||||
| student1 | C1 | student |
|
||||
| student1 | C2 | student |
|
||||
And the following "activities" exist:
|
||||
| activity | name | intro | course | idnumber |
|
||||
| customcert | Custom certificate 1 | Custom certificate 1 intro | C1 | customcert1 |
|
||||
| customcert | Custom certificate 2 | Custom certificate 2 intro | C2 | customcert2 |
|
||||
|
||||
Scenario: View your issued certificates on the my certificates page
|
||||
And I log in as "student1"
|
||||
And I am on "Course 1" course homepage
|
||||
And I follow "Custom certificate 1"
|
||||
And I press "Download certificate"
|
||||
And I follow "Profile" in the user menu
|
||||
And I follow "My certificates"
|
||||
And I should see "Custom certificate 1"
|
||||
And I should not see "Custom certificate 2"
|
||||
And I am on "Course 2" course homepage
|
||||
And I follow "Custom certificate 2"
|
||||
And I press "Download certificate"
|
||||
And I follow "Profile" in the user menu
|
||||
And I follow "My certificates"
|
||||
And I should see "Custom certificate 1"
|
||||
And I should see "Custom certificate 2"
|
39
tests/behat/required_minutes.feature
Normal file
39
tests/behat/required_minutes.feature
Normal file
|
@ -0,0 +1,39 @@
|
|||
@mod @mod_customcert
|
||||
Feature: Being able to set the required minutes in a course before viewing the certificate
|
||||
In order to ensure the required minutes in a course setting works as expected
|
||||
As a teacher
|
||||
I need to ensure students can not view a certificate until the required minutes have passed
|
||||
|
||||
Background:
|
||||
Given the following "courses" exist:
|
||||
| fullname | shortname | category |
|
||||
| Course 1 | C1 | 0 |
|
||||
And the following "users" exist:
|
||||
| username | firstname | lastname | email |
|
||||
| teacher1 | Teacher | 1 | teacher1@example.com |
|
||||
| student1 | Student | 1 | student1@example.com |
|
||||
And the following "course enrolments" exist:
|
||||
| user | course | role |
|
||||
| teacher1 | C1 | editingteacher |
|
||||
| student1 | C1 | student |
|
||||
And the following "activities" exist:
|
||||
| activity | name | intro | course | idnumber | requiredtime |
|
||||
| customcert | Custom certificate 1 | Custom certificate 1 intro | C1 | customcert1 | 1 |
|
||||
|
||||
Scenario: Check the user can not access the certificate before the required time
|
||||
And I log in as "student1"
|
||||
And I am on "Course 1" course homepage
|
||||
And I follow "Custom certificate 1"
|
||||
And I should see "You must spend at least a minimum of"
|
||||
And I should not see "Download certificate"
|
||||
And I press "Continue"
|
||||
And I should see "Custom certificate 1"
|
||||
|
||||
Scenario: Check the user can access the certificate after the required time
|
||||
And I log in as "student1"
|
||||
And I am on "Course 1" course homepage
|
||||
And I wait "60" seconds
|
||||
And I am on "Course 1" course homepage
|
||||
And I follow "Custom certificate 1"
|
||||
And I should not see "You must spend at least a minimum of"
|
||||
And I should see "Download certificate"
|
52
tests/behat/show_position_x_y.feature
Normal file
52
tests/behat/show_position_x_y.feature
Normal file
|
@ -0,0 +1,52 @@
|
|||
@mod @mod_customcert
|
||||
Feature: Being able to set a site setting to determine whether or not to display the position X and Y fields
|
||||
In order to ensure the show position X and Y fields setting works as expected
|
||||
As an admin
|
||||
I need to ensure teachers can see the position X and Y fields depending on the site setting
|
||||
|
||||
Background:
|
||||
Given the following "courses" exist:
|
||||
| fullname | shortname | category |
|
||||
| Course 1 | C1 | 0 |
|
||||
And the following "users" exist:
|
||||
| username | firstname | lastname | email |
|
||||
| teacher1 | Teacher | 1 | teacher1@example.com |
|
||||
And the following "course enrolments" exist:
|
||||
| user | course | role |
|
||||
| teacher1 | C1 | editingteacher |
|
||||
And the following "activities" exist:
|
||||
| activity | name | intro | course | idnumber |
|
||||
| customcert | Custom certificate 1 | Custom certificate 1 intro | C1 | customcert1 |
|
||||
|
||||
Scenario: Adding an element with the show position X and Y setting disabled
|
||||
And I log in as "teacher1"
|
||||
And I am on "Course 1" course homepage
|
||||
And I follow "Custom certificate 1"
|
||||
And I navigate to "Edit certificate" in current page administration
|
||||
And I add the element "Code" to page "1" of the "Custom certificate 1" certificate template
|
||||
And I should not see "Position X"
|
||||
And I should not see "Position Y"
|
||||
|
||||
Scenario: Adding an element with the show position X and Y setting enabled
|
||||
And I log in as "admin"
|
||||
And I navigate to "Plugins" in site administration
|
||||
And I follow "Manage activities"
|
||||
And I click on "Settings" "link" in the "Custom certificate" "table_row"
|
||||
And I set the field "Show position X and Y" to "1"
|
||||
And I press "Save changes"
|
||||
And I log out
|
||||
And I log in as "teacher1"
|
||||
And I am on "Course 1" course homepage
|
||||
And I follow "Custom certificate 1"
|
||||
And I navigate to "Edit certificate" in current page administration
|
||||
And I add the element "Code" to page "1" of the "Custom certificate 1" certificate template
|
||||
And I should see "Position X"
|
||||
And I should see "Position Y"
|
||||
And I set the following fields to these values:
|
||||
| Position X | 5 |
|
||||
| Position Y | 10 |
|
||||
And I press "Save changes"
|
||||
And I click on ".edit-icon" "css_element" in the "Code" "table_row"
|
||||
And the following fields match these values:
|
||||
| Position X | 5 |
|
||||
| Position Y | 10 |
|
108
tests/behat/verify_certificates.feature
Normal file
108
tests/behat/verify_certificates.feature
Normal file
|
@ -0,0 +1,108 @@
|
|||
@mod @mod_customcert
|
||||
Feature: Being able to verify that a certificate is valid or not
|
||||
In order to ensure that a user can verify a certificate is valid
|
||||
As a teacher and non-user
|
||||
I need to be able to verify a certificate
|
||||
|
||||
Background:
|
||||
Given the following "courses" exist:
|
||||
| fullname | shortname | category |
|
||||
| Course 1 | C1 | 0 |
|
||||
And the following "users" exist:
|
||||
| username | firstname | lastname | email |
|
||||
| teacher1 | Teacher | 1 | teacher1@example.com |
|
||||
| student1 | Student | 1 | student1@example.com |
|
||||
And the following "course enrolments" exist:
|
||||
| user | course | role |
|
||||
| teacher1 | C1 | editingteacher |
|
||||
| student1 | C1 | student |
|
||||
And the following "activities" exist:
|
||||
| activity | name | intro | course | idnumber | verifyany |
|
||||
| customcert | Custom certificate 1 | Custom certificate 1 intro | C1 | customcert1 | 0 |
|
||||
| customcert | Custom certificate 2 | Custom certificate 2 intro | C1 | customcert2 | 1 |
|
||||
|
||||
Scenario: Verify a certificate as a teacher
|
||||
And I log in as "student1"
|
||||
And I am on "Course 1" course homepage
|
||||
And I follow "Custom certificate 1"
|
||||
And I press "Download certificate"
|
||||
And I log out
|
||||
And I log in as "teacher1"
|
||||
And I am on "Course 1" course homepage
|
||||
And I follow "Custom certificate 1"
|
||||
And I navigate to "Verify certificate" in current page administration
|
||||
And I set the field "Code" to "NOTAVALIDCODE"
|
||||
And I press "Verify"
|
||||
And I should see "Not verified"
|
||||
And I verify the "Custom certificate 1" certificate for the user "student1"
|
||||
|
||||
Scenario: Attempt to verify a certificate as a non-user
|
||||
And I visit the verification url for the "Custom certificate 1" certificate
|
||||
# User should get redirected to log in as we do not allow non-users to verify.
|
||||
And I should see "Remember username"
|
||||
|
||||
Scenario: Verify a certificate as a non-user
|
||||
And I log in as "student1"
|
||||
And I am on "Course 1" course homepage
|
||||
And I follow "Custom certificate 2"
|
||||
And I press "Download certificate"
|
||||
And I log out
|
||||
And I visit the verification url for the "Custom certificate 2" certificate
|
||||
And I set the field "Code" to "NOTAVALIDCODE"
|
||||
And I press "Verify"
|
||||
And I should see "Not verified"
|
||||
And I verify the "Custom certificate 2" certificate for the user "student1"
|
||||
|
||||
Scenario: Attempt to verify a certificate as a non-user using the site-wide URL
|
||||
And the following config values are set as admin:
|
||||
| verifyallcertificates | 0 | customcert |
|
||||
And I visit the verification url for the site
|
||||
# User should see an error message as we do not allow non-users to verify all certificates on the site.
|
||||
And I should see "You do not have the permission to verify all certificates on the site"
|
||||
|
||||
Scenario: Attempt to verify a certificate as a teacher using the site-wide URL
|
||||
And the following config values are set as admin:
|
||||
| verifyallcertificates | 0 | customcert |
|
||||
And I log in as "teacher1"
|
||||
And I visit the verification url for the site
|
||||
# User should see an error message as we do not allow teachers to verify all certificates on the site.
|
||||
And I should see "You do not have the permission to verify all certificates on the site"
|
||||
|
||||
Scenario: Verify a certificate as an admin using the site-wide URL
|
||||
And the following config values are set as admin:
|
||||
| verifyallcertificates | 0 | customcert |
|
||||
And I log in as "student1"
|
||||
And I am on "Course 1" course homepage
|
||||
And I follow "Custom certificate 1"
|
||||
And I press "Download certificate"
|
||||
And I am on "Course 1" course homepage
|
||||
And I follow "Custom certificate 2"
|
||||
And I press "Download certificate"
|
||||
And I log out
|
||||
And I log in as "admin"
|
||||
# The admin (or anyone with the capability 'mod/customcert:verifyallcertificates') can visit the URL regardless of the setting.
|
||||
And I visit the verification url for the site
|
||||
And I set the field "Code" to "NOTAVALIDCODE"
|
||||
And I press "Verify"
|
||||
And I should see "Not verified"
|
||||
# The admin (or anyone with the capability 'mod/customcert:verifyallcertificates') can verify any certificate regardless of the 'verifyany' setting.
|
||||
And I verify the "Custom certificate 1" certificate for the user "student1"
|
||||
And I verify the "Custom certificate 2" certificate for the user "student1"
|
||||
|
||||
Scenario: Verify a certificate as a non-user using the site-wide URL
|
||||
And the following config values are set as admin:
|
||||
| verifyallcertificates | 1 | customcert |
|
||||
And I log in as "student1"
|
||||
And I am on "Course 1" course homepage
|
||||
And I follow "Custom certificate 1"
|
||||
And I press "Download certificate"
|
||||
And I am on "Course 1" course homepage
|
||||
And I follow "Custom certificate 2"
|
||||
And I press "Download certificate"
|
||||
And I log out
|
||||
And I visit the verification url for the site
|
||||
And I set the field "Code" to "NOTAVALIDCODE"
|
||||
And I press "Verify"
|
||||
And I should see "Not verified"
|
||||
And I can not verify the "Custom certificate 1" certificate for the user "student1"
|
||||
And I verify the "Custom certificate 2" certificate for the user "student1"
|
67
tests/behat/view_issued_certificates.feature
Normal file
67
tests/behat/view_issued_certificates.feature
Normal file
|
@ -0,0 +1,67 @@
|
|||
@mod @mod_customcert
|
||||
Feature: Being able to view the certificates that have been issued
|
||||
In order to ensure that a user can view the certificates that have been issued
|
||||
As a teacher
|
||||
I need to view the certificates that have been issued
|
||||
|
||||
Background:
|
||||
Given the following "courses" exist:
|
||||
| fullname | shortname | category |
|
||||
| Course 1 | C1 | 0 |
|
||||
And the following "users" exist:
|
||||
| username | firstname | lastname | email |
|
||||
| teacher1 | Teacher | 1 | teacher1@example.com |
|
||||
| student1 | Student | 1 | student1@example.com |
|
||||
| student2 | Student | 2 | student2@example.com |
|
||||
And the following "course enrolments" exist:
|
||||
| user | course | role |
|
||||
| teacher1 | C1 | editingteacher |
|
||||
| student1 | C1 | student |
|
||||
| student2 | C1 | student |
|
||||
And the following "activities" exist:
|
||||
| activity | name | intro | course | idnumber |
|
||||
| customcert | Custom certificate 1 | Custom certificate 1 intro | C1 | customcert1 |
|
||||
|
||||
Scenario: View the issued certificates
|
||||
And I log in as "student1"
|
||||
And I am on "Course 1" course homepage
|
||||
And I follow "Custom certificate 1"
|
||||
And I press "Download certificate"
|
||||
And I log out
|
||||
And I log in as "student2"
|
||||
And I am on "Course 1" course homepage
|
||||
And I follow "Custom certificate 1"
|
||||
And I press "Download certificate"
|
||||
And I log out
|
||||
And I log in as "teacher1"
|
||||
And I am on "Course 1" course homepage
|
||||
And I follow "Custom certificate 1"
|
||||
And I follow "View 2 issued certificates"
|
||||
And I should see "Student 1"
|
||||
And I should see "Student 2"
|
||||
|
||||
Scenario: Delete an issued certificate
|
||||
And I log in as "student1"
|
||||
And I am on "Course 1" course homepage
|
||||
And I follow "Custom certificate 1"
|
||||
And I press "Download certificate"
|
||||
And I log out
|
||||
And I log in as "student2"
|
||||
And I am on "Course 1" course homepage
|
||||
And I follow "Custom certificate 1"
|
||||
And I press "Download certificate"
|
||||
And I log out
|
||||
And I log in as "teacher1"
|
||||
And I am on "Course 1" course homepage
|
||||
And I follow "Custom certificate 1"
|
||||
And I follow "View 2 issued certificates"
|
||||
And I should see "Student 1"
|
||||
And I should see "Student 2"
|
||||
And I click on ".delete-icon" "css_element" in the "Student 2" "table_row"
|
||||
And I press "Cancel"
|
||||
And I should see "Student 1"
|
||||
And I should see "Student 2"
|
||||
And I click on ".delete-icon" "css_element" in the "Student 2" "table_row"
|
||||
And I press "Continue"
|
||||
And I should see "Student 1"
|
||||
And I should not see "Student 2"
|
315
tests/element_helper_test.php
Normal file
315
tests/element_helper_test.php
Normal file
|
@ -0,0 +1,315 @@
|
|||
<?php
|
||||
// This file is part of Moodle - http://moodle.org/
|
||||
//
|
||||
// Moodle is free software: you can redistribute it and/or modify
|
||||
// it under the terms of the GNU General Public License as published by
|
||||
// the Free Software Foundation, either version 3 of the License, or
|
||||
// (at your option) any later version.
|
||||
//
|
||||
// Moodle is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
/**
|
||||
* File contains the unit tests for the element helper class.
|
||||
*
|
||||
* @package mod_customcert
|
||||
* @category test
|
||||
* @copyright 2017 Mark Nelson <markn@moodle.com>
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
*/
|
||||
|
||||
defined('MOODLE_INTERNAL') || die();
|
||||
|
||||
global $CFG;
|
||||
|
||||
/**
|
||||
* Unit tests for the element helper class.
|
||||
*
|
||||
* @package mod_customcert
|
||||
* @category test
|
||||
* @copyright 2017 Mark Nelson <markn@moodle.com>
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
*/
|
||||
class mod_customcert_element_helper_testcase extends advanced_testcase {
|
||||
|
||||
/**
|
||||
* Test set up.
|
||||
*/
|
||||
public function setUp() {
|
||||
$this->resetAfterTest();
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests we are returning the correct course id for an element in a course customcert activity.
|
||||
*/
|
||||
public function test_get_courseid_element_in_course_certificate() {
|
||||
global $DB;
|
||||
|
||||
// Create a course.
|
||||
$course = $this->getDataGenerator()->create_course();
|
||||
|
||||
// Create a custom certificate in the course.
|
||||
$customcert = $this->getDataGenerator()->create_module('customcert', array('course' => $course->id));
|
||||
|
||||
// Get the template to add elements to.
|
||||
$template = $DB->get_record('customcert_templates', array('contextid' => context_module::instance($customcert->cmid)->id));
|
||||
$template = new \mod_customcert\template($template);
|
||||
|
||||
// Add a page to the template.
|
||||
$pageid = $template->add_page();
|
||||
|
||||
// Add an element to this page.
|
||||
$element = new \stdClass();
|
||||
$element->name = 'Test element';
|
||||
$element->element = 'testelement';
|
||||
$element->pageid = $pageid;
|
||||
$element->sequence = \mod_customcert\element_helper::get_element_sequence($element->pageid);
|
||||
$element->timecreated = time();
|
||||
$element->id = $DB->insert_record('customcert_elements', $element);
|
||||
|
||||
// Confirm the correct course id is returned.
|
||||
$this->assertEquals($course->id, \mod_customcert\element_helper::get_courseid($element->id));
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests we are returning the correct course id for an element in a site template.
|
||||
*/
|
||||
public function test_get_courseid_element_in_site_template() {
|
||||
global $DB, $SITE;
|
||||
|
||||
// Add a template to the site.
|
||||
$template = \mod_customcert\template::create('Site template', context_system::instance()->id);
|
||||
|
||||
// Add a page to the template.
|
||||
$pageid = $template->add_page();
|
||||
|
||||
// Add an element to this page.
|
||||
$element = new \stdClass();
|
||||
$element->name = 'Test element';
|
||||
$element->element = 'testelement';
|
||||
$element->pageid = $pageid;
|
||||
$element->sequence = \mod_customcert\element_helper::get_element_sequence($element->pageid);
|
||||
$element->timecreated = time();
|
||||
$element->id = $DB->insert_record('customcert_elements', $element);
|
||||
|
||||
// Confirm the correct course id is returned.
|
||||
$this->assertEquals($SITE->id, \mod_customcert\element_helper::get_courseid($element->id));
|
||||
}
|
||||
|
||||
/**
|
||||
* Test we return the correct grade items in a course.
|
||||
*/
|
||||
public function test_get_grade_items() {
|
||||
global $DB;
|
||||
|
||||
// Create a course.
|
||||
$course = $this->getDataGenerator()->create_course();
|
||||
|
||||
// Create a few gradeable items.
|
||||
$assign1 = $this->getDataGenerator()->create_module('assign', array('course' => $course->id));
|
||||
$assign2 = $this->getDataGenerator()->create_module('assign', array('course' => $course->id));
|
||||
$assign3 = $this->getDataGenerator()->create_module('assign', array('course' => $course->id));
|
||||
|
||||
// Create a manual grade item.
|
||||
$gi = $this->getDataGenerator()->create_grade_item(['courseid' => $course->id]);
|
||||
|
||||
// Create a category grade item.
|
||||
$gc = $this->getDataGenerator()->create_grade_category(['courseid' => $course->id]);
|
||||
$gc = $DB->get_record('grade_items', ['itemtype' => 'category', 'iteminstance' => $gc->id]);
|
||||
|
||||
// Confirm the function returns the correct number of grade items.
|
||||
$gradeitems = \mod_customcert\element_helper::get_grade_items($course);
|
||||
$this->assertCount(5, $gradeitems);
|
||||
$this->assertArrayHasKey($assign1->cmid, $gradeitems);
|
||||
$this->assertArrayHasKey($assign2->cmid, $gradeitems);
|
||||
$this->assertArrayHasKey($assign3->cmid, $gradeitems);
|
||||
$this->assertArrayHasKey('gradeitem:' . $gi->id, $gradeitems);
|
||||
$this->assertArrayHasKey('gradeitem:' . $gc->id, $gradeitems);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test we return the correct grade information for an activity.
|
||||
*/
|
||||
public function test_get_mod_grade_info() {
|
||||
// Create a course.
|
||||
$course = $this->getDataGenerator()->create_course();
|
||||
|
||||
// Create two users.
|
||||
$student1 = $this->getDataGenerator()->create_user();
|
||||
$student2 = $this->getDataGenerator()->create_user();
|
||||
|
||||
// Enrol them into the course.
|
||||
$this->getDataGenerator()->enrol_user($student1->id, $course->id);
|
||||
$this->getDataGenerator()->enrol_user($student2->id, $course->id);
|
||||
|
||||
// Create a gradeable item.
|
||||
$assign = $this->getDataGenerator()->create_module('assign', array('course' => $course->id));
|
||||
|
||||
// Give a grade to the student.
|
||||
$gi = grade_item::fetch(
|
||||
[
|
||||
'itemtype' => 'mod',
|
||||
'itemmodule' => 'assign',
|
||||
'iteminstance' => $assign->id,
|
||||
'courseid' => $course->id
|
||||
]
|
||||
);
|
||||
$datagrade = 50;
|
||||
$time = time();
|
||||
$grade = new grade_grade();
|
||||
$grade->itemid = $gi->id;
|
||||
$grade->userid = $student1->id;
|
||||
$grade->rawgrade = $datagrade;
|
||||
$grade->finalgrade = $datagrade;
|
||||
$grade->rawgrademax = 100;
|
||||
$grade->rawgrademin = 0;
|
||||
$grade->timecreated = $time;
|
||||
$grade->timemodified = $time;
|
||||
$grade->insert();
|
||||
|
||||
// Check that the user received the grade.
|
||||
$grade = \mod_customcert\element_helper::get_mod_grade_info(
|
||||
$assign->cmid,
|
||||
GRADE_DISPLAY_TYPE_PERCENTAGE,
|
||||
$student1->id
|
||||
);
|
||||
|
||||
$this->assertEquals($assign->name, $grade->get_name());
|
||||
$this->assertEquals('50.00000', $grade->get_grade());
|
||||
$this->assertEquals('50 %', $grade->get_displaygrade());
|
||||
$this->assertEquals($time, $grade->get_dategraded());
|
||||
|
||||
// Check that the user we did not grade has no grade.
|
||||
$grade = \mod_customcert\element_helper::get_mod_grade_info(
|
||||
$assign->cmid,
|
||||
GRADE_DISPLAY_TYPE_PERCENTAGE,
|
||||
$student2->id
|
||||
);
|
||||
$this->assertEquals($assign->name, $grade->get_name());
|
||||
$this->assertEquals(null, $grade->get_grade());
|
||||
$this->assertEquals('-', $grade->get_displaygrade());
|
||||
$this->assertEquals(null, $grade->get_dategraded());
|
||||
}
|
||||
|
||||
/**
|
||||
* Test we return the correct grade information for a course.
|
||||
*/
|
||||
public function test_get_course_grade_info() {
|
||||
global $CFG;
|
||||
|
||||
// Including to use constant.
|
||||
require_once($CFG->dirroot . '/mod/customcert/element/grade/classes/element.php');
|
||||
|
||||
// Create a course.
|
||||
$course = $this->getDataGenerator()->create_course();
|
||||
|
||||
// Create two users.
|
||||
$student1 = $this->getDataGenerator()->create_user();
|
||||
$student2 = $this->getDataGenerator()->create_user();
|
||||
|
||||
// Enrol them into the course.
|
||||
$this->getDataGenerator()->enrol_user($student1->id, $course->id);
|
||||
$this->getDataGenerator()->enrol_user($student2->id, $course->id);
|
||||
|
||||
// Get the course item.
|
||||
$coursegradeitem = grade_item::fetch_course_item($course->id);
|
||||
|
||||
$datagrade = 50;
|
||||
$time = time();
|
||||
$grade = new grade_grade();
|
||||
$grade->itemid = $coursegradeitem->id;
|
||||
$grade->userid = $student1->id;
|
||||
$grade->rawgrade = $datagrade;
|
||||
$grade->finalgrade = $datagrade;
|
||||
$grade->rawgrademax = 100;
|
||||
$grade->rawgrademin = 0;
|
||||
$grade->timecreated = $time;
|
||||
$grade->timemodified = $time;
|
||||
$grade->insert();
|
||||
|
||||
// Check that the user received the grade.
|
||||
$grade = \mod_customcert\element_helper::get_course_grade_info(
|
||||
$course->id,
|
||||
GRADE_DISPLAY_TYPE_PERCENTAGE,
|
||||
$student1->id
|
||||
);
|
||||
|
||||
$this->assertEquals(get_string('coursetotal', 'grades'), $grade->get_name());
|
||||
$this->assertEquals('50.00000', $grade->get_grade());
|
||||
$this->assertEquals('50 %', $grade->get_displaygrade());
|
||||
$this->assertEquals($time, $grade->get_dategraded());
|
||||
|
||||
// Check that the user we did not grade has no grade.
|
||||
$grade = \mod_customcert\element_helper::get_course_grade_info(
|
||||
$course->id,
|
||||
GRADE_DISPLAY_TYPE_PERCENTAGE,
|
||||
$student2->id
|
||||
);
|
||||
$this->assertEquals(get_string('coursetotal', 'grades'), $grade->get_name());
|
||||
$this->assertEquals(null, $grade->get_grade());
|
||||
$this->assertEquals('-', $grade->get_displaygrade());
|
||||
$this->assertEquals(null, $grade->get_dategraded());
|
||||
}
|
||||
|
||||
/**
|
||||
* Test we return the correct grade information for a grade item.
|
||||
*/
|
||||
public function test_get_grade_item_info() {
|
||||
// Create a course.
|
||||
$course = $this->getDataGenerator()->create_course();
|
||||
|
||||
// Create two users.
|
||||
$student1 = $this->getDataGenerator()->create_user();
|
||||
$student2 = $this->getDataGenerator()->create_user();
|
||||
|
||||
// Enrol them into the course.
|
||||
$this->getDataGenerator()->enrol_user($student1->id, $course->id);
|
||||
$this->getDataGenerator()->enrol_user($student2->id, $course->id);
|
||||
|
||||
// Create a manual grade item.
|
||||
$gi = $this->getDataGenerator()->create_grade_item(['itemname' => 'Grade item yo', 'courseid' => $course->id]);
|
||||
|
||||
// Give a grade to the student.
|
||||
$gi = grade_item::fetch(['id' => $gi->id]);
|
||||
$datagrade = 50;
|
||||
$time = time();
|
||||
$grade = new grade_grade();
|
||||
$grade->itemid = $gi->id;
|
||||
$grade->userid = $student1->id;
|
||||
$grade->rawgrade = $datagrade;
|
||||
$grade->finalgrade = $datagrade;
|
||||
$grade->rawgrademax = 100;
|
||||
$grade->rawgrademin = 0;
|
||||
$grade->timecreated = $time;
|
||||
$grade->timemodified = $time;
|
||||
$grade->insert();
|
||||
|
||||
// Check that the user received the grade.
|
||||
$grade = \mod_customcert\element_helper::get_grade_item_info(
|
||||
$gi->id,
|
||||
GRADE_DISPLAY_TYPE_PERCENTAGE,
|
||||
$student1->id
|
||||
);
|
||||
|
||||
$this->assertEquals('Grade item yo', $grade->get_name());
|
||||
$this->assertEquals('50.00000', $grade->get_grade());
|
||||
$this->assertEquals('50 %', $grade->get_displaygrade());
|
||||
$this->assertEquals($time, $grade->get_dategraded());
|
||||
|
||||
// Check that the user we did not grade has no grade.
|
||||
$grade = \mod_customcert\element_helper::get_grade_item_info(
|
||||
$gi->id,
|
||||
GRADE_DISPLAY_TYPE_PERCENTAGE,
|
||||
$student2->id
|
||||
);
|
||||
$this->assertEquals('Grade item yo', $grade->get_name());
|
||||
$this->assertEquals(null, $grade->get_grade());
|
||||
$this->assertEquals('-', $grade->get_displaygrade());
|
||||
$this->assertEquals(null, $grade->get_dategraded());
|
||||
}
|
||||
}
|
|
@ -71,15 +71,7 @@ class mod_customcert_task_email_certificate_task_testcase extends advanced_testc
|
|||
'emailstudents' => 1));
|
||||
|
||||
// Ok, now issue this to one user.
|
||||
$customcertissue = new stdClass();
|
||||
$customcertissue->customcertid = $customcert->id;
|
||||
$customcertissue->userid = $user1->id;
|
||||
$customcertissue->code = \mod_customcert\certificate::generate_code();
|
||||
$customcertissue->timecreated = time();
|
||||
$customcertissue->emailed = 0;
|
||||
|
||||
// Insert the record into the database.
|
||||
$DB->insert_record('customcert_issues', $customcertissue);
|
||||
\mod_customcert\certificate::issue_certificate($customcert->id, $user1->id);
|
||||
|
||||
// Confirm there is only one entry in this table.
|
||||
$this->assertEquals(1, $DB->count_records('customcert_issues'));
|
||||
|
@ -110,6 +102,17 @@ class mod_customcert_task_email_certificate_task_testcase extends advanced_testc
|
|||
$this->assertContains(fullname($user3), $emails[1]->header);
|
||||
$this->assertEquals($CFG->noreplyaddress, $emails[1]->from);
|
||||
$this->assertEquals($user2->email, $emails[1]->to);
|
||||
|
||||
// Now, run the task again and ensure we did not issue any more certificates.
|
||||
$sink = $this->redirectEmails();
|
||||
$task = new \mod_customcert\task\email_certificate_task();
|
||||
$task->execute();
|
||||
$emails = $sink->get_messages();
|
||||
|
||||
$issues = $DB->get_records('customcert_issues');
|
||||
|
||||
$this->assertCount(2, $issues);
|
||||
$this->assertCount(0, $emails);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -39,8 +39,8 @@ class mod_customcert_generator extends testing_module_generator {
|
|||
* Creates an instance of the custom certificate.
|
||||
*
|
||||
* @param array|stdClass|null $record
|
||||
* @param array|null $options.
|
||||
* @return stdClass.
|
||||
* @param array|null $options
|
||||
* @return stdClass
|
||||
*/
|
||||
public function create_instance($record = null, array $options = null) {
|
||||
$record = (object)(array)$record;
|
||||
|
|
|
@ -44,7 +44,7 @@ if ($uploadform->is_cancelled()) {
|
|||
redirect(new moodle_url('/admin/settings.php?section=modsettingcustomcert'));
|
||||
} else if ($data = $uploadform->get_data()) {
|
||||
// Handle file uploads.
|
||||
\mod_customcert\certificate::upload_imagefiles($data->customcertimage, $context->id);
|
||||
\mod_customcert\certificate::upload_files($data->customcertimage, $context->id);
|
||||
|
||||
redirect(new moodle_url('/mod/customcert/upload_image.php'), get_string('changessaved'));
|
||||
}
|
||||
|
|
|
@ -22,25 +22,61 @@
|
|||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
*/
|
||||
|
||||
// @codingStandardsIgnoreLine
|
||||
require_once('../../config.php');
|
||||
|
||||
$contextid = required_param('contextid', PARAM_INT);
|
||||
$contextid = optional_param('contextid', context_system::instance()->id, PARAM_INT);
|
||||
$code = optional_param('code', '', PARAM_ALPHANUM); // The code for the certificate we are verifying.
|
||||
|
||||
// Need to be logged in.
|
||||
require_login();
|
||||
|
||||
// Ok, now check the user has the ability to verify certificates.
|
||||
require_capability('mod/customcert:verifycertificate', context::instance_by_id($contextid));
|
||||
$context = context::instance_by_id($contextid);
|
||||
|
||||
// Set up the page.
|
||||
$pageurl = new moodle_url('/mod/customcert/verify_certificate.php', array('contextid' => $contextid));
|
||||
|
||||
// Ok, a certificate was specified.
|
||||
if ($context->contextlevel != CONTEXT_SYSTEM) {
|
||||
$cm = get_coursemodule_from_id('customcert', $context->instanceid, 0, false, MUST_EXIST);
|
||||
$course = $DB->get_record('course', array('id' => $cm->course), '*', MUST_EXIST);
|
||||
$customcert = $DB->get_record('customcert', array('id' => $cm->instance), '*', MUST_EXIST);
|
||||
|
||||
// Check if we are allowing anyone to verify, if so, no need to check login, or permissions.
|
||||
if (!$customcert->verifyany) {
|
||||
// Need to be logged in.
|
||||
require_login($course, false, $cm);
|
||||
// Ok, now check the user has the ability to verify certificates.
|
||||
require_capability('mod/customcert:verifycertificate', $context);
|
||||
} else {
|
||||
$PAGE->set_cm($cm, $course);
|
||||
}
|
||||
|
||||
$checkallofsite = false;
|
||||
} else {
|
||||
// If the 'verifyallcertificates' is not set and the user does not have the capability 'mod/customcert:verifyallcertificates'
|
||||
// then show them a message letting them know they can not proceed.
|
||||
$verifyallcertificates = get_config('customcert', 'verifyallcertificates');
|
||||
$canverifyallcertificates = has_capability('mod/customcert:verifyallcertificates', $context);
|
||||
if (!$verifyallcertificates && !$canverifyallcertificates) {
|
||||
$strheading = get_string('verifycertificate', 'customcert');
|
||||
$PAGE->navbar->add($strheading);
|
||||
$PAGE->set_context(context_system::instance());
|
||||
$PAGE->set_title($strheading);
|
||||
$PAGE->set_url($pageurl);
|
||||
echo $OUTPUT->header();
|
||||
echo $OUTPUT->heading($strheading);
|
||||
echo $OUTPUT->notification(get_string('cannotverifyallcertificates', 'customcert'));
|
||||
echo $OUTPUT->footer();
|
||||
exit();
|
||||
}
|
||||
|
||||
$checkallofsite = true;
|
||||
}
|
||||
|
||||
if ($code) {
|
||||
$pageurl->param('code', $code);
|
||||
}
|
||||
|
||||
$PAGE->set_url($pageurl);
|
||||
$PAGE->set_context(context_system::instance());
|
||||
$PAGE->set_context($context);
|
||||
$PAGE->set_title(get_string('verifycertificate', 'customcert'));
|
||||
|
||||
// The form we are using to verify these codes.
|
||||
|
@ -53,7 +89,7 @@ if ($form->get_data()) {
|
|||
// Ok, now check if the code is valid.
|
||||
$userfields = get_all_user_name_fields(true, 'u');
|
||||
$sql = "SELECT ci.id, u.id as userid, $userfields, co.id as courseid,
|
||||
co.fullname as coursefullname, c.name as certificatename
|
||||
co.fullname as coursefullname, c.name as certificatename, c.verifyany
|
||||
FROM {customcert} c
|
||||
JOIN {customcert_issues} ci
|
||||
ON c.id = ci.customcertid
|
||||
|
@ -61,10 +97,23 @@ if ($form->get_data()) {
|
|||
ON c.course = co.id
|
||||
JOIN {user} u
|
||||
ON ci.userid = u.id
|
||||
WHERE ci.code = :code
|
||||
AND u.deleted = 0";
|
||||
WHERE ci.code = :code";
|
||||
|
||||
if ($checkallofsite) {
|
||||
// Only people with the capability to verify all the certificates can verify any.
|
||||
if (!$canverifyallcertificates) {
|
||||
$sql .= " AND c.verifyany = 1";
|
||||
}
|
||||
$params = ['code' => $code];
|
||||
} else {
|
||||
$sql .= " AND c.id = :customcertid";
|
||||
$params = ['code' => $code, 'customcertid' => $customcert->id];
|
||||
}
|
||||
|
||||
$sql .= " AND u.deleted = 0";
|
||||
|
||||
// It is possible (though unlikely) that there is the same code for issued certificates.
|
||||
if ($issues = $DB->get_records_sql($sql, array('code' => $code))) {
|
||||
if ($issues = $DB->get_records_sql($sql, $params)) {
|
||||
$result->success = true;
|
||||
$result->issues = $issues;
|
||||
} else {
|
||||
|
|
|
@ -24,10 +24,10 @@
|
|||
|
||||
defined('MOODLE_INTERNAL') || die('Direct access to this script is forbidden.');
|
||||
|
||||
$plugin->version = 2016120506; // The current module version (Date: YYYYMMDDXX).
|
||||
$plugin->version = 2016120516; // The current module version (Date: YYYYMMDDXX).
|
||||
$plugin->requires = 2016120500; // Requires this Moodle version (3.2).
|
||||
$plugin->cron = 0; // Period for cron to check this module (secs).
|
||||
$plugin->component = 'mod_customcert';
|
||||
|
||||
$plugin->maturity = MATURITY_STABLE;
|
||||
$plugin->release = "3.2 release (Build: 2016120506)"; // User-friendly version number.
|
||||
$plugin->release = "3.2 release (Build: 2016120516)"; // User-friendly version number.
|
||||
|
|
16
view.php
16
view.php
|
@ -68,7 +68,7 @@ if (empty($action)) {
|
|||
|
||||
// Generate the link to the report if there are issues to display.
|
||||
$reportlink = '';
|
||||
if (has_capability('mod/customcert:manage', $context)) {
|
||||
if (has_capability('mod/customcert:viewreport', $context)) {
|
||||
// Get the total number of issues.
|
||||
$numissues = \mod_customcert\certificate::get_number_of_issues($customcert->id, $cm, $groupmode);
|
||||
$href = new moodle_urL('/mod/customcert/report.php', array('id' => $cm->id));
|
||||
|
@ -121,20 +121,20 @@ if (empty($action)) {
|
|||
} else { // Output to pdf.
|
||||
// Create new customcert issue record if one does not already exist.
|
||||
if (!$DB->record_exists('customcert_issues', array('userid' => $USER->id, 'customcertid' => $customcert->id))) {
|
||||
$customcertissue = new stdClass();
|
||||
$customcertissue->customcertid = $customcert->id;
|
||||
$customcertissue->userid = $USER->id;
|
||||
$customcertissue->code = \mod_customcert\certificate::generate_code();
|
||||
$customcertissue->timecreated = time();
|
||||
// Insert the record into the database.
|
||||
$DB->insert_record('customcert_issues', $customcertissue);
|
||||
\mod_customcert\certificate::issue_certificate($customcert->id, $USER->id);
|
||||
}
|
||||
|
||||
// Set the custom certificate as viewed.
|
||||
$completion = new completion_info($course);
|
||||
$completion->set_module_viewed($cm);
|
||||
|
||||
// Hack alert - don't initiate the download when running Behat.
|
||||
if (defined('BEHAT_SITE_RUNNING')) {
|
||||
redirect(new moodle_url('/mod/customcert/view.php', array('id' => $cm->id)));
|
||||
}
|
||||
|
||||
// Now we want to generate the PDF.
|
||||
$template = new \mod_customcert\template($template);
|
||||
$template->generate_pdf();
|
||||
exit();
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue