From 09d7812fe1f985070bad4a1d7013dcc5ff553528 Mon Sep 17 00:00:00 2001 From: Mark Nelson Date: Mon, 13 Nov 2017 11:33:41 +0800 Subject: [PATCH 01/93] Updated travis --- .travis.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.travis.yml b/.travis.yml index b105091a8..f2065687e 100644 --- a/.travis.yml +++ b/.travis.yml @@ -7,15 +7,15 @@ cache: - $HOME/.composer/cache php: - - 5.6 - 7.0 + - 7.1 addons: postgresql: 9.3 env: global: - - MOODLE_BRANCH=MOODLE_33_STABLE + - MOODLE_BRANCH=MOODLE_34_STABLE matrix: - DB=pgsql - DB=mysqli From 60398c42aad1090a879ee9a213340a675233bdcf Mon Sep 17 00:00:00 2001 From: Mark Nelson Date: Mon, 13 Nov 2017 11:38:33 +0800 Subject: [PATCH 02/93] Bumped version for 3.4 --- element/bgimage/version.php | 4 ++-- element/border/version.php | 4 ++-- element/categoryname/version.php | 4 ++-- element/code/version.php | 4 ++-- element/coursename/version.php | 4 ++-- element/date/version.php | 4 ++-- element/digitalsignature/version.php | 4 ++-- element/grade/version.php | 4 ++-- element/gradeitemname/version.php | 4 ++-- element/image/version.php | 4 ++-- element/studentname/version.php | 4 ++-- element/teachername/version.php | 4 ++-- element/text/version.php | 4 ++-- element/userfield/version.php | 4 ++-- element/userpicture/version.php | 4 ++-- version.php | 6 +++--- 16 files changed, 33 insertions(+), 33 deletions(-) diff --git a/element/bgimage/version.php b/element/bgimage/version.php index 7ded31f64..847512d54 100644 --- a/element/bgimage/version.php +++ b/element/bgimage/version.php @@ -24,6 +24,6 @@ defined('MOODLE_INTERNAL') || die('Direct access to this script is forbidden.'); -$plugin->version = 2017050500; // The current module version (Date: YYYYMMDDXX). -$plugin->requires = 2017050500; // Requires this Moodle version (3.3). +$plugin->version = 2017111300; // The current module version (Date: YYYYMMDDXX). +$plugin->requires = 2017111300; // Requires this Moodle version (3.4). $plugin->component = 'customcertelement_bgimage'; diff --git a/element/border/version.php b/element/border/version.php index aec8ecacb..2aa335097 100644 --- a/element/border/version.php +++ b/element/border/version.php @@ -24,6 +24,6 @@ defined('MOODLE_INTERNAL') || die('Direct access to this script is forbidden.'); -$plugin->version = 2017050500; // The current module version (Date: YYYYMMDDXX). -$plugin->requires = 2017050500; // Requires this Moodle version (3.3). +$plugin->version = 2017111300; // The current module version (Date: YYYYMMDDXX). +$plugin->requires = 2017111300; // Requires this Moodle version (3.4). $plugin->component = 'customcertelement_border'; diff --git a/element/categoryname/version.php b/element/categoryname/version.php index ec4c99a38..6f9b86535 100644 --- a/element/categoryname/version.php +++ b/element/categoryname/version.php @@ -24,6 +24,6 @@ defined('MOODLE_INTERNAL') || die('Direct access to this script is forbidden.'); -$plugin->version = 2017050500; // The current module version (Date: YYYYMMDDXX). -$plugin->requires = 2017050500; // Requires this Moodle version (3.3). +$plugin->version = 2017111300; // The current module version (Date: YYYYMMDDXX). +$plugin->requires = 2017111300; // Requires this Moodle version (3.4). $plugin->component = 'customcertelement_categoryname'; diff --git a/element/code/version.php b/element/code/version.php index 80ac61995..b95025a73 100644 --- a/element/code/version.php +++ b/element/code/version.php @@ -24,6 +24,6 @@ defined('MOODLE_INTERNAL') || die('Direct access to this script is forbidden.'); -$plugin->version = 2017050500; // The current module version (Date: YYYYMMDDXX). -$plugin->requires = 2017050500; // Requires this Moodle version (3.3). +$plugin->version = 2017111300; // The current module version (Date: YYYYMMDDXX). +$plugin->requires = 2017111300; // Requires this Moodle version (3.4). $plugin->component = 'customcertelement_code'; diff --git a/element/coursename/version.php b/element/coursename/version.php index 2ba2993c7..0bf953167 100644 --- a/element/coursename/version.php +++ b/element/coursename/version.php @@ -24,6 +24,6 @@ defined('MOODLE_INTERNAL') || die('Direct access to this script is forbidden.'); -$plugin->version = 2017050500; // The current module version (Date: YYYYMMDDXX). -$plugin->requires = 2017050500; // Requires this Moodle version (3.3). +$plugin->version = 2017111300; // The current module version (Date: YYYYMMDDXX). +$plugin->requires = 2017111300; // Requires this Moodle version (3.4). $plugin->component = 'customcertelement_coursename'; diff --git a/element/date/version.php b/element/date/version.php index a81b9d0ce..d98a3164c 100644 --- a/element/date/version.php +++ b/element/date/version.php @@ -24,6 +24,6 @@ defined('MOODLE_INTERNAL') || die('Direct access to this script is forbidden.'); -$plugin->version = 2017050500; // The current module version (Date: YYYYMMDDXX). -$plugin->requires = 2017050500; // Requires this Moodle version (3.3). +$plugin->version = 2017111300; // The current module version (Date: YYYYMMDDXX). +$plugin->requires = 2017111300; // Requires this Moodle version (3.4). $plugin->component = 'customcertelement_date'; diff --git a/element/digitalsignature/version.php b/element/digitalsignature/version.php index e35d28051..01892ac0c 100644 --- a/element/digitalsignature/version.php +++ b/element/digitalsignature/version.php @@ -24,6 +24,6 @@ defined('MOODLE_INTERNAL') || die('Direct access to this script is forbidden.'); -$plugin->version = 2017050500; // The current module version (Date: YYYYMMDDXX). -$plugin->requires = 2017050500; // Requires this Moodle version (3.3). +$plugin->version = 2017111300; // The current module version (Date: YYYYMMDDXX). +$plugin->requires = 2017111300; // Requires this Moodle version (3.4). $plugin->component = 'customcertelement_digitalsignature'; diff --git a/element/grade/version.php b/element/grade/version.php index cd59a8796..8f24b547f 100644 --- a/element/grade/version.php +++ b/element/grade/version.php @@ -24,6 +24,6 @@ defined('MOODLE_INTERNAL') || die('Direct access to this script is forbidden.'); -$plugin->version = 2017050500; // The current module version (Date: YYYYMMDDXX). -$plugin->requires = 2017050500; // Requires this Moodle version (3.3). +$plugin->version = 2017111300; // The current module version (Date: YYYYMMDDXX). +$plugin->requires = 2017111300; // Requires this Moodle version (3.4). $plugin->component = 'customcertelement_grade'; diff --git a/element/gradeitemname/version.php b/element/gradeitemname/version.php index b6265f4f1..9aff1dc4e 100644 --- a/element/gradeitemname/version.php +++ b/element/gradeitemname/version.php @@ -24,6 +24,6 @@ defined('MOODLE_INTERNAL') || die('Direct access to this script is forbidden.'); -$plugin->version = 2017050500; // The current module version (Date: YYYYMMDDXX). -$plugin->requires = 2017050500; // Requires this Moodle version (3.3). +$plugin->version = 2017111300; // The current module version (Date: YYYYMMDDXX). +$plugin->requires = 2017111300; // Requires this Moodle version (3.4). $plugin->component = 'customcertelement_gradeitemname'; diff --git a/element/image/version.php b/element/image/version.php index 3aaf16c9d..55e6c8161 100644 --- a/element/image/version.php +++ b/element/image/version.php @@ -24,6 +24,6 @@ defined('MOODLE_INTERNAL') || die('Direct access to this script is forbidden.'); -$plugin->version = 2017050500; // The current module version (Date: YYYYMMDDXX). -$plugin->requires = 2017050500; // Requires this Moodle version (3.3). +$plugin->version = 2017111300; // The current module version (Date: YYYYMMDDXX). +$plugin->requires = 2017111300; // Requires this Moodle version (3.4). $plugin->component = 'customcertelement_image'; diff --git a/element/studentname/version.php b/element/studentname/version.php index dd4ccef68..cb37cfa68 100644 --- a/element/studentname/version.php +++ b/element/studentname/version.php @@ -24,6 +24,6 @@ defined('MOODLE_INTERNAL') || die('Direct access to this script is forbidden.'); -$plugin->version = 2017050500; // The current module version (Date: YYYYMMDDXX). -$plugin->requires = 2017050500; // Requires this Moodle version (3.3). +$plugin->version = 2017111300; // The current module version (Date: YYYYMMDDXX). +$plugin->requires = 2017111300; // Requires this Moodle version (3.4). $plugin->component = 'customcertelement_studentname'; diff --git a/element/teachername/version.php b/element/teachername/version.php index 8b41b889a..f11f0ceb1 100644 --- a/element/teachername/version.php +++ b/element/teachername/version.php @@ -24,6 +24,6 @@ defined('MOODLE_INTERNAL') || die('Direct access to this script is forbidden.'); -$plugin->version = 2017050500; // The current module version (Date: YYYYMMDDXX). -$plugin->requires = 2017050500; // Requires this Moodle version (3.3). +$plugin->version = 2017111300; // The current module version (Date: YYYYMMDDXX). +$plugin->requires = 2017111300; // Requires this Moodle version (3.4). $plugin->component = 'customcertelement_teachername'; diff --git a/element/text/version.php b/element/text/version.php index 705f10af8..0084c3ad6 100644 --- a/element/text/version.php +++ b/element/text/version.php @@ -24,6 +24,6 @@ defined('MOODLE_INTERNAL') || die('Direct access to this script is forbidden.'); -$plugin->version = 2017050500; // The current module version (Date: YYYYMMDDXX). -$plugin->requires = 2017050500; // Requires this Moodle version (3.3). +$plugin->version = 2017111300; // The current module version (Date: YYYYMMDDXX). +$plugin->requires = 2017111300; // Requires this Moodle version (3.4). $plugin->component = 'customcertelement_text'; diff --git a/element/userfield/version.php b/element/userfield/version.php index cb0207ccc..b908ffbd5 100644 --- a/element/userfield/version.php +++ b/element/userfield/version.php @@ -24,6 +24,6 @@ defined('MOODLE_INTERNAL') || die('Direct access to this script is forbidden.'); -$plugin->version = 2017050500; // The current module version (Date: YYYYMMDDXX). -$plugin->requires = 2017050500; // Requires this Moodle version (3.3). +$plugin->version = 2017111300; // The current module version (Date: YYYYMMDDXX). +$plugin->requires = 2017111300; // Requires this Moodle version (3.4). $plugin->component = 'customcertelement_userfield'; diff --git a/element/userpicture/version.php b/element/userpicture/version.php index 1df9c7d56..f6a3173d2 100644 --- a/element/userpicture/version.php +++ b/element/userpicture/version.php @@ -24,6 +24,6 @@ defined('MOODLE_INTERNAL') || die('Direct access to this script is forbidden.'); -$plugin->version = 2017050500; // The current module version (Date: YYYYMMDDXX). -$plugin->requires = 2017050500; // Requires this Moodle version (3.3). +$plugin->version = 2017111300; // The current module version (Date: YYYYMMDDXX). +$plugin->requires = 2017111300; // Requires this Moodle version (3.4). $plugin->component = 'customcertelement_userpicture'; diff --git a/version.php b/version.php index 57cd0dc99..7588a9ccc 100644 --- a/version.php +++ b/version.php @@ -24,10 +24,10 @@ defined('MOODLE_INTERNAL') || die('Direct access to this script is forbidden.'); -$plugin->version = 2017050509; // The current module version (Date: YYYYMMDDXX). -$plugin->requires = 2017050500; // Requires this Moodle version (3.3). +$plugin->version = 2017111300; // The current module version (Date: YYYYMMDDXX). +$plugin->requires = 2017111300; // Requires this Moodle version (3.4). $plugin->cron = 0; // Period for cron to check this module (secs). $plugin->component = 'mod_customcert'; $plugin->maturity = MATURITY_STABLE; -$plugin->release = "3.3 release (Build: 2017050509)"; // User-friendly version number. +$plugin->release = "3.4 release (Build: 2017111300)"; // User-friendly version number. From 52d161390266d87c222843b992cdbc7ae40d28d6 Mon Sep 17 00:00:00 2001 From: Mark Nelson Date: Mon, 4 Dec 2017 21:19:54 +0800 Subject: [PATCH 03/93] Coding style fixes --- amd/build/rearrange-area.min.js | 2 +- amd/src/rearrange-area.js | 2 +- tests/generator/lib.php | 4 ++-- verify_certificate.php | 1 + 4 files changed, 5 insertions(+), 4 deletions(-) diff --git a/amd/build/rearrange-area.min.js b/amd/build/rearrange-area.min.js index 3622b193d..6df33c4f7 100644 --- a/amd/build/rearrange-area.min.js +++ b/amd/build/rearrange-area.min.js @@ -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,"
",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)}}}); \ No newline at end of file +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,"
",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)}}}); \ No newline at end of file diff --git a/amd/src/rearrange-area.js b/amd/src/rearrange-area.js index 7e42270f1..ea7905148 100644 --- a/amd/src/rearrange-area.js +++ b/amd/src/rearrange-area.js @@ -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)); diff --git a/tests/generator/lib.php b/tests/generator/lib.php index bcc3d2ffc..edc4c26fe 100644 --- a/tests/generator/lib.php +++ b/tests/generator/lib.php @@ -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; diff --git a/verify_certificate.php b/verify_certificate.php index f3a8cc94b..8c3bff7ce 100644 --- a/verify_certificate.php +++ b/verify_certificate.php @@ -22,6 +22,7 @@ * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later */ +// @codingStandardsIgnoreLine require_once('../../config.php'); $contextid = optional_param('contextid', context_system::instance()->id, PARAM_INT); From b14ccbba574815b2706cffc3ed3493fe755cbae9 Mon Sep 17 00:00:00 2001 From: Mark Nelson Date: Thu, 22 Feb 2018 18:49:48 +0800 Subject: [PATCH 04/93] #166 Fixed encoding content links --- backup/moodle2/backup_customcert_activity_task.class.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/backup/moodle2/backup_customcert_activity_task.class.php b/backup/moodle2/backup_customcert_activity_task.class.php index 321e24214..a071cc3da 100644 --- a/backup/moodle2/backup_customcert_activity_task.class.php +++ b/backup/moodle2/backup_customcert_activity_task.class.php @@ -63,11 +63,11 @@ static public function encode_content_links($content) { // 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; } From 666ed6b2d4a71b48ca9de4051bcfd072d160533e Mon Sep 17 00:00:00 2001 From: Mark Nelson Date: Thu, 22 Feb 2018 19:07:13 +0800 Subject: [PATCH 05/93] #169 Ensure we backup the 'verifyany' setting --- backup/moodle2/backup_customcert_stepslib.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/backup/moodle2/backup_customcert_stepslib.php b/backup/moodle2/backup_customcert_stepslib.php index 8567e0a24..e6bf6170a 100644 --- a/backup/moodle2/backup_customcert_stepslib.php +++ b/backup/moodle2/backup_customcert_stepslib.php @@ -42,7 +42,7 @@ protected function define_structure() { // 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. From 78931854ee44cc7fae3eb3f7c62f804f75952c6a Mon Sep 17 00:00:00 2001 From: Eugene Venter Date: Tue, 27 Mar 2018 15:30:50 +1300 Subject: [PATCH 06/93] #173 Fix race condition on certificate issues in scheduled task --- classes/task/email_certificate_task.php | 25 +++++++++++++++---------- 1 file changed, 15 insertions(+), 10 deletions(-) diff --git a/classes/task/email_certificate_task.php b/classes/task/email_certificate_task.php index 80b6f52d1..3a305a86d 100644 --- a/classes/task/email_certificate_task.php +++ b/classes/task/email_certificate_task.php @@ -125,16 +125,21 @@ public function execute() { } } - // 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. + $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); + } // Add them to the array so we email them. $enroluser->issueid = $issueid; From 787e370907053850a574e9473114983b972a9cd6 Mon Sep 17 00:00:00 2001 From: Mark Nelson Date: Tue, 15 May 2018 12:27:33 +0800 Subject: [PATCH 07/93] Bumped to PHP 7.2 in travis.yml --- .travis.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index f2065687e..08d8b3c99 100644 --- a/.travis.yml +++ b/.travis.yml @@ -8,7 +8,7 @@ cache: php: - 7.0 - - 7.1 + - 7.2 addons: postgresql: 9.3 From 1e977bbf311d434276f3d5cdb0cb0e9cbcabbfec Mon Sep 17 00:00:00 2001 From: Mark Nelson Date: Tue, 15 May 2018 16:31:06 +0800 Subject: [PATCH 08/93] #189 Implemented privacy provider for GDPR compliance --- classes/privacy/provider.php | 237 ++++++++++++++++++ element/bgimage/classes/privacy/provider.php | 46 ++++ .../lang/en/customcertelement_bgimage.php | 1 + element/border/classes/privacy/provider.php | 46 ++++ .../lang/en/customcertelement_border.php | 1 + .../categoryname/classes/privacy/provider.php | 46 ++++ .../en/customcertelement_categoryname.php | 1 + element/code/classes/privacy/provider.php | 46 ++++ .../code/lang/en/customcertelement_code.php | 1 + .../coursename/classes/privacy/provider.php | 46 ++++ .../lang/en/customcertelement_coursename.php | 1 + element/date/classes/privacy/provider.php | 46 ++++ .../date/lang/en/customcertelement_date.php | 1 + .../classes/privacy/provider.php | 46 ++++ .../en/customcertelement_digitalsignature.php | 1 + element/grade/classes/privacy/provider.php | 46 ++++ .../grade/lang/en/customcertelement_grade.php | 1 + .../classes/privacy/provider.php | 46 ++++ .../en/customcertelement_gradeitemname.php | 1 + element/image/classes/privacy/provider.php | 46 ++++ .../image/lang/en/customcertelement_image.php | 1 + .../studentname/classes/privacy/provider.php | 46 ++++ .../lang/en/customcertelement_studentname.php | 1 + .../teachername/classes/privacy/provider.php | 46 ++++ .../lang/en/customcertelement_teachername.php | 1 + element/text/classes/privacy/provider.php | 46 ++++ .../text/lang/en/customcertelement_text.php | 1 + .../userfield/classes/privacy/provider.php | 46 ++++ .../lang/en/customcertelement_userfield.php | 1 + .../userpicture/classes/privacy/provider.php | 46 ++++ .../lang/en/customcertelement_userpicture.php | 1 + lang/en/customcert.php | 6 + tests/privacy_provider_test.php | 207 +++++++++++++++ 33 files changed, 1155 insertions(+) create mode 100644 classes/privacy/provider.php create mode 100644 element/bgimage/classes/privacy/provider.php create mode 100644 element/border/classes/privacy/provider.php create mode 100644 element/categoryname/classes/privacy/provider.php create mode 100644 element/code/classes/privacy/provider.php create mode 100644 element/coursename/classes/privacy/provider.php create mode 100644 element/date/classes/privacy/provider.php create mode 100644 element/digitalsignature/classes/privacy/provider.php create mode 100644 element/grade/classes/privacy/provider.php create mode 100644 element/gradeitemname/classes/privacy/provider.php create mode 100644 element/image/classes/privacy/provider.php create mode 100644 element/studentname/classes/privacy/provider.php create mode 100644 element/teachername/classes/privacy/provider.php create mode 100644 element/text/classes/privacy/provider.php create mode 100644 element/userfield/classes/privacy/provider.php create mode 100644 element/userpicture/classes/privacy/provider.php create mode 100644 tests/privacy_provider_test.php diff --git a/classes/privacy/provider.php b/classes/privacy/provider.php new file mode 100644 index 000000000..d2119a48b --- /dev/null +++ b/classes/privacy/provider.php @@ -0,0 +1,237 @@ +. + +/** + * Privacy Subsystem implementation for mod_customcert. + * + * @package mod_customcert + * @copyright 2018 Mark Nelson + * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later + */ +namespace mod_customcert\privacy; + +use core_privacy\local\metadata\collection; +use core_privacy\local\request\approved_contextlist; +use core_privacy\local\request\contextlist; +use core_privacy\local\request\helper; +use core_privacy\local\request\transform; +use core_privacy\local\request\writer; + +defined('MOODLE_INTERNAL') || die(); + +/** + * Privacy Subsystem implementation for mod_customcert. + * + * @copyright 2018 Mark Nelson + * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later + */ +class provider implements + \core_privacy\local\metadata\provider, + \core_privacy\local\request\plugin\provider { + + /** + * Return the fields which contain personal data. + * + * @param collection $items a reference to the collection to use to store the metadata. + * @return collection the updated collection of metadata items. + */ + public static function get_metadata(collection $items) : collection { + $items->add_database_table( + 'customcert_issues', + [ + 'userid' => 'privacy:metadata:customcert_issues:userid', + 'customcertid' => 'privacy:metadata:customcert_issues:customcertid', + 'code' => 'privacy:metadata:customcert_issues:code', + 'emailed' => 'privacy:metadata:customcert_issues:emailed', + 'timecreated' => 'privacy:metadata:customcert_issues:timecreated', + ], + 'privacy:metadata:customcert_issues' + ); + + return $items; + } + + /** + * Get the list of contexts that contain user information for the specified user. + * + * @param int $userid the userid. + * @return contextlist the list of contexts containing user info for the user. + */ + public static function get_contexts_for_userid(int $userid) : contextlist { + $sql = "SELECT c.id + FROM {context} c + INNER JOIN {course_modules} cm + ON cm.id = c.instanceid + AND c.contextlevel = :contextlevel + INNER JOIN {modules} m + ON m.id = cm.module + AND m.name = :modulename + INNER JOIN {customcert} customcert + ON customcert.id = cm.instance + INNER JOIN {customcert_issues} customcertissues + ON customcertissues.customcertid = customcert.id + WHERE customcertissues.userid = :userid"; + + $params = [ + 'modulename' => 'customcert', + 'contextlevel' => CONTEXT_MODULE, + 'userid' => $userid, + ]; + $contextlist = new contextlist(); + $contextlist->add_from_sql($sql, $params); + + return $contextlist; + } + + /** + * Export personal data for the given approved_contextlist. User and context information is contained within the contextlist. + * + * @param approved_contextlist $contextlist a list of contexts approved for export. + */ + public static function export_user_data(approved_contextlist $contextlist) { + global $DB; + + // Filter out any contexts that are not related to modules. + $cmids = array_reduce($contextlist->get_contexts(), function($carry, $context) { + if ($context->contextlevel == CONTEXT_MODULE) { + $carry[] = $context->instanceid; + } + return $carry; + }, []); + + if (empty($cmids)) { + return; + } + + $user = $contextlist->get_user(); + + // Get all the customcert activities associated with the above course modules. + $customcertidstocmids = self::get_customcert_ids_to_cmids_from_cmids($cmids); + + list($insql, $inparams) = $DB->get_in_or_equal(array_keys($customcertidstocmids), SQL_PARAMS_NAMED); + $params = array_merge($inparams, ['userid' => $user->id]); + $recordset = $DB->get_recordset_select('customcert_issues', "customcertid $insql AND userid = :userid", + $params, 'timecreated, id ASC'); + self::recordset_loop_and_export($recordset, 'customcertid', [], function($carry, $record) { + $carry[] = [ + 'code' => $record->code, + 'emailed' => transform::yesno($record->emailed), + 'timecreated' => transform::datetime($record->timecreated) + ]; + return $carry; + }, function($customcertid, $data) use ($user, $customcertidstocmids) { + $context = \context_module::instance($customcertidstocmids[$customcertid]); + $contextdata = helper::get_context_data($context, $user); + $finaldata = (object) array_merge((array) $contextdata, ['issues' => $data]); + helper::export_context_files($context, $user); + writer::with_context($context)->export_data([], $finaldata); + }); + } + + /** + * Delete all data for all users in the specified context. + * + * @param \context $context the context to delete in. + */ + public static function delete_data_for_all_users_in_context(\context $context) { + global $DB; + + if (!$context instanceof \context_module) { + return; + } + + if (!$cm = get_coursemodule_from_id('customcert', $context->instanceid)) { + return; + } + + $DB->delete_records('customcert_issues', ['customcertid' => $cm->instance]); + } + + /** + * Delete all user data for the specified user, in the specified contexts. + * + * @param approved_contextlist $contextlist a list of contexts approved for deletion. + */ + public static function delete_data_for_user(approved_contextlist $contextlist) { + global $DB; + + if (empty($contextlist->count())) { + return; + } + + $userid = $contextlist->get_user()->id; + foreach ($contextlist->get_contexts() as $context) { + if (!$context instanceof \context_module) { + continue; + } + $instanceid = $DB->get_field('course_modules', 'instance', ['id' => $context->instanceid], MUST_EXIST); + $DB->delete_records('customcert_issues', ['customcertid' => $instanceid, 'userid' => $userid]); + } + } + + /** + * Return a list of Customcert IDs mapped to their course module ID. + * + * @param array $cmids The course module IDs. + * @return array In the form of [$customcertid => $cmid]. + */ + protected static function get_customcert_ids_to_cmids_from_cmids(array $cmids) { + global $DB; + + list($insql, $inparams) = $DB->get_in_or_equal($cmids, SQL_PARAMS_NAMED); + $sql = "SELECT customcert.id, cm.id AS cmid + FROM {customcert} customcert + JOIN {modules} m + ON m.name = :modulename + JOIN {course_modules} cm + ON cm.instance = customcert.id + AND cm.module = m.id + WHERE cm.id $insql"; + $params = array_merge($inparams, ['modulename' => 'customcert']); + + return $DB->get_records_sql_menu($sql, $params); + } + + /** + * Loop and export from a recordset. + * + * @param \moodle_recordset $recordset The recordset. + * @param string $splitkey The record key to determine when to export. + * @param mixed $initial The initial data to reduce from. + * @param callable $reducer The function to return the dataset, receives current dataset, and the current record. + * @param callable $export The function to export the dataset, receives the last value from $splitkey and the dataset. + * @return void + */ + protected static function recordset_loop_and_export(\moodle_recordset $recordset, $splitkey, $initial, + callable $reducer, callable $export) { + $data = $initial; + $lastid = null; + + foreach ($recordset as $record) { + if ($lastid && $record->{$splitkey} != $lastid) { + $export($lastid, $data); + $data = $initial; + } + $data = $reducer($data, $record); + $lastid = $record->{$splitkey}; + } + $recordset->close(); + + if (!empty($lastid)) { + $export($lastid, $data); + } + } +} diff --git a/element/bgimage/classes/privacy/provider.php b/element/bgimage/classes/privacy/provider.php new file mode 100644 index 000000000..61a208273 --- /dev/null +++ b/element/bgimage/classes/privacy/provider.php @@ -0,0 +1,46 @@ +. + +/** + * Privacy Subsystem implementation for customcertelement_bgimage. + * + * @package customcertelement_bgimage + * @copyright 2018 Mark Nelson + * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later + */ + +namespace customcertelement_bgimage\privacy; + +defined('MOODLE_INTERNAL') || die(); + +/** + * Privacy Subsystem for customcertelement_bgimage implementing null_provider. + * + * @copyright 2018 Mark Nelson + * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later + */ +class provider implements \core_privacy\local\metadata\null_provider { + + /** + * Get the language string identifier with the component's language + * file to explain why this plugin stores no data. + * + * @return string + */ + public static function get_reason() : string { + return 'privacy:metadata'; + } +} diff --git a/element/bgimage/lang/en/customcertelement_bgimage.php b/element/bgimage/lang/en/customcertelement_bgimage.php index ef6357c08..467bfa250 100644 --- a/element/bgimage/lang/en/customcertelement_bgimage.php +++ b/element/bgimage/lang/en/customcertelement_bgimage.php @@ -23,3 +23,4 @@ */ $string['pluginname'] = 'Background image'; +$string['privacy:metadata'] = 'The Background image plugin does not store any personal data.'; diff --git a/element/border/classes/privacy/provider.php b/element/border/classes/privacy/provider.php new file mode 100644 index 000000000..0aa2b0a61 --- /dev/null +++ b/element/border/classes/privacy/provider.php @@ -0,0 +1,46 @@ +. + +/** + * Privacy Subsystem implementation for customcertelement_border. + * + * @package customcertelement_border + * @copyright 2018 Mark Nelson + * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later + */ + +namespace customcertelement_border\privacy; + +defined('MOODLE_INTERNAL') || die(); + +/** + * Privacy Subsystem for customcertelement_border implementing null_provider. + * + * @copyright 2018 Mark Nelson + * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later + */ +class provider implements \core_privacy\local\metadata\null_provider { + + /** + * Get the language string identifier with the component's language + * file to explain why this plugin stores no data. + * + * @return string + */ + public static function get_reason() : string { + return 'privacy:metadata'; + } +} diff --git a/element/border/lang/en/customcertelement_border.php b/element/border/lang/en/customcertelement_border.php index c6098e78c..b3e6aed85 100644 --- a/element/border/lang/en/customcertelement_border.php +++ b/element/border/lang/en/customcertelement_border.php @@ -23,6 +23,7 @@ */ $string['pluginname'] = 'Border'; +$string['privacy:metadata'] = 'The Border plugin does not store any personal data.'; $string['invalidwidth'] = 'The width has to be a valid number greater than 0.'; $string['width'] = 'Width'; $string['width_help'] = 'Width of the border in mm.'; diff --git a/element/categoryname/classes/privacy/provider.php b/element/categoryname/classes/privacy/provider.php new file mode 100644 index 000000000..bcdb8a759 --- /dev/null +++ b/element/categoryname/classes/privacy/provider.php @@ -0,0 +1,46 @@ +. + +/** + * Privacy Subsystem implementation for customcertelement_categoryname. + * + * @package customcertelement_categoryname + * @copyright 2018 Mark Nelson + * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later + */ + +namespace customcertelement_categoryname\privacy; + +defined('MOODLE_INTERNAL') || die(); + +/** + * Privacy Subsystem for customcertelement_categoryname implementing null_provider. + * + * @copyright 2018 Mark Nelson + * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later + */ +class provider implements \core_privacy\local\metadata\null_provider { + + /** + * Get the language string identifier with the component's language + * file to explain why this plugin stores no data. + * + * @return string + */ + public static function get_reason() : string { + return 'privacy:metadata'; + } +} diff --git a/element/categoryname/lang/en/customcertelement_categoryname.php b/element/categoryname/lang/en/customcertelement_categoryname.php index d537cc81f..a3c444ded 100644 --- a/element/categoryname/lang/en/customcertelement_categoryname.php +++ b/element/categoryname/lang/en/customcertelement_categoryname.php @@ -23,3 +23,4 @@ */ $string['pluginname'] = 'Category name'; +$string['privacy:metadata'] = 'The Category name plugin does not store any personal data.'; diff --git a/element/code/classes/privacy/provider.php b/element/code/classes/privacy/provider.php new file mode 100644 index 000000000..cbdbb5019 --- /dev/null +++ b/element/code/classes/privacy/provider.php @@ -0,0 +1,46 @@ +. + +/** + * Privacy Subsystem implementation for customcertelement_code. + * + * @package customcertelement_code + * @copyright 2018 Mark Nelson + * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later + */ + +namespace customcertelement_code\privacy; + +defined('MOODLE_INTERNAL') || die(); + +/** + * Privacy Subsystem for customcertelement_code implementing null_provider. + * + * @copyright 2018 Mark Nelson + * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later + */ +class provider implements \core_privacy\local\metadata\null_provider { + + /** + * Get the language string identifier with the component's language + * file to explain why this plugin stores no data. + * + * @return string + */ + public static function get_reason() : string { + return 'privacy:metadata'; + } +} diff --git a/element/code/lang/en/customcertelement_code.php b/element/code/lang/en/customcertelement_code.php index 03dea67c5..e67616c7b 100644 --- a/element/code/lang/en/customcertelement_code.php +++ b/element/code/lang/en/customcertelement_code.php @@ -23,3 +23,4 @@ */ $string['pluginname'] = 'Code'; +$string['privacy:metadata'] = 'The Code plugin does not store any personal data.'; diff --git a/element/coursename/classes/privacy/provider.php b/element/coursename/classes/privacy/provider.php new file mode 100644 index 000000000..1c2d02a3b --- /dev/null +++ b/element/coursename/classes/privacy/provider.php @@ -0,0 +1,46 @@ +. + +/** + * Privacy Subsystem implementation for customcertelement_coursename. + * + * @package customcertelement_coursename + * @copyright 2018 Mark Nelson + * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later + */ + +namespace customcertelement_coursename\privacy; + +defined('MOODLE_INTERNAL') || die(); + +/** + * Privacy Subsystem for customcertelement_coursename implementing null_provider. + * + * @copyright 2018 Mark Nelson + * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later + */ +class provider implements \core_privacy\local\metadata\null_provider { + + /** + * Get the language string identifier with the component's language + * file to explain why this plugin stores no data. + * + * @return string + */ + public static function get_reason() : string { + return 'privacy:metadata'; + } +} diff --git a/element/coursename/lang/en/customcertelement_coursename.php b/element/coursename/lang/en/customcertelement_coursename.php index 85c3b4af1..48781e419 100644 --- a/element/coursename/lang/en/customcertelement_coursename.php +++ b/element/coursename/lang/en/customcertelement_coursename.php @@ -23,3 +23,4 @@ */ $string['pluginname'] = 'Course name'; +$string['privacy:metadata'] = 'The Course name plugin does not store any personal data.'; diff --git a/element/date/classes/privacy/provider.php b/element/date/classes/privacy/provider.php new file mode 100644 index 000000000..1ce5f23d3 --- /dev/null +++ b/element/date/classes/privacy/provider.php @@ -0,0 +1,46 @@ +. + +/** + * Privacy Subsystem implementation for customcertelement_date. + * + * @package customcertelement_date + * @copyright 2018 Mark Nelson + * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later + */ + +namespace customcertelement_date\privacy; + +defined('MOODLE_INTERNAL') || die(); + +/** + * Privacy Subsystem for customcertelement_date implementing null_provider. + * + * @copyright 2018 Mark Nelson + * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later + */ +class provider implements \core_privacy\local\metadata\null_provider { + + /** + * Get the language string identifier with the component's language + * file to explain why this plugin stores no data. + * + * @return string + */ + public static function get_reason() : string { + return 'privacy:metadata'; + } +} diff --git a/element/date/lang/en/customcertelement_date.php b/element/date/lang/en/customcertelement_date.php index 23990c12c..366ac6ea0 100644 --- a/element/date/lang/en/customcertelement_date.php +++ b/element/date/lang/en/customcertelement_date.php @@ -32,6 +32,7 @@ $string['dateitem_help'] = 'This will be the date that is printed on the certificate'; $string['issueddate'] = 'Issued date'; $string['pluginname'] = 'Date'; +$string['privacy:metadata'] = 'The Date plugin does not store any personal data.'; $string['numbersuffix_nd_as_in_second'] = 'nd'; $string['numbersuffix_rd_as_in_third'] = 'rd'; $string['numbersuffix_st_as_in_first'] = 'st'; diff --git a/element/digitalsignature/classes/privacy/provider.php b/element/digitalsignature/classes/privacy/provider.php new file mode 100644 index 000000000..6e46add57 --- /dev/null +++ b/element/digitalsignature/classes/privacy/provider.php @@ -0,0 +1,46 @@ +. + +/** + * Privacy Subsystem implementation for customcertelement_digitalsignature. + * + * @package customcertelement_digitalsignature + * @copyright 2018 Mark Nelson + * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later + */ + +namespace customcertelement_digitalsignature\privacy; + +defined('MOODLE_INTERNAL') || die(); + +/** + * Privacy Subsystem for customcertelement_digitalsignature implementing null_provider. + * + * @copyright 2018 Mark Nelson + * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later + */ +class provider implements \core_privacy\local\metadata\null_provider { + + /** + * Get the language string identifier with the component's language + * file to explain why this plugin stores no data. + * + * @return string + */ + public static function get_reason() : string { + return 'privacy:metadata'; + } +} diff --git a/element/digitalsignature/lang/en/customcertelement_digitalsignature.php b/element/digitalsignature/lang/en/customcertelement_digitalsignature.php index 79a51cd67..81661f4fe 100644 --- a/element/digitalsignature/lang/en/customcertelement_digitalsignature.php +++ b/element/digitalsignature/lang/en/customcertelement_digitalsignature.php @@ -25,6 +25,7 @@ $string['digitalsignature'] = 'Digital signature'; $string['nosignature'] = 'No signature'; $string['pluginname'] = 'Digital signature'; +$string['privacy:metadata'] = 'The Digital signature plugin does not store any personal data.'; $string['signaturename'] = 'Signature name'; $string['signaturepassword'] = 'Signature password'; $string['signaturelocation'] = 'Signature location'; diff --git a/element/grade/classes/privacy/provider.php b/element/grade/classes/privacy/provider.php new file mode 100644 index 000000000..2f6b29599 --- /dev/null +++ b/element/grade/classes/privacy/provider.php @@ -0,0 +1,46 @@ +. + +/** + * Privacy Subsystem implementation for customcertelement_grade. + * + * @package customcertelement_grade + * @copyright 2018 Mark Nelson + * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later + */ + +namespace customcertelement_grade\privacy; + +defined('MOODLE_INTERNAL') || die(); + +/** + * Privacy Subsystem for customcertelement_grade implementing null_provider. + * + * @copyright 2018 Mark Nelson + * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later + */ +class provider implements \core_privacy\local\metadata\null_provider { + + /** + * Get the language string identifier with the component's language + * file to explain why this plugin stores no data. + * + * @return string + */ + public static function get_reason() : string { + return 'privacy:metadata'; + } +} diff --git a/element/grade/lang/en/customcertelement_grade.php b/element/grade/lang/en/customcertelement_grade.php index 2d4d4b511..903932983 100644 --- a/element/grade/lang/en/customcertelement_grade.php +++ b/element/grade/lang/en/customcertelement_grade.php @@ -33,3 +33,4 @@ $string['gradeletter'] = 'Letter'; $string['pluginname'] = 'Grade'; $string['previewgrade'] = 'Preview grade'; +$string['privacy:metadata'] = 'The Grade plugin does not store any personal data.'; diff --git a/element/gradeitemname/classes/privacy/provider.php b/element/gradeitemname/classes/privacy/provider.php new file mode 100644 index 000000000..8cf3b952e --- /dev/null +++ b/element/gradeitemname/classes/privacy/provider.php @@ -0,0 +1,46 @@ +. + +/** + * Privacy Subsystem implementation for customcertelement_gradeitemname. + * + * @package customcertelement_gradeitemname + * @copyright 2018 Mark Nelson + * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later + */ + +namespace customcertelement_gradeitemname\privacy; + +defined('MOODLE_INTERNAL') || die(); + +/** + * Privacy Subsystem for customcertelement_gradeitemname implementing null_provider. + * + * @copyright 2018 Mark Nelson + * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later + */ +class provider implements \core_privacy\local\metadata\null_provider { + + /** + * Get the language string identifier with the component's language + * file to explain why this plugin stores no data. + * + * @return string + */ + public static function get_reason() : string { + return 'privacy:metadata'; + } +} diff --git a/element/gradeitemname/lang/en/customcertelement_gradeitemname.php b/element/gradeitemname/lang/en/customcertelement_gradeitemname.php index 97fada36f..f76c40fda 100644 --- a/element/gradeitemname/lang/en/customcertelement_gradeitemname.php +++ b/element/gradeitemname/lang/en/customcertelement_gradeitemname.php @@ -25,3 +25,4 @@ $string['gradeitem'] = 'Grade item'; $string['gradeitem_help'] = 'The name of the selected item will be displayed on the PDF.'; $string['pluginname'] = 'Grade item name'; +$string['privacy:metadata'] = 'The Grade item name plugin does not store any personal data.'; diff --git a/element/image/classes/privacy/provider.php b/element/image/classes/privacy/provider.php new file mode 100644 index 000000000..f800d6c4e --- /dev/null +++ b/element/image/classes/privacy/provider.php @@ -0,0 +1,46 @@ +. + +/** + * Privacy Subsystem implementation for customcertelement_image. + * + * @package customcertelement_image + * @copyright 2018 Mark Nelson + * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later + */ + +namespace customcertelement_image\privacy; + +defined('MOODLE_INTERNAL') || die(); + +/** + * Privacy Subsystem for customcertelement_image implementing null_provider. + * + * @copyright 2018 Mark Nelson + * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later + */ +class provider implements \core_privacy\local\metadata\null_provider { + + /** + * Get the language string identifier with the component's language + * file to explain why this plugin stores no data. + * + * @return string + */ + public static function get_reason() : string { + return 'privacy:metadata'; + } +} diff --git a/element/image/lang/en/customcertelement_image.php b/element/image/lang/en/customcertelement_image.php index 659fca85b..1422b6b9e 100644 --- a/element/image/lang/en/customcertelement_image.php +++ b/element/image/lang/en/customcertelement_image.php @@ -28,5 +28,6 @@ $string['invalidheight'] = 'The height has to be a valid number greater than or equal to 0.'; $string['invalidwidth'] = 'The width has to be a valid number greater than or equal to 0.'; $string['pluginname'] = 'Image'; +$string['privacy:metadata'] = 'The Image plugin does not store any personal data.'; $string['width'] = 'Width'; $string['width_help'] = 'Width of the image in mm. If equal to zero, it is automatically calculated.'; diff --git a/element/studentname/classes/privacy/provider.php b/element/studentname/classes/privacy/provider.php new file mode 100644 index 000000000..a7ae40215 --- /dev/null +++ b/element/studentname/classes/privacy/provider.php @@ -0,0 +1,46 @@ +. + +/** + * Privacy Subsystem implementation for customcertelement_studentname. + * + * @package customcertelement_studentname + * @copyright 2018 Mark Nelson + * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later + */ + +namespace customcertelement_studentname\privacy; + +defined('MOODLE_INTERNAL') || die(); + +/** + * Privacy Subsystem for customcertelement_studentname implementing null_provider. + * + * @copyright 2018 Mark Nelson + * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later + */ +class provider implements \core_privacy\local\metadata\null_provider { + + /** + * Get the language string identifier with the component's language + * file to explain why this plugin stores no data. + * + * @return string + */ + public static function get_reason() : string { + return 'privacy:metadata'; + } +} diff --git a/element/studentname/lang/en/customcertelement_studentname.php b/element/studentname/lang/en/customcertelement_studentname.php index 9811fa6b6..9e6fd3fb1 100644 --- a/element/studentname/lang/en/customcertelement_studentname.php +++ b/element/studentname/lang/en/customcertelement_studentname.php @@ -23,3 +23,4 @@ */ $string['pluginname'] = 'Student name'; +$string['privacy:metadata'] = 'The Student name plugin does not store any personal data.'; diff --git a/element/teachername/classes/privacy/provider.php b/element/teachername/classes/privacy/provider.php new file mode 100644 index 000000000..800c91f2f --- /dev/null +++ b/element/teachername/classes/privacy/provider.php @@ -0,0 +1,46 @@ +. + +/** + * Privacy Subsystem implementation for customcertelement_teachername. + * + * @package customcertelement_teachername + * @copyright 2018 Mark Nelson + * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later + */ + +namespace customcertelement_teachername\privacy; + +defined('MOODLE_INTERNAL') || die(); + +/** + * Privacy Subsystem for customcertelement_teachername implementing null_provider. + * + * @copyright 2018 Mark Nelson + * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later + */ +class provider implements \core_privacy\local\metadata\null_provider { + + /** + * Get the language string identifier with the component's language + * file to explain why this plugin stores no data. + * + * @return string + */ + public static function get_reason() : string { + return 'privacy:metadata'; + } +} diff --git a/element/teachername/lang/en/customcertelement_teachername.php b/element/teachername/lang/en/customcertelement_teachername.php index fff92048b..48265bc98 100644 --- a/element/teachername/lang/en/customcertelement_teachername.php +++ b/element/teachername/lang/en/customcertelement_teachername.php @@ -23,5 +23,6 @@ */ $string['pluginname'] = 'Teacher name'; +$string['privacy:metadata'] = 'The Teacher name plugin does not store any personal data.'; $string['teacher'] = 'Teacher'; $string['teacher_help'] = 'This is the teacher name that will be displayed.'; diff --git a/element/text/classes/privacy/provider.php b/element/text/classes/privacy/provider.php new file mode 100644 index 000000000..19ca3e3a9 --- /dev/null +++ b/element/text/classes/privacy/provider.php @@ -0,0 +1,46 @@ +. + +/** + * Privacy Subsystem implementation for customcertelement_text. + * + * @package customcertelement_text + * @copyright 2018 Mark Nelson + * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later + */ + +namespace customcertelement_text\privacy; + +defined('MOODLE_INTERNAL') || die(); + +/** + * Privacy Subsystem for customcertelement_text implementing null_provider. + * + * @copyright 2018 Mark Nelson + * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later + */ +class provider implements \core_privacy\local\metadata\null_provider { + + /** + * Get the language string identifier with the component's language + * file to explain why this plugin stores no data. + * + * @return string + */ + public static function get_reason() : string { + return 'privacy:metadata'; + } +} diff --git a/element/text/lang/en/customcertelement_text.php b/element/text/lang/en/customcertelement_text.php index 81be2e104..077b85a6e 100644 --- a/element/text/lang/en/customcertelement_text.php +++ b/element/text/lang/en/customcertelement_text.php @@ -23,5 +23,6 @@ */ $string['pluginname'] = 'Text'; +$string['privacy:metadata'] = 'The Text plugin does not store any personal data.'; $string['text'] = 'Text'; $string['text_help'] = 'This is the text that will display on the PDF.'; diff --git a/element/userfield/classes/privacy/provider.php b/element/userfield/classes/privacy/provider.php new file mode 100644 index 000000000..4669a8616 --- /dev/null +++ b/element/userfield/classes/privacy/provider.php @@ -0,0 +1,46 @@ +. + +/** + * Privacy Subsystem implementation for customcertelement_userfield. + * + * @package customcertelement_userfield + * @copyright 2018 Mark Nelson + * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later + */ + +namespace customcertelement_userfield\privacy; + +defined('MOODLE_INTERNAL') || die(); + +/** + * Privacy Subsystem for customcertelement_userfield implementing null_provider. + * + * @copyright 2018 Mark Nelson + * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later + */ +class provider implements \core_privacy\local\metadata\null_provider { + + /** + * Get the language string identifier with the component's language + * file to explain why this plugin stores no data. + * + * @return string + */ + public static function get_reason() : string { + return 'privacy:metadata'; + } +} diff --git a/element/userfield/lang/en/customcertelement_userfield.php b/element/userfield/lang/en/customcertelement_userfield.php index 8095c8c03..7b3cb4408 100644 --- a/element/userfield/lang/en/customcertelement_userfield.php +++ b/element/userfield/lang/en/customcertelement_userfield.php @@ -23,5 +23,6 @@ */ $string['pluginname'] = 'User field'; +$string['privacy:metadata'] = 'The User field plugin does not store any personal data.'; $string['userfield'] = 'User field'; $string['userfield_help'] = 'This is the user field that will be displayed on the PDF.'; diff --git a/element/userpicture/classes/privacy/provider.php b/element/userpicture/classes/privacy/provider.php new file mode 100644 index 000000000..8b0b3f0f8 --- /dev/null +++ b/element/userpicture/classes/privacy/provider.php @@ -0,0 +1,46 @@ +. + +/** + * Privacy Subsystem implementation for customcertelement_userpicture. + * + * @package customcertelement_userpicture + * @copyright 2018 Mark Nelson + * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later + */ + +namespace customcertelement_userpicture\privacy; + +defined('MOODLE_INTERNAL') || die(); + +/** + * Privacy Subsystem for customcertelement_userpicture implementing null_provider. + * + * @copyright 2018 Mark Nelson + * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later + */ +class provider implements \core_privacy\local\metadata\null_provider { + + /** + * Get the language string identifier with the component's language + * file to explain why this plugin stores no data. + * + * @return string + */ + public static function get_reason() : string { + return 'privacy:metadata'; + } +} diff --git a/element/userpicture/lang/en/customcertelement_userpicture.php b/element/userpicture/lang/en/customcertelement_userpicture.php index b18c3238a..bd32cb31f 100644 --- a/element/userpicture/lang/en/customcertelement_userpicture.php +++ b/element/userpicture/lang/en/customcertelement_userpicture.php @@ -27,5 +27,6 @@ $string['invalidheight'] = 'The height has to be a valid number greater than or equal to 0.'; $string['invalidwidth'] = 'The width has to be a valid number greater than or equal to 0.'; $string['pluginname'] = 'User picture'; +$string['privacy:metadata'] = 'The User picture plugin does not store any personal data.'; $string['width'] = 'Width'; $string['width_help'] = 'Width of the image in mm. If equal to zero, it is automatically calculated.'; diff --git a/lang/en/customcert.php b/lang/en/customcert.php index 054053db0..bb95aa8f7 100644 --- a/lang/en/customcert.php +++ b/lang/en/customcert.php @@ -127,6 +127,12 @@ $string['posy'] = 'Position Y'; $string['posy_help'] = 'This is the position in mm from the top left corner you wish the element\'s reference point to locate in the y direction.'; $string['print'] = 'Print'; +$string['privacy:metadata:customcert_issues'] = 'The list of issued certificates'; +$string['privacy:metadata:customcert_issues:code'] = 'The code that belongs to the certificate'; +$string['privacy:metadata:customcert_issues:customcertid'] = 'The ID of the certificate'; +$string['privacy:metadata:customcert_issues:emailed'] = 'Whether or not the certificate was emailed'; +$string['privacy:metadata:customcert_issues:timecreated'] = 'The time the certificate was issued'; +$string['privacy:metadata:customcert_issues:userid'] = 'The ID of the user who was issued the certificate'; $string['rearrangeelements'] = 'Reposition elements'; $string['rearrangeelementsheading'] = 'Drag and drop elements to change where they are positioned on the certificate.'; $string['receiveddate'] = 'Received date'; diff --git a/tests/privacy_provider_test.php b/tests/privacy_provider_test.php new file mode 100644 index 000000000..17e003270 --- /dev/null +++ b/tests/privacy_provider_test.php @@ -0,0 +1,207 @@ +. + +/** + * Privacy provider tests. + * + * @package mod_customcert + * @copyright 2018 Mark Nelson + * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later + */ + +use mod_customcert\privacy\provider; + +defined('MOODLE_INTERNAL') || die(); + +/** + * Privacy provider tests class. + * + * @package mod_customcert + * @copyright 2018 Mark Nelson + * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later + */ +class mod_customcert_privacy_provider_testcase extends \core_privacy\tests\provider_testcase { + + /** + * Test for provider::get_contexts_for_userid(). + */ + public function test_get_contexts_for_userid() { + $this->resetAfterTest(); + + $course = $this->getDataGenerator()->create_course(); + + // The customcert activity the user will have an issue from. + $customcert = $this->getDataGenerator()->create_module('customcert', ['course' => $course->id]); + + // Another customcert activity that has no issued certificates. + $this->getDataGenerator()->create_module('customcert', ['course' => $course->id]); + + // Create a user who will be issued a certificate. + $user = $this->getDataGenerator()->create_user(); + + // Issue the certificate. + $this->create_certificate_issue($customcert->id, $user->id); + + // Check the context supplied is correct. + $contextlist = provider::get_contexts_for_userid($user->id); + $this->assertCount(1, $contextlist); + + $contextformodule = $contextlist->current(); + $cmcontext = context_module::instance($customcert->cmid); + $this->assertEquals($cmcontext->id, $contextformodule->id); + } + + /** + * Test for provider::export_user_data(). + */ + public function test_export_for_context() { + $this->resetAfterTest(); + + $course = $this->getDataGenerator()->create_course(); + + $customcert = $this->getDataGenerator()->create_module('customcert', array('course' => $course->id)); + + // Create users who will be issued a certificate. + $user1 = $this->getDataGenerator()->create_user(); + $user2 = $this->getDataGenerator()->create_user(); + + $this->create_certificate_issue($customcert->id, $user1->id); + $this->create_certificate_issue($customcert->id, $user1->id); + $this->create_certificate_issue($customcert->id, $user2->id); + + // Export all of the data for the context for user 1. + $cmcontext = context_module::instance($customcert->cmid); + $this->export_context_data_for_user($user1->id, $cmcontext, 'mod_customcert'); + $writer = \core_privacy\local\request\writer::with_context($cmcontext); + + $this->assertTrue($writer->has_any_data()); + + $data = $writer->get_data(); + $this->assertCount(2, $data->issues); + + $issues = $data->issues; + foreach ($issues as $issue) { + $this->assertArrayHasKey('code', $issue); + $this->assertArrayHasKey('emailed', $issue); + $this->assertArrayHasKey('timecreated', $issue); + } + } + + /** + * Test for provider::delete_data_for_all_users_in_context(). + */ + public function test_delete_data_for_all_users_in_context() { + global $DB; + + $this->resetAfterTest(); + + $course = $this->getDataGenerator()->create_course(); + + $customcert = $this->getDataGenerator()->create_module('customcert', array('course' => $course->id)); + $customcert2 = $this->getDataGenerator()->create_module('customcert', array('course' => $course->id)); + + // Create users who will be issued a certificate. + $user1 = $this->getDataGenerator()->create_user(); + $user2 = $this->getDataGenerator()->create_user(); + + $this->create_certificate_issue($customcert->id, $user1->id); + $this->create_certificate_issue($customcert->id, $user2->id); + + $this->create_certificate_issue($customcert2->id, $user1->id); + $this->create_certificate_issue($customcert2->id, $user2->id); + + // Before deletion, we should have 2 issued certificates for the first certificate. + $count = $DB->count_records('customcert_issues', ['customcertid' => $customcert->id]); + $this->assertEquals(2, $count); + + // Delete data based on context. + $cmcontext = context_module::instance($customcert->cmid); + provider::delete_data_for_all_users_in_context($cmcontext); + + // After deletion, the issued certificates for the activity should have been deleted. + $count = $DB->count_records('customcert_issues', ['customcertid' => $customcert->id]); + $this->assertEquals(0, $count); + + // We should still have the issues for the second certificate. + $count = $DB->count_records('customcert_issues', ['customcertid' => $customcert2->id]); + $this->assertEquals(2, $count); + } + + /** + * Test for provider::delete_data_for_user(). + */ + public function test_delete_data_for_user() { + global $DB; + + $this->resetAfterTest(); + + $course = $this->getDataGenerator()->create_course(); + + $customcert = $this->getDataGenerator()->create_module('customcert', array('course' => $course->id)); + + // Create users who will be issued a certificate. + $user1 = $this->getDataGenerator()->create_user(); + $user2 = $this->getDataGenerator()->create_user(); + + $this->create_certificate_issue($customcert->id, $user1->id); + $this->create_certificate_issue($customcert->id, $user2->id); + + // Before deletion we should have 2 issued certificates. + $count = $DB->count_records('customcert_issues', ['customcertid' => $customcert->id]); + $this->assertEquals(2, $count); + + $context = \context_module::instance($customcert->cmid); + $contextlist = new \core_privacy\local\request\approved_contextlist($user1, 'customcert', + [$context->id]); + provider::delete_data_for_user($contextlist); + + // After deletion, the issued certificates for the first user should have been deleted. + $count = $DB->count_records('customcert_issues', ['customcertid' => $customcert->id, 'userid' => $user1->id]); + $this->assertEquals(0, $count); + + // Check the issue for the other user is still there. + $customcertissue = $DB->get_records('customcert_issues'); + $this->assertCount(1, $customcertissue); + $lastissue = reset($customcertissue); + $this->assertEquals($user2->id, $lastissue->userid); + } + + /** + * Mimicks the creation of a customcert issue. + * + * There is no API we can use to insert an customcert issue, so we + * will simply insert directly into the database. + * + * @param int $customcertid + * @param int $userid + */ + protected function create_certificate_issue(int $customcertid, int $userid) { + global $DB; + + static $i = 1; + + $customcertissue = new stdClass(); + $customcertissue->customcertid = $customcertid; + $customcertissue->userid = $userid; + $customcertissue->code = \mod_customcert\certificate::generate_code(); + $customcertissue->timecreated = time() + $i; + + // Insert the record into the database. + $DB->insert_record('customcert_issues', $customcertissue); + + $i++; + } +} From 4958b07f0720df00efda2d9cf75dcb330db474b7 Mon Sep 17 00:00:00 2001 From: Mark Nelson Date: Thu, 17 May 2018 14:37:29 +0800 Subject: [PATCH 09/93] Updated CHANGES.md --- CHANGES.md | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/CHANGES.md b/CHANGES.md index b96167d4a..d3b69dc26 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -1,6 +1,17 @@ # Changelog -All notable changes to this project will be documented in this file. +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.4.1] - 2018-05-17 +### Added +- GDPR Compliance (#189). + +### 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.3.9] - 2017-11-13 ### Added From b43d7d33eae632449beae67df271b88a7ea5bf7f Mon Sep 17 00:00:00 2001 From: Mark Nelson Date: Thu, 17 May 2018 14:40:51 +0800 Subject: [PATCH 10/93] Bump version --- version.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/version.php b/version.php index 7588a9ccc..bc3ebf94e 100644 --- a/version.php +++ b/version.php @@ -24,10 +24,10 @@ defined('MOODLE_INTERNAL') || die('Direct access to this script is forbidden.'); -$plugin->version = 2017111300; // The current module version (Date: YYYYMMDDXX). +$plugin->version = 2017111301; // The current module version (Date: YYYYMMDDXX). $plugin->requires = 2017111300; // Requires this Moodle version (3.4). $plugin->cron = 0; // Period for cron to check this module (secs). $plugin->component = 'mod_customcert'; $plugin->maturity = MATURITY_STABLE; -$plugin->release = "3.4 release (Build: 2017111300)"; // User-friendly version number. +$plugin->release = "3.4 release (Build: 2017111301)"; // User-friendly version number. From f7732690ab4b3788d684f3e2ea8c9e8858128f64 Mon Sep 17 00:00:00 2001 From: Mark Nelson Date: Thu, 17 May 2018 19:42:36 +0800 Subject: [PATCH 11/93] #148 Increase size limit on fonts --- classes/certificate.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/classes/certificate.php b/classes/certificate.php index ab2609b83..918c188c3 100644 --- a/classes/certificate.php +++ b/classes/certificate.php @@ -155,7 +155,7 @@ public static function get_font_sizes() { // Array to store the sizes. $sizes = array(); - for ($i = 1; $i <= 60; $i++) { + for ($i = 1; $i <= 200; $i++) { $sizes[$i] = $i; } From f28c2324e2e3c45c3303d8bc778c82226afcda0f Mon Sep 17 00:00:00 2001 From: Mark Nelson Date: Mon, 21 May 2018 21:34:53 +0800 Subject: [PATCH 12/93] Changed icon for downloading certificate from reports This was done because the core 'import' icon was mapped to the Font Awesome icon 'fa-level-up' which did not look appropriate. --- classes/my_certificates_table.php | 2 +- classes/report_table.php | 2 +- lib.php | 9 +++++++++ pix/download.png | Bin 0 -> 207 bytes pix/download.svg | 3 +++ 5 files changed, 14 insertions(+), 2 deletions(-) create mode 100644 pix/download.png create mode 100644 pix/download.svg diff --git a/classes/my_certificates_table.php b/classes/my_certificates_table.php index b0c0858b1..38107225b 100644 --- a/classes/my_certificates_table.php +++ b/classes/my_certificates_table.php @@ -136,7 +136,7 @@ public function col_code($certificate) { public function col_download($certificate) { global $OUTPUT; - $icon = new \pix_icon('i/import', get_string('download')); + $icon = new \pix_icon('download', get_string('download'), 'customcert'); $link = new \moodle_url('/mod/customcert/my_certificates.php', array('userid' => $this->userid, 'certificateid' => $certificate->id, diff --git a/classes/report_table.php b/classes/report_table.php index e34be5bfc..e554bb6b8 100644 --- a/classes/report_table.php +++ b/classes/report_table.php @@ -145,7 +145,7 @@ public function col_code($user) { public function col_download($user) { global $OUTPUT; - $icon = new \pix_icon('i/import', get_string('download')); + $icon = new \pix_icon('download', get_string('download'), 'customcert'); $link = new \moodle_url('/mod/customcert/report.php', array('id' => $this->cm->id, 'downloadcert' => '1', diff --git a/lib.php b/lib.php index 491d91a0a..ff7c8db1a 100644 --- a/lib.php +++ b/lib.php @@ -418,3 +418,12 @@ function mod_customcert_inplace_editable($itemtype, $itemid, $newvalue) { $updateelement->name, $updateelement->name); } } + +/** + * Get icon mapping for font-awesome. + */ +function mod_customcert_get_fontawesome_icon_map() { + return [ + 'mod_customcert:download' => 'fa-download' + ]; +} diff --git a/pix/download.png b/pix/download.png new file mode 100644 index 0000000000000000000000000000000000000000..0f08f9761d0abbc8a659f55a6c3f68773a5e4c4a GIT binary patch literal 207 zcmeAS@N?(olHy`uVBq!ia0vp^0wB!73?$#)eFPFv3GfMV1=2GKflF!kL7KTsg8YIR z1PmJb=da&?{{DNXpue#|VSi5-$B+ufWCo_!XL$qy_R6w1Z!G?HZYGxl+wD9B4F;nK z2OjnbF<;)@jc&a1ignHIa`u9^NjLU3DpqMTf6o(WzR7Tkfk}i-L_uP;;uk#zDQEqj U4RL-7K%*HvUHx3vIVCg!08GeA?*IS* literal 0 HcmV?d00001 diff --git a/pix/download.svg b/pix/download.svg new file mode 100644 index 000000000..007cc995b --- /dev/null +++ b/pix/download.svg @@ -0,0 +1,3 @@ + +]> \ No newline at end of file From adb17cf61e707f8959926bae9c8945b4d928797c Mon Sep 17 00:00:00 2001 From: Mark Nelson Date: Wed, 23 May 2018 14:01:55 +0800 Subject: [PATCH 13/93] Added helper function to issue certificates --- classes/certificate.php | 21 +++++++++++++++++++++ classes/task/email_certificate_task.php | 10 +--------- tests/email_certificate_task_test.php | 10 +--------- view.php | 8 +------- 4 files changed, 24 insertions(+), 25 deletions(-) diff --git a/classes/certificate.php b/classes/certificate.php index 918c188c3..84afcbdb1 100644 --- a/classes/certificate.php +++ b/classes/certificate.php @@ -421,6 +421,27 @@ public static function get_certificates_for_user($userid, $limitfrom, $limitnum, 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. * diff --git a/classes/task/email_certificate_task.php b/classes/task/email_certificate_task.php index 3a305a86d..88fe7a6ad 100644 --- a/classes/task/email_certificate_task.php +++ b/classes/task/email_certificate_task.php @@ -130,15 +130,7 @@ public function execute() { array('userid' => $enroluser->id, 'customcertid' => $customcert->id)); if (empty($issueid)) { // 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); + $issueid = \mod_customcert\certificate::issue_certificate($customcert->id, $enroluser->id); } // Add them to the array so we email them. diff --git a/tests/email_certificate_task_test.php b/tests/email_certificate_task_test.php index 972baec2a..b05f7f1fa 100644 --- a/tests/email_certificate_task_test.php +++ b/tests/email_certificate_task_test.php @@ -71,15 +71,7 @@ public function test_email_certificates_students() { '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')); diff --git a/view.php b/view.php index 5d09752ac..4a9983934 100644 --- a/view.php +++ b/view.php @@ -121,13 +121,7 @@ } 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. From 45494e3586f32edb694cdcfbabec25fffc691a5e Mon Sep 17 00:00:00 2001 From: Mark Nelson Date: Thu, 24 May 2018 14:15:18 +0800 Subject: [PATCH 14/93] Fixed PHPDoc --- classes/certificate.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/classes/certificate.php b/classes/certificate.php index 84afcbdb1..a7693a31e 100644 --- a/classes/certificate.php +++ b/classes/certificate.php @@ -247,7 +247,7 @@ public static function get_course_time($courseid, $userid = 0) { * @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; From b93a12a74f02cb49854ba9e92ce9bf6535aad74e Mon Sep 17 00:00:00 2001 From: Roberto Pinna Date: Thu, 24 May 2018 11:30:50 +0200 Subject: [PATCH 15/93] #192 Fixed report fields for download --- classes/report_table.php | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/classes/report_table.php b/classes/report_table.php index e554bb6b8..5fcd71c99 100644 --- a/classes/report_table.php +++ b/classes/report_table.php @@ -86,7 +86,7 @@ public function __construct($customcertid, $cm, $groupmode, $download = null) { $headers[] = get_string('file'); } - if (has_capability('mod/customcert:manage', \context_module::instance($cm->id))) { + if (!$this->is_downloading() && has_capability('mod/customcert:manage', \context_module::instance($cm->id))) { $columns[] = 'actions'; $headers[] = ''; } @@ -113,7 +113,11 @@ public function __construct($customcertid, $cm, $groupmode, $download = null) { 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); + } } /** From c80fee36ec634672cf899001ae98b62e6426a009 Mon Sep 17 00:00:00 2001 From: Mark Nelson Date: Wed, 6 Jun 2018 21:31:39 +0800 Subject: [PATCH 16/93] Fixed typo in PHPDoc --- classes/element.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/classes/element.php b/classes/element.php index cd28f661e..7acad0b1b 100644 --- a/classes/element.php +++ b/classes/element.php @@ -29,7 +29,7 @@ /** * Class element * - * All customercert element plugins are based on this class. + * All customcert element plugins are based on this class. * * @package mod_customcert * @copyright 2013 Mark Nelson From 9bf0fc4e94843e9ae9a5ff628842ea7ff2c985ea Mon Sep 17 00:00:00 2001 From: Mark Nelson Date: Wed, 6 Jun 2018 20:38:08 +0800 Subject: [PATCH 17/93] #170 Elements now respect filters --- element/categoryname/classes/element.php | 8 +++++--- element/coursename/classes/element.php | 6 ++++-- element/gradeitemname/classes/element.php | 4 ++++ element/text/classes/element.php | 8 ++++++-- element/userfield/classes/element.php | 4 ++++ 5 files changed, 23 insertions(+), 7 deletions(-) diff --git a/element/categoryname/classes/element.php b/element/categoryname/classes/element.php index adf7d7051..054a70bff 100644 --- a/element/categoryname/classes/element.php +++ b/element/categoryname/classes/element.php @@ -57,7 +57,8 @@ public function render($pdf, $preview, $user) { public function render_html() { global $COURSE; - return \mod_customcert\element_helper::render_html_content($this, $COURSE->fullname); + $categoryname = format_string($COURSE->fullname, true, ['context' => \context_course::instance($COURSE->id)]); + return \mod_customcert\element_helper::render_html_content($this, $categoryname); } /** @@ -74,9 +75,10 @@ protected static function get_category_name($elementid) { // 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); + $categoryname = $DB->get_field('course_categories', 'name', array('id' => $course->category), MUST_EXIST); + return format_string($categoryname, true, ['context' => \context_course::instance($courseid)]); } else { // Must be in a site template. - return $SITE->fullname; + return format_string($SITE->fullname, true, ['context' => \context_system::instance()]); } } } diff --git a/element/coursename/classes/element.php b/element/coursename/classes/element.php index a4d105843..5b0f78dc2 100644 --- a/element/coursename/classes/element.php +++ b/element/coursename/classes/element.php @@ -46,7 +46,8 @@ public function render($pdf, $preview, $user) { $courseid = \mod_customcert\element_helper::get_courseid($this->get_id()); $course = get_course($courseid); - \mod_customcert\element_helper::render_content($pdf, $this, $course->fullname); + $coursename = format_string($course->fullname, true, ['context' => \context_course::instance($courseid)]); + \mod_customcert\element_helper::render_content($pdf, $this, $coursename); } /** @@ -60,6 +61,7 @@ public function render($pdf, $preview, $user) { public function render_html() { global $COURSE; - return \mod_customcert\element_helper::render_html_content($this, $COURSE->fullname); + $coursename = format_string($COURSE->fullname, true, ['context' => \context_course::instance($COURSE->id)]); + return \mod_customcert\element_helper::render_html_content($this, $coursename); } } diff --git a/element/gradeitemname/classes/element.php b/element/gradeitemname/classes/element.php index 82c743559..afa792c6e 100644 --- a/element/gradeitemname/classes/element.php +++ b/element/gradeitemname/classes/element.php @@ -82,7 +82,9 @@ public function render($pdf, $preview, $user) { $module = $DB->get_record('modules', array('id' => $cm->module), '*', MUST_EXIST); // Get the name of the item. + $courseid = \mod_customcert\element_helper::get_courseid($this->get_data()); $itemname = $DB->get_field($module->name, 'name', array('id' => $cm->instance), MUST_EXIST); + $itemname = format_string($itemname, true, ['context' => \context_course::instance($courseid)]); \mod_customcert\element_helper::render_content($pdf, $this, $itemname); } @@ -106,7 +108,9 @@ public function render_html() { $module = $DB->get_record('modules', array('id' => $cm->module), '*', MUST_EXIST); // Get the name of the item. + $courseid = \mod_customcert\element_helper::get_courseid($this->get_data()); $itemname = $DB->get_field($module->name, 'name', array('id' => $cm->instance), MUST_EXIST); + $itemname = format_string($itemname, true, ['context' => \context_course::instance($courseid)]); return \mod_customcert\element_helper::render_html_content($this, $itemname); } diff --git a/element/text/classes/element.php b/element/text/classes/element.php index 9ae500fcd..bb5e0b94c 100644 --- a/element/text/classes/element.php +++ b/element/text/classes/element.php @@ -67,7 +67,9 @@ public function save_unique_data($data) { * @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->get_data()); + $courseid = \mod_customcert\element_helper::get_courseid($this->get_id()); + $text = format_text($this->get_data(), FORMAT_MOODLE, ['context' => \context_course::instance($courseid)]); + \mod_customcert\element_helper::render_content($pdf, $this, $text); } /** @@ -79,7 +81,9 @@ public function render($pdf, $preview, $user) { * @return string the html */ public function render_html() { - return \mod_customcert\element_helper::render_html_content($this, $this->get_data()); + $courseid = \mod_customcert\element_helper::get_courseid($this->get_id()); + $text = format_text($this->get_data(), FORMAT_MOODLE, ['context' => \context_course::instance($courseid)]); + return \mod_customcert\element_helper::render_html_content($this, $text); } /** diff --git a/element/userfield/classes/element.php b/element/userfield/classes/element.php index 1b8708688..ad9ceff57 100644 --- a/element/userfield/classes/element.php +++ b/element/userfield/classes/element.php @@ -119,6 +119,8 @@ public function render($pdf, $preview, $user) { $value = $user->$field; } + $courseid = \mod_customcert\element_helper::get_courseid($this->get_id()); + $value = format_string($value, true, ['context' => \context_course::instance($courseid)]); \mod_customcert\element_helper::render_content($pdf, $this, $value); } @@ -155,6 +157,8 @@ public function render_html() { $value = $USER->$field; } + $courseid = \mod_customcert\element_helper::get_courseid($this->get_id()); + $value = format_string($value, true, ['context' => \context_course::instance($courseid)]); return \mod_customcert\element_helper::render_html_content($this, $value); } From 2fa7191d12449e460e729b18f2b8cb1c7d7d383a Mon Sep 17 00:00:00 2001 From: Mark Nelson Date: Wed, 23 May 2018 14:35:23 +0800 Subject: [PATCH 18/93] #70 Added mobile app support This allows students to view the activity and download their certificate. It also allows teachers to view the list of issued certificates, with the ability to revoke any. This is for Moodle Mobile v3.5.0 (not to be confused with your Moodle site version) and will not work on Mobile versions earlier than this. If you are running a Moodle site on version 3.4 or below you will need to install the local_mobile plugin in order for this to work. If you are running a Moodle site on version 3.0 or below then you will need to upgrade. --- classes/external.php | 53 ++++ classes/output/mobile.php | 262 +++++++++++++++++++ db/mobile.php | 55 ++++ db/services.php | 9 + mobile/pluginfile.php | 88 +++++++ templates/mobile_report_page.mustache | 101 +++++++ templates/mobile_view_activity_page.mustache | 71 +++++ tests/external_test.php | 150 +++++++++++ version.php | 4 +- 9 files changed, 791 insertions(+), 2 deletions(-) create mode 100644 classes/output/mobile.php create mode 100644 db/mobile.php create mode 100644 mobile/pluginfile.php create mode 100644 templates/mobile_report_page.mustache create mode 100644 templates/mobile_view_activity_page.mustache create mode 100644 tests/external_test.php diff --git a/classes/external.php b/classes/external.php index d8e48da63..b428848fa 100644 --- a/classes/external.php +++ b/classes/external.php @@ -174,4 +174,57 @@ public static function get_element_html($templateid, $elementid) { public static function get_element_html_returns() { return new \external_value(PARAM_RAW, 'The HTML'); } + + /** + * Returns the delete_issue() parameters. + * + * @return \external_function_parameters + */ + public static function delete_issue_parameters() { + return new \external_function_parameters( + array( + 'certificateid' => new \external_value(PARAM_INT, 'The certificate id'), + 'issueid' => new \external_value(PARAM_INT, 'The issue id'), + ) + ); + } + + /** + * Handles deleting a customcert issue. + * + * @param int $certificateid The certificate id. + * @param int $issueid The issue id. + * @return bool + */ + public static function delete_issue($certificateid, $issueid) { + global $DB; + + $params = [ + 'certificateid' => $certificateid, + 'issueid' => $issueid + ]; + self::validate_parameters(self::delete_issue_parameters(), $params); + + $certificate = $DB->get_record('customcert', ['id' => $certificateid], '*', MUST_EXIST); + $issue = $DB->get_record('customcert_issues', ['id' => $issueid, 'customcertid' => $certificateid], '*', MUST_EXIST); + + $cm = get_coursemodule_from_instance('customcert', $certificate->id, 0, false, MUST_EXIST); + + // Make sure the user has the required capabilities. + $context = \context_module::instance($cm->id); + self::validate_context($context); + require_capability('mod/customcert:manage', $context); + + // Delete the issue. + return $DB->delete_records('customcert_issues', ['id' => $issue->id]); + } + + /** + * Returns the delete_issue result value. + * + * @return \external_value + */ + public static function delete_issue_returns() { + return new \external_value(PARAM_BOOL, 'True if successful, false otherwise'); + } } diff --git a/classes/output/mobile.php b/classes/output/mobile.php new file mode 100644 index 000000000..c21593841 --- /dev/null +++ b/classes/output/mobile.php @@ -0,0 +1,262 @@ +. + +/** + * Contains the mobile output class for the custom certificate. + * + * @package mod_customcert + * @copyright 2018 Mark Nelson + * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later + */ + +namespace mod_customcert\output; + +defined('MOODLE_INTERNAL') || die(); + +/** + * Mobile output class for the custom certificate. + * + * @copyright 2018 Mark Nelson + * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later + */ +class mobile { + + /** + * Returns the initial page when viewing the activity for the mobile app. + * + * @param array $args Arguments from tool_mobile_get_content WS + * @return array HTML, javascript and other data + */ + public static function mobile_view_activity($args) { + global $OUTPUT, $DB, $USER; + + $args = (object) $args; + + // Get the group variable. + $groupid = empty($args->group) ? 0 : $args->group; // By default, group 0. + $cmid = $args->cmid; + + // Capabilities check. + $cm = get_coursemodule_from_id('customcert', $cmid); + $context = \context_module::instance($cm->id); + self::require_capability($cm, $context, 'mod/customcert:view'); + + // Set some variables we are going to be using. + $certificate = $DB->get_record('customcert', ['id' => $cm->instance], '*', MUST_EXIST); + $certificate->name = format_string($certificate->name); + list($certificate->intro, $certificate->introformat) = external_format_text($certificate->intro, + $certificate->introformat, $context->id, 'mod_customcert', 'intro'); + + // Get the groups (if any) to display - also sets active group. + $groups = self::get_groups($cm, $groupid, $USER->id); + + // Get any issues this person may have. + $issues = $DB->get_records('customcert_issues', ['userid' => $USER->id, 'customcertid' => $certificate->id]); + + $candownload = true; + if ($certificate->requiredtime && !has_capability('mod/certificate:manage', $context)) { + if (\mod_customcert\certificate::get_course_time($certificate->course) < ($certificate->requiredtime * 60)) { + $candownload = false; + } + } + + $fileurl = ""; + if ($candownload) { + $fileurl = new \moodle_url('/mod/customcert/mobile/pluginfile.php', ['certificateid' => $certificate->id, + 'userid' => $USER->id]); + $fileurl = $fileurl->out(true); + } + + $showreport = false; + $numissues = 0; + if (has_capability('mod/customcert:viewreport', $context)) { + // Get the total number of issues. + $showreport = true; + $groupmode = groups_get_activity_groupmode($cm); + if (has_capability('moodle/site:accessallgroups', $context)) { + $groupmode = 'aag'; + } + $numissues = \mod_customcert\certificate::get_number_of_issues($certificate->id, $cm, $groupmode); + } + + $data = [ + 'certificate' => $certificate, + 'cmid' => $cm->id, + 'groupselected' => $groupid, + 'showgroups' => !empty($groups), + 'groups' => array_values($groups), + 'hasissues' => !empty($issues), + 'issues' => array_values($issues), + 'candownload' => $candownload, + 'fileurl' => $fileurl, + 'showreport' => $showreport, + 'numissuesinreport' => $numissues, + 'currenttimestamp' => time() + ]; + + return [ + 'templates' => [ + [ + 'id' => 'main', + 'html' => $OUTPUT->render_from_template('mod_customcert/mobile_view_activity_page', $data), + ], + ], + 'javascript' => '', + 'otherdata' => '' + ]; + } + + /** + * Returns the list of issues certificates for the activity for the mobile app. + * + * @param array $args Arguments from tool_mobile_get_content WS + * @return array HTML, javascript and other data + */ + public static function mobile_view_report($args) { + global $DB, $OUTPUT, $USER; + + $args = (object) $args; + + $cmid = $args->cmid; + $groupid = empty($args->group) ? 0 : $args->group; // By default, group 0. + + // Capabilities check. + $cm = get_coursemodule_from_id('customcert', $cmid); + $context = \context_module::instance($cm->id); + + self::require_capability($cm, $context, 'mod/customcert:viewreport'); + + // Get the groups (if any) to display - also sets active group. + $groups = self::get_groups($cm, $groupid, $USER->id); + + $certificate = $DB->get_record('customcert', ['id' => $cm->instance], '*', MUST_EXIST); + $certificate->name = format_string($certificate->name); + list($certificate->intro, $certificate->introformat) = external_format_text($certificate->intro, + $certificate->introformat, $context->id, 'mod_customcert', 'intro'); + + $groupmode = groups_get_activity_groupmode($cm); + if (has_capability('moodle/site:accessallgroups', $context)) { + $groupmode = 'aag'; + } + + $issues = \mod_customcert\certificate::get_issues($certificate->id, $groupmode, $cm, 0, 0); + foreach ($issues as $issue) { + $issue->displayname = fullname($issue); + $issue->fileurl = new \moodle_url('/mod/customcert/mobile/pluginfile.php', ['certificateid' => $certificate->id, + 'userid' => $issue->id]); + } + + $data = [ + 'certificate' => $certificate, + 'cmid' => $cmid, + 'showgroups' => !empty($groups), + 'groups' => array_values($groups), + 'canmanage' => has_capability('mod/customcert:manage', $context), + 'hasissues' => !empty($issues), + 'issues' => array_values($issues), + 'currenttimestamp' => time() + ]; + + return [ + 'templates' => [ + [ + 'id' => 'main', + 'html' => $OUTPUT->render_from_template('mod_customcert/mobile_report_page', $data), + ], + ], + 'javascript' => '', + 'otherdata' => '' + ]; + } + + /** + * Returns an array of groups to be displayed (if applicable) for the activity. + * + * The groups API is a mess hence the hackiness. + * + * @param \stdClass $cm The course module + * @param int $groupid The group id + * @param int $userid The user id + * @return array The array of groups, may be empty. + */ + protected static function get_groups($cm, $groupid, $userid) { + $arrgroups = []; + if ($groupmode = groups_get_activity_groupmode($cm)) { + if ($groups = groups_get_activity_allowed_groups($cm, $userid)) { + $context = \context_module::instance($cm->id); + if ($groupmode == VISIBLEGROUPS || has_capability('moodle/site:accessallgroups', $context)) { + $allparticipants = new \stdClass(); + $allparticipants->id = 0; + $allparticipants->name = get_string('allparticipants'); + $allparticipants->selected = $groupid === 0; + $arrgroups[0] = $allparticipants; + } + self::update_active_group($groupmode, $groupid, $groups, $cm); + // Detect which group is selected. + foreach ($groups as $gid => $group) { + $group->selected = $gid == $groupid; + $arrgroups[] = $group; + } + } + } + + return $arrgroups; + } + + /** + * Update the active group in the session. + * + * This is a hack. We can't call groups_get_activity_group to update the active group as it relies + * on optional_param('group' .. which we won't have when using the mobile app. + * + * @param int $groupmode The group mode we are in, eg. NOGROUPS, VISIBLEGROUPS + * @param int $groupid The id of the group that has been selected + * @param array $allowedgroups The allowed groups this user can access + * @param \stdClass $cm The course module + */ + private static function update_active_group($groupmode, $groupid, $allowedgroups, $cm) { + global $SESSION; + + $context = \context_module::instance($cm->id); + + if (has_capability('moodle/site:accessallgroups', $context)) { + $groupmode = 'aag'; + } + + if ($groupid == 0) { + // The groups are only all visible in VISIBLEGROUPS mode or if the user can access all groups. + if ($groupmode == VISIBLEGROUPS || has_capability('moodle/site:accessallgroups', $context)) { + $SESSION->activegroup[$cm->course][$groupmode][$cm->groupingid] = 0; + } + } else { + if ($allowedgroups && array_key_exists($groupid, $allowedgroups)) { + $SESSION->activegroup[$cm->course][$groupmode][$cm->groupingid] = $groupid; + } + } + } + + /** + * Confirms the user is logged in and has the specified capability. + * + * @param \stdClass $cm + * @param \context $context + * @param string $cap + */ + protected static function require_capability(\stdClass $cm, \context $context, string $cap) { + require_login($cm->course, false, $cm, true, true); + require_capability($cap, $context); + } +} diff --git a/db/mobile.php b/db/mobile.php new file mode 100644 index 000000000..e9ece986e --- /dev/null +++ b/db/mobile.php @@ -0,0 +1,55 @@ +. + +/** + * Defines mobile handlers. + * + * @package mod_customcert + * @copyright 2018 Mark Nelson + * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later + */ + +defined('MOODLE_INTERNAL') || die(); + +$addons = array( + 'mod_customcert' => [ // Plugin identifier. + 'handlers' => [ // Different places where the plugin will display content. + 'issueview' => [ // Handler unique name. + 'displaydata' => [ + 'icon' => $CFG->wwwroot . '/mod/customcert/pix/icon.png', + 'class' => '', + ], + 'delegate' => 'CoreCourseModuleDelegate', // Delegate (where to display the link to the plugin). + 'method' => 'mobile_view_activity', // Main function in \mod_customcert\output\mobile. + ] + ], + 'lang' => [ // Language strings that are used in all the handlers. + ['code', 'customcert'], + ['deleteissueconfirm', 'customcert'], + ['file', 'moodle'], + ['fullname', 'moodle'], + ['getcustomcert', 'customcert'], + ['modulenameplural', 'customcert'], + ['nothingtodisplay', 'moodle'], + ['pluginname', 'customcert'], + ['receiveddate', 'customcert'], + ['requiredtimenotmet', 'customcert'], + ['selectagroup', 'moodle'], + ['summaryofissue', 'customcert'], + ['viewcustomcertissues', 'customcert'] + ], + ] +); diff --git a/db/services.php b/db/services.php index b0b6343ad..923d84283 100644 --- a/db/services.php +++ b/db/services.php @@ -25,6 +25,15 @@ defined('MOODLE_INTERNAL') || die(); $functions = array( + 'mod_customcert_delete_issue' => array( + 'classname' => 'mod_customcert\external', + 'methodname' => 'delete_issue', + 'classpath' => '', + 'description' => 'Delete an issue for a certificate', + 'type' => 'write', + 'ajax' => true, + 'services' => array(MOODLE_OFFICIAL_MOBILE_SERVICE) + ), 'mod_customcert_save_element' => array( 'classname' => 'mod_customcert\external', 'methodname' => 'save_element', diff --git a/mobile/pluginfile.php b/mobile/pluginfile.php new file mode 100644 index 000000000..c74c11b77 --- /dev/null +++ b/mobile/pluginfile.php @@ -0,0 +1,88 @@ +. + +/** + * Serves files for the mobile app. + * + * @package mod_customcert + * @copyright 2018 Mark Nelson + * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later + */ + +/** + * AJAX_SCRIPT - exception will be converted into JSON. + */ +define('AJAX_SCRIPT', true); + +/** + * NO_MOODLE_COOKIES - we don't want any cookie. + */ +define('NO_MOODLE_COOKIES', true); + +require_once('../../../config.php'); +require_once($CFG->libdir . '/filelib.php'); +require_once($CFG->dirroot . '/webservice/lib.php'); + +// Allow CORS requests. +header('Access-Control-Allow-Origin: *'); + +// Authenticate the user. +$token = required_param('token', PARAM_ALPHANUM); +$certificateid = required_param('certificateid', PARAM_INT); +$userid = required_param('userid', PARAM_INT); + +$webservicelib = new webservice(); +$authenticationinfo = $webservicelib->authenticate_user($token); + +// Check the service allows file download. +$enabledfiledownload = (int) ($authenticationinfo['service']->downloadfiles); +if (empty($enabledfiledownload)) { + throw new webservice_access_exception('Web service file downloading must be enabled in external service settings'); +} + +$cm = get_coursemodule_from_instance('customcert', $certificateid, 0, false, MUST_EXIST); +$certificate = $DB->get_record('customcert', ['id' => $certificateid], '*', MUST_EXIST); +$template = $DB->get_record('customcert_templates', ['id' => $certificate->templateid], '*', MUST_EXIST); + +// Capabilities check. +require_capability('mod/customcert:view', \context_module::instance($cm->id)); +if ($userid != $USER->id) { + require_capability('mod/customcert:viewreport', \context_module::instance($cm->id)); +} else { + // Make sure the user has met the required time. + if ($certificate->requiredtime) { + if (\mod_customcert\certificate::get_course_time($certificate->course) < ($certificate->requiredtime * 60)) { + exit(); + } + } +} + +$issue = $DB->get_record('customcert_issues', ['customcertid' => $certificateid, 'userid' => $userid]); + +// If we are doing it for the logged in user then we want to issue the certificate. +if (!$issue) { + // If the other user doesn't have an issue, then there is nothing to do. + if ($userid != $USER->id) { + exit(); + } + + \mod_customcert\certificate::issue_certificate($certificate->id, $USER->id); +} + +// Now we want to generate the PDF. +$template = new \mod_customcert\template($template); +$template->generate_pdf(false, $userid); +exit(); diff --git a/templates/mobile_report_page.mustache b/templates/mobile_report_page.mustache new file mode 100644 index 000000000..7f3ca664f --- /dev/null +++ b/templates/mobile_report_page.mustache @@ -0,0 +1,101 @@ +{{! + 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 . +}} +{{! + @template mod_customcert/mobile_report_page + + The page that lists the custom certificates issued + + Classes required for JS: + * None + + Data attibutes required for JS: + * All data attributes are required +}} +{{=<% %>=}} +
+ + <%#showgroups%> + + {{ 'plugin.mod_customcert.selectagroup' | translate }} + + <%#groups%> + selected<%/selected%>><% name %> + <%/groups%> + + + <%/showgroups%> + +

{{ 'plugin.mod_customcert.modulenameplural' | translate }}

+
+ <%#hasissues%> + + + + + {{ 'plugin.mod_customcert.fullname' | translate }} + + + {{ 'plugin.mod_customcert.receiveddate' | translate }} + + + {{ 'plugin.mod_customcert.code' | translate }} + + + {{ 'plugin.mod_customcert.file' | translate }} + + <%#canmanage%> + + <%/canmanage%> + + <%#issues%> + + + <% displayname %> + + + {{ <% timecreated %> | coreToLocaleString }} + + + <% code %> + + + + + <%#canmanage%> + + + + <%/canmanage%> + + <%/issues%> + + + <%/hasissues%> + <%^hasissues%> + + {{ 'plugin.mod_customcert.nothingtodisplay' | translate }} + + <%/hasissues%> +
diff --git a/templates/mobile_view_activity_page.mustache b/templates/mobile_view_activity_page.mustache new file mode 100644 index 000000000..bbc39eb9e --- /dev/null +++ b/templates/mobile_view_activity_page.mustache @@ -0,0 +1,71 @@ +{{! + 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 . +}} +{{! + @template mod_customcert/mobile_view_activity_page + + The main page to view the custom certificate activity + + Classes required for JS: + * None + + Data attibutes required for JS: + * All data attributes are required +}} +{{=<% %>=}} +
+ + <%#showgroups%> + + {{ 'plugin.mod_customcert.selectagroup' | translate }} + + <%#groups%> + selected<%/selected%>><% name %> + <%/groups%> + + + <%/showgroups%> + <%#showreport%> + + {{ 'plugin.mod_customcert.viewcustomcertissues' | translate: {$a: <% numissuesinreport %>} }} + + <%/showreport%> + <%#hasissues%> + + +

{{ 'plugin.mod_customcert.summaryofissue' | translate }}

+
+ <%#issues%> + + {{ <% timecreated %> | coreToLocaleString }} + + <%/issues%> +
+ <%/hasissues%> + <%#candownload%> + + + + <%/candownload%> + <%^candownload%> + +

{{ 'plugin.mod_customcert.requiredtimenotmet' | translate: {$a: { requiredtime: <% certificate.requiredtime %>} } }}

+
+ <%/candownload%> +
diff --git a/tests/external_test.php b/tests/external_test.php new file mode 100644 index 000000000..6540e644f --- /dev/null +++ b/tests/external_test.php @@ -0,0 +1,150 @@ +. + +/** + * File contains the unit tests for the webservices. + * + * @package mod_customcert + * @category test + * @copyright 2018 Mark Nelson + * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later + */ + +defined('MOODLE_INTERNAL') || die(); + +global $CFG; + +/** + * Unit tests for the webservices. + * + * @package mod_customcert + * @category test + * @copyright 2018 Mark Nelson + * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later + */ +class mod_customcert_external_test_testcase extends advanced_testcase { + + /** + * Test set up. + */ + public function setUp() { + $this->resetAfterTest(); + } + + /** + * Test the delete_issue web service. + */ + public function test_delete_issue() { + global $DB; + + $this->setAdminUser(); + + // Create a course. + $course = $this->getDataGenerator()->create_course(); + + // Create a custom certificate in the course. + $customcert = $this->getDataGenerator()->create_module('customcert', ['course' => $course->id]); + + // 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); + + // Issue them both certificates. + $i1 = \mod_customcert\certificate::issue_certificate($customcert->id, $student1->id); + $i2 = \mod_customcert\certificate::issue_certificate($customcert->id, $student2->id); + + $this->assertEquals(2, $DB->count_records('customcert_issues')); + + $result = \mod_customcert\external::delete_issue($customcert->id, $i2); + + // We need to execute the return values cleaning process to simulate the web service server. + external_api::clean_returnvalue(\mod_customcert\external::delete_issue_returns(), $result); + + $issues = $DB->get_records('customcert_issues'); + $this->assertCount(1, $issues); + + $issue = reset($issues); + $this->assertEquals($student1->id, $issue->userid); + } + + /** + * Test the delete_issue web service. + */ + public function test_delete_issue_no_login() { + global $DB; + + // Create a course. + $course = $this->getDataGenerator()->create_course(); + + // Create a custom certificate in the course. + $customcert = $this->getDataGenerator()->create_module('customcert', ['course' => $course->id]); + + // 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); + + // Issue them both certificates. + $i1 = \mod_customcert\certificate::issue_certificate($customcert->id, $student1->id); + $i2 = \mod_customcert\certificate::issue_certificate($customcert->id, $student2->id); + + $this->assertEquals(2, $DB->count_records('customcert_issues')); + + // Try and delete without logging in. + $this->expectException('require_login_exception'); + \mod_customcert\external::delete_issue($customcert->id, $i2); + } + + /** + * Test the delete_issue web service. + */ + public function test_delete_issue_no_capability() { + global $DB; + + // Create a course. + $course = $this->getDataGenerator()->create_course(); + + // Create a custom certificate in the course. + $customcert = $this->getDataGenerator()->create_module('customcert', ['course' => $course->id]); + + // Create two users. + $student1 = $this->getDataGenerator()->create_user(); + $student2 = $this->getDataGenerator()->create_user(); + + $this->setUser($student1); + + // Enrol them into the course. + $this->getDataGenerator()->enrol_user($student1->id, $course->id); + $this->getDataGenerator()->enrol_user($student2->id, $course->id); + + // Issue them both certificates. + $i1 = \mod_customcert\certificate::issue_certificate($customcert->id, $student1->id); + $i2 = \mod_customcert\certificate::issue_certificate($customcert->id, $student2->id); + + $this->assertEquals(2, $DB->count_records('customcert_issues')); + + // Try and delete without the required capability. + $this->expectException('required_capability_exception'); + \mod_customcert\external::delete_issue($customcert->id, $i2); + } +} diff --git a/version.php b/version.php index bc3ebf94e..5045953fd 100644 --- a/version.php +++ b/version.php @@ -24,10 +24,10 @@ defined('MOODLE_INTERNAL') || die('Direct access to this script is forbidden.'); -$plugin->version = 2017111301; // The current module version (Date: YYYYMMDDXX). +$plugin->version = 2017111302; // The current module version (Date: YYYYMMDDXX). $plugin->requires = 2017111300; // Requires this Moodle version (3.4). $plugin->cron = 0; // Period for cron to check this module (secs). $plugin->component = 'mod_customcert'; $plugin->maturity = MATURITY_STABLE; -$plugin->release = "3.4 release (Build: 2017111301)"; // User-friendly version number. +$plugin->release = "3.4 release (Build: 2017111302)"; // User-friendly version number. From 24068856f134295ab38592985da42bb10cb1ce04 Mon Sep 17 00:00:00 2001 From: Mark Nelson Date: Wed, 6 Jun 2018 21:54:57 +0800 Subject: [PATCH 19/93] Updated CHANGES.md --- CHANGES.md | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) diff --git a/CHANGES.md b/CHANGES.md index d3b69dc26..a5f5e56fc 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -4,6 +4,38 @@ 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.4.2] - 2018-06-06 +### Added +- Mobile app support (#70). +``` + This allows students to view the activity and download + their certificate. It also allows teachers to view the + list of issued certificates, with the ability to revoke + any. + + This is for the soon-to-be released Moodle Mobile v3.5.0 + (not to be confused with your Moodle site version) and + will not work on Mobile versions earlier than this. + + If you are running a Moodle site on version 3.4 or below + you will need to install the local_mobile plugin in order + for this to work. + + If you are running a Moodle site on version 3.0 or below + then you will need to upgrade. +``` +- More font sizes (#148). +- Added new download icon. +``` + This was done because the core 'import' icon was mapped + to the Font Awesome icon 'fa-level-up' which did not look + appropriate. So, a new icon was added and that was mapped + to the 'fa-download' icon. +``` +### Fixed +- No longer display the 'action' column and user picture URL when downloading the user report (#192). +- Elements no longer ignore filters (#170). + ## [3.4.1] - 2018-05-17 ### Added - GDPR Compliance (#189). From a42bc9ebe1cf7b9a0eeaa73de6eebff3fcfc1a6f Mon Sep 17 00:00:00 2001 From: Mark Nelson Date: Thu, 7 Jun 2018 18:55:54 +0800 Subject: [PATCH 20/93] #196 Use FORMAT_HTML when calling format_text() --- element/text/classes/element.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/element/text/classes/element.php b/element/text/classes/element.php index bb5e0b94c..659301d57 100644 --- a/element/text/classes/element.php +++ b/element/text/classes/element.php @@ -68,7 +68,7 @@ public function save_unique_data($data) { */ public function render($pdf, $preview, $user) { $courseid = \mod_customcert\element_helper::get_courseid($this->get_id()); - $text = format_text($this->get_data(), FORMAT_MOODLE, ['context' => \context_course::instance($courseid)]); + $text = format_text($this->get_data(), FORMAT_HTML, ['context' => \context_course::instance($courseid)]); \mod_customcert\element_helper::render_content($pdf, $this, $text); } From 0e5ef79ab9511dae3daf0f9a90b5953b52b5d2d8 Mon Sep 17 00:00:00 2001 From: Mark Nelson Date: Thu, 7 Jun 2018 19:29:34 +0800 Subject: [PATCH 21/93] Add example JSON context to templates --- templates/mobile_report_page.mustache | 42 ++++++++++++++++++ templates/mobile_view_activity_page.mustache | 46 ++++++++++++++++++++ 2 files changed, 88 insertions(+) diff --git a/templates/mobile_report_page.mustache b/templates/mobile_report_page.mustache index 7f3ca664f..168367fb8 100644 --- a/templates/mobile_report_page.mustache +++ b/templates/mobile_report_page.mustache @@ -24,6 +24,48 @@ Data attibutes required for JS: * All data attributes are required + + Context variables required for this template: + * certificate + * cmid + * showgroups + * groups + * canmanage + * hasissues + * issues + * currenttimestamp + + Example context (json): + { + "certificate": { + "id": "1", + "course": "2", + "name": "A rad certificate name!", + "intro": "A certificate" + }, + "cmid": "25", + "showgroups": "true", + "groups": [ + { + "id": "2", + "selected": "false", + "name": "Group A" + } + ], + "canmanage": "true", + "hasissues": "true", + "issues": [ + { + "id": "2", + "issueid": "3", + "displayname": "Michaelangelo (Mickey)", + "fileurl": "http://yoursite.com/mod/customcert/mobile/pluginfile.php?id=4", + "code": "Xyt78axR", + "timecreated": "1528370177" + } + ], + "currenttimestamp": "1528370177" + } }} {{=<% %>=}}
diff --git a/templates/mobile_view_activity_page.mustache b/templates/mobile_view_activity_page.mustache index bbc39eb9e..678b07d22 100644 --- a/templates/mobile_view_activity_page.mustache +++ b/templates/mobile_view_activity_page.mustache @@ -24,6 +24,52 @@ Data attibutes required for JS: * All data attributes are required + + Context variables required for this template: + * certificate + * cmid + * groupselected + * showgroups + * groups + * hasissues + * issues + * candownload + * fileurl + * showreport + * numissuesinreport + * currenttimestamp + + Example context (json): + { + "certificate": { + "id": "1", + "course": "2", + "name": "A rad certificate name!", + "intro": "A certificate", + "requiredtime": "60" + }, + "cmid": "25", + "groupselected": "5", + "showgroups": "true", + "groups": [ + { + "id": "2", + "selected": "false", + "name": "Group A" + } + ], + "hasissues": "true", + "issues": [ + { + "timecreated": "1528370177" + } + ], + "candownload": "true", + "fileurl": "http://yoursite.com/mod/customcert/mobile/pluginfile.php?id=4", + "showreport": "true", + "numissuesinreport": "5", + "currenttimestamp": "1528370177" + } }} {{=<% %>=}}
From 9bfaa5da66bd3367493f6e1ed272e19c6fd64f4b Mon Sep 17 00:00:00 2001 From: Mark Nelson Date: Thu, 7 Jun 2018 19:34:07 +0800 Subject: [PATCH 22/93] Updated CHANGES.md --- CHANGES.md | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/CHANGES.md b/CHANGES.md index a5f5e56fc..325af13bc 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -4,6 +4,11 @@ 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.4.3] - 2018-06-07 +### Fixed + +- Hotfix to prevent misalignment of 'text' elements after last release (#196). + ## [3.4.2] - 2018-06-06 ### Added - Mobile app support (#70). From ff31b4b824559cc49f0405d0b7ed3fea1040721a Mon Sep 17 00:00:00 2001 From: Mark Nelson Date: Thu, 7 Jun 2018 19:34:13 +0800 Subject: [PATCH 23/93] Bumped version --- version.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/version.php b/version.php index 5045953fd..9fa8e68cb 100644 --- a/version.php +++ b/version.php @@ -24,10 +24,10 @@ defined('MOODLE_INTERNAL') || die('Direct access to this script is forbidden.'); -$plugin->version = 2017111302; // The current module version (Date: YYYYMMDDXX). +$plugin->version = 2017111303; // The current module version (Date: YYYYMMDDXX). $plugin->requires = 2017111300; // Requires this Moodle version (3.4). $plugin->cron = 0; // Period for cron to check this module (secs). $plugin->component = 'mod_customcert'; $plugin->maturity = MATURITY_STABLE; -$plugin->release = "3.4 release (Build: 2017111302)"; // User-friendly version number. +$plugin->release = "3.4.3"; // User-friendly version number. From 743d1fb86a3f673552bea1b5bed92a43b845107b Mon Sep 17 00:00:00 2001 From: Mark Nelson Date: Thu, 7 Jun 2018 20:10:34 +0800 Subject: [PATCH 24/93] #196 Use FORMAT_HTML when calling format_text() (again) This commit is not as vital as the previous one as it does not affect the layout of the PDF. --- element/text/classes/element.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/element/text/classes/element.php b/element/text/classes/element.php index 659301d57..a2909df20 100644 --- a/element/text/classes/element.php +++ b/element/text/classes/element.php @@ -82,7 +82,7 @@ public function render($pdf, $preview, $user) { */ public function render_html() { $courseid = \mod_customcert\element_helper::get_courseid($this->get_id()); - $text = format_text($this->get_data(), FORMAT_MOODLE, ['context' => \context_course::instance($courseid)]); + $text = format_text($this->get_data(), FORMAT_HTML, ['context' => \context_course::instance($courseid)]); return \mod_customcert\element_helper::render_html_content($this, $text); } From 7038b60c51ed8ed8ca65b616b6d8829081a5b422 Mon Sep 17 00:00:00 2001 From: Mark Nelson Date: Wed, 13 Jun 2018 18:41:34 +0800 Subject: [PATCH 25/93] #202 Make web service accessible by 'local_mobile' --- db/services.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/db/services.php b/db/services.php index 923d84283..da1c93e20 100644 --- a/db/services.php +++ b/db/services.php @@ -32,7 +32,7 @@ 'description' => 'Delete an issue for a certificate', 'type' => 'write', 'ajax' => true, - 'services' => array(MOODLE_OFFICIAL_MOBILE_SERVICE) + 'services' => array(MOODLE_OFFICIAL_MOBILE_SERVICE, 'local_mobile') ), 'mod_customcert_save_element' => array( 'classname' => 'mod_customcert\external', From fab998e07df47b4888fe533c676d23fcb8234b08 Mon Sep 17 00:00:00 2001 From: Mark Nelson Date: Tue, 12 Jun 2018 16:42:27 +0800 Subject: [PATCH 26/93] #197 Respect filters in 'My certificates' and 'Verify certificate' pages --- classes/my_certificates_table.php | 10 ++++++++-- classes/output/verify_certificate_result.php | 7 +++++-- verify_certificate.php | 3 ++- 3 files changed, 15 insertions(+), 5 deletions(-) diff --git a/classes/my_certificates_table.php b/classes/my_certificates_table.php index 38107225b..8da147383 100644 --- a/classes/my_certificates_table.php +++ b/classes/my_certificates_table.php @@ -94,7 +94,10 @@ public function __construct($userid, $download = null) { * @return string */ public function col_name($certificate) { - return $certificate->name; + $cm = get_coursemodule_from_instance('customcert', $certificate->id); + $context = \context_module::instance($cm->id); + + return format_string($certificate->name, true, ['context' => $context]); } /** @@ -104,7 +107,10 @@ public function col_name($certificate) { * @return string */ public function col_coursename($certificate) { - return $certificate->coursename; + $cm = get_coursemodule_from_instance('customcert', $certificate->id); + $context = \context_module::instance($cm->id); + + return format_string($certificate->coursename, true, ['context' => $context]); } /** diff --git a/classes/output/verify_certificate_result.php b/classes/output/verify_certificate_result.php index e6b698c2a..f421eb744 100644 --- a/classes/output/verify_certificate_result.php +++ b/classes/output/verify_certificate_result.php @@ -69,12 +69,15 @@ class verify_certificate_result implements templatable, renderable { * @param \stdClass $result */ public function __construct($result) { + $cm = get_coursemodule_from_instance('customcert', $result->certificateid); + $context = \context_module::instance($cm->id); + $this->userprofileurl = new \moodle_url('/user/view.php', array('id' => $result->userid, 'course' => $result->courseid)); $this->userfullname = fullname($result); $this->courseurl = new \moodle_url('/course/view.php', array('id' => $result->courseid)); - $this->coursefullname = $result->coursefullname; - $this->certificatename = $result->certificatename; + $this->coursefullname = format_string($result->coursefullname, true, ['context' => $context]); + $this->certificatename = format_string($result->certificatename, true, ['context' => $context]); } /** diff --git a/verify_certificate.php b/verify_certificate.php index 8c3bff7ce..d626f69f4 100644 --- a/verify_certificate.php +++ b/verify_certificate.php @@ -89,7 +89,8 @@ // 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, c.verifyany + co.fullname as coursefullname, c.id as certificateid, + c.name as certificatename, c.verifyany FROM {customcert} c JOIN {customcert_issues} ci ON c.id = ci.customcertid From 9c633f1b28465124db9cb552557128644461478a Mon Sep 17 00:00:00 2001 From: Mark Nelson Date: Mon, 18 Jun 2018 18:38:03 +0800 Subject: [PATCH 27/93] #203 Removed confusing 'summaryofissue' string --- db/mobile.php | 1 - lang/en/customcert.php | 1 - templates/mobile_view_activity_page.mustache | 3 --- view.php | 4 +--- 4 files changed, 1 insertion(+), 8 deletions(-) diff --git a/db/mobile.php b/db/mobile.php index e9ece986e..53db001ab 100644 --- a/db/mobile.php +++ b/db/mobile.php @@ -48,7 +48,6 @@ ['receiveddate', 'customcert'], ['requiredtimenotmet', 'customcert'], ['selectagroup', 'moodle'], - ['summaryofissue', 'customcert'], ['viewcustomcertissues', 'customcert'] ], ] diff --git a/lang/en/customcert.php b/lang/en/customcert.php index bb95aa8f7..6afcf03c6 100644 --- a/lang/en/customcert.php +++ b/lang/en/customcert.php @@ -154,7 +154,6 @@ $string['showposxy_desc'] = 'This will show the X and Y position when editing of an element, allowing the user to accurately specify the location. This isn\'t required if you plan on solely using the drag and drop interface for this purpose.'; -$string['summaryofissue'] = 'Summary of issue'; $string['taskemailcertificate'] = 'Handles emailing certificates.'; $string['templatename'] = 'Template name'; $string['templatenameexists'] = 'That template name is currently in use, please choose another.'; diff --git a/templates/mobile_view_activity_page.mustache b/templates/mobile_view_activity_page.mustache index 678b07d22..008dcfc80 100644 --- a/templates/mobile_view_activity_page.mustache +++ b/templates/mobile_view_activity_page.mustache @@ -91,9 +91,6 @@ <%/showreport%> <%#hasissues%> - -

{{ 'plugin.mod_customcert.summaryofissue' | translate }}

-
<%#issues%> {{ <% timecreated %> | coreToLocaleString }} diff --git a/view.php b/view.php index 4a9983934..2f0736f5b 100644 --- a/view.php +++ b/view.php @@ -86,8 +86,6 @@ // If the current user has been issued a customcert generate HTML to display the details. $issuelist = ''; if ($issues = $DB->get_records('customcert_issues', array('userid' => $USER->id, 'customcertid' => $customcert->id))) { - $header = $OUTPUT->heading(get_string('summaryofissue', 'customcert')); - $table = new html_table(); $table->class = 'generaltable'; $table->head = array(get_string('issued', 'customcert')); @@ -100,7 +98,7 @@ $table->data[$issue->id] = $row; } - $issuelist = $header . html_writer::table($table) . "
"; + $issuelist = html_writer::table($table) . "
"; } // Create the button to download the customcert. From aeee01b7be43ab40d749503f4aa9987d8337c329 Mon Sep 17 00:00:00 2001 From: Mark Nelson Date: Mon, 18 Jun 2018 18:39:29 +0800 Subject: [PATCH 28/93] #203 Removed 'issued' string and replaced with 'receiveddate' Also renamed 'Received date' to 'Awarded on'. --- index.php | 4 ++-- lang/en/customcert.php | 3 +-- lib.php | 4 ++-- templates/mobile_view_activity_page.mustache | 3 +++ view.php | 2 +- 5 files changed, 9 insertions(+), 7 deletions(-) diff --git a/index.php b/index.php index b4d1cb966..1ab05ed96 100644 --- a/index.php +++ b/index.php @@ -60,9 +60,9 @@ if ($usesections = course_format_uses_sections($course->format)) { $table->head = array(get_string('sectionname', 'format_'.$course->format), get_string('name'), - get_string('issued', 'customcert')); + get_string('receiveddate', 'customcert')); } else { - $table->head = array(get_string('name'), get_string('issued', 'customcert')); + $table->head = array(get_string('name'), get_string('receiveddate', 'customcert')); } $currentsection = ''; diff --git a/lang/en/customcert.php b/lang/en/customcert.php index 6afcf03c6..9ba4470d6 100644 --- a/lang/en/customcert.php +++ b/lang/en/customcert.php @@ -94,7 +94,6 @@ $string['invalidheight'] = 'The height has to be a valid number greater than 0.'; $string['invalidmargin'] = 'The margin has to be a valid number greater than 0.'; $string['invalidwidth'] = 'The width has to be a valid number greater than 0.'; -$string['issued'] = 'Issued'; $string['landscape'] = 'Landscape'; $string['leftmargin'] = 'Left margin'; $string['leftmargin_help'] = 'This is the left margin of the certificate PDF in mm.'; @@ -135,7 +134,7 @@ $string['privacy:metadata:customcert_issues:userid'] = 'The ID of the user who was issued the certificate'; $string['rearrangeelements'] = 'Reposition elements'; $string['rearrangeelementsheading'] = 'Drag and drop elements to change where they are positioned on the certificate.'; -$string['receiveddate'] = 'Received date'; +$string['receiveddate'] = 'Awarded on'; $string['refpoint'] = 'Reference point location'; $string['refpoint_help'] = 'The reference point is the location of an element from which its x and y coordinates are determined. It is indicated by the \'+\' that appears in the centre or corners of the element.'; $string['replacetemplate'] = 'Replace'; diff --git a/lib.php b/lib.php index ff7c8db1a..575814d6f 100644 --- a/lib.php +++ b/lib.php @@ -181,7 +181,7 @@ function customcert_user_outline($course, $user, $mod, $customcert) { $result = new stdClass(); if ($issue = $DB->get_record('customcert_issues', array('customcertid' => $customcert->id, 'userid' => $user->id))) { - $result->info = get_string('issued', 'customcert'); + $result->info = get_string('receiveddate', 'customcert'); $result->time = $issue->timecreated; } else { $result->info = get_string('notissued', 'customcert'); @@ -205,7 +205,7 @@ function customcert_user_complete($course, $user, $mod, $customcert) { if ($issue = $DB->get_record('customcert_issues', array('customcertid' => $customcert->id, 'userid' => $user->id))) { echo $OUTPUT->box_start(); - echo get_string('issued', 'customcert') . ": "; + echo get_string('receiveddate', 'customcert') . ": "; echo userdate($issue->timecreated); echo $OUTPUT->box_end(); } else { diff --git a/templates/mobile_view_activity_page.mustache b/templates/mobile_view_activity_page.mustache index 008dcfc80..5a7334396 100644 --- a/templates/mobile_view_activity_page.mustache +++ b/templates/mobile_view_activity_page.mustache @@ -91,6 +91,9 @@ <%/showreport%> <%#hasissues%> + + {{ 'plugin.mod_customcert.receiveddate' | translate }} + <%#issues%> {{ <% timecreated %> | coreToLocaleString }} diff --git a/view.php b/view.php index 2f0736f5b..408d8d1c7 100644 --- a/view.php +++ b/view.php @@ -88,7 +88,7 @@ if ($issues = $DB->get_records('customcert_issues', array('userid' => $USER->id, 'customcertid' => $customcert->id))) { $table = new html_table(); $table->class = 'generaltable'; - $table->head = array(get_string('issued', 'customcert')); + $table->head = array(get_string('receiveddate', 'customcert')); $table->align = array('left'); $table->attributes = array('style' => 'width:20%; margin:auto'); From 3f4e2be973a0a26ef90c770a5499f444c975c128 Mon Sep 17 00:00:00 2001 From: Mark Nelson Date: Tue, 19 Jun 2018 11:56:16 +0800 Subject: [PATCH 29/93] #203 Make mobile layout friendly on small screens --- db/mobile.php | 3 -- templates/mobile_report_page.mustache | 75 ++++++++++----------------- 2 files changed, 27 insertions(+), 51 deletions(-) diff --git a/db/mobile.php b/db/mobile.php index 53db001ab..9e1d36840 100644 --- a/db/mobile.php +++ b/db/mobile.php @@ -37,10 +37,7 @@ ] ], 'lang' => [ // Language strings that are used in all the handlers. - ['code', 'customcert'], ['deleteissueconfirm', 'customcert'], - ['file', 'moodle'], - ['fullname', 'moodle'], ['getcustomcert', 'customcert'], ['modulenameplural', 'customcert'], ['nothingtodisplay', 'moodle'], diff --git a/templates/mobile_report_page.mustache b/templates/mobile_report_page.mustache index 168367fb8..b00a1a2e3 100644 --- a/templates/mobile_report_page.mustache +++ b/templates/mobile_report_page.mustache @@ -84,56 +84,35 @@

{{ 'plugin.mod_customcert.modulenameplural' | translate }}

<%#hasissues%> - - - - - {{ 'plugin.mod_customcert.fullname' | translate }} - - - {{ 'plugin.mod_customcert.receiveddate' | translate }} - - - {{ 'plugin.mod_customcert.code' | translate }} - - - {{ 'plugin.mod_customcert.file' | translate }} - - <%#canmanage%> - - <%/canmanage%> - - <%#issues%> - - - <% displayname %> - - - {{ <% timecreated %> | coreToLocaleString }} - - - <% code %> - - - - - <%#canmanage%> - - + <%#canmanage%> + + <%/canmanage%> - <%/canmanage%> - - <%/issues%> - - + + +
+ <%/issues%> +
<%/hasissues%> <%^hasissues%> From 9f4492e7e92e7bb7bfa726b83a6411f98563a924 Mon Sep 17 00:00:00 2001 From: Mark Nelson Date: Tue, 19 Jun 2018 19:05:25 +0800 Subject: [PATCH 30/93] Fixed reference to 'mod/certificate' capability --- classes/output/mobile.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/classes/output/mobile.php b/classes/output/mobile.php index c21593841..c757984e0 100644 --- a/classes/output/mobile.php +++ b/classes/output/mobile.php @@ -67,7 +67,7 @@ public static function mobile_view_activity($args) { $issues = $DB->get_records('customcert_issues', ['userid' => $USER->id, 'customcertid' => $certificate->id]); $candownload = true; - if ($certificate->requiredtime && !has_capability('mod/certificate:manage', $context)) { + if ($certificate->requiredtime && !has_capability('mod/customcert:manage', $context)) { if (\mod_customcert\certificate::get_course_time($certificate->course) < ($certificate->requiredtime * 60)) { $candownload = false; } From 5b56acad9b757b280890ba1fa3fe22ffc8e37eb8 Mon Sep 17 00:00:00 2001 From: Mark Nelson Date: Tue, 19 Jun 2018 19:10:08 +0800 Subject: [PATCH 31/93] #203 Don't show 'Awarded on' date to managers --- classes/output/mobile.php | 4 +++- templates/mobile_view_activity_page.mustache | 22 +++++++++++--------- view.php | 7 +++++-- 3 files changed, 20 insertions(+), 13 deletions(-) diff --git a/classes/output/mobile.php b/classes/output/mobile.php index c757984e0..b33580a35 100644 --- a/classes/output/mobile.php +++ b/classes/output/mobile.php @@ -67,7 +67,8 @@ public static function mobile_view_activity($args) { $issues = $DB->get_records('customcert_issues', ['userid' => $USER->id, 'customcertid' => $certificate->id]); $candownload = true; - if ($certificate->requiredtime && !has_capability('mod/customcert:manage', $context)) { + $canmanage = has_capability('mod/customcert:manage', $context); + if ($certificate->requiredtime && !$canmanage) { if (\mod_customcert\certificate::get_course_time($certificate->course) < ($certificate->requiredtime * 60)) { $candownload = false; } @@ -100,6 +101,7 @@ public static function mobile_view_activity($args) { 'groups' => array_values($groups), 'hasissues' => !empty($issues), 'issues' => array_values($issues), + 'canmanage' => $canmanage, 'candownload' => $candownload, 'fileurl' => $fileurl, 'showreport' => $showreport, diff --git a/templates/mobile_view_activity_page.mustache b/templates/mobile_view_activity_page.mustache index 5a7334396..b1c0fb95a 100644 --- a/templates/mobile_view_activity_page.mustache +++ b/templates/mobile_view_activity_page.mustache @@ -90,16 +90,18 @@ <%/showreport%> <%#hasissues%> - - - {{ 'plugin.mod_customcert.receiveddate' | translate }} - - <%#issues%> - - {{ <% timecreated %> | coreToLocaleString }} - - <%/issues%> - + <%^canmanage%> + + + {{ 'plugin.mod_customcert.receiveddate' | translate }} + + <%#issues%> + + {{ <% timecreated %> | coreToLocaleString }} + + <%/issues%> + + <%/canmanage%> <%/hasissues%> <%#candownload%> diff --git a/view.php b/view.php index 408d8d1c7..7570d7dc1 100644 --- a/view.php +++ b/view.php @@ -37,12 +37,14 @@ $context = context_module::instance($cm->id); require_capability('mod/customcert:view', $context); +$canmanage = has_capability('mod/customcert:manage', $context); + // Initialise $PAGE. $pageurl = new moodle_url('/mod/customcert/view.php', array('id' => $cm->id)); \mod_customcert\page_helper::page_setup($pageurl, $context, format_string($customcert->name)); // Check if the user can view the certificate based on time spent in course. -if ($customcert->requiredtime && !has_capability('mod/customcert:manage', $context)) { +if ($customcert->requiredtime && !$canmanage) { if (\mod_customcert\certificate::get_course_time($course->id) < ($customcert->requiredtime * 60)) { $a = new stdClass; $a->requiredtime = $customcert->requiredtime; @@ -85,7 +87,8 @@ // If the current user has been issued a customcert generate HTML to display the details. $issuelist = ''; - if ($issues = $DB->get_records('customcert_issues', array('userid' => $USER->id, 'customcertid' => $customcert->id))) { + $issues = $DB->get_records('customcert_issues', array('userid' => $USER->id, 'customcertid' => $customcert->id)); + if ($issues && !$canmanage) { $table = new html_table(); $table->class = 'generaltable'; $table->head = array(get_string('receiveddate', 'customcert')); From 75a9357dd1f074a75cc5c6f7989a27fa22600cac Mon Sep 17 00:00:00 2001 From: Mark Nelson Date: Tue, 19 Jun 2018 19:21:17 +0800 Subject: [PATCH 32/93] #203 Don't display group select on activity view page --- classes/output/mobile.php | 8 ------- templates/mobile_view_activity_page.mustache | 24 +------------------- view.php | 1 - 3 files changed, 1 insertion(+), 32 deletions(-) diff --git a/classes/output/mobile.php b/classes/output/mobile.php index b33580a35..fb503b692 100644 --- a/classes/output/mobile.php +++ b/classes/output/mobile.php @@ -45,8 +45,6 @@ public static function mobile_view_activity($args) { $args = (object) $args; - // Get the group variable. - $groupid = empty($args->group) ? 0 : $args->group; // By default, group 0. $cmid = $args->cmid; // Capabilities check. @@ -60,9 +58,6 @@ public static function mobile_view_activity($args) { list($certificate->intro, $certificate->introformat) = external_format_text($certificate->intro, $certificate->introformat, $context->id, 'mod_customcert', 'intro'); - // Get the groups (if any) to display - also sets active group. - $groups = self::get_groups($cm, $groupid, $USER->id); - // Get any issues this person may have. $issues = $DB->get_records('customcert_issues', ['userid' => $USER->id, 'customcertid' => $certificate->id]); @@ -96,9 +91,6 @@ public static function mobile_view_activity($args) { $data = [ 'certificate' => $certificate, 'cmid' => $cm->id, - 'groupselected' => $groupid, - 'showgroups' => !empty($groups), - 'groups' => array_values($groups), 'hasissues' => !empty($issues), 'issues' => array_values($issues), 'canmanage' => $canmanage, diff --git a/templates/mobile_view_activity_page.mustache b/templates/mobile_view_activity_page.mustache index b1c0fb95a..34d3a5c99 100644 --- a/templates/mobile_view_activity_page.mustache +++ b/templates/mobile_view_activity_page.mustache @@ -28,9 +28,6 @@ Context variables required for this template: * certificate * cmid - * groupselected - * showgroups - * groups * hasissues * issues * candownload @@ -49,15 +46,6 @@ "requiredtime": "60" }, "cmid": "25", - "groupselected": "5", - "showgroups": "true", - "groups": [ - { - "id": "2", - "selected": "false", - "name": "Group A" - } - ], "hasissues": "true", "issues": [ { @@ -74,18 +62,8 @@ {{=<% %>=}}
- <%#showgroups%> - - {{ 'plugin.mod_customcert.selectagroup' | translate }} - - <%#groups%> - selected<%/selected%>><% name %> - <%/groups%> - - - <%/showgroups%> <%#showreport%> - + {{ 'plugin.mod_customcert.viewcustomcertissues' | translate: {$a: <% numissuesinreport %>} }} <%/showreport%> diff --git a/view.php b/view.php index 7570d7dc1..0850e10be 100644 --- a/view.php +++ b/view.php @@ -112,7 +112,6 @@ // Output all the page data. echo $OUTPUT->header(); - groups_print_activity_menu($cm, $pageurl); echo $reportlink; echo $intro; echo $issuelist; From 18ce8da214ab674f93e68ef2be8d9a7fcc327d1c Mon Sep 17 00:00:00 2001 From: Mark Nelson Date: Tue, 19 Jun 2018 21:33:11 +0800 Subject: [PATCH 33/93] #203 Added new string for list of awarded certificates --- db/mobile.php | 2 +- lang/en/customcert.php | 1 + report.php | 2 +- templates/mobile_report_page.mustache | 2 +- 4 files changed, 4 insertions(+), 3 deletions(-) diff --git a/db/mobile.php b/db/mobile.php index 9e1d36840..5e76dfab5 100644 --- a/db/mobile.php +++ b/db/mobile.php @@ -39,7 +39,7 @@ 'lang' => [ // Language strings that are used in all the handlers. ['deleteissueconfirm', 'customcert'], ['getcustomcert', 'customcert'], - ['modulenameplural', 'customcert'], + ['listofissues', 'customcert'], ['nothingtodisplay', 'moodle'], ['pluginname', 'customcert'], ['receiveddate', 'customcert'], diff --git a/lang/en/customcert.php b/lang/en/customcert.php index 9ba4470d6..a442c0656 100644 --- a/lang/en/customcert.php +++ b/lang/en/customcert.php @@ -97,6 +97,7 @@ $string['landscape'] = 'Landscape'; $string['leftmargin'] = 'Left margin'; $string['leftmargin_help'] = 'This is the left margin of the certificate PDF in mm.'; +$string['listofissues'] = 'List of awarded certificates'; $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.'; diff --git a/report.php b/report.php index 4f2e94aad..a00e74ab0 100644 --- a/report.php +++ b/report.php @@ -110,7 +110,7 @@ $PAGE->navbar->add(get_string('customcertreport', 'customcert')); echo $OUTPUT->header(); -echo $OUTPUT->heading(get_string('modulenameplural', 'customcert')); +echo $OUTPUT->heading(get_string('listofissues', 'customcert')); groups_print_activity_menu($cm, $url); diff --git a/templates/mobile_report_page.mustache b/templates/mobile_report_page.mustache index b00a1a2e3..4ddda7672 100644 --- a/templates/mobile_report_page.mustache +++ b/templates/mobile_report_page.mustache @@ -81,7 +81,7 @@ <%/showgroups%> -

{{ 'plugin.mod_customcert.modulenameplural' | translate }}

+

{{ 'plugin.mod_customcert.listofissues' | translate }}

<%#hasissues%> From 3680c4586c6afc1628dd93d0d7d128d6071cf5a9 Mon Sep 17 00:00:00 2001 From: Mark Nelson Date: Wed, 20 Jun 2018 17:03:51 +0800 Subject: [PATCH 34/93] #203 Added heading to activity view page in browser --- view.php | 1 + 1 file changed, 1 insertion(+) diff --git a/view.php b/view.php index 0850e10be..7de14f0a3 100644 --- a/view.php +++ b/view.php @@ -112,6 +112,7 @@ // Output all the page data. echo $OUTPUT->header(); + echo $OUTPUT->heading(format_string($customcert->name), 2); echo $reportlink; echo $intro; echo $issuelist; From 930850ac3b019fbbada12f010ffc0b40fdffa304 Mon Sep 17 00:00:00 2001 From: Mark Nelson Date: Wed, 20 Jun 2018 17:44:03 +0800 Subject: [PATCH 35/93] #203 Changed 'listofissues' string to avoid confusion --- lang/en/customcert.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lang/en/customcert.php b/lang/en/customcert.php index a442c0656..fb108484b 100644 --- a/lang/en/customcert.php +++ b/lang/en/customcert.php @@ -97,7 +97,7 @@ $string['landscape'] = 'Landscape'; $string['leftmargin'] = 'Left margin'; $string['leftmargin_help'] = 'This is the left margin of the certificate PDF in mm.'; -$string['listofissues'] = 'List of awarded certificates'; +$string['listofissues'] = 'List of recipients'; $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.'; From 2e146373dd0b7a4d520022dee244bbfbc532b6c9 Mon Sep 17 00:00:00 2001 From: Mark Nelson Date: Mon, 25 Jun 2018 14:49:26 +0800 Subject: [PATCH 36/93] #203 Make report heading/title consistent with core activities --- lang/en/customcert.php | 1 - report.php | 6 +++--- 2 files changed, 3 insertions(+), 4 deletions(-) diff --git a/lang/en/customcert.php b/lang/en/customcert.php index fb108484b..0e6665a5a 100644 --- a/lang/en/customcert.php +++ b/lang/en/customcert.php @@ -33,7 +33,6 @@ $string['coursetimereq_help'] = 'Enter here the minimum amount of time, in minutes, that a student must be logged into the course before they will be able to receive the certificate.'; $string['createtemplate'] = 'Create template'; -$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'; diff --git a/report.php b/report.php index a00e74ab0..41bf6cf5c 100644 --- a/report.php +++ b/report.php @@ -104,13 +104,13 @@ } // Set up the page. -\mod_customcert\page_helper::page_setup($pageurl, $context, get_string('customcertreport', 'customcert')); +\mod_customcert\page_helper::page_setup($pageurl, $context, $customcert->name); // Additional page setup. -$PAGE->navbar->add(get_string('customcertreport', 'customcert')); +$PAGE->navbar->add(get_string('listofissues', 'customcert')); echo $OUTPUT->header(); -echo $OUTPUT->heading(get_string('listofissues', 'customcert')); +echo $OUTPUT->heading(format_string($customcert->name), 2); groups_print_activity_menu($cm, $url); From e5939c8076b39a9a85491c0ec3f00096982f4777 Mon Sep 17 00:00:00 2001 From: Mark Nelson Date: Tue, 26 Jun 2018 14:54:40 +0800 Subject: [PATCH 37/93] #203 Improved 'listofissues' string --- lang/en/customcert.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lang/en/customcert.php b/lang/en/customcert.php index 0e6665a5a..c83937ba7 100644 --- a/lang/en/customcert.php +++ b/lang/en/customcert.php @@ -96,7 +96,7 @@ $string['landscape'] = 'Landscape'; $string['leftmargin'] = 'Left margin'; $string['leftmargin_help'] = 'This is the left margin of the certificate PDF in mm.'; -$string['listofissues'] = 'List of recipients'; +$string['listofissues'] = 'Recipients'; $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.'; From 9d27015a5fdda4488513a82d6987b3feedf43b97 Mon Sep 17 00:00:00 2001 From: Mark Nelson Date: Tue, 26 Jun 2018 17:14:42 +0800 Subject: [PATCH 38/93] #203 Removed 'code' column Not all certificates contain a 'code' element, making this column unnecessary. It may also confuse users when it is not applicable. For those who are interested they can always use the 'verify' functionality to confirm certificates, rather than using this page. --- classes/report_table.php | 17 ++--------------- 1 file changed, 2 insertions(+), 15 deletions(-) diff --git a/classes/report_table.php b/classes/report_table.php index 5fcd71c99..f3eddd51e 100644 --- a/classes/report_table.php +++ b/classes/report_table.php @@ -67,13 +67,11 @@ public function __construct($customcertid, $cm, $groupmode, $download = null) { $columns = array( 'fullname', - 'timecreated', - 'code' + 'timecreated' ); $headers = array( get_string('fullname'), - get_string('receiveddate', 'customcert'), - get_string('code', 'customcert') + get_string('receiveddate', 'customcert') ); // Check if we were passed a filename, which means we want to download it. @@ -95,7 +93,6 @@ public function __construct($customcertid, $cm, $groupmode, $download = null) { $this->define_headers($headers); $this->collapsible(false); $this->sortable(true); - $this->no_sorting('code'); $this->no_sorting('download'); $this->is_downloadable(true); @@ -130,16 +127,6 @@ public function col_timecreated($user) { return userdate($user->timecreated); } - /** - * Generate the code column. - * - * @param \stdClass $user - * @return string - */ - public function col_code($user) { - return $user->code; - } - /** * Generate the download column. * From c1a70c763e8484a2a3f5f4b2166c91185da93fc9 Mon Sep 17 00:00:00 2001 From: Mark Nelson Date: Tue, 26 Jun 2018 18:50:21 +0800 Subject: [PATCH 39/93] #203 Consistency among headings/titles on all pages --- edit.php | 24 +++++++++++++++++------- edit_element.php | 14 +++++++++++--- lang/en/customcert.php | 1 + manage_templates.php | 25 +++++++++++++++---------- report.php | 24 +++++++++++++++--------- settings.php | 4 ++++ upload_image.php | 3 ++- verify_certificate.php | 38 +++++++++++++++++++++----------------- 8 files changed, 86 insertions(+), 47 deletions(-) diff --git a/edit.php b/edit.php index 60cf5b7ab..c84ca085a 100644 --- a/edit.php +++ b/edit.php @@ -51,19 +51,31 @@ if ($context->contextlevel == CONTEXT_MODULE) { $cm = get_coursemodule_from_id('customcert', $context->instanceid, 0, false, MUST_EXIST); require_login($cm->course, false, $cm); + + $customcert = $DB->get_record('customcert', ['id' => $cm->instance], '*', MUST_EXIST); + $title = $customcert->name; + $heading = format_string($title); } else { require_login(); + $title = $SITE->fullname; + $heading = $title; } + require_capability('mod/customcert:manage', $context); // Set up the page. -\mod_customcert\page_helper::page_setup($pageurl, $context, get_string('editcustomcert', 'customcert')); +\mod_customcert\page_helper::page_setup($pageurl, $context, $title); if ($context->contextlevel == CONTEXT_SYSTEM) { // We are managing a template - add some navigation. $PAGE->navbar->add(get_string('managetemplates', 'customcert'), new moodle_url('/mod/customcert/manage_templates.php')); - $PAGE->navbar->add(get_string('editcustomcert', 'customcert')); + if (!$tid) { + $PAGE->navbar->add(get_string('editcustomcert', 'customcert')); + } else { + $PAGE->navbar->add(get_string('editcustomcert', 'customcert'), + new moodle_url('/mod/customcert/edit.php', ['tid' => $tid])); + } } // Flag to determine if we are deleting anything. @@ -140,11 +152,9 @@ // Check if we are deleting either a page or an element. if ($deleting) { // Show a confirmation page. - $strheading = get_string('deleteconfirm', 'customcert'); - $PAGE->navbar->add($strheading); - $PAGE->set_title($strheading); + $PAGE->navbar->add(get_string('deleteconfirm', 'customcert')); echo $OUTPUT->header(); - echo $OUTPUT->heading($strheading); + echo $OUTPUT->heading($heading); echo $OUTPUT->confirm($message, $yesurl, $nourl); echo $OUTPUT->footer(); exit(); @@ -230,7 +240,7 @@ } echo $OUTPUT->header(); -echo $OUTPUT->heading(get_string('editcustomcert', 'customcert')); +echo $OUTPUT->heading($heading); $mform->display(); if ($tid && $context->contextlevel == CONTEXT_MODULE) { $loadtemplateurl = new moodle_url('/mod/customcert/load_template.php', array('tid' => $tid)); diff --git a/edit_element.php b/edit_element.php index c39d89da1..e8aba70f9 100644 --- a/edit_element.php +++ b/edit_element.php @@ -41,6 +41,15 @@ // Make sure the user has the required capabilities. $template->require_manage(); +if ($template->get_context()->contextlevel == CONTEXT_MODULE) { + $customcert = $DB->get_record('customcert', ['id' => $cm->instance], '*', MUST_EXIST); + $title = $customcert->name; + $heading = format_string($title); +} else { + $title = $SITE->fullname; + $heading = $title; +} + if ($action == 'edit') { // The id of the element must be supplied if we are currently editing one. $id = required_param('id', PARAM_INT); @@ -56,7 +65,6 @@ } // Set up the page. -$title = get_string('editelement', 'customcert'); \mod_customcert\page_helper::page_setup($pageurl, $template->get_context(), $title); // Additional page setup. @@ -66,7 +74,7 @@ } $PAGE->navbar->add(get_string('editcustomcert', 'customcert'), new moodle_url('/mod/customcert/edit.php', array('tid' => $tid))); -$PAGE->navbar->add($title); +$PAGE->navbar->add(get_string('editelement', 'customcert')); $mform = new \mod_customcert\edit_element_form($pageurl, array('element' => $element)); @@ -95,6 +103,6 @@ } echo $OUTPUT->header(); -echo $OUTPUT->heading(get_string('editelement', 'customcert')); +echo $OUTPUT->heading($heading); $mform->display(); echo $OUTPUT->footer(); diff --git a/lang/en/customcert.php b/lang/en/customcert.php index c83937ba7..c8b3baaba 100644 --- a/lang/en/customcert.php +++ b/lang/en/customcert.php @@ -170,6 +170,7 @@ 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['verifycertificatedesc'] = 'This link will take you to a new screen where you will be able to verify certificates on the site'; $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'; diff --git a/manage_templates.php b/manage_templates.php index 6cfe590ad..42d223d49 100644 --- a/manage_templates.php +++ b/manage_templates.php @@ -46,12 +46,20 @@ require_login(); require_capability('mod/customcert:manage', $context); +$title = $SITE->fullname; +$heading = $title; + // Set up the page. $pageurl = new moodle_url('/mod/customcert/manage_templates.php'); -\mod_customcert\page_helper::page_setup($pageurl, $context, get_string('managetemplates', 'customcert')); +\mod_customcert\page_helper::page_setup($pageurl, $context, $title); // Additional page setup. -$PAGE->navbar->add(get_string('managetemplates', 'customcert')); +if ($tid && $action && confirm_sesskey()) { + $PAGE->navbar->add(get_string('managetemplates', 'customcert'), + new moodle_url('/mod/customcert/manage_templates.php')); +} else { + $PAGE->navbar->add(get_string('managetemplates', 'customcert')); +} if ($tid) { if ($action && confirm_sesskey()) { @@ -69,12 +77,10 @@ if ($action == 'delete') { if (!$confirm) { // Show a confirmation page. - $strheading = get_string('deleteconfirm', 'customcert'); - $PAGE->navbar->add($strheading); - $PAGE->set_title($strheading); + $PAGE->navbar->add(get_string('deleteconfirm', 'customcert')); $message = get_string('deletetemplateconfirm', 'customcert'); echo $OUTPUT->header(); - echo $OUTPUT->heading($strheading); + echo $OUTPUT->heading($heading); echo $OUTPUT->confirm($message, $yesurl, $nourl); echo $OUTPUT->footer(); exit(); @@ -88,12 +94,10 @@ } else if ($action == 'duplicate') { if (!$confirm) { // Show a confirmation page. - $strheading = get_string('duplicateconfirm', 'customcert'); - $PAGE->navbar->add($strheading); - $PAGE->set_title($strheading); + $PAGE->navbar->add(get_string('duplicateconfirm', 'customcert')); $message = get_string('duplicatetemplateconfirm', 'customcert'); echo $OUTPUT->header(); - echo $OUTPUT->heading($strheading); + echo $OUTPUT->heading($heading); echo $OUTPUT->confirm($message, $yesurl, $nourl); echo $OUTPUT->footer(); exit(); @@ -120,6 +124,7 @@ $table->define_baseurl($pageurl); echo $OUTPUT->header(); +echo $OUTPUT->heading($heading); $table->out($perpage, false); $url = new moodle_url('/mod/customcert/edit.php?contextid=' . $contextid); echo $OUTPUT->single_button($url, get_string('createtemplate', 'customcert'), 'get'); diff --git a/report.php b/report.php index 41bf6cf5c..afafe9bb1 100644 --- a/report.php +++ b/report.php @@ -48,6 +48,19 @@ $context = context_module::instance($cm->id); require_capability('mod/customcert:viewreport', $context); +// Set up the page. +$title = $customcert->name; +$heading = format_string($title); +\mod_customcert\page_helper::page_setup($pageurl, $context, $title); + +// Additional page setup. +if ($deleteissue && confirm_sesskey()) { + $PAGE->navbar->add(get_string('listofissues', 'customcert'), + new moodle_url('/mod/customcert/report.php', ['id' => $id])); +} else { + $PAGE->navbar->add(get_string('listofissues', 'customcert')); +} + if ($deleteissue && confirm_sesskey()) { require_capability('mod/customcert:manage', $context); @@ -63,13 +76,10 @@ ); // Show a confirmation page. - $strheading = get_string('deleteconfirm', 'customcert'); - $PAGE->navbar->add($strheading); - $PAGE->set_title($strheading); - $PAGE->set_url($url); + $PAGE->navbar->add(get_string('deleteconfirm', 'customcert')); $message = get_string('deleteissueconfirm', 'customcert'); echo $OUTPUT->header(); - echo $OUTPUT->heading($strheading); + echo $OUTPUT->heading($heading); echo $OUTPUT->confirm($message, $yesurl, $nourl); echo $OUTPUT->footer(); exit(); @@ -103,11 +113,7 @@ exit(); } -// Set up the page. -\mod_customcert\page_helper::page_setup($pageurl, $context, $customcert->name); -// Additional page setup. -$PAGE->navbar->add(get_string('listofissues', 'customcert')); echo $OUTPUT->header(); echo $OUTPUT->heading(format_string($customcert->name), 2); diff --git a/settings.php b/settings.php index c6a781710..9ae24bc83 100644 --- a/settings.php +++ b/settings.php @@ -35,6 +35,10 @@ get_string('showposxy_desc', 'customcert'), 0)); +$settings->add(new \mod_customcert\admin_setting_link('customcert/verifycertificate', + get_string('verifycertificate', 'customcert'), get_string('verifycertificatedesc', 'customcert'), + get_string('verifycertificate', 'customcert'), new moodle_url('/mod/customcert/verify_certificate.php'), '')); + $settings->add(new \mod_customcert\admin_setting_link('customcert/managetemplates', get_string('managetemplates', 'customcert'), get_string('managetemplatesdesc', 'customcert'), get_string('managetemplates', 'customcert'), new moodle_url('/mod/customcert/manage_templates.php'), '')); diff --git a/upload_image.php b/upload_image.php index fb1832b3c..dbfa1c76d 100644 --- a/upload_image.php +++ b/upload_image.php @@ -33,7 +33,7 @@ // Set the page variables. $pageurl = new moodle_url('/mod/customcert/upload_image.php'); -\mod_customcert\page_helper::page_setup($pageurl, $context, $struploadimage, $SITE->fullname); +\mod_customcert\page_helper::page_setup($pageurl, $context, $SITE->fullname); // Additional page setup. $PAGE->navbar->add($struploadimage); @@ -50,5 +50,6 @@ } echo $OUTPUT->header(); +echo $OUTPUT->heading($SITE->fullname); $uploadform->display(); echo $OUTPUT->footer(); diff --git a/verify_certificate.php b/verify_certificate.php index d626f69f4..a3577cd12 100644 --- a/verify_certificate.php +++ b/verify_certificate.php @@ -33,6 +33,10 @@ // Set up the page. $pageurl = new moodle_url('/mod/customcert/verify_certificate.php', array('contextid' => $contextid)); +if ($code) { + $pageurl->param('code', $code); +} + // Ok, a certificate was specified. if ($context->contextlevel != CONTEXT_SYSTEM) { $cm = get_coursemodule_from_id('customcert', $context->instanceid, 0, false, MUST_EXIST); @@ -49,36 +53,36 @@ $PAGE->set_cm($cm, $course); } + $title = $customcert->name; + $heading = format_string($title); $checkallofsite = false; } else { + $title = $SITE->fullname; + $heading = $title; + $checkallofsite = true; +} + +\mod_customcert\page_helper::page_setup($pageurl, $context, $title); + +// Additional page setup. +if ($context->contextlevel == CONTEXT_SYSTEM) { + $PAGE->navbar->add(get_string('verifycertificate', 'customcert')); +} + +if ($checkallofsite) { // 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->heading($heading); 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); -$PAGE->set_title(get_string('verifycertificate', 'customcert')); - // The form we are using to verify these codes. $form = new \mod_customcert\verify_certificate_form($pageurl); @@ -124,7 +128,7 @@ } echo $OUTPUT->header(); -echo $OUTPUT->heading(get_string('verifycertificate', 'customcert')); +echo $OUTPUT->heading($heading); echo $form->display(); if (isset($result)) { $renderer = $PAGE->get_renderer('mod_customcert'); From 6fafe6aea9eec04e9199ed153c9bc486af6ba5d5 Mon Sep 17 00:00:00 2001 From: Mark Nelson Date: Tue, 26 Jun 2018 19:23:03 +0800 Subject: [PATCH 40/93] Updated CHANGES.md --- CHANGES.md | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/CHANGES.md b/CHANGES.md index 325af13bc..187cb9dfb 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -4,6 +4,17 @@ 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.4.4] - 2018-06-26 +### Fixed + +- Respect filters in the 'My certificates' and 'Verify certificate' pages (#197). +- Fixed reference to 'mod/certificate' capability. +- Provided access to necessary web services for mobile functionality to the tool_mobile plugin (#202). + +### Changed + +- Multiple UX improvements to both the browser and mobile views (#203). + ## [3.4.3] - 2018-06-07 ### Fixed From bb627df42e8330ea5e6ade2b3e0f659bdca2c579 Mon Sep 17 00:00:00 2001 From: Mark Nelson Date: Tue, 26 Jun 2018 20:11:01 +0800 Subject: [PATCH 41/93] #203 Added missing consistency changes for headings/titles --- load_template.php | 17 ++++++++++++++++- rearrange.php | 12 +++++++++++- 2 files changed, 27 insertions(+), 2 deletions(-) diff --git a/load_template.php b/load_template.php index e962e3343..2daa7710f 100644 --- a/load_template.php +++ b/load_template.php @@ -41,6 +41,15 @@ } $template->require_manage(); +if ($template->get_context()->contextlevel == CONTEXT_MODULE) { + $customcert = $DB->get_record('customcert', ['id' => $cm->instance], '*', MUST_EXIST); + $title = $customcert->name; + $heading = format_string($title); +} else { + $title = $SITE->fullname; + $heading = $title; +} + // Check that they have confirmed they wish to load the template. if ($confirm && confirm_sesskey()) { // First, remove all the existing elements and pages. @@ -77,9 +86,15 @@ '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')); +\mod_customcert\page_helper::page_setup($pageurl, $template->get_context(), $title); + +$str = get_string('editcustomcert', 'customcert'); +$link = new moodle_url('/mod/customcert/edit.php', array('tid' => $template->get_id())); +$PAGE->navbar->add($str, new \action_link($link, $str)); +$PAGE->navbar->add(get_string('loadtemplate', 'customcert')); // Show a confirmation page. echo $OUTPUT->header(); +echo $OUTPUT->heading($heading); echo $OUTPUT->confirm(get_string('loadtemplatemsg', 'customcert'), $yesurl, $nourl); echo $OUTPUT->footer(); \ No newline at end of file diff --git a/rearrange.php b/rearrange.php index 5505422b3..78f40ade8 100644 --- a/rearrange.php +++ b/rearrange.php @@ -42,9 +42,18 @@ // Make sure the user has the required capabilities. $template->require_manage(); +if ($template->get_context()->contextlevel == CONTEXT_MODULE) { + $customcert = $DB->get_record('customcert', ['id' => $cm->instance], '*', MUST_EXIST); + $title = $customcert->name; + $heading = format_string($title); +} else { + $title = $SITE->fullname; + $heading = $title; +} + // Set the $PAGE settings. $pageurl = new moodle_url('/mod/customcert/rearrange.php', array('pid' => $pid)); -\mod_customcert\page_helper::page_setup($pageurl, $template->get_context(), get_string('rearrangeelements', 'customcert')); +\mod_customcert\page_helper::page_setup($pageurl, $template->get_context(), $title); // Add more links to the navigation. if (!$cm = $template->get_cm()) { @@ -115,6 +124,7 @@ $html .= html_writer::end_tag('div'); echo $OUTPUT->header(); +echo $OUTPUT->heading($heading); echo $OUTPUT->heading(get_string('rearrangeelementsheading', 'customcert'), 4); echo $html; $PAGE->requires->js_call_amd('mod_customcert/rearrange-area', 'init', array('#pdf')); From 7f12ab8a400919333e5d500889e0f39ada04c231 Mon Sep 17 00:00:00 2001 From: Mark Nelson Date: Tue, 26 Jun 2018 21:40:42 +0800 Subject: [PATCH 42/93] Bumped version --- version.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/version.php b/version.php index 9fa8e68cb..d0fa94505 100644 --- a/version.php +++ b/version.php @@ -24,10 +24,10 @@ defined('MOODLE_INTERNAL') || die('Direct access to this script is forbidden.'); -$plugin->version = 2017111303; // The current module version (Date: YYYYMMDDXX). +$plugin->version = 2017111304; // The current module version (Date: YYYYMMDDXX). $plugin->requires = 2017111300; // Requires this Moodle version (3.4). $plugin->cron = 0; // Period for cron to check this module (secs). $plugin->component = 'mod_customcert'; $plugin->maturity = MATURITY_STABLE; -$plugin->release = "3.4.3"; // User-friendly version number. +$plugin->release = "3.4.4"; // User-friendly version number. From 752c7d17a9fdcc404b520981233611ef4e65d6ad Mon Sep 17 00:00:00 2001 From: Mark Nelson Date: Tue, 26 Jun 2018 21:34:55 +0800 Subject: [PATCH 43/93] Removed unnecessary new lines --- report.php | 5 ----- 1 file changed, 5 deletions(-) diff --git a/report.php b/report.php index afafe9bb1..9c6f64226 100644 --- a/report.php +++ b/report.php @@ -113,13 +113,8 @@ exit(); } - - echo $OUTPUT->header(); echo $OUTPUT->heading(format_string($customcert->name), 2); - groups_print_activity_menu($cm, $url); - $table->out($perpage, false); - echo $OUTPUT->footer(); From 9589bad2d839313305e3aec1a2b999896b0a4209 Mon Sep 17 00:00:00 2001 From: Mark Nelson Date: Wed, 27 Jun 2018 11:33:05 +0800 Subject: [PATCH 44/93] Fixed reference to tool_mobile in CHANGES.md --- CHANGES.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CHANGES.md b/CHANGES.md index 187cb9dfb..14e4259e1 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -9,7 +9,7 @@ Note - All hash comments refer to the issue number. Eg. #169 refers to https://g - Respect filters in the 'My certificates' and 'Verify certificate' pages (#197). - Fixed reference to 'mod/certificate' capability. -- Provided access to necessary web services for mobile functionality to the tool_mobile plugin (#202). +- Provided access to necessary web services for mobile functionality to the local_mobile plugin (#202). ### Changed From 2736eceb6ae5736c9661929364f8f2995fc8ed2a Mon Sep 17 00:00:00 2001 From: Mark Nelson Date: Sun, 1 Jul 2018 20:18:09 +0800 Subject: [PATCH 45/93] #207 Follow-up UX improvements The majority of this change involved moving the report page logic into the view page for both browser and mobile. --- ...restore_customcert_activity_task.class.php | 4 +- classes/output/email_certificate.php | 2 +- classes/output/mobile.php | 84 +++--------- classes/report_table.php | 12 +- db/mobile.php | 3 +- lang/en/customcert.php | 4 +- report.php | 90 +------------ templates/mobile_report_page.mustache | 122 ------------------ templates/mobile_view_activity_page.mustache | 82 +++++++++++- tests/behat/my_certificates.feature | 4 +- tests/behat/required_minutes.feature | 4 +- tests/behat/verify_certificates.feature | 12 +- tests/behat/view_issued_certificates.feature | 10 +- view.php | 94 ++++++++++---- 14 files changed, 193 insertions(+), 334 deletions(-) delete mode 100644 templates/mobile_report_page.mustache diff --git a/backup/moodle2/restore_customcert_activity_task.class.php b/backup/moodle2/restore_customcert_activity_task.class.php index 609dc215d..dbb58f24f 100644 --- a/backup/moodle2/restore_customcert_activity_task.class.php +++ b/backup/moodle2/restore_customcert_activity_task.class.php @@ -86,8 +86,8 @@ static public function define_restore_log_rules() { $rules[] = new restore_log_rule('customcert', 'add', 'view.php?id={course_module}', '{customcert}'); $rules[] = new restore_log_rule('customcert', 'update', 'view.php?id={course_module}', '{customcert}'); $rules[] = new restore_log_rule('customcert', 'view', 'view.php?id={course_module}', '{customcert}'); - $rules[] = new restore_log_rule('customcert', 'received', 'report.php?a={customcert}', '{customcert}'); - $rules[] = new restore_log_rule('customcert', 'view report', 'report.php?id={customcert}', '{customcert}'); + $rules[] = new restore_log_rule('customcert', 'received', 'view.php?id={course_module}', '{customcert}'); + $rules[] = new restore_log_rule('customcert', 'view report', 'view.php?id={course_module}', '{customcert}'); return $rules; } diff --git a/classes/output/email_certificate.php b/classes/output/email_certificate.php index 9c45c68c5..c113f485b 100644 --- a/classes/output/email_certificate.php +++ b/classes/output/email_certificate.php @@ -107,7 +107,7 @@ public function export_for_template(\renderer_base $renderer) { } else { $data->emailgreeting = get_string('emailnonstudentgreeting', 'customcert'); $data->emailbody = get_string('emailnonstudentbody', 'customcert', $info); - $data->emailcertificatelink = new \moodle_url('/mod/customcert/report.php', array('id' => $this->cmid)); + $data->emailcertificatelink = new \moodle_url('/mod/customcert/view.php', array('id' => $this->cmid)); $data->emailcertificatetext = get_string('emailnonstudentcertificatelinktext', 'customcert'); } diff --git a/classes/output/mobile.php b/classes/output/mobile.php index fb503b692..1e36d6312 100644 --- a/classes/output/mobile.php +++ b/classes/output/mobile.php @@ -46,6 +46,7 @@ public static function mobile_view_activity($args) { $args = (object) $args; $cmid = $args->cmid; + $groupid = empty($args->group) ? 0 : $args->group; // By default, group 0. // Capabilities check. $cm = get_coursemodule_from_id('customcert', $cmid); @@ -77,15 +78,24 @@ public static function mobile_view_activity($args) { } $showreport = false; - $numissues = 0; + $groups = []; + $recipients = []; if (has_capability('mod/customcert:viewreport', $context)) { - // Get the total number of issues. $showreport = true; + + // Get the groups (if any) to display - also sets active group. + $groups = self::get_groups($cm, $groupid, $USER->id); $groupmode = groups_get_activity_groupmode($cm); if (has_capability('moodle/site:accessallgroups', $context)) { $groupmode = 'aag'; } - $numissues = \mod_customcert\certificate::get_number_of_issues($certificate->id, $cm, $groupmode); + + $recipients = \mod_customcert\certificate::get_issues($certificate->id, $groupmode, $cm, 0, 0); + foreach ($recipients as $recipient) { + $recipient->displayname = fullname($recipient); + $recipient->fileurl = new \moodle_url('/mod/customcert/mobile/pluginfile.php', ['certificateid' => $certificate->id, + 'userid' => $recipient->id]); + } } $data = [ @@ -93,11 +103,14 @@ public static function mobile_view_activity($args) { 'cmid' => $cm->id, 'hasissues' => !empty($issues), 'issues' => array_values($issues), + 'showgroups' => !empty($groups), + 'groups' => array_values($groups), 'canmanage' => $canmanage, 'candownload' => $candownload, 'fileurl' => $fileurl, 'showreport' => $showreport, - 'numissuesinreport' => $numissues, + 'hasrecipients' => !empty($recipients), + 'recipients' => array_values($recipients), 'currenttimestamp' => time() ]; @@ -113,69 +126,6 @@ public static function mobile_view_activity($args) { ]; } - /** - * Returns the list of issues certificates for the activity for the mobile app. - * - * @param array $args Arguments from tool_mobile_get_content WS - * @return array HTML, javascript and other data - */ - public static function mobile_view_report($args) { - global $DB, $OUTPUT, $USER; - - $args = (object) $args; - - $cmid = $args->cmid; - $groupid = empty($args->group) ? 0 : $args->group; // By default, group 0. - - // Capabilities check. - $cm = get_coursemodule_from_id('customcert', $cmid); - $context = \context_module::instance($cm->id); - - self::require_capability($cm, $context, 'mod/customcert:viewreport'); - - // Get the groups (if any) to display - also sets active group. - $groups = self::get_groups($cm, $groupid, $USER->id); - - $certificate = $DB->get_record('customcert', ['id' => $cm->instance], '*', MUST_EXIST); - $certificate->name = format_string($certificate->name); - list($certificate->intro, $certificate->introformat) = external_format_text($certificate->intro, - $certificate->introformat, $context->id, 'mod_customcert', 'intro'); - - $groupmode = groups_get_activity_groupmode($cm); - if (has_capability('moodle/site:accessallgroups', $context)) { - $groupmode = 'aag'; - } - - $issues = \mod_customcert\certificate::get_issues($certificate->id, $groupmode, $cm, 0, 0); - foreach ($issues as $issue) { - $issue->displayname = fullname($issue); - $issue->fileurl = new \moodle_url('/mod/customcert/mobile/pluginfile.php', ['certificateid' => $certificate->id, - 'userid' => $issue->id]); - } - - $data = [ - 'certificate' => $certificate, - 'cmid' => $cmid, - 'showgroups' => !empty($groups), - 'groups' => array_values($groups), - 'canmanage' => has_capability('mod/customcert:manage', $context), - 'hasissues' => !empty($issues), - 'issues' => array_values($issues), - 'currenttimestamp' => time() - ]; - - return [ - 'templates' => [ - [ - 'id' => 'main', - 'html' => $OUTPUT->render_from_template('mod_customcert/mobile_report_page', $data), - ], - ], - 'javascript' => '', - 'otherdata' => '' - ]; - } - /** * Returns an array of groups to be displayed (if applicable) for the activity. * diff --git a/classes/report_table.php b/classes/report_table.php index f3eddd51e..978a6fe50 100644 --- a/classes/report_table.php +++ b/classes/report_table.php @@ -137,10 +137,12 @@ public function col_download($user) { global $OUTPUT; $icon = new \pix_icon('download', get_string('download'), 'customcert'); - $link = new \moodle_url('/mod/customcert/report.php', - array('id' => $this->cm->id, - 'downloadcert' => '1', - 'userid' => $user->id)); + $link = new \moodle_url('/mod/customcert/view.php', + [ + 'id' => $this->cm->id, + 'downloadissue' => $user->id + ] + ); return $OUTPUT->action_link($link, '', null, null, $icon); } @@ -155,7 +157,7 @@ public function col_actions($user) { global $OUTPUT; $icon = new \pix_icon('i/delete', get_string('delete')); - $link = new \moodle_url('/mod/customcert/report.php', + $link = new \moodle_url('/mod/customcert/view.php', [ 'id' => $this->cm->id, 'deleteissue' => $user->issueid, diff --git a/db/mobile.php b/db/mobile.php index 5e76dfab5..5e48962d9 100644 --- a/db/mobile.php +++ b/db/mobile.php @@ -44,8 +44,7 @@ ['pluginname', 'customcert'], ['receiveddate', 'customcert'], ['requiredtimenotmet', 'customcert'], - ['selectagroup', 'moodle'], - ['viewcustomcertissues', 'customcert'] + ['selectagroup', 'moodle'] ], ] ); diff --git a/lang/en/customcert.php b/lang/en/customcert.php index c8b3baaba..9c3172f38 100644 --- a/lang/en/customcert.php +++ b/lang/en/customcert.php @@ -83,7 +83,7 @@ $string['fontcolour_help'] = 'The colour of the font.'; $string['fontsize'] = 'Size'; $string['fontsize_help'] = 'The size of the font in points.'; -$string['getcustomcert'] = 'Download certificate'; +$string['getcustomcert'] = 'View certificate'; $string['height'] = 'Height'; $string['height_help'] = 'This is the height of the certificate PDF in mm. For reference an A4 piece of paper is 297mm high and a letter is 279mm high.'; $string['invalidcode'] = 'Invalid code supplied.'; @@ -113,6 +113,7 @@ $string['nametoolong'] = 'You have exceeded the maximum length allowed for the name'; $string['nocustomcerts'] = 'There are no certificates for this course'; $string['noimage'] = 'No image'; +$string['norecipients'] = 'No recipients'; $string['notemplates'] = 'No templates'; $string['notissued'] = 'Not issued'; $string['notverified'] = 'Not verified'; @@ -173,6 +174,5 @@ $string['verifycertificatedesc'] = 'This link will take you to a new screen where you will be able to verify certificates on the site'; $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.'; diff --git a/report.php b/report.php index 9c6f64226..fde4f2692 100644 --- a/report.php +++ b/report.php @@ -17,6 +17,8 @@ /** * Handles viewing a report that shows who has received a customcert. * + * This is now just a stub page - all logic has been moved to view.php. + * * @package mod_customcert * @copyright 2013 Mark Nelson * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later @@ -25,96 +27,10 @@ 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); -} - -$page = optional_param('page', 0, PARAM_INT); -$perpage = optional_param('perpage', \mod_customcert\certificate::CUSTOMCERT_PER_PAGE, PARAM_INT); -$pageurl = $url = new moodle_url('/mod/customcert/report.php', array('id' => $id, 'page' => $page, 'perpage' => $perpage)); $cm = get_coursemodule_from_id('customcert', $id, 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); -// Requires a course login. require_login($course, false, $cm); -// Check capabilities. -$context = context_module::instance($cm->id); -require_capability('mod/customcert:viewreport', $context); - -// Set up the page. -$title = $customcert->name; -$heading = format_string($title); -\mod_customcert\page_helper::page_setup($pageurl, $context, $title); - -// Additional page setup. -if ($deleteissue && confirm_sesskey()) { - $PAGE->navbar->add(get_string('listofissues', 'customcert'), - new moodle_url('/mod/customcert/report.php', ['id' => $id])); -} else { - $PAGE->navbar->add(get_string('listofissues', 'customcert')); -} - -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. - $PAGE->navbar->add(get_string('deleteconfirm', 'customcert')); - $message = get_string('deleteissueconfirm', 'customcert'); - echo $OUTPUT->header(); - echo $OUTPUT->heading($heading); - 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) { - $template = $DB->get_record('customcert_templates', array('id' => $customcert->templateid), '*', MUST_EXIST); - $template = new \mod_customcert\template($template); - $template->generate_pdf(false, $userid); - exit(); -} - -// Check if we are in group mode. -if ($groupmode = groups_get_activity_groupmode($cm)) { - groups_get_activity_group($cm, true); -} - -$table = new \mod_customcert\report_table($customcert->id, $cm, $groupmode, $download); -$table->define_baseurl($pageurl); - -if ($table->is_downloading()) { - $table->download(); - exit(); -} - -echo $OUTPUT->header(); -echo $OUTPUT->heading(format_string($customcert->name), 2); -groups_print_activity_menu($cm, $url); -$table->out($perpage, false); -echo $OUTPUT->footer(); +redirect(new moodle_url('/mod/customcert/view.php', ['id' => $id])); diff --git a/templates/mobile_report_page.mustache b/templates/mobile_report_page.mustache deleted file mode 100644 index 4ddda7672..000000000 --- a/templates/mobile_report_page.mustache +++ /dev/null @@ -1,122 +0,0 @@ -{{! - 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 . -}} -{{! - @template mod_customcert/mobile_report_page - - The page that lists the custom certificates issued - - Classes required for JS: - * None - - Data attibutes required for JS: - * All data attributes are required - - Context variables required for this template: - * certificate - * cmid - * showgroups - * groups - * canmanage - * hasissues - * issues - * currenttimestamp - - Example context (json): - { - "certificate": { - "id": "1", - "course": "2", - "name": "A rad certificate name!", - "intro": "A certificate" - }, - "cmid": "25", - "showgroups": "true", - "groups": [ - { - "id": "2", - "selected": "false", - "name": "Group A" - } - ], - "canmanage": "true", - "hasissues": "true", - "issues": [ - { - "id": "2", - "issueid": "3", - "displayname": "Michaelangelo (Mickey)", - "fileurl": "http://yoursite.com/mod/customcert/mobile/pluginfile.php?id=4", - "code": "Xyt78axR", - "timecreated": "1528370177" - } - ], - "currenttimestamp": "1528370177" - } -}} -{{=<% %>=}} -
- - <%#showgroups%> - - {{ 'plugin.mod_customcert.selectagroup' | translate }} - - <%#groups%> - selected<%/selected%>><% name %> - <%/groups%> - - - <%/showgroups%> - -

{{ 'plugin.mod_customcert.listofissues' | translate }}

-
- <%#hasissues%> - - <%#issues%> - - - - - <% displayname %> -
- {{ <% timecreated %> | coreToLocaleString }} -
- - - <%#canmanage%> - - <%/canmanage%> - -
-
-
- <%/issues%> -
- <%/hasissues%> - <%^hasissues%> - - {{ 'plugin.mod_customcert.nothingtodisplay' | translate }} - - <%/hasissues%> -
diff --git a/templates/mobile_view_activity_page.mustache b/templates/mobile_view_activity_page.mustache index 34d3a5c99..63712577a 100644 --- a/templates/mobile_view_activity_page.mustache +++ b/templates/mobile_view_activity_page.mustache @@ -30,10 +30,14 @@ * cmid * hasissues * issues + * showgroups + * groups + * canmanage * candownload + * hasrecipients + * recipients * fileurl * showreport - * numissuesinreport * currenttimestamp Example context (json): @@ -52,21 +56,34 @@ "timecreated": "1528370177" } ], + "showgroups": "true", + "groups": [ + { + "id": "2", + "selected": "false", + "name": "Group A" + } + ], + "canmanage": "true", "candownload": "true", "fileurl": "http://yoursite.com/mod/customcert/mobile/pluginfile.php?id=4", "showreport": "true", - "numissuesinreport": "5", + "hasrecipients": "true", + "recipients": [ + { + "id": "2", + "issueid": "3", + "displayname": "Michaelangelo (Mickey)", + "fileurl": "http://yoursite.com/mod/customcert/mobile/pluginfile.php?id=4", + "timecreated": "1528370177" + } + ], "currenttimestamp": "1528370177" } }} {{=<% %>=}}
- <%#showreport%> - - {{ 'plugin.mod_customcert.viewcustomcertissues' | translate: {$a: <% numissuesinreport %>} }} - - <%/showreport%> <%#hasissues%> <%^canmanage%> @@ -94,4 +111,55 @@

{{ 'plugin.mod_customcert.requiredtimenotmet' | translate: {$a: { requiredtime: <% certificate.requiredtime %>} } }}

<%/candownload%> + <%#showreport%> + + {{ 'plugin.mod_customcert.listofissues' | translate }} + + <%#showgroups%> + + {{ 'plugin.mod_customcert.selectagroup' | translate }} + + <%#groups%> + selected<%/selected%>><% name %> + <%/groups%> + + + <%/showgroups%> + <%#hasrecipients%> + + <%#recipients%> + + + + + <% displayname %> +
+ {{ <% timecreated %> | coreToLocaleString }} +
+ + + <%#canmanage%> + + <%/canmanage%> + +
+
+
+ <%/recipients%> +
+ <%/hasrecipients%> + <%^hasrecipients%> + + {{ 'plugin.mod_customcert.nothingtodisplay' | translate }} + + <%/hasrecipients%> + <%/showreport%>
diff --git a/tests/behat/my_certificates.feature b/tests/behat/my_certificates.feature index 1ad44166d..cc59261ee 100644 --- a/tests/behat/my_certificates.feature +++ b/tests/behat/my_certificates.feature @@ -25,14 +25,14 @@ Feature: Being able to view the certificates you have been issued 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 press "View 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 press "View certificate" And I follow "Profile" in the user menu And I follow "My certificates" And I should see "Custom certificate 1" diff --git a/tests/behat/required_minutes.feature b/tests/behat/required_minutes.feature index 49e85b2eb..e65cf4d6b 100644 --- a/tests/behat/required_minutes.feature +++ b/tests/behat/required_minutes.feature @@ -25,7 +25,7 @@ Feature: Being able to set the required minutes in a course before viewing the c 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 should not see "View certificate" And I press "Continue" And I should see "Custom certificate 1" @@ -36,4 +36,4 @@ Feature: Being able to set the required minutes in a course before viewing the c 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" + And I should see "View certificate" diff --git a/tests/behat/verify_certificates.feature b/tests/behat/verify_certificates.feature index 7864397c0..936bdacce 100644 --- a/tests/behat/verify_certificates.feature +++ b/tests/behat/verify_certificates.feature @@ -25,7 +25,7 @@ Feature: Being able to verify that a certificate is valid or not 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 press "View certificate" And I log out And I log in as "teacher1" And I am on "Course 1" course homepage @@ -45,7 +45,7 @@ Feature: Being able to verify that a certificate is valid or not 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 press "View 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" @@ -74,10 +74,10 @@ Feature: Being able to verify that a certificate is valid or not 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 press "View certificate" And I am on "Course 1" course homepage And I follow "Custom certificate 2" - And I press "Download certificate" + And I press "View 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. @@ -95,10 +95,10 @@ Feature: Being able to verify that a certificate is valid or not 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 press "View certificate" And I am on "Course 1" course homepage And I follow "Custom certificate 2" - And I press "Download certificate" + And I press "View certificate" And I log out And I visit the verification url for the site And I set the field "Code" to "NOTAVALIDCODE" diff --git a/tests/behat/view_issued_certificates.feature b/tests/behat/view_issued_certificates.feature index 5e952e760..f8cb0a529 100644 --- a/tests/behat/view_issued_certificates.feature +++ b/tests/behat/view_issued_certificates.feature @@ -26,17 +26,16 @@ Feature: Being able to view the certificates that have been issued 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 press "View 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 press "View 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" @@ -44,17 +43,16 @@ Feature: Being able to view the certificates that have been issued 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 press "View 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 press "View 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" diff --git a/view.php b/view.php index 7de14f0a3..a6e9ce832 100644 --- a/view.php +++ b/view.php @@ -25,7 +25,13 @@ require_once('../../config.php'); $id = required_param('id', PARAM_INT); -$action = optional_param('action', '', PARAM_ALPHA); +$downloadown = optional_param('downloadown', false, PARAM_BOOL); +$downloadtable = optional_param('download', null, PARAM_ALPHA); +$downloadissue = optional_param('downloadissue', 0, PARAM_INT); +$deleteissue = optional_param('deleteissue', 0, PARAM_INT); +$confirm = optional_param('confirm', false, PARAM_BOOL); +$page = optional_param('page', 0, PARAM_INT); +$perpage = optional_param('perpage', \mod_customcert\certificate::CUSTOMCERT_PER_PAGE, PARAM_INT); $cm = get_coursemodule_from_id('customcert', $id, 0, false, MUST_EXIST); $course = $DB->get_record('course', array('id' => $cm->course), '*', MUST_EXIST); @@ -38,6 +44,7 @@ require_capability('mod/customcert:view', $context); $canmanage = has_capability('mod/customcert:manage', $context); +$canviewreport = has_capability('mod/customcert:viewreport', $context); // Initialise $PAGE. $pageurl = new moodle_url('/mod/customcert/view.php', array('id' => $cm->id)); @@ -53,6 +60,36 @@ } } +// Check if we are deleting an issue. +if ($deleteissue && $canmanage && confirm_sesskey()) { + if (!$confirm) { + $nourl = new moodle_url('/mod/customcert/view.php', ['id' => $id]); + $yesurl = new moodle_url('/mod/customcert/view.php', + [ + 'id' => $id, + 'deleteissue' => $deleteissue, + 'confirm' => 1, + 'sesskey' => sesskey() + ] + ); + + // Show a confirmation page. + $PAGE->navbar->add(get_string('deleteconfirm', 'customcert')); + $message = get_string('deleteissueconfirm', 'customcert'); + echo $OUTPUT->header(); + echo $OUTPUT->heading(format_string($customcert->name)); + 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/view.php', array('id' => $id))); +} + $event = \mod_customcert\event\course_module_viewed::create(array( 'objectid' => $customcert->id, 'context' => $context, @@ -61,22 +98,23 @@ $event->add_record_snapshot('customcert', $customcert); $event->trigger(); -// Check that no action was passed, if so that means we are not outputting to PDF. -if (empty($action)) { +// Check that we are not downloading a certificate PDF. +if (!$downloadown && !$downloadissue) { // Get the current groups mode. if ($groupmode = groups_get_activity_groupmode($cm)) { groups_get_activity_group($cm, true); } - // Generate the link to the report if there are issues to display. - $reportlink = ''; - if (has_capability('mod/customcert:viewreport', $context)) { + // Generate the table to the report if there are issues to display. + if ($canviewreport) { // 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)); - $url = html_writer::tag('a', get_string('viewcustomcertissues', 'customcert', $numissues), - array('href' => $href->out())); - $reportlink = html_writer::tag('div', $url, array('class' => 'reportlink')); + $reporttable = new \mod_customcert\report_table($customcert->id, $cm, $groupmode, $downloadtable); + $reporttable->define_baseurl($pageurl); + + if ($reporttable->is_downloading()) { + $reporttable->download(); + exit(); + } } // Generate the intro content if it exists. @@ -106,28 +144,38 @@ // Create the button to download the customcert. $linkname = get_string('getcustomcert', 'customcert'); - $link = new moodle_url('/mod/customcert/view.php', array('id' => $cm->id, 'action' => 'download')); + $link = new moodle_url('/mod/customcert/view.php', array('id' => $cm->id, 'downloadown' => true)); $downloadbutton = new single_button($link, $linkname); $downloadbutton = html_writer::tag('div', $OUTPUT->render($downloadbutton), array('style' => 'text-align:center')); // Output all the page data. echo $OUTPUT->header(); - echo $OUTPUT->heading(format_string($customcert->name), 2); - echo $reportlink; + echo $OUTPUT->heading(format_string($customcert->name)); echo $intro; echo $issuelist; echo $downloadbutton; + if (isset($reporttable)) { + echo $OUTPUT->heading(get_string('listofissues', 'customcert'), 3); + groups_print_activity_menu($cm, $pageurl); + echo $reporttable->out($perpage, false); + } echo $OUTPUT->footer($course); - exit; + exit(); } 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))) { - \mod_customcert\certificate::issue_certificate($customcert->id, $USER->id); - } + // Set the userid value of who we are downloading the certificate for. + $userid = $USER->id; + if ($downloadown) { + // Create new customcert issue record if one does not already exist. + if (!$DB->record_exists('customcert_issues', array('userid' => $USER->id, 'customcertid' => $customcert->id))) { + \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); + // Set the custom certificate as viewed. + $completion = new completion_info($course); + $completion->set_module_viewed($cm); + } else if ($downloadissue && $canviewreport) { + $userid = $downloadissue; + } // Hack alert - don't initiate the download when running Behat. if (defined('BEHAT_SITE_RUNNING')) { @@ -136,6 +184,6 @@ // Now we want to generate the PDF. $template = new \mod_customcert\template($template); - $template->generate_pdf(); + $template->generate_pdf(false, $userid); exit(); } From f63d61d164d0f51f7ef6900bf36b2f3885d69341 Mon Sep 17 00:00:00 2001 From: Mark Nelson Date: Mon, 9 Jul 2018 22:48:49 +0800 Subject: [PATCH 46/93] #207 Changed font-size for awarded time in the report in mobile view Also made minor alignment changes. --- db/mobile.php | 10 +++++++--- mobile/styles.css | 3 +++ templates/mobile_view_activity_page.mustache | 18 +++++++++--------- 3 files changed, 19 insertions(+), 12 deletions(-) create mode 100644 mobile/styles.css diff --git a/db/mobile.php b/db/mobile.php index 5e48962d9..ffbaffe12 100644 --- a/db/mobile.php +++ b/db/mobile.php @@ -24,7 +24,7 @@ defined('MOODLE_INTERNAL') || die(); -$addons = array( +$addons = [ 'mod_customcert' => [ // Plugin identifier. 'handlers' => [ // Different places where the plugin will display content. 'issueview' => [ // Handler unique name. @@ -34,6 +34,10 @@ ], 'delegate' => 'CoreCourseModuleDelegate', // Delegate (where to display the link to the plugin). 'method' => 'mobile_view_activity', // Main function in \mod_customcert\output\mobile. + 'styles' => [ + 'url' => '/mod/customcert/mobile/styles.css', + 'version' => 1 + ] ] ], 'lang' => [ // Language strings that are used in all the handlers. @@ -45,6 +49,6 @@ ['receiveddate', 'customcert'], ['requiredtimenotmet', 'customcert'], ['selectagroup', 'moodle'] - ], + ] ] -); +]; diff --git a/mobile/styles.css b/mobile/styles.css new file mode 100644 index 000000000..7c3ee6928 --- /dev/null +++ b/mobile/styles.css @@ -0,0 +1,3 @@ +.timerewarded { + font-size: 14px; +} diff --git a/templates/mobile_view_activity_page.mustache b/templates/mobile_view_activity_page.mustache index 63712577a..1d389e242 100644 --- a/templates/mobile_view_activity_page.mustache +++ b/templates/mobile_view_activity_page.mustache @@ -120,7 +120,7 @@ {{ 'plugin.mod_customcert.selectagroup' | translate }} <%#groups%> - selected<%/selected%>><% name %> + selected<%/selected%>><% name %> <%/groups%> @@ -134,20 +134,20 @@ <% displayname %>
- {{ <% timecreated %> | coreToLocaleString }} +
{{ <% timecreated %> | coreToLocaleString }}
<%#canmanage%> - + <%/canmanage%> From 520d6a2a5d4b92f7362e2feba5c8c054ea7c7603 Mon Sep 17 00:00:00 2001 From: Mark Nelson Date: Mon, 9 Jul 2018 23:45:19 +0800 Subject: [PATCH 47/93] #207 No need to use a table/list when displaying only one issue --- classes/output/mobile.php | 9 ++++--- templates/mobile_view_activity_page.mustache | 28 +++++++------------- view.php | 25 ++++++----------- 3 files changed, 24 insertions(+), 38 deletions(-) diff --git a/classes/output/mobile.php b/classes/output/mobile.php index 1e36d6312..f8abaccdc 100644 --- a/classes/output/mobile.php +++ b/classes/output/mobile.php @@ -60,7 +60,11 @@ public static function mobile_view_activity($args) { $certificate->introformat, $context->id, 'mod_customcert', 'intro'); // Get any issues this person may have. - $issues = $DB->get_records('customcert_issues', ['userid' => $USER->id, 'customcertid' => $certificate->id]); + $issue = false; + if ($issues = $DB->get_records('customcert_issues', ['userid' => $USER->id, 'customcertid' => $certificate->id], + 'timecreated DESC')) { + $issue = reset($issues); + } $candownload = true; $canmanage = has_capability('mod/customcert:manage', $context); @@ -101,8 +105,7 @@ public static function mobile_view_activity($args) { $data = [ 'certificate' => $certificate, 'cmid' => $cm->id, - 'hasissues' => !empty($issues), - 'issues' => array_values($issues), + 'issue' => $issue, 'showgroups' => !empty($groups), 'groups' => array_values($groups), 'canmanage' => $canmanage, diff --git a/templates/mobile_view_activity_page.mustache b/templates/mobile_view_activity_page.mustache index 1d389e242..8488f5121 100644 --- a/templates/mobile_view_activity_page.mustache +++ b/templates/mobile_view_activity_page.mustache @@ -50,12 +50,9 @@ "requiredtime": "60" }, "cmid": "25", - "hasissues": "true", - "issues": [ - { - "timecreated": "1528370177" - } - ], + "issue": { + "timecreated": "1528370177" + }, "showgroups": "true", "groups": [ { @@ -84,20 +81,15 @@ {{=<% %>=}}
- <%#hasissues%> + <%#issue%> <%^canmanage%> - - - {{ 'plugin.mod_customcert.receiveddate' | translate }} - - <%#issues%> - - {{ <% timecreated %> | coreToLocaleString }} - - <%/issues%> - + + {{ 'plugin.mod_customcert.receiveddate' | translate }} +
+
{{ <% timecreated %> | coreToLocaleString }}
+
<%/canmanage%> - <%/hasissues%> + <%/issue%> <%#candownload%> + + + - <%/canmanage%> - <%/issue%> - <%#candownload%> + <%/requiredtimemet%> + <%^requiredtimemet%> + +

{{ 'plugin.mod_customcert.requiredtimenotmet' | translate: {$a: { requiredtime: <% certificate.requiredtime %>} } }}

+
+ <%/requiredtimemet%> + <%/canmanage%> + <%#canmanage%> - <%/candownload%> - <%^candownload%> - -

{{ 'plugin.mod_customcert.requiredtimenotmet' | translate: {$a: { requiredtime: <% certificate.requiredtime %>} } }}

-
- <%/candownload%> + <%/canmanage%> <%#showreport%> {{ 'plugin.mod_customcert.listofissues' | translate }} From 7b35bcee9e8110929de01275f38ca4e959734d6a Mon Sep 17 00:00:00 2001 From: Mark Nelson Date: Thu, 12 Jul 2018 12:23:17 +0800 Subject: [PATCH 49/93] #211 Use custom fonts if present --- classes/certificate.php | 40 ++++++++++++++++++---------------------- 1 file changed, 18 insertions(+), 22 deletions(-) diff --git a/classes/certificate.php b/classes/certificate.php index a7693a31e..01e2b8685 100644 --- a/classes/certificate.php +++ b/classes/certificate.php @@ -102,23 +102,20 @@ public static function upload_files($draftitemid, $contextid, $filearea = 'image public static function get_fonts() { global $CFG; - // Array to store the available fonts. - $options = array(); - - // Location of fonts in Moodle. - $fontdir = "$CFG->dirroot/lib/tcpdf/fonts"; - // Check that the directory exists. - if (file_exists($fontdir)) { - // Get directory contents. - $fonts = new \DirectoryIterator($fontdir); - // Loop through the font folder. - foreach ($fonts as $font) { - // If it is not a file, or either '.' or '..', or - // the extension is not php, or we can not open file, - // skip it. - if (!$font->isFile() || $font->isDot() || ($font->getExtension() != 'php')) { - continue; + require_once($CFG->libdir . '/pdflib.php'); + + $arrfonts = []; + $pdf = new \pdf(); + $fontfamilies = $pdf->get_font_families(); + foreach ($fontfamilies as $fontfamily => $fontstyles) { + foreach ($fontstyles as $fontstyle) { + $fontstyle = strtolower($fontstyle); + if ($fontstyle == 'r') { + $filenamewoextension = $fontfamily; + } else { + $filenamewoextension = $fontfamily . $fontstyle; } + $fullpath = \TCPDF_FONTS::_getfontpath() . $filenamewoextension; // Set the name of the font to null, the include next should then set this // value, if it is not set then the file does not include the necessary data. $name = null; @@ -127,25 +124,24 @@ public static function get_fonts() { $displayname = null; // Some of the TCPDF files include files that are not present, so we have to // suppress warnings, this is the TCPDF libraries fault, grrr. - @include("$fontdir/$font"); + @include($fullpath . '.php'); // If no $name variable in file, skip it. if (is_null($name)) { continue; } - // Remove the extension of the ".php" file that contains the font information. - $filename = basename($font, ".php"); // Check if there is no display name to use. if (is_null($displayname)) { // Format the font name, so "FontName-Style" becomes "Font Name - Style". $displayname = preg_replace("/([a-z])([A-Z])/", "$1 $2", $name); $displayname = preg_replace("/([a-zA-Z])-([a-zA-Z])/", "$1 - $2", $displayname); } - $options[$filename] = $displayname; + + $arrfonts[$filenamewoextension] = $displayname; } - ksort($options); } + ksort($arrfonts); - return $options; + return $arrfonts; } /** From 7e9414313ec33ef10fbf497338b3668a22d77cb0 Mon Sep 17 00:00:00 2001 From: Mark Nelson Date: Thu, 12 Jul 2018 15:16:24 +0800 Subject: [PATCH 50/93] #187 Fix broken SQL on Oracle --- classes/task/email_certificate_task.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/classes/task/email_certificate_task.php b/classes/task/email_certificate_task.php index 88fe7a6ad..3f13c013c 100644 --- a/classes/task/email_certificate_task.php +++ b/classes/task/email_certificate_task.php @@ -50,6 +50,7 @@ public function execute() { global $DB, $PAGE; // Get all the certificates that have requested someone get emailed. + $emailotherslengthsql = $DB->sql_length('c.emailothers'); $sql = "SELECT c.*, ct.id as templateid, ct.name as templatename, ct.contextid, co.id as courseid, co.fullname as coursefullname, co.shortname as courseshortname FROM {customcert} c @@ -59,7 +60,7 @@ public function execute() { ON c.course = co.id WHERE (c.emailstudents = :emailstudents OR c.emailteachers = :emailteachers - OR c.emailothers != '')"; + OR $emailotherslengthsql >= 3)"; if ($customcerts = $DB->get_records_sql($sql, array('emailstudents' => 1, 'emailteachers' => 1))) { // The renderers used for sending emails. $htmlrenderer = $PAGE->get_renderer('mod_customcert', 'email', 'htmlemail'); From 83f337f5c45c7945f1858dc0d5268209744826bb Mon Sep 17 00:00:00 2001 From: Mark Nelson Date: Thu, 12 Jul 2018 16:12:24 +0800 Subject: [PATCH 51/93] #154 Don't display 'Add page' link for unsaved templates --- classes/edit_form.php | 26 ++++++++++++++------------ 1 file changed, 14 insertions(+), 12 deletions(-) diff --git a/classes/edit_form.php b/classes/edit_form.php index c586778eb..50f642c0c 100644 --- a/classes/edit_form.php +++ b/classes/edit_form.php @@ -80,18 +80,20 @@ public function definition() { $this->add_customcert_page_elements($page); } - // 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'))); + // Link to add another page, only display it when the template has been created. + if (isset($this->_customdata['tid'])) { + $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(); From 3f082b7e564463d6409e5e2532629595a4e5a119 Mon Sep 17 00:00:00 2001 From: Mark Nelson Date: Thu, 12 Jul 2018 16:51:10 +0800 Subject: [PATCH 52/93] #210 Improve code for adding date strings to select --- element/date/classes/element.php | 39 +++++++++++++++++++------------- 1 file changed, 23 insertions(+), 16 deletions(-) diff --git a/element/date/classes/element.php b/element/date/classes/element.php index a466ae3cd..bdbead94a 100644 --- a/element/date/classes/element.php +++ b/element/date/classes/element.php @@ -260,23 +260,30 @@ public static function get_date_formats() { $suffix = self::get_ordinal_number_suffix(userdate($date, '%d')); - $dateformats = array( + $dateformats = [ 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')) - ); + 2 => userdate($date, '%B %d' . $suffix . ', %Y') + ]; + + $strdateformats = [ + 'strftimedate', + 'strftimedatefullshort', + 'strftimedateshort', + 'strftimedatetime', + 'strftimedatetimeshort', + 'strftimedaydate', + 'strftimedaydatetime', + 'strftimedayshort', + 'strftimedaytime', + 'strftimemonthyear', + 'strftimerecent', + 'strftimerecentfull', + 'strftimetime' + ]; + + foreach ($strdateformats as $strdateformat) { + $dateformats[$strdateformat] = userdate($date, get_string($strdateformat, 'langconfig')); + } return $dateformats; } From 5f80f246cb88d19ae56499c2cd6cb365dfc360a9 Mon Sep 17 00:00:00 2001 From: Mark Nelson Date: Fri, 13 Jul 2018 12:17:35 +0800 Subject: [PATCH 53/93] #210 Allow short dates with leading zeros --- element/date/classes/element.php | 22 +++++++++++++++++++--- 1 file changed, 19 insertions(+), 3 deletions(-) diff --git a/element/date/classes/element.php b/element/date/classes/element.php index bdbead94a..e03e655f7 100644 --- a/element/date/classes/element.php +++ b/element/date/classes/element.php @@ -256,7 +256,9 @@ public function after_restore($restore) { * @return array the list of date formats */ public static function get_date_formats() { - $date = time(); + // Hard-code date so users can see the difference between short dates with and without the leading zero. + // Eg. 06/07/18 vs 6/07/18. + $date = 1530849658; $suffix = self::get_ordinal_number_suffix(userdate($date, '%d')); @@ -268,9 +270,11 @@ public static function get_date_formats() { $strdateformats = [ 'strftimedate', 'strftimedatefullshort', + 'strftimedatefullshortwleadingzero', 'strftimedateshort', 'strftimedatetime', 'strftimedatetimeshort', + 'strftimedatetimeshortwleadingzero', 'strftimedaydate', 'strftimedaydatetime', 'strftimedayshort', @@ -282,7 +286,13 @@ public static function get_date_formats() { ]; foreach ($strdateformats as $strdateformat) { - $dateformats[$strdateformat] = userdate($date, get_string($strdateformat, 'langconfig')); + if ($strdateformat == 'strftimedatefullshortwleadingzero') { + $dateformats[$strdateformat] = userdate($date, get_string('strftimedatefullshort', 'langconfig'), 99, false); + } else if ($strdateformat == 'strftimedatetimeshortwleadingzero') { + $dateformats[$strdateformat] = userdate($date, get_string('strftimedatetimeshort', 'langconfig'), 99, false); + } else { + $dateformats[$strdateformat] = userdate($date, get_string($strdateformat, 'langconfig')); + } } return $dateformats; @@ -319,7 +329,13 @@ protected function get_date_format_string($date, $dateformat) { // Ok, so we must have been passed the actual format in the lang file. if (!isset($certificatedate)) { - $certificatedate = userdate($date, get_string($dateformat, 'langconfig')); + if ($dateformat == 'strftimedatefullshortwleadingzero') { + $certificatedate = userdate($date, get_string('strftimedatefullshort', 'langconfig'), 99, false); + } else if ($dateformat == 'strftimedatetimeshortwleadingzero') { + $certificatedate = userdate($date, get_string('strftimedatetimeshort', 'langconfig'), 99, false); + } else { + $certificatedate = userdate($date, get_string($dateformat, 'langconfig')); + } } return $certificatedate; From ed24576728c8fd5706229597ad6169f871c78247 Mon Sep 17 00:00:00 2001 From: Tristan Mackay Date: Tue, 10 Apr 2018 11:53:46 +0800 Subject: [PATCH 54/93] #176 Only get users details who are enrolled within the course --- classes/task/email_certificate_task.php | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/classes/task/email_certificate_task.php b/classes/task/email_certificate_task.php index 3f13c013c..b150ca986 100644 --- a/classes/task/email_certificate_task.php +++ b/classes/task/email_certificate_task.php @@ -71,8 +71,7 @@ public function execute() { // Get the person we are going to send this email on behalf of. // Look through the teachers. - if ($teachers = get_users_by_capability($context, 'moodle/course:update', 'u.*', 'u.id ASC', - '', '', '', '', false, true)) { + if ($teachers = get_enrolled_users($context, 'moodle/course:update')) { $teachers = sort_by_roleassignment_authority($teachers, $context); $userfrom = reset($teachers); } else { // Ok, no teachers, use administrator name. From 0d68d4891d277c032892701225b31a30fa6ea112 Mon Sep 17 00:00:00 2001 From: Mark Nelson Date: Fri, 13 Jul 2018 20:46:17 +0800 Subject: [PATCH 55/93] #171 Only get teachers who are enrolled within the course --- element/teachername/classes/element.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/element/teachername/classes/element.php b/element/teachername/classes/element.php index a2cba2d12..c35d474ad 100644 --- a/element/teachername/classes/element.php +++ b/element/teachername/classes/element.php @@ -106,7 +106,7 @@ protected function get_list_of_teachers() { $teachers = array(); // Now return all users who can manage the customcert in this context. - if ($users = get_users_by_capability($PAGE->context, 'mod/customcert:manage')) { + if ($users = get_enrolled_users($PAGE->context, 'mod/customcert:manage')) { foreach ($users as $user) { $teachers[$user->id] = fullname($user); } From 0f5aaffd8d00a93762988e008a1cc8a5aee0872b Mon Sep 17 00:00:00 2001 From: Mark Nelson Date: Fri, 13 Jul 2018 22:06:16 +0800 Subject: [PATCH 56/93] Updated CHANGES.md --- CHANGES.md | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/CHANGES.md b/CHANGES.md index 14e4259e1..0e51ff419 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -4,6 +4,21 @@ 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.4.5] - 2018-07-13 +### Fixed + +- Use custom fonts if present (#211). +- Fix broken SQL on Oracle in the email certificate task (#187). +- Fixed exception when clicking 'Add page' when template has not been saved (#154). +- Only email teachers who are enrolled within the course (#176). +- Only display teachers who are enrolled within the course in the dropdown (#171). + +### Changed + +- Multiple UX improvements to both the browser and mobile views (#207). + - One big change here is combining the report and activity view page into one. +- Allow short dates with leading zeros (#210). + ## [3.4.4] - 2018-06-26 ### Fixed From 928e70d5e7a2ed7280e1742faa0699fa34f8a779 Mon Sep 17 00:00:00 2001 From: Mark Nelson Date: Fri, 13 Jul 2018 22:41:09 +0800 Subject: [PATCH 57/93] Bumped version --- version.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/version.php b/version.php index d0fa94505..39b892046 100644 --- a/version.php +++ b/version.php @@ -24,10 +24,10 @@ defined('MOODLE_INTERNAL') || die('Direct access to this script is forbidden.'); -$plugin->version = 2017111304; // The current module version (Date: YYYYMMDDXX). +$plugin->version = 2017111305; // The current module version (Date: YYYYMMDDXX). $plugin->requires = 2017111300; // Requires this Moodle version (3.4). $plugin->cron = 0; // Period for cron to check this module (secs). $plugin->component = 'mod_customcert'; $plugin->maturity = MATURITY_STABLE; -$plugin->release = "3.4.4"; // User-friendly version number. +$plugin->release = "3.4.5"; // User-friendly version number. From 273100840154a9c29029688a72f810fbcb1a82c5 Mon Sep 17 00:00:00 2001 From: Dmitrii Metelkin Date: Tue, 17 Jul 2018 16:49:26 +1000 Subject: [PATCH 58/93] #213 Allow element plugins to have admin settings --- classes/plugininfo/customcertelement.php | 40 ++++++++++++++++++++++++ lang/en/customcert.php | 2 ++ settings.php | 15 +++++++++ 3 files changed, 57 insertions(+) diff --git a/classes/plugininfo/customcertelement.php b/classes/plugininfo/customcertelement.php index 5cd107bb9..5eeeab4f3 100644 --- a/classes/plugininfo/customcertelement.php +++ b/classes/plugininfo/customcertelement.php @@ -44,4 +44,44 @@ class customcertelement extends base { public function is_uninstall_allowed() { return false; } + + /** + * Loads plugin settings to the settings tree. + * + * @param \part_of_admin_tree $adminroot + * @param string $parentnodename + * @param bool $hassiteconfig whether the current user has moodle/site:config capability + */ + public function load_settings(\part_of_admin_tree $adminroot, $parentnodename, $hassiteconfig) { + global $CFG, $USER, $DB, $OUTPUT, $PAGE; + $ADMIN = $adminroot; + $plugininfo = $this; + + if (!$this->is_installed_and_upgraded()) { + return; + } + + if (!$hassiteconfig or !file_exists($this->full_path('settings.php'))) { + return; + } + + $section = $this->get_settings_section_name(); + $settings = new \admin_settingpage($section, $this->displayname, 'moodle/site:config', false); + + include($this->full_path('settings.php')); + $ADMIN->add($parentnodename, $settings); + } + + /** + * Get the settings section name. + * + * @return null|string the settings section name. + */ + public function get_settings_section_name() { + if (file_exists($this->full_path('settings.php'))) { + return 'customcertelement_' . $this->name; + } else { + return null; + } + } } diff --git a/lang/en/customcert.php b/lang/en/customcert.php index 41f3df98c..91007c6b7 100644 --- a/lang/en/customcert.php +++ b/lang/en/customcert.php @@ -40,6 +40,7 @@ $string['customcert:viewallcertificates'] = 'View all certificates'; $string['customcert:verifyallcertificates'] = 'Verify all certificates on the site'; $string['customcert:verifycertificate'] = 'Verify a certificate'; +$string['customcertsettings'] = 'Custom certificate settings'; $string['deletecertpage'] = 'Delete page'; $string['deleteconfirm'] = 'Delete confirmation'; $string['deleteelement'] = 'Delete element'; @@ -57,6 +58,7 @@ $string['edittemplate'] = 'Edit template'; $string['elementname'] = 'Element name'; $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['elementplugins'] = 'Element plugins'; $string['elements'] = 'Elements'; $string['elements_help'] = 'This is the list of elements that will be displayed on the certificate. diff --git a/settings.php b/settings.php index 9ae24bc83..484c813e5 100644 --- a/settings.php +++ b/settings.php @@ -25,6 +25,10 @@ defined('MOODLE_INTERNAL') || die; $url = $CFG->wwwroot . '/mod/customcert/verify_certificate.php'; + +$ADMIN->add('modsettings', new admin_category('customcert', get_string('pluginname', 'mod_customcert'))); +$settings = new admin_settingpage('modsettingcustomcert', new lang_string('customcertsettings', 'mod_customcert')); + $settings->add(new admin_setting_configcheckbox('customcert/verifyallcertificates', get_string('verifyallcertificates', 'customcert'), get_string('verifyallcertificates_desc', 'customcert', $url), @@ -46,3 +50,14 @@ $settings->add(new \mod_customcert\admin_setting_link('customcert/uploadimage', get_string('uploadimage', 'customcert'), get_string('uploadimagedesc', 'customcert'), get_string('uploadimage', 'customcert'), new moodle_url('/mod/customcert/upload_image.php'), '')); +$ADMIN->add('customcert', $settings); + +// Element plugin settings. +$ADMIN->add('customcert', new admin_category('customcertelements', get_string('elementplugins', 'customcert'))); +$plugins = \core_plugin_manager::instance()->get_plugins_of_type('customcertelement'); +foreach ($plugins as $plugin) { + $plugin->load_settings($ADMIN, 'customcertelements', $hassiteconfig); +} + +// Tell core we already added the settings structure. +$settings = null; From 7118f7966c42cc0f20c13ca304932b89c5d4293a Mon Sep 17 00:00:00 2001 From: Mark Nelson Date: Sat, 4 Aug 2018 12:44:21 +0800 Subject: [PATCH 59/93] Added LICENSE.md --- LICENSE.md | 674 +++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 674 insertions(+) create mode 100644 LICENSE.md diff --git a/LICENSE.md b/LICENSE.md new file mode 100644 index 000000000..94a9ed024 --- /dev/null +++ b/LICENSE.md @@ -0,0 +1,674 @@ + GNU GENERAL PUBLIC LICENSE + Version 3, 29 June 2007 + + Copyright (C) 2007 Free Software Foundation, Inc. + Everyone is permitted to copy and distribute verbatim copies + of this license document, but changing it is not allowed. + + Preamble + + The GNU General Public License is a free, copyleft license for +software and other kinds of works. + + The licenses for most software and other practical works are designed +to take away your freedom to share and change the works. By contrast, +the GNU General Public License is intended to guarantee your freedom to +share and change all versions of a program--to make sure it remains free +software for all its users. We, the Free Software Foundation, use the +GNU General Public License for most of our software; it applies also to +any other work released this way by its authors. You can apply it to +your programs, too. + + When we speak of free software, we are referring to freedom, not +price. Our General Public Licenses are designed to make sure that you +have the freedom to distribute copies of free software (and charge for +them if you wish), that you receive source code or can get it if you +want it, that you can change the software or use pieces of it in new +free programs, and that you know you can do these things. + + To protect your rights, we need to prevent others from denying you +these rights or asking you to surrender the rights. Therefore, you have +certain responsibilities if you distribute copies of the software, or if +you modify it: responsibilities to respect the freedom of others. + + For example, if you distribute copies of such a program, whether +gratis or for a fee, you must pass on to the recipients the same +freedoms that you received. You must make sure that they, too, receive +or can get the source code. And you must show them these terms so they +know their rights. + + Developers that use the GNU GPL protect your rights with two steps: +(1) assert copyright on the software, and (2) offer you this License +giving you legal permission to copy, distribute and/or modify it. + + For the developers' and authors' protection, the GPL clearly explains +that there is no warranty for this free software. For both users' and +authors' sake, the GPL requires that modified versions be marked as +changed, so that their problems will not be attributed erroneously to +authors of previous versions. + + Some devices are designed to deny users access to install or run +modified versions of the software inside them, although the manufacturer +can do so. This is fundamentally incompatible with the aim of +protecting users' freedom to change the software. The systematic +pattern of such abuse occurs in the area of products for individuals to +use, which is precisely where it is most unacceptable. Therefore, we +have designed this version of the GPL to prohibit the practice for those +products. If such problems arise substantially in other domains, we +stand ready to extend this provision to those domains in future versions +of the GPL, as needed to protect the freedom of users. + + Finally, every program is threatened constantly by software patents. +States should not allow patents to restrict development and use of +software on general-purpose computers, but in those that do, we wish to +avoid the special danger that patents applied to a free program could +make it effectively proprietary. To prevent this, the GPL assures that +patents cannot be used to render the program non-free. + + The precise terms and conditions for copying, distribution and +modification follow. + + TERMS AND CONDITIONS + + 0. Definitions. + + "This License" refers to version 3 of the GNU General Public License. + + "Copyright" also means copyright-like laws that apply to other kinds of +works, such as semiconductor masks. + + "The Program" refers to any copyrightable work licensed under this +License. Each licensee is addressed as "you". "Licensees" and +"recipients" may be individuals or organizations. + + To "modify" a work means to copy from or adapt all or part of the work +in a fashion requiring copyright permission, other than the making of an +exact copy. The resulting work is called a "modified version" of the +earlier work or a work "based on" the earlier work. + + A "covered work" means either the unmodified Program or a work based +on the Program. + + To "propagate" a work means to do anything with it that, without +permission, would make you directly or secondarily liable for +infringement under applicable copyright law, except executing it on a +computer or modifying a private copy. Propagation includes copying, +distribution (with or without modification), making available to the +public, and in some countries other activities as well. + + To "convey" a work means any kind of propagation that enables other +parties to make or receive copies. Mere interaction with a user through +a computer network, with no transfer of a copy, is not conveying. + + An interactive user interface displays "Appropriate Legal Notices" +to the extent that it includes a convenient and prominently visible +feature that (1) displays an appropriate copyright notice, and (2) +tells the user that there is no warranty for the work (except to the +extent that warranties are provided), that licensees may convey the +work under this License, and how to view a copy of this License. If +the interface presents a list of user commands or options, such as a +menu, a prominent item in the list meets this criterion. + + 1. Source Code. + + The "source code" for a work means the preferred form of the work +for making modifications to it. "Object code" means any non-source +form of a work. + + A "Standard Interface" means an interface that either is an official +standard defined by a recognized standards body, or, in the case of +interfaces specified for a particular programming language, one that +is widely used among developers working in that language. + + The "System Libraries" of an executable work include anything, other +than the work as a whole, that (a) is included in the normal form of +packaging a Major Component, but which is not part of that Major +Component, and (b) serves only to enable use of the work with that +Major Component, or to implement a Standard Interface for which an +implementation is available to the public in source code form. A +"Major Component", in this context, means a major essential component +(kernel, window system, and so on) of the specific operating system +(if any) on which the executable work runs, or a compiler used to +produce the work, or an object code interpreter used to run it. + + The "Corresponding Source" for a work in object code form means all +the source code needed to generate, install, and (for an executable +work) run the object code and to modify the work, including scripts to +control those activities. However, it does not include the work's +System Libraries, or general-purpose tools or generally available free +programs which are used unmodified in performing those activities but +which are not part of the work. For example, Corresponding Source +includes interface definition files associated with source files for +the work, and the source code for shared libraries and dynamically +linked subprograms that the work is specifically designed to require, +such as by intimate data communication or control flow between those +subprograms and other parts of the work. + + The Corresponding Source need not include anything that users +can regenerate automatically from other parts of the Corresponding +Source. + + The Corresponding Source for a work in source code form is that +same work. + + 2. Basic Permissions. + + All rights granted under this License are granted for the term of +copyright on the Program, and are irrevocable provided the stated +conditions are met. This License explicitly affirms your unlimited +permission to run the unmodified Program. The output from running a +covered work is covered by this License only if the output, given its +content, constitutes a covered work. This License acknowledges your +rights of fair use or other equivalent, as provided by copyright law. + + You may make, run and propagate covered works that you do not +convey, without conditions so long as your license otherwise remains +in force. You may convey covered works to others for the sole purpose +of having them make modifications exclusively for you, or provide you +with facilities for running those works, provided that you comply with +the terms of this License in conveying all material for which you do +not control copyright. Those thus making or running the covered works +for you must do so exclusively on your behalf, under your direction +and control, on terms that prohibit them from making any copies of +your copyrighted material outside their relationship with you. + + Conveying under any other circumstances is permitted solely under +the conditions stated below. Sublicensing is not allowed; section 10 +makes it unnecessary. + + 3. Protecting Users' Legal Rights From Anti-Circumvention Law. + + No covered work shall be deemed part of an effective technological +measure under any applicable law fulfilling obligations under article +11 of the WIPO copyright treaty adopted on 20 December 1996, or +similar laws prohibiting or restricting circumvention of such +measures. + + When you convey a covered work, you waive any legal power to forbid +circumvention of technological measures to the extent such circumvention +is effected by exercising rights under this License with respect to +the covered work, and you disclaim any intention to limit operation or +modification of the work as a means of enforcing, against the work's +users, your or third parties' legal rights to forbid circumvention of +technological measures. + + 4. Conveying Verbatim Copies. + + You may convey verbatim copies of the Program's source code as you +receive it, in any medium, provided that you conspicuously and +appropriately publish on each copy an appropriate copyright notice; +keep intact all notices stating that this License and any +non-permissive terms added in accord with section 7 apply to the code; +keep intact all notices of the absence of any warranty; and give all +recipients a copy of this License along with the Program. + + You may charge any price or no price for each copy that you convey, +and you may offer support or warranty protection for a fee. + + 5. Conveying Modified Source Versions. + + You may convey a work based on the Program, or the modifications to +produce it from the Program, in the form of source code under the +terms of section 4, provided that you also meet all of these conditions: + + a) The work must carry prominent notices stating that you modified + it, and giving a relevant date. + + b) The work must carry prominent notices stating that it is + released under this License and any conditions added under section + 7. This requirement modifies the requirement in section 4 to + "keep intact all notices". + + c) You must license the entire work, as a whole, under this + License to anyone who comes into possession of a copy. This + License will therefore apply, along with any applicable section 7 + additional terms, to the whole of the work, and all its parts, + regardless of how they are packaged. This License gives no + permission to license the work in any other way, but it does not + invalidate such permission if you have separately received it. + + d) If the work has interactive user interfaces, each must display + Appropriate Legal Notices; however, if the Program has interactive + interfaces that do not display Appropriate Legal Notices, your + work need not make them do so. + + A compilation of a covered work with other separate and independent +works, which are not by their nature extensions of the covered work, +and which are not combined with it such as to form a larger program, +in or on a volume of a storage or distribution medium, is called an +"aggregate" if the compilation and its resulting copyright are not +used to limit the access or legal rights of the compilation's users +beyond what the individual works permit. Inclusion of a covered work +in an aggregate does not cause this License to apply to the other +parts of the aggregate. + + 6. Conveying Non-Source Forms. + + You may convey a covered work in object code form under the terms +of sections 4 and 5, provided that you also convey the +machine-readable Corresponding Source under the terms of this License, +in one of these ways: + + a) Convey the object code in, or embodied in, a physical product + (including a physical distribution medium), accompanied by the + Corresponding Source fixed on a durable physical medium + customarily used for software interchange. + + b) Convey the object code in, or embodied in, a physical product + (including a physical distribution medium), accompanied by a + written offer, valid for at least three years and valid for as + long as you offer spare parts or customer support for that product + model, to give anyone who possesses the object code either (1) a + copy of the Corresponding Source for all the software in the + product that is covered by this License, on a durable physical + medium customarily used for software interchange, for a price no + more than your reasonable cost of physically performing this + conveying of source, or (2) access to copy the + Corresponding Source from a network server at no charge. + + c) Convey individual copies of the object code with a copy of the + written offer to provide the Corresponding Source. This + alternative is allowed only occasionally and noncommercially, and + only if you received the object code with such an offer, in accord + with subsection 6b. + + d) Convey the object code by offering access from a designated + place (gratis or for a charge), and offer equivalent access to the + Corresponding Source in the same way through the same place at no + further charge. You need not require recipients to copy the + Corresponding Source along with the object code. If the place to + copy the object code is a network server, the Corresponding Source + may be on a different server (operated by you or a third party) + that supports equivalent copying facilities, provided you maintain + clear directions next to the object code saying where to find the + Corresponding Source. Regardless of what server hosts the + Corresponding Source, you remain obligated to ensure that it is + available for as long as needed to satisfy these requirements. + + e) Convey the object code using peer-to-peer transmission, provided + you inform other peers where the object code and Corresponding + Source of the work are being offered to the general public at no + charge under subsection 6d. + + A separable portion of the object code, whose source code is excluded +from the Corresponding Source as a System Library, need not be +included in conveying the object code work. + + A "User Product" is either (1) a "consumer product", which means any +tangible personal property which is normally used for personal, family, +or household purposes, or (2) anything designed or sold for incorporation +into a dwelling. In determining whether a product is a consumer product, +doubtful cases shall be resolved in favor of coverage. For a particular +product received by a particular user, "normally used" refers to a +typical or common use of that class of product, regardless of the status +of the particular user or of the way in which the particular user +actually uses, or expects or is expected to use, the product. A product +is a consumer product regardless of whether the product has substantial +commercial, industrial or non-consumer uses, unless such uses represent +the only significant mode of use of the product. + + "Installation Information" for a User Product means any methods, +procedures, authorization keys, or other information required to install +and execute modified versions of a covered work in that User Product from +a modified version of its Corresponding Source. The information must +suffice to ensure that the continued functioning of the modified object +code is in no case prevented or interfered with solely because +modification has been made. + + If you convey an object code work under this section in, or with, or +specifically for use in, a User Product, and the conveying occurs as +part of a transaction in which the right of possession and use of the +User Product is transferred to the recipient in perpetuity or for a +fixed term (regardless of how the transaction is characterized), the +Corresponding Source conveyed under this section must be accompanied +by the Installation Information. But this requirement does not apply +if neither you nor any third party retains the ability to install +modified object code on the User Product (for example, the work has +been installed in ROM). + + The requirement to provide Installation Information does not include a +requirement to continue to provide support service, warranty, or updates +for a work that has been modified or installed by the recipient, or for +the User Product in which it has been modified or installed. Access to a +network may be denied when the modification itself materially and +adversely affects the operation of the network or violates the rules and +protocols for communication across the network. + + Corresponding Source conveyed, and Installation Information provided, +in accord with this section must be in a format that is publicly +documented (and with an implementation available to the public in +source code form), and must require no special password or key for +unpacking, reading or copying. + + 7. Additional Terms. + + "Additional permissions" are terms that supplement the terms of this +License by making exceptions from one or more of its conditions. +Additional permissions that are applicable to the entire Program shall +be treated as though they were included in this License, to the extent +that they are valid under applicable law. If additional permissions +apply only to part of the Program, that part may be used separately +under those permissions, but the entire Program remains governed by +this License without regard to the additional permissions. + + When you convey a copy of a covered work, you may at your option +remove any additional permissions from that copy, or from any part of +it. (Additional permissions may be written to require their own +removal in certain cases when you modify the work.) You may place +additional permissions on material, added by you to a covered work, +for which you have or can give appropriate copyright permission. + + Notwithstanding any other provision of this License, for material you +add to a covered work, you may (if authorized by the copyright holders of +that material) supplement the terms of this License with terms: + + a) Disclaiming warranty or limiting liability differently from the + terms of sections 15 and 16 of this License; or + + b) Requiring preservation of specified reasonable legal notices or + author attributions in that material or in the Appropriate Legal + Notices displayed by works containing it; or + + c) Prohibiting misrepresentation of the origin of that material, or + requiring that modified versions of such material be marked in + reasonable ways as different from the original version; or + + d) Limiting the use for publicity purposes of names of licensors or + authors of the material; or + + e) Declining to grant rights under trademark law for use of some + trade names, trademarks, or service marks; or + + f) Requiring indemnification of licensors and authors of that + material by anyone who conveys the material (or modified versions of + it) with contractual assumptions of liability to the recipient, for + any liability that these contractual assumptions directly impose on + those licensors and authors. + + All other non-permissive additional terms are considered "further +restrictions" within the meaning of section 10. If the Program as you +received it, or any part of it, contains a notice stating that it is +governed by this License along with a term that is a further +restriction, you may remove that term. If a license document contains +a further restriction but permits relicensing or conveying under this +License, you may add to a covered work material governed by the terms +of that license document, provided that the further restriction does +not survive such relicensing or conveying. + + If you add terms to a covered work in accord with this section, you +must place, in the relevant source files, a statement of the +additional terms that apply to those files, or a notice indicating +where to find the applicable terms. + + Additional terms, permissive or non-permissive, may be stated in the +form of a separately written license, or stated as exceptions; +the above requirements apply either way. + + 8. Termination. + + You may not propagate or modify a covered work except as expressly +provided under this License. Any attempt otherwise to propagate or +modify it is void, and will automatically terminate your rights under +this License (including any patent licenses granted under the third +paragraph of section 11). + + However, if you cease all violation of this License, then your +license from a particular copyright holder is reinstated (a) +provisionally, unless and until the copyright holder explicitly and +finally terminates your license, and (b) permanently, if the copyright +holder fails to notify you of the violation by some reasonable means +prior to 60 days after the cessation. + + Moreover, your license from a particular copyright holder is +reinstated permanently if the copyright holder notifies you of the +violation by some reasonable means, this is the first time you have +received notice of violation of this License (for any work) from that +copyright holder, and you cure the violation prior to 30 days after +your receipt of the notice. + + Termination of your rights under this section does not terminate the +licenses of parties who have received copies or rights from you under +this License. If your rights have been terminated and not permanently +reinstated, you do not qualify to receive new licenses for the same +material under section 10. + + 9. Acceptance Not Required for Having Copies. + + You are not required to accept this License in order to receive or +run a copy of the Program. Ancillary propagation of a covered work +occurring solely as a consequence of using peer-to-peer transmission +to receive a copy likewise does not require acceptance. However, +nothing other than this License grants you permission to propagate or +modify any covered work. These actions infringe copyright if you do +not accept this License. Therefore, by modifying or propagating a +covered work, you indicate your acceptance of this License to do so. + + 10. Automatic Licensing of Downstream Recipients. + + Each time you convey a covered work, the recipient automatically +receives a license from the original licensors, to run, modify and +propagate that work, subject to this License. You are not responsible +for enforcing compliance by third parties with this License. + + An "entity transaction" is a transaction transferring control of an +organization, or substantially all assets of one, or subdividing an +organization, or merging organizations. If propagation of a covered +work results from an entity transaction, each party to that +transaction who receives a copy of the work also receives whatever +licenses to the work the party's predecessor in interest had or could +give under the previous paragraph, plus a right to possession of the +Corresponding Source of the work from the predecessor in interest, if +the predecessor has it or can get it with reasonable efforts. + + You may not impose any further restrictions on the exercise of the +rights granted or affirmed under this License. For example, you may +not impose a license fee, royalty, or other charge for exercise of +rights granted under this License, and you may not initiate litigation +(including a cross-claim or counterclaim in a lawsuit) alleging that +any patent claim is infringed by making, using, selling, offering for +sale, or importing the Program or any portion of it. + + 11. Patents. + + A "contributor" is a copyright holder who authorizes use under this +License of the Program or a work on which the Program is based. The +work thus licensed is called the contributor's "contributor version". + + A contributor's "essential patent claims" are all patent claims +owned or controlled by the contributor, whether already acquired or +hereafter acquired, that would be infringed by some manner, permitted +by this License, of making, using, or selling its contributor version, +but do not include claims that would be infringed only as a +consequence of further modification of the contributor version. For +purposes of this definition, "control" includes the right to grant +patent sublicenses in a manner consistent with the requirements of +this License. + + Each contributor grants you a non-exclusive, worldwide, royalty-free +patent license under the contributor's essential patent claims, to +make, use, sell, offer for sale, import and otherwise run, modify and +propagate the contents of its contributor version. + + In the following three paragraphs, a "patent license" is any express +agreement or commitment, however denominated, not to enforce a patent +(such as an express permission to practice a patent or covenant not to +sue for patent infringement). To "grant" such a patent license to a +party means to make such an agreement or commitment not to enforce a +patent against the party. + + If you convey a covered work, knowingly relying on a patent license, +and the Corresponding Source of the work is not available for anyone +to copy, free of charge and under the terms of this License, through a +publicly available network server or other readily accessible means, +then you must either (1) cause the Corresponding Source to be so +available, or (2) arrange to deprive yourself of the benefit of the +patent license for this particular work, or (3) arrange, in a manner +consistent with the requirements of this License, to extend the patent +license to downstream recipients. "Knowingly relying" means you have +actual knowledge that, but for the patent license, your conveying the +covered work in a country, or your recipient's use of the covered work +in a country, would infringe one or more identifiable patents in that +country that you have reason to believe are valid. + + If, pursuant to or in connection with a single transaction or +arrangement, you convey, or propagate by procuring conveyance of, a +covered work, and grant a patent license to some of the parties +receiving the covered work authorizing them to use, propagate, modify +or convey a specific copy of the covered work, then the patent license +you grant is automatically extended to all recipients of the covered +work and works based on it. + + A patent license is "discriminatory" if it does not include within +the scope of its coverage, prohibits the exercise of, or is +conditioned on the non-exercise of one or more of the rights that are +specifically granted under this License. You may not convey a covered +work if you are a party to an arrangement with a third party that is +in the business of distributing software, under which you make payment +to the third party based on the extent of your activity of conveying +the work, and under which the third party grants, to any of the +parties who would receive the covered work from you, a discriminatory +patent license (a) in connection with copies of the covered work +conveyed by you (or copies made from those copies), or (b) primarily +for and in connection with specific products or compilations that +contain the covered work, unless you entered into that arrangement, +or that patent license was granted, prior to 28 March 2007. + + Nothing in this License shall be construed as excluding or limiting +any implied license or other defenses to infringement that may +otherwise be available to you under applicable patent law. + + 12. No Surrender of Others' Freedom. + + If conditions are imposed on you (whether by court order, agreement or +otherwise) that contradict the conditions of this License, they do not +excuse you from the conditions of this License. If you cannot convey a +covered work so as to satisfy simultaneously your obligations under this +License and any other pertinent obligations, then as a consequence you may +not convey it at all. For example, if you agree to terms that obligate you +to collect a royalty for further conveying from those to whom you convey +the Program, the only way you could satisfy both those terms and this +License would be to refrain entirely from conveying the Program. + + 13. Use with the GNU Affero General Public License. + + Notwithstanding any other provision of this License, you have +permission to link or combine any covered work with a work licensed +under version 3 of the GNU Affero General Public License into a single +combined work, and to convey the resulting work. The terms of this +License will continue to apply to the part which is the covered work, +but the special requirements of the GNU Affero General Public License, +section 13, concerning interaction through a network will apply to the +combination as such. + + 14. Revised Versions of this License. + + The Free Software Foundation may publish revised and/or new versions of +the GNU General Public License from time to time. Such new versions will +be similar in spirit to the present version, but may differ in detail to +address new problems or concerns. + + Each version is given a distinguishing version number. If the +Program specifies that a certain numbered version of the GNU General +Public License "or any later version" applies to it, you have the +option of following the terms and conditions either of that numbered +version or of any later version published by the Free Software +Foundation. If the Program does not specify a version number of the +GNU General Public License, you may choose any version ever published +by the Free Software Foundation. + + If the Program specifies that a proxy can decide which future +versions of the GNU General Public License can be used, that proxy's +public statement of acceptance of a version permanently authorizes you +to choose that version for the Program. + + Later license versions may give you additional or different +permissions. However, no additional obligations are imposed on any +author or copyright holder as a result of your choosing to follow a +later version. + + 15. Disclaimer of Warranty. + + THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY +APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT +HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY +OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, +THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR +PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM +IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF +ALL NECESSARY SERVICING, REPAIR OR CORRECTION. + + 16. Limitation of Liability. + + IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING +WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS +THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY +GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE +USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF +DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD +PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS), +EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF +SUCH DAMAGES. + + 17. Interpretation of Sections 15 and 16. + + If the disclaimer of warranty and limitation of liability provided +above cannot be given local legal effect according to their terms, +reviewing courts shall apply local law that most closely approximates +an absolute waiver of all civil liability in connection with the +Program, unless a warranty or assumption of liability accompanies a +copy of the Program in return for a fee. + + END OF TERMS AND CONDITIONS + + How to Apply These Terms to Your New Programs + + If you develop a new program, and you want it to be of the greatest +possible use to the public, the best way to achieve this is to make it +free software which everyone can redistribute and change under these terms. + + To do so, attach the following notices to the program. It is safest +to attach them to the start of each source file to most effectively +state the exclusion of warranty; and each file should have at least +the "copyright" line and a pointer to where the full notice is found. + + + Copyright (C) + + This program 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. + + This program 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 this program. If not, see . + +Also add information on how to contact you by electronic and paper mail. + + If the program does terminal interaction, make it output a short +notice like this when it starts in an interactive mode: + + Copyright (C) + This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'. + This is free software, and you are welcome to redistribute it + under certain conditions; type `show c' for details. + +The hypothetical commands `show w' and `show c' should show the appropriate +parts of the General Public License. Of course, your program's commands +might be different; for a GUI interface, you would use an "about box". + + You should also get your employer (if you work as a programmer) or school, +if any, to sign a "copyright disclaimer" for the program, if necessary. +For more information on this, and how to apply and follow the GNU GPL, see +. + + The GNU General Public License does not permit incorporating your program +into proprietary programs. If your program is a subroutine library, you +may consider it more useful to permit linking proprietary applications with +the library. If this is what you want to do, use the GNU Lesser General +Public License instead of this License. But first, please read +. From 65dbda63786572e24b4bf76e2a72092957231587 Mon Sep 17 00:00:00 2001 From: Dmitrii Metelkin Date: Thu, 19 Jul 2018 15:41:29 +1000 Subject: [PATCH 60/93] #179 Add possibility to selectively disable activity instance settings --- db/access.php | 60 +++++++++++++++++++++++++++++ lang/en/customcert.php | 6 +++ mod_form.php | 86 +++++++++++++++++++++++++++++++----------- 3 files changed, 131 insertions(+), 21 deletions(-) diff --git a/db/access.php b/db/access.php index 7848fedf8..2fbea48c0 100644 --- a/db/access.php +++ b/db/access.php @@ -96,4 +96,64 @@ 'manager' => CAP_ALLOW ) ), + + 'mod/customcert:manageemailstudents' => array( + 'captype' => 'write', + 'contextlevel' => CONTEXT_COURSE, + 'archetypes' => array( + 'editingteacher' => CAP_ALLOW, + 'manager' => CAP_ALLOW + ), + 'clonepermissionsfrom' => 'moodle/course:manageactivities' + ), + + 'mod/customcert:manageemailteachers' => array( + 'captype' => 'write', + 'contextlevel' => CONTEXT_COURSE, + 'archetypes' => array( + 'editingteacher' => CAP_ALLOW, + 'manager' => CAP_ALLOW + ), + 'clonepermissionsfrom' => 'moodle/course:manageactivities' + ), + + 'mod/customcert:manageemailothers' => array( + 'captype' => 'write', + 'contextlevel' => CONTEXT_COURSE, + 'archetypes' => array( + 'editingteacher' => CAP_ALLOW, + 'manager' => CAP_ALLOW + ), + 'clonepermissionsfrom' => 'moodle/course:manageactivities' + ), + + 'mod/customcert:manageverifyany' => array( + 'captype' => 'write', + 'contextlevel' => CONTEXT_COURSE, + 'archetypes' => array( + 'editingteacher' => CAP_ALLOW, + 'manager' => CAP_ALLOW + ), + 'clonepermissionsfrom' => 'moodle/course:manageactivities' + ), + + 'mod/customcert:managerequiredtime' => array( + 'captype' => 'write', + 'contextlevel' => CONTEXT_COURSE, + 'archetypes' => array( + 'editingteacher' => CAP_ALLOW, + 'manager' => CAP_ALLOW + ), + 'clonepermissionsfrom' => 'moodle/course:manageactivities' + ), + + 'mod/customcert:manageprotection' => array( + 'captype' => 'write', + 'contextlevel' => CONTEXT_COURSE, + 'archetypes' => array( + 'editingteacher' => CAP_ALLOW, + 'manager' => CAP_ALLOW + ), + 'clonepermissionsfrom' => 'moodle/course:manageactivities' + ), ); diff --git a/lang/en/customcert.php b/lang/en/customcert.php index 91007c6b7..bbb52156f 100644 --- a/lang/en/customcert.php +++ b/lang/en/customcert.php @@ -35,6 +35,12 @@ $string['createtemplate'] = 'Create template'; $string['customcert:addinstance'] = 'Add a new custom certificate instance'; $string['customcert:manage'] = 'Manage a custom certificate'; +$string['customcert:manageemailstudents'] = 'Manage email students setting'; +$string['customcert:manageemailteachers'] = 'Manage email teachers setting'; +$string['customcert:manageemailothers'] = 'Manage email others setting'; +$string['customcert:manageverifyany'] = 'Manage verification setting'; +$string['customcert:managerequiredtime'] = 'Manage time required setting'; +$string['customcert:manageprotection'] = 'Manage protection setting'; $string['customcert:view'] = 'View a custom certificate'; $string['customcert:viewreport'] = 'View course report'; $string['customcert:viewallcertificates'] = 'View all certificates'; diff --git a/mod_form.php b/mod_form.php index 89f28ad73..93fbae16c 100644 --- a/mod_form.php +++ b/mod_form.php @@ -55,33 +55,77 @@ public function definition() { $this->standard_intro_elements(get_string('description', 'customcert')); - $mform->addElement('header', 'options', get_string('options', 'customcert')); + $optionsheader = $mform->createElement('header', 'options', get_string('options', 'customcert')); - $mform->addElement('selectyesno', 'emailstudents', get_string('emailstudents', 'customcert')); - $mform->setType('emailstudents', 0); - $mform->addHelpButton('emailstudents', 'emailstudents', 'customcert'); + if (has_capability('mod/customcert:manageemailstudents', $this->get_context())) { + $mform->addElement('selectyesno', 'emailstudents', get_string('emailstudents', 'customcert')); + $mform->setDefault('emailstudents', 0); + $mform->addHelpButton('emailstudents', 'emailstudents', 'customcert'); + $firstoption = 'emailstudents'; + } else { + $mform->addElement('hidden', 'emailstudents', 0); + $mform->setType('emailstudents', PARAM_INT); + } - $mform->addElement('selectyesno', 'emailteachers', get_string('emailteachers', 'customcert')); - $mform->setDefault('emailteachers', 0); - $mform->addHelpButton('emailteachers', 'emailteachers', 'customcert'); + if (has_capability('mod/customcert:manageemailteachers', $this->get_context())) { + $mform->addElement('selectyesno', 'emailteachers', get_string('emailteachers', 'customcert')); + $mform->setDefault('emailteachers', 0); + $mform->addHelpButton('emailteachers', 'emailteachers', 'customcert'); + $firstoption = empty($firstoption) ? 'emailteachers' : $firstoption; + } else { + $mform->addElement('hidden', 'emailteachers', 0); + $mform->setType('emailstudents', PARAM_INT); + } + + if (has_capability('mod/customcert:manageemailothers', $this->get_context())) { + $mform->addElement('text', 'emailothers', get_string('emailothers', 'customcert'), array('size' => '40')); + $mform->setType('emailothers', PARAM_TEXT); + $mform->addHelpButton('emailothers', 'emailothers', 'customcert'); + $firstoption = empty($firstoption) ? 'emailothers' : $firstoption; + } else { + $mform->addElement('hidden', 'emailothers', ''); + $mform->setType('emailothers', PARAM_TEXT); + } - $mform->addElement('text', 'emailothers', get_string('emailothers', 'customcert'), array('size' => '40')); - $mform->setType('emailothers', PARAM_TEXT); - $mform->addHelpButton('emailothers', 'emailothers', 'customcert'); + if (has_capability('mod/customcert:manageverifyany', $this->get_context())) { + $mform->addElement('selectyesno', 'verifyany', get_string('verifycertificateanyone', 'customcert')); + $mform->setType('verifyany', 0); + $mform->addHelpButton('verifyany', 'verifycertificateanyone', 'customcert'); + $firstoption = empty($firstoption) ? 'verifyany' : $firstoption; + } else { + $mform->addElement('hidden', 'verifyany', 0); + $mform->setType('emailothers', PARAM_INT); + } - $mform->addElement('selectyesno', 'verifyany', get_string('verifycertificateanyone', 'customcert')); - $mform->setType('verifyany', 0); - $mform->addHelpButton('verifyany', 'verifycertificateanyone', 'customcert'); + if (has_capability('mod/customcert:managerequiredtime', $this->get_context())) { + $mform->addElement('text', 'requiredtime', get_string('coursetimereq', 'customcert'), array('size' => '3')); + $mform->setType('requiredtime', PARAM_INT); + $mform->addHelpButton('requiredtime', 'coursetimereq', 'customcert'); + $firstoption = empty($firstoption) ? 'requiredtime' : $firstoption; + } else { + $mform->addElement('hidden', 'requiredtime', 0); + $mform->setType('requiredtime', PARAM_INT); + } - $mform->addElement('text', 'requiredtime', get_string('coursetimereq', 'customcert'), array('size' => '3')); - $mform->setType('requiredtime', PARAM_INT); - $mform->addHelpButton('requiredtime', 'coursetimereq', 'customcert'); + if (has_capability('mod/customcert:manageprotection', $this->get_context())) { + $mform->addElement('checkbox', 'protection_print', get_string('setprotection', 'customcert'), + get_string('print', 'customcert')); + $mform->addElement('checkbox', 'protection_modify', '', get_string('modify', 'customcert')); + $mform->addElement('checkbox', 'protection_copy', '', get_string('copy', 'customcert')); + $mform->addHelpButton('protection_print', 'setprotection', 'customcert'); + $firstoption = empty($firstoption) ? 'protection_print' : $firstoption; + } else { + $mform->addElement('hidden', 'protection_print', 0); + $mform->addElement('hidden', 'protection_modify', 0); + $mform->addElement('hidden', 'protection_copy', 0); + $mform->setType('protection_print', PARAM_INT); + $mform->setType('protection_modify', PARAM_INT); + $mform->setType('protection_copy', PARAM_INT); + } - $mform->addElement('checkbox', 'protection_print', get_string('setprotection', 'customcert'), - get_string('print', 'customcert')); - $mform->addElement('checkbox', 'protection_modify', '', get_string('modify', 'customcert')); - $mform->addElement('checkbox', 'protection_copy', '', get_string('copy', 'customcert')); - $mform->addHelpButton('protection_print', 'setprotection', 'customcert'); + if (!empty($firstoption)) { + $mform->insertElementBefore($optionsheader, $firstoption); + } $this->standard_coursemodule_elements(); From 67aa5a7850551253ed58a22d81bd914bdb9079f0 Mon Sep 17 00:00:00 2001 From: Dmitrii Metelkin Date: Mon, 23 Jul 2018 16:17:30 +1000 Subject: [PATCH 61/93] #180 Add possibility to set default values of activity instance --- lang/en/customcert.php | 6 ++++++ mod_form.php | 43 ++++++++++++++++++++++-------------------- settings.php | 33 ++++++++++++++++++++++++++++++++ 3 files changed, 62 insertions(+), 20 deletions(-) diff --git a/lang/en/customcert.php b/lang/en/customcert.php index bbb52156f..c38ec9c08 100644 --- a/lang/en/customcert.php +++ b/lang/en/customcert.php @@ -134,6 +134,12 @@ $string['posx_help'] = 'This is the position in mm from the top left corner you wish the element\'s reference point to locate in the x direction.'; $string['posy'] = 'Position Y'; $string['posy_help'] = 'This is the position in mm from the top left corner you wish the element\'s reference point to locate in the y direction.'; +$string['preventcopy'] = 'Prevent copy'; +$string['preventcopy_desc'] = 'Enable protection from print action.'; +$string['preventprint'] = 'Prevent print'; +$string['preventprint_desc'] = 'Enable protection from modify action.'; +$string['preventmodify'] = 'Prevent modify'; +$string['preventmodify_desc'] = 'Enable protection from copy action.'; $string['print'] = 'Print'; $string['privacy:metadata:customcert_issues'] = 'The list of issued certificates'; $string['privacy:metadata:customcert_issues:code'] = 'The code that belongs to the certificate'; diff --git a/mod_form.php b/mod_form.php index 93fbae16c..ccccdc805 100644 --- a/mod_form.php +++ b/mod_form.php @@ -59,53 +59,53 @@ public function definition() { if (has_capability('mod/customcert:manageemailstudents', $this->get_context())) { $mform->addElement('selectyesno', 'emailstudents', get_string('emailstudents', 'customcert')); - $mform->setDefault('emailstudents', 0); + $mform->setDefault('emailstudents', get_config('customcert', 'emailstudents')); $mform->addHelpButton('emailstudents', 'emailstudents', 'customcert'); $firstoption = 'emailstudents'; } else { - $mform->addElement('hidden', 'emailstudents', 0); - $mform->setType('emailstudents', PARAM_INT); + $mform->addElement('hidden', 'emailstudents', get_config('customcert', 'emailstudents')); } + $mform->setType('emailstudents', PARAM_INT); if (has_capability('mod/customcert:manageemailteachers', $this->get_context())) { $mform->addElement('selectyesno', 'emailteachers', get_string('emailteachers', 'customcert')); - $mform->setDefault('emailteachers', 0); + $mform->setDefault('emailteachers', get_config('customcert', 'emailteachers')); $mform->addHelpButton('emailteachers', 'emailteachers', 'customcert'); $firstoption = empty($firstoption) ? 'emailteachers' : $firstoption; } else { - $mform->addElement('hidden', 'emailteachers', 0); - $mform->setType('emailstudents', PARAM_INT); + $mform->addElement('hidden', 'emailteachers', get_config('customcert', 'emailteachers')); } + $mform->setType('emailteachers', PARAM_INT); if (has_capability('mod/customcert:manageemailothers', $this->get_context())) { $mform->addElement('text', 'emailothers', get_string('emailothers', 'customcert'), array('size' => '40')); - $mform->setType('emailothers', PARAM_TEXT); $mform->addHelpButton('emailothers', 'emailothers', 'customcert'); + $mform->setDefault('emailothers', get_config('customcert', 'emailothers')); $firstoption = empty($firstoption) ? 'emailothers' : $firstoption; } else { - $mform->addElement('hidden', 'emailothers', ''); - $mform->setType('emailothers', PARAM_TEXT); + $mform->addElement('hidden', 'emailothers', get_config('customcert', 'emailothers')); } + $mform->setType('emailothers', PARAM_TEXT); if (has_capability('mod/customcert:manageverifyany', $this->get_context())) { $mform->addElement('selectyesno', 'verifyany', get_string('verifycertificateanyone', 'customcert')); - $mform->setType('verifyany', 0); $mform->addHelpButton('verifyany', 'verifycertificateanyone', 'customcert'); + $mform->setDefault('verifyany', get_config('customcert', 'verifyany')); $firstoption = empty($firstoption) ? 'verifyany' : $firstoption; } else { - $mform->addElement('hidden', 'verifyany', 0); - $mform->setType('emailothers', PARAM_INT); + $mform->addElement('hidden', 'verifyany', get_config('customcert', 'verifyany')); } + $mform->setType('verifyany', PARAM_INT); if (has_capability('mod/customcert:managerequiredtime', $this->get_context())) { $mform->addElement('text', 'requiredtime', get_string('coursetimereq', 'customcert'), array('size' => '3')); - $mform->setType('requiredtime', PARAM_INT); $mform->addHelpButton('requiredtime', 'coursetimereq', 'customcert'); + $mform->setDefault('requiredtime', get_config('customcert', 'coursetimereq')); $firstoption = empty($firstoption) ? 'requiredtime' : $firstoption; } else { $mform->addElement('hidden', 'requiredtime', 0); - $mform->setType('requiredtime', PARAM_INT); } + $mform->setType('requiredtime', PARAM_INT); if (has_capability('mod/customcert:manageprotection', $this->get_context())) { $mform->addElement('checkbox', 'protection_print', get_string('setprotection', 'customcert'), @@ -113,15 +113,18 @@ public function definition() { $mform->addElement('checkbox', 'protection_modify', '', get_string('modify', 'customcert')); $mform->addElement('checkbox', 'protection_copy', '', get_string('copy', 'customcert')); $mform->addHelpButton('protection_print', 'setprotection', 'customcert'); + $mform->setDefault('protection_print', get_config('customcert', 'protection_print')); + $mform->setDefault('protection_modify', get_config('customcert', 'protection_modify')); + $mform->setDefault('protection_copy', get_config('customcert', 'protection_copy')); $firstoption = empty($firstoption) ? 'protection_print' : $firstoption; } else { - $mform->addElement('hidden', 'protection_print', 0); - $mform->addElement('hidden', 'protection_modify', 0); - $mform->addElement('hidden', 'protection_copy', 0); - $mform->setType('protection_print', PARAM_INT); - $mform->setType('protection_modify', PARAM_INT); - $mform->setType('protection_copy', PARAM_INT); + $mform->addElement('hidden', 'protection_print', get_config('customcert', 'protection_print')); + $mform->addElement('hidden', 'protection_modify', get_config('customcert', 'protection_modify')); + $mform->addElement('hidden', 'protection_copy', get_config('customcert', 'protection_copy')); } + $mform->setType('protection_print', PARAM_BOOL); + $mform->setType('protection_modify', PARAM_BOOL); + $mform->setType('protection_copy', PARAM_BOOL); if (!empty($firstoption)) { $mform->insertElementBefore($optionsheader, $firstoption); diff --git a/settings.php b/settings.php index 484c813e5..6a648edc3 100644 --- a/settings.php +++ b/settings.php @@ -50,6 +50,39 @@ $settings->add(new \mod_customcert\admin_setting_link('customcert/uploadimage', get_string('uploadimage', 'customcert'), get_string('uploadimagedesc', 'customcert'), get_string('uploadimage', 'customcert'), new moodle_url('/mod/customcert/upload_image.php'), '')); + +$settings->add(new admin_setting_heading('defaults', + get_string('modeditdefaults', 'admin'), get_string('condifmodeditdefaults', 'admin'))); + +$yesnooptions = [ + 0 => get_string('no'), + 1 => get_string('yes'), +]; + +$settings->add(new admin_setting_configselect('customcert/emailstudents', + get_string('emailstudents', 'customcert'), get_string('emailstudents_help', 'customcert'), 0, $yesnooptions)); +$settings->add(new admin_setting_configselect('customcert/emailteachers', + get_string('emailteachers', 'customcert'), get_string('emailteachers_help', 'customcert'), 0, $yesnooptions)); +$settings->add(new admin_setting_configtext('customcert/emailothers', + get_string('emailothers', 'customcert'), get_string('emailothers_help', 'customcert'), '', PARAM_TEXT)); +$settings->add(new admin_setting_configselect('customcert/verifyany', + get_string('verifycertificateanyone', 'customcert'), get_string('verifycertificateanyone_help', 'customcert'), + 0, $yesnooptions)); +$settings->add(new admin_setting_configtext('customcert/requiredtime', + get_string('coursetimereq', 'customcert'), get_string('coursetimereq_help', 'customcert'), 0, PARAM_INT)); +$settings->add(new admin_setting_configcheckbox('customcert/protection_print', + get_string('preventprint', 'customcert'), + get_string('preventprint_desc', 'customcert'), + 0)); +$settings->add(new admin_setting_configcheckbox('customcert/protection_modify', + get_string('preventmodify', 'customcert'), + get_string('preventmodify_desc', 'customcert'), + 0)); +$settings->add(new admin_setting_configcheckbox('customcert/protection_copy', + get_string('preventcopy', 'customcert'), + get_string('preventcopy_desc', 'customcert'), + 0)); + $ADMIN->add('customcert', $settings); // Element plugin settings. From 5b369e84c18b54bdeee7b896c9ff6ad0f4fd9671 Mon Sep 17 00:00:00 2001 From: Dmitrii Metelkin Date: Mon, 30 Jul 2018 17:33:16 +1000 Subject: [PATCH 62/93] #179 Don't display form elements if a user doesn't have capabilities --- mod_form.php | 135 ++++++++++++++++++++++++++++++++++++++------------- 1 file changed, 100 insertions(+), 35 deletions(-) diff --git a/mod_form.php b/mod_form.php index ccccdc805..fb023a463 100644 --- a/mod_form.php +++ b/mod_form.php @@ -61,51 +61,41 @@ public function definition() { $mform->addElement('selectyesno', 'emailstudents', get_string('emailstudents', 'customcert')); $mform->setDefault('emailstudents', get_config('customcert', 'emailstudents')); $mform->addHelpButton('emailstudents', 'emailstudents', 'customcert'); + $mform->setType('emailstudents', PARAM_INT); $firstoption = 'emailstudents'; - } else { - $mform->addElement('hidden', 'emailstudents', get_config('customcert', 'emailstudents')); } - $mform->setType('emailstudents', PARAM_INT); if (has_capability('mod/customcert:manageemailteachers', $this->get_context())) { $mform->addElement('selectyesno', 'emailteachers', get_string('emailteachers', 'customcert')); $mform->setDefault('emailteachers', get_config('customcert', 'emailteachers')); $mform->addHelpButton('emailteachers', 'emailteachers', 'customcert'); + $mform->setType('emailteachers', PARAM_INT); $firstoption = empty($firstoption) ? 'emailteachers' : $firstoption; - } else { - $mform->addElement('hidden', 'emailteachers', get_config('customcert', 'emailteachers')); } - $mform->setType('emailteachers', PARAM_INT); if (has_capability('mod/customcert:manageemailothers', $this->get_context())) { $mform->addElement('text', 'emailothers', get_string('emailothers', 'customcert'), array('size' => '40')); $mform->addHelpButton('emailothers', 'emailothers', 'customcert'); $mform->setDefault('emailothers', get_config('customcert', 'emailothers')); + $mform->setType('emailothers', PARAM_TEXT); $firstoption = empty($firstoption) ? 'emailothers' : $firstoption; - } else { - $mform->addElement('hidden', 'emailothers', get_config('customcert', 'emailothers')); } - $mform->setType('emailothers', PARAM_TEXT); if (has_capability('mod/customcert:manageverifyany', $this->get_context())) { $mform->addElement('selectyesno', 'verifyany', get_string('verifycertificateanyone', 'customcert')); $mform->addHelpButton('verifyany', 'verifycertificateanyone', 'customcert'); $mform->setDefault('verifyany', get_config('customcert', 'verifyany')); + $mform->setType('verifyany', PARAM_INT); $firstoption = empty($firstoption) ? 'verifyany' : $firstoption; - } else { - $mform->addElement('hidden', 'verifyany', get_config('customcert', 'verifyany')); } - $mform->setType('verifyany', PARAM_INT); if (has_capability('mod/customcert:managerequiredtime', $this->get_context())) { $mform->addElement('text', 'requiredtime', get_string('coursetimereq', 'customcert'), array('size' => '3')); $mform->addHelpButton('requiredtime', 'coursetimereq', 'customcert'); - $mform->setDefault('requiredtime', get_config('customcert', 'coursetimereq')); + $mform->setDefault('requiredtime', get_config('customcert', 'requiredtime')); + $mform->setType('requiredtime', PARAM_INT); $firstoption = empty($firstoption) ? 'requiredtime' : $firstoption; - } else { - $mform->addElement('hidden', 'requiredtime', 0); } - $mform->setType('requiredtime', PARAM_INT); if (has_capability('mod/customcert:manageprotection', $this->get_context())) { $mform->addElement('checkbox', 'protection_print', get_string('setprotection', 'customcert'), @@ -113,18 +103,11 @@ public function definition() { $mform->addElement('checkbox', 'protection_modify', '', get_string('modify', 'customcert')); $mform->addElement('checkbox', 'protection_copy', '', get_string('copy', 'customcert')); $mform->addHelpButton('protection_print', 'setprotection', 'customcert'); - $mform->setDefault('protection_print', get_config('customcert', 'protection_print')); - $mform->setDefault('protection_modify', get_config('customcert', 'protection_modify')); - $mform->setDefault('protection_copy', get_config('customcert', 'protection_copy')); + $mform->setType('protection_print', PARAM_BOOL); + $mform->setType('protection_modify', PARAM_BOOL); + $mform->setType('protection_copy', PARAM_BOOL); $firstoption = empty($firstoption) ? 'protection_print' : $firstoption; - } else { - $mform->addElement('hidden', 'protection_print', get_config('customcert', 'protection_print')); - $mform->addElement('hidden', 'protection_modify', get_config('customcert', 'protection_modify')); - $mform->addElement('hidden', 'protection_copy', get_config('customcert', 'protection_copy')); } - $mform->setType('protection_print', PARAM_BOOL); - $mform->setType('protection_modify', PARAM_BOOL); - $mform->setType('protection_copy', PARAM_BOOL); if (!empty($firstoption)) { $mform->insertElementBefore($optionsheader, $firstoption); @@ -141,17 +124,51 @@ public function definition() { * @param array $defaultvalues */ public function data_preprocessing(&$defaultvalues) { - if (!empty($defaultvalues['protection'])) { - $protection = explode(', ', $defaultvalues['protection']); - // Set the values in the form to what has been set in database. - if (in_array(\mod_customcert\certificate::PROTECTION_PRINT, $protection)) { - $defaultvalues['protection_print'] = 1; + // Set the values in the form to what has been set in database if updating + // or set default configured values if creating. + if (!empty($defaultvalues['update'])) { + if (!empty($defaultvalues['protection'])) { + $protection = $this->build_protection_data($defaultvalues['protection']); + + $defaultvalues['protection_print'] = $protection->protection_print; + $defaultvalues['protection_modify'] = $protection->protection_modify; + $defaultvalues['protection_copy'] = $protection->protection_copy; } - if (in_array(\mod_customcert\certificate::PROTECTION_MODIFY, $protection)) { - $defaultvalues['protection_modify'] = 1; + } else { + $defaultvalues['protection_print'] = get_config('customcert', 'protection_print'); + $defaultvalues['protection_modify'] = get_config('customcert', 'protection_modify'); + $defaultvalues['protection_copy'] = get_config('customcert', 'protection_copy'); + } + } + + /** + * Post process form data. + * + * @param \stdClass $data + * + * @throws \dml_exception + */ + public function data_postprocessing($data) { + global $DB; + + parent::data_postprocessing($data); + + // If creating a new activity. + if (!empty($data->add)) { + foreach ($this->get_options_elements_with_required_caps() as $name => $capability) { + if (!isset($data->$name) && !has_capability($capability, $this->get_context())) { + $data->$name = get_config('customcert', $name); + } } - if (in_array(\mod_customcert\certificate::PROTECTION_COPY, $protection)) { - $defaultvalues['protection_copy'] = 1; + } else { + // If updating, but a user can't manage protection, then get data from database. + if (!has_capability('mod/customcert:manageprotection', $this->get_context())) { + $customcert = $DB->get_record('customcert', array('id' => $data->instance)); + + $protection = $this->build_protection_data($customcert->protection); + $data->protection_print = $protection->protection_print; + $data->protection_modify = $protection->protection_modify; + $data->protection_copy = $protection->protection_copy; } } } @@ -175,4 +192,52 @@ public function validation($data, $files) { return $errors; } + + /** + * Get a list of all options form elements with required capabilities for managing each element. + * + * @return array + */ + protected function get_options_elements_with_required_caps() { + return [ + 'emailstudents' => 'mod/customcert:manageemailstudents', + 'emailteachers' => 'mod/customcert:manageemailteachers', + 'emailothers' => 'mod/customcert:manageemailothers', + 'verifyany' => 'mod/customcert:manageverifyany', + 'requiredtime' => 'mod/customcert:managerequiredtime', + 'protection_print' => 'mod/customcert:manageprotection', + 'protection_modify' => 'mod/customcert:manageprotection', + 'protection_copy' => 'mod/customcert:manageprotection' + ]; + } + + /** + * Build a protection data to be able to set to the form. + * + * @param string $protection Protection sting from database. + * + * @return \stdClass + */ + protected function build_protection_data($protection) { + $data = new stdClass(); + + $data->protection_print = 0; + $data->protection_modify = 0; + $data->protection_copy = 0; + + $protection = explode(', ', $protection); + + if (in_array(\mod_customcert\certificate::PROTECTION_PRINT, $protection)) { + $data->protection_print = 1; + } + if (in_array(\mod_customcert\certificate::PROTECTION_MODIFY, $protection)) { + $data->protection_modify = 1; + } + if (in_array(\mod_customcert\certificate::PROTECTION_COPY, $protection)) { + $data->protection_copy = 1; + } + + return $data; + } + } From 04b0fde43286a5c1fdf9388af22ef9a753c6655e Mon Sep 17 00:00:00 2001 From: Dmitrii Metelkin Date: Wed, 25 Jul 2018 17:30:56 +1000 Subject: [PATCH 63/93] Add tests to support new permissions and default activity options --- tests/behat/activtiy_options.feature | 142 +++++++++++++++++++++++++++ 1 file changed, 142 insertions(+) create mode 100644 tests/behat/activtiy_options.feature diff --git a/tests/behat/activtiy_options.feature b/tests/behat/activtiy_options.feature new file mode 100644 index 000000000..b5957bc64 --- /dev/null +++ b/tests/behat/activtiy_options.feature @@ -0,0 +1,142 @@ +@mod @mod_customcert +Feature: Being able to correctly display options on the certificate activity edit form + + 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 | + | manager1 | Manager | 1 | Manager1@example.com | + And the following "course enrolments" exist: + | user | course | role | + | teacher1 | C1 | editingteacher | + | manager1 | C1 | manager | + And the following "activities" exist: + | activity | name | intro | course | idnumber | + | customcert | Custom certificate 1 | Custom certificate 1 intro | C1 | customcert1 | + + Scenario: Edit an activity as an Editing Teacher I can see all custom certificate options + And I log in as "teacher1" + And I am on "Course 1" course homepage with editing mode on + And I follow "Custom certificate 1" + And I navigate to "Edit settings" in current page administration + And I should see "Email students" + And I should see "Email teachers" + And I should see "Email others" + And I should see "Allow anyone to verify a certificate" + And I should see "Required minutes in course" + And I should see "Set protection" + + Scenario: Create an activity as an Editing Teacher I can see all custom certificate options + And I log in as "teacher1" + And I am on "Course 1" course homepage with editing mode on + And I add a "Custom certificate" to section "1" + And I should see "Email students" + And I should see "Email teachers" + And I should see "Email others" + And I should see "Allow anyone to verify a certificate" + And I should see "Required minutes in course" + And I should see "Set protection" + + Scenario: Add an activity as a Manager I can see all custom certificate options + And I log in as "manager1" + And I am on "Course 1" course homepage with editing mode on + And I add a "Custom certificate" to section "1" + And I should see "Email students" + And I should see "Email teachers" + And I should see "Email others" + And I should see "Allow anyone to verify a certificate" + And I should see "Required minutes in course" + And I should see "Set protection" + + Scenario: Edit an activity as a Manager Teacher I can see all custom certificate options + And I log in as "manager1" + And I am on "Course 1" course homepage with editing mode on + And I follow "Custom certificate 1" + And I navigate to "Edit settings" in current page administration + And I should see "Email students" + And I should see "Email teachers" + And I should see "Email others" + And I should see "Allow anyone to verify a certificate" + And I should see "Required minutes in course" + And I should see "Set protection" + + Scenario: Create an activity as an Editing Teacher without required capabilities I can't see all custom certificate options + And I log in as "admin" + And I set the following system permissions of "Teacher" role: + | capability | permission | + | mod/customcert:manageemailstudents | Prevent | + | mod/customcert:manageemailteachers | Prevent | + | mod/customcert:manageemailothers | Prevent | + | mod/customcert:manageverifyany | Prevent | + | mod/customcert:managerequiredtime | Prevent | + | mod/customcert:manageprotection | Prevent | + And I log out + When I log in as "teacher1" + And I am on "Course 1" course homepage with editing mode on + And I add a "Custom certificate" to section "1" + And I should not see "Email students" + And I should not see "Email teachers" + And I should not see "Email others" + And I should not see "Allow anyone to verify a certificate" + And I should not see "Required minutes in course" + And I should not see "Set protection" + + Scenario: Edit an activity as an Editing Teacher without required capabilities I can't see all custom certificate options + And I log in as "admin" + And I set the following system permissions of "Teacher" role: + | capability | permission | + | mod/customcert:manageemailstudents | Prevent | + | mod/customcert:manageemailteachers | Prevent | + | mod/customcert:manageemailothers | Prevent | + | mod/customcert:manageverifyany | Prevent | + | mod/customcert:managerequiredtime | Prevent | + | mod/customcert:manageprotection | Prevent | + And I log out + When I log in as "teacher1" + And I am on "Course 1" course homepage with editing mode on + And I follow "Custom certificate 1" + And I navigate to "Edit settings" in current page administration + And I should not see "Email students" + And I should not see "Email teachers" + And I should not see "Email others" + And I should not see "Allow anyone to verify a certificate" + And I should not see "Required minutes in course" + And I should not see "Set protection" + + Scenario: Add an activity using default custom certificate options + And I log in as "manager1" + And I am on "Course 1" course homepage with editing mode on + And I add a "Custom certificate" to section "0" + And the field "emailstudents" matches value "0" + And the field "emailteachers" matches value "0" + And the field "emailothers" matches value "" + And the field "verifyany" matches value "0" + And the field "requiredtime" matches value "0" + And the field "protection_print" matches value "0" + And the field "protection_modify" matches value "0" + And the field "protection_copy" matches value "0" + + Scenario: Add an activity using configured custom certificate options + And the following config values are set as admin: + | emailstudents | 1 | customcert | + | emailteachers | 1 | customcert | + | emailothers | test@moodle.com | customcert | + | verifyany | 1 | customcert | + | requiredtime | 5 | customcert | + | protection_print | 1 | customcert | + | protection_modify | 1 | customcert | + | protection_copy | 1 | customcert | + And I log in as "manager1" + And I am on "Course 1" course homepage with editing mode on + And I add a "Custom certificate" to section "1" + And the field "emailstudents" matches value "1" + And the field "emailteachers" matches value "1" + And the field "emailothers" matches value "test@moodle.com" + And the field "verifyany" matches value "1" + And the field "requiredtime" matches value "5" + And the field "protection_print" matches value "1" + And the field "protection_modify" matches value "1" + And the field "protection_copy" matches value "1" From 64e91c271617f504d57cb7537d88127cbb29b43d Mon Sep 17 00:00:00 2001 From: Mark Nelson Date: Mon, 6 Aug 2018 20:32:15 +0800 Subject: [PATCH 64/93] #223 Removed incorrect course reset logic --- lib.php | 6 ------ 1 file changed, 6 deletions(-) diff --git a/lib.php b/lib.php index 8ebb6dff3..4633d62a6 100644 --- a/lib.php +++ b/lib.php @@ -136,12 +136,6 @@ function customcert_reset_userdata($data) { 'error' => false); } - // Updating dates - shift may be negative too. - if ($data->timeshift) { - shift_course_mod_dates('customcert', array('timeopen', 'timeclose'), $data->timeshift, $data->courseid); - $status[] = array('component' => $componentstr, 'item' => get_string('datechanged'), 'error' => false); - } - return $status; } From ce4da8c1b296756f2f50db6ef57656a4222bf369 Mon Sep 17 00:00:00 2001 From: Marina Glancy Date: Tue, 30 Oct 2018 14:52:10 +0100 Subject: [PATCH 65/93] Update travis (#250) Bring the travis.yml up to date with https://github.com/blackboard-open-source/moodle-plugin-ci/blob/master/.travis.dist.yml use grunt to validate js and css add validation of mustache, savepoints, allow javascript behat tests --- .travis.yml | 24 +++++++++++++++++------- verify_certificate.php | 1 + 2 files changed, 18 insertions(+), 7 deletions(-) diff --git a/.travis.yml b/.travis.yml index 08d8b3c99..2aa0c4501 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,30 +1,39 @@ language: php -sudo: false +# For javascript behat tests we need sudo +sudo: true cache: directories: - $HOME/.composer/cache + - $HOME/.npm php: - 7.0 - 7.2 addons: + firefox: 47.0.1 postgresql: 9.3 + apt: + packages: + - oracle-java8-installer + - oracle-java8-set-default env: global: - MOODLE_BRANCH=MOODLE_34_STABLE + - IGNORE_NAMES=mobile_*.mustache # Mobile mustache has specific syntax, ignore their templates matrix: - DB=pgsql - DB=mysqli before_install: - phpenv config-rm xdebug.ini + - nvm install 8.9 + - nvm use 8.9 - cd ../.. - - composer selfupdate - - composer create-project -n --no-dev --prefer-dist moodlerooms/moodle-plugin-ci ci ^1 + - composer create-project -n --no-dev --prefer-dist moodlerooms/moodle-plugin-ci ci ^2 - export PATH="$(cd ci/bin; pwd):$(cd ci/vendor/bin; pwd):$PATH" install: @@ -32,11 +41,12 @@ install: script: - moodle-plugin-ci phplint + # - moodle-plugin-ci phpcpd # subplugins often have similar code and cause "duplicated code" errors + # - moodle-plugin-ci phpmd # too much noise from this check, maybe, some day... - moodle-plugin-ci codechecker - - moodle-plugin-ci csslint - - moodle-plugin-ci shifter - - moodle-plugin-ci jshint - moodle-plugin-ci validate + - moodle-plugin-ci savepoints + - moodle-plugin-ci mustache + - moodle-plugin-ci grunt -t stylelint:css -t js - moodle-plugin-ci phpunit - moodle-plugin-ci behat - diff --git a/verify_certificate.php b/verify_certificate.php index a3577cd12..4f245be37 100644 --- a/verify_certificate.php +++ b/verify_certificate.php @@ -22,6 +22,7 @@ * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later */ +// This file does not need require_login because capability to verify can be granted to guests, skip codechecker here. // @codingStandardsIgnoreLine require_once('../../config.php'); From 2cdbc60c7667f098e3be796f5d5d5e0b2acde614 Mon Sep 17 00:00:00 2001 From: Mark Nelson Date: Mon, 17 Dec 2018 09:50:44 +0800 Subject: [PATCH 66/93] Changed reference to moodlerooms (#250) --- .travis.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index 2aa0c4501..1086084d2 100644 --- a/.travis.yml +++ b/.travis.yml @@ -33,7 +33,7 @@ before_install: - nvm install 8.9 - nvm use 8.9 - cd ../.. - - composer create-project -n --no-dev --prefer-dist moodlerooms/moodle-plugin-ci ci ^2 + - composer create-project -n --no-dev --prefer-dist blackboard-open-source/moodle-plugin-ci ci ^2 - export PATH="$(cd ci/bin; pwd):$(cd ci/vendor/bin; pwd):$PATH" install: From e9ed3b28c7ec2caa1f72f5963be1fc9aedf6b320 Mon Sep 17 00:00:00 2001 From: Alexander Bias Date: Wed, 8 Aug 2018 13:45:20 +0200 Subject: [PATCH 67/93] #225 Allow element plugins to control if they can be added --- classes/element.php | 10 ++++++++++ classes/element_helper.php | 7 +++++-- 2 files changed, 15 insertions(+), 2 deletions(-) diff --git a/classes/element.php b/classes/element.php index 7acad0b1b..134414f5d 100644 --- a/classes/element.php +++ b/classes/element.php @@ -352,6 +352,16 @@ public function copy_element($data) { return true; } + /** + * This defines if an element plugin can be added to a certificate. + * Can be overridden if an element plugin wants to take over the control. + * + * @return bool returns true if the element can be added, false otherwise + */ + public static function allow_add() { + return true; + } + /** * Handles rendering the element on the pdf. * diff --git a/classes/element_helper.php b/classes/element_helper.php index e365c70bd..b9775bb34 100644 --- a/classes/element_helper.php +++ b/classes/element_helper.php @@ -412,8 +412,11 @@ public static function get_available_element_types() { $classname = '\\customcertelement_' . $foldername . '\\element'; // Ensure the necessary class exists. if (class_exists($classname)) { - $component = "customcertelement_{$foldername}"; - $options[$foldername] = get_string('pluginname', $component); + // Additionally, check if the user is allowed to add the element at all. + if ($classname::allow_add()) { + $component = "customcertelement_{$foldername}"; + $options[$foldername] = get_string('pluginname', $component); + } } } } From 17934659b6de6b76d47061e42df048a77508153e Mon Sep 17 00:00:00 2001 From: Mark Nelson Date: Thu, 23 Aug 2018 20:37:32 +0800 Subject: [PATCH 68/93] #225 Renamed static function --- classes/element.php | 2 +- classes/element_helper.php | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/classes/element.php b/classes/element.php index 134414f5d..00331a8d9 100644 --- a/classes/element.php +++ b/classes/element.php @@ -358,7 +358,7 @@ public function copy_element($data) { * * @return bool returns true if the element can be added, false otherwise */ - public static function allow_add() { + public static function can_add() { return true; } diff --git a/classes/element_helper.php b/classes/element_helper.php index b9775bb34..b5cb893da 100644 --- a/classes/element_helper.php +++ b/classes/element_helper.php @@ -413,7 +413,7 @@ public static function get_available_element_types() { // Ensure the necessary class exists. if (class_exists($classname)) { // Additionally, check if the user is allowed to add the element at all. - if ($classname::allow_add()) { + if ($classname::can_add()) { $component = "customcertelement_{$foldername}"; $options[$foldername] = get_string('pluginname', $component); } From c8ab936b34bd141df8553b4b1bba7f682a786117 Mon Sep 17 00:00:00 2001 From: Sara Arjona Date: Thu, 13 Dec 2018 13:34:32 +0100 Subject: [PATCH 69/93] #252 Privacy API update Add support to get_users_in_context and delete_data_for_users methods added since 3.4.6 and 3.5.3 and 3.6. --- classes/privacy/provider.php | 60 ++++++++++++++++++++ tests/privacy_provider_test.php | 97 +++++++++++++++++++++++++++++++++ 2 files changed, 157 insertions(+) diff --git a/classes/privacy/provider.php b/classes/privacy/provider.php index d2119a48b..b3024d306 100644 --- a/classes/privacy/provider.php +++ b/classes/privacy/provider.php @@ -25,9 +25,11 @@ use core_privacy\local\metadata\collection; use core_privacy\local\request\approved_contextlist; +use core_privacy\local\request\approved_userlist; use core_privacy\local\request\contextlist; use core_privacy\local\request\helper; use core_privacy\local\request\transform; +use core_privacy\local\request\userlist; use core_privacy\local\request\writer; defined('MOODLE_INTERNAL') || die(); @@ -96,6 +98,37 @@ public static function get_contexts_for_userid(int $userid) : contextlist { return $contextlist; } + /** + * Get the list of users who have data within a context. + * + * @param userlist $userlist The userlist containing the list of users who have data in this context/plugin combination. + */ + public static function get_users_in_context(userlist $userlist) { + $context = $userlist->get_context(); + + if (!$context instanceof \context_module) { + return; + } + + // Fetch all users who have a custom certificate. + $sql = "SELECT customcertissues.userid + FROM {course_modules} cm + JOIN {modules} m + ON m.id = cm.module AND m.name = :modname + JOIN {customcert} customcert + ON customcert.id = cm.instance + JOIN {customcert_issues} customcertissues + ON customcertissues.customcertid = customcert.id + WHERE cm.id = :cmid"; + + $params = [ + 'cmid' => $context->instanceid, + 'modname' => 'customcert', + ]; + + $userlist->add_from_sql('userid', $sql, $params); + } + /** * Export personal data for the given approved_contextlist. User and context information is contained within the contextlist. * @@ -182,6 +215,33 @@ public static function delete_data_for_user(approved_contextlist $contextlist) { } } + /** + * Delete multiple users within a single context. + * + * @param approved_userlist $userlist The approved context and user information to delete information for. + */ + public static function delete_data_for_users(approved_userlist $userlist) { + global $DB; + + $context = $userlist->get_context(); + if (!$context instanceof \context_module) { + return; + } + + $cm = get_coursemodule_from_id('customcert', $context->instanceid); + if (!$cm) { + // Only customcert module will be handled. + return; + } + + $userids = $userlist->get_userids(); + list($usersql, $userparams) = $DB->get_in_or_equal($userids, SQL_PARAMS_NAMED); + + $select = "customcertid = :customcertid AND userid $usersql"; + $params = ['customcertid' => $cm->instance] + $userparams; + $DB->delete_records_select('customcert_issues', $select, $params); + } + /** * Return a list of Customcert IDs mapped to their course module ID. * diff --git a/tests/privacy_provider_test.php b/tests/privacy_provider_test.php index 17e003270..bd9fe1aa1 100644 --- a/tests/privacy_provider_test.php +++ b/tests/privacy_provider_test.php @@ -64,6 +64,57 @@ public function test_get_contexts_for_userid() { $this->assertEquals($cmcontext->id, $contextformodule->id); } + /** + * Test for provider::get_users_in_context(). + */ + public function test_get_users_in_context() { + $this->resetAfterTest(); + + $course = $this->getDataGenerator()->create_course(); + + // The customcert activity the user will have an issue from. + $customcert1 = $this->getDataGenerator()->create_module('customcert', ['course' => $course->id]); + $customcert2 = $this->getDataGenerator()->create_module('customcert', ['course' => $course->id]); + + // Call get_users_in_context() when the customcert hasn't any user. + $cm = get_coursemodule_from_instance('customcert', $customcert1->id); + $cmcontext = context_module::instance($cm->id); + $userlist = new \core_privacy\local\request\userlist($cmcontext, 'mod_customcert'); + provider::get_users_in_context($userlist); + + // Check no user has been returned. + $this->assertCount(0, $userlist->get_userids()); + + // Create some users who will be issued a certificate. + $user1 = $this->getDataGenerator()->create_user(); + $user2 = $this->getDataGenerator()->create_user(); + $user3 = $this->getDataGenerator()->create_user(); + $this->create_certificate_issue($customcert1->id, $user1->id); + $this->create_certificate_issue($customcert1->id, $user2->id); + $this->create_certificate_issue($customcert2->id, $user3->id); + + // Call get_users_in_context() again. + provider::get_users_in_context($userlist); + + // Check this time there are 2 users. + $this->assertCount(2, $userlist->get_userids()); + $this->assertContains($user1->id, $userlist->get_userids()); + $this->assertContains($user2->id, $userlist->get_userids()); + $this->assertNotContains($user3->id, $userlist->get_userids()); + } + + /** + * Test for provider::get_users_in_context() with invalid context type. + */ + public function test_get_users_in_context_invalid_context_type() { + $systemcontext = context_system::instance(); + + $userlist = new \core_privacy\local\request\userlist($systemcontext, 'mod_customcert'); + \mod_customcert\privacy\provider::get_users_in_context($userlist); + + $this->assertCount(0, $userlist->get_userids()); + } + /** * Test for provider::export_user_data(). */ @@ -179,6 +230,52 @@ public function test_delete_data_for_user() { $this->assertEquals($user2->id, $lastissue->userid); } + /** + * Test for provider::delete_data_for_users(). + */ + public function test_delete_data_for_users() { + global $DB; + + $this->resetAfterTest(); + + // Create course, customcert and users who will be issued a certificate. + $course = $this->getDataGenerator()->create_course(); + $customcert1 = $this->getDataGenerator()->create_module('customcert', array('course' => $course->id)); + $customcert2 = $this->getDataGenerator()->create_module('customcert', array('course' => $course->id)); + $cm1 = get_coursemodule_from_instance('customcert', $customcert1->id); + $cm2 = get_coursemodule_from_instance('customcert', $customcert2->id); + $user1 = $this->getDataGenerator()->create_user(); + $user2 = $this->getDataGenerator()->create_user(); + $user3 = $this->getDataGenerator()->create_user(); + $this->create_certificate_issue($customcert1->id, $user1->id); + $this->create_certificate_issue($customcert1->id, $user2->id); + $this->create_certificate_issue($customcert1->id, $user3->id); + $this->create_certificate_issue($customcert2->id, $user1->id); + $this->create_certificate_issue($customcert2->id, $user2->id); + + // Before deletion we should have 3 + 2 issued certificates. + $count = $DB->count_records('customcert_issues', ['customcertid' => $customcert1->id]); + $this->assertEquals(3, $count); + $count = $DB->count_records('customcert_issues', ['customcertid' => $customcert2->id]); + $this->assertEquals(2, $count); + + $context1 = context_module::instance($cm1->id); + $approveduserlist = new \core_privacy\local\request\approved_userlist($context1, 'customcert', + [$user1->id, $user2->id]); + provider::delete_data_for_users($approveduserlist); + + // After deletion, the customcert of the 2 students provided above should have been deleted + // from the activity. So there should only remain 1 certificate which is for $user3. + $customcertissues1 = $DB->get_records('customcert_issues', ['customcertid' => $customcert1->id]); + $this->assertCount(1, $customcertissues1); + $lastissue = reset($customcertissues1); + $this->assertEquals($user3->id, $lastissue->userid); + + // Confirm that the certificates issues in the other activity are intact. + $customcertissues1 = $DB->get_records('customcert_issues', ['customcertid' => $customcert2->id]); + $this->assertCount(2, $customcertissues1); + } + /** * Mimicks the creation of a customcert issue. * From 1e30f4d05a55cf45288ed28b60dace39d9369b95 Mon Sep 17 00:00:00 2001 From: james-cnz <5689414+james-cnz@users.noreply.github.com> Date: Tue, 20 Nov 2018 15:19:31 +1300 Subject: [PATCH 70/93] Matched up prevent x description strings (#254) The description strings for the settings prevent copy, prevent print, and prevent modify were mixed up when added with: #180 Add possibility to set default values of activity instance --- lang/en/customcert.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/lang/en/customcert.php b/lang/en/customcert.php index c38ec9c08..70bfb6a06 100644 --- a/lang/en/customcert.php +++ b/lang/en/customcert.php @@ -135,11 +135,11 @@ $string['posy'] = 'Position Y'; $string['posy_help'] = 'This is the position in mm from the top left corner you wish the element\'s reference point to locate in the y direction.'; $string['preventcopy'] = 'Prevent copy'; -$string['preventcopy_desc'] = 'Enable protection from print action.'; +$string['preventcopy_desc'] = 'Enable protection from copy action.'; $string['preventprint'] = 'Prevent print'; -$string['preventprint_desc'] = 'Enable protection from modify action.'; +$string['preventprint_desc'] = 'Enable protection from print action.'; $string['preventmodify'] = 'Prevent modify'; -$string['preventmodify_desc'] = 'Enable protection from copy action.'; +$string['preventmodify_desc'] = 'Enable protection from modify action.'; $string['print'] = 'Print'; $string['privacy:metadata:customcert_issues'] = 'The list of issued certificates'; $string['privacy:metadata:customcert_issues:code'] = 'The code that belongs to the certificate'; From 93b00b27b415ab9dbd7bad36d708ca93f3a565df Mon Sep 17 00:00:00 2001 From: Aaron Parker Date: Fri, 24 Aug 2018 16:24:02 +0100 Subject: [PATCH 71/93] Added plaintext lang variants for email bodies and updated template (#230) --- classes/output/email_certificate.php | 2 ++ lang/en/customcert.php | 2 ++ templates/email_certificate_text.mustache | 6 +++--- 3 files changed, 7 insertions(+), 3 deletions(-) diff --git a/classes/output/email_certificate.php b/classes/output/email_certificate.php index c113f485b..3020caa1e 100644 --- a/classes/output/email_certificate.php +++ b/classes/output/email_certificate.php @@ -102,11 +102,13 @@ public function export_for_template(\renderer_base $renderer) { if ($this->isstudent) { $data->emailgreeting = get_string('emailstudentgreeting', 'customcert', $this->userfullname); $data->emailbody = get_string('emailstudentbody', 'customcert', $info); + $data->emailbodyplaintext = get_string('emailstudentbodyplaintext', 'customcert', $info); $data->emailcertificatelink = new \moodle_url('/mod/customcert/view.php', array('id' => $this->cmid)); $data->emailcertificatetext = get_string('emailstudentcertificatelinktext', 'customcert'); } else { $data->emailgreeting = get_string('emailnonstudentgreeting', 'customcert'); $data->emailbody = get_string('emailnonstudentbody', 'customcert', $info); + $data->emailbodyplaintext = get_string('emailnonstudentbodyplaintext', 'customcert', $info); $data->emailcertificatelink = new \moodle_url('/mod/customcert/view.php', array('id' => $this->cmid)); $data->emailcertificatetext = get_string('emailnonstudentcertificatelinktext', 'customcert'); } diff --git a/lang/en/customcert.php b/lang/en/customcert.php index 70bfb6a06..f705c9545 100644 --- a/lang/en/customcert.php +++ b/lang/en/customcert.php @@ -72,10 +72,12 @@ $string['elementwidth'] = 'Width'; $string['elementwidth_help'] = 'Specify the width of the element - \'0\' means that there is no width constraint.'; $string['emailnonstudentbody'] = 'Attached is the certificate \'{$a->certificatename}\' for \'{$a->userfullname}\' for the course \'{$a->coursefullname}\'.'; +$string['emailnonstudentbodyplaintext'] = '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->coursefullname}: {$a->certificatename}'; $string['emailstudentbody'] = 'Attached is your certificate \'{$a->certificatename}\' for the course \'{$a->coursefullname}\'.'; +$string['emailstudentbodyplaintext'] = 'Attached is your certificate \'{$a->certificatename}\' for the course \'{$a->coursefullname}\'.'; $string['emailstudentcertificatelinktext'] = 'View certificate'; $string['emailstudentgreeting'] = 'Dear {$a}'; $string['emailstudentsubject'] = '{$a->coursefullname}: {$a->certificatename}'; diff --git a/templates/email_certificate_text.mustache b/templates/email_certificate_text.mustache index efcb9aefa..4a5876054 100644 --- a/templates/email_certificate_text.mustache +++ b/templates/email_certificate_text.mustache @@ -27,18 +27,18 @@ Context variables required for this template: * emailgreeting - * emailbody + * emailbodyplaintext * emailcertificatelink * emailcertificatelinktext Example context (json): { "emailgreeting": "Dear Angus MacGyver", - "emailbody": "Attached is your certificate 'The basics' for the course 'Survival as an '80s action hero'", + "emailbodyplaintext": "Attached is your certificate 'The basics' for the course 'Survival as an '80s action hero'", "emailcertificatelink": "http://yoursite.com/mod/customcert/view.php?id=4", "emailcertificatelinktext": "Certificate report" } }} {{{emailgreeting}}} -{{{emailbody}}} +{{{emailbodyplaintext}}} From 30f80d70f7e87e45e7125690e9bf73aa84c5c2e0 Mon Sep 17 00:00:00 2001 From: Mark Nelson Date: Mon, 17 Dec 2018 12:36:37 +0800 Subject: [PATCH 72/93] Change field 'element' to character rather than text (#241) --- db/install.xml | 2 +- db/upgrade.php | 11 +++++++++++ version.php | 2 +- 3 files changed, 13 insertions(+), 2 deletions(-) diff --git a/db/install.xml b/db/install.xml index 1fbf10912..1e2a78921 100644 --- a/db/install.xml +++ b/db/install.xml @@ -75,7 +75,7 @@ - + diff --git a/db/upgrade.php b/db/upgrade.php index a666e9326..cd2721e46 100644 --- a/db/upgrade.php +++ b/db/upgrade.php @@ -135,5 +135,16 @@ function xmldb_customcert_upgrade($oldversion) { upgrade_mod_savepoint(true, 2017050506, 'customcert'); } + if ($oldversion < 2017111306) { + $table = new xmldb_table('customcert_elements'); + $field = new xmldb_field('element', XMLDB_TYPE_CHAR, '255', null, XMLDB_NOTNULL, null, null, 'name'); + + // Alter the 'element' column to be characters, rather than text. + $dbman->change_field_type($table, $field); + + // Savepoint reached. + upgrade_mod_savepoint(true, 2017111306, 'customcert'); + } + return true; } diff --git a/version.php b/version.php index 39b892046..26350c150 100644 --- a/version.php +++ b/version.php @@ -24,7 +24,7 @@ defined('MOODLE_INTERNAL') || die('Direct access to this script is forbidden.'); -$plugin->version = 2017111305; // The current module version (Date: YYYYMMDDXX). +$plugin->version = 2017111306; // The current module version (Date: YYYYMMDDXX). $plugin->requires = 2017111300; // Requires this Moodle version (3.4). $plugin->cron = 0; // Period for cron to check this module (secs). $plugin->component = 'mod_customcert'; From 149e3cfc6cdfd47055b5d1d09efb679ee32821da Mon Sep 17 00:00:00 2001 From: mwithheld Date: Fri, 5 Oct 2018 14:31:37 -0700 Subject: [PATCH 73/93] Reduce code nesting level in task (#237) Make the code easier to read and understand --- classes/task/email_certificate_task.php | 282 ++++++++++++------------ 1 file changed, 143 insertions(+), 139 deletions(-) diff --git a/classes/task/email_certificate_task.php b/classes/task/email_certificate_task.php index b150ca986..40330264c 100644 --- a/classes/task/email_certificate_task.php +++ b/classes/task/email_certificate_task.php @@ -61,169 +61,173 @@ public function execute() { WHERE (c.emailstudents = :emailstudents OR c.emailteachers = :emailteachers OR $emailotherslengthsql >= 3)"; - if ($customcerts = $DB->get_records_sql($sql, array('emailstudents' => 1, 'emailteachers' => 1))) { - // The renderers used for sending emails. - $htmlrenderer = $PAGE->get_renderer('mod_customcert', 'email', 'htmlemail'); - $textrenderer = $PAGE->get_renderer('mod_customcert', 'email', 'textemail'); - foreach ($customcerts as $customcert) { - // Get the context. - $context = \context::instance_by_id($customcert->contextid); - - // Get the person we are going to send this email on behalf of. - // Look through the teachers. - if ($teachers = get_enrolled_users($context, 'moodle/course:update')) { - $teachers = sort_by_roleassignment_authority($teachers, $context); - $userfrom = reset($teachers); - } else { // Ok, no teachers, use administrator name. - $userfrom = get_admin(); + if (!$customcerts = $DB->get_records_sql($sql, array('emailstudents' => 1, 'emailteachers' => 1))) { + return false; + } + + // The renderers used for sending emails. + $htmlrenderer = $PAGE->get_renderer('mod_customcert', 'email', 'htmlemail'); + $textrenderer = $PAGE->get_renderer('mod_customcert', 'email', 'textemail'); + foreach ($customcerts as $customcert) { + // Get the context. + $context = \context::instance_by_id($customcert->contextid); + + // Get the person we are going to send this email on behalf of. + // Look through the teachers. + if ($teachers = get_enrolled_users($context, 'moodle/course:update')) { + $teachers = sort_by_roleassignment_authority($teachers, $context); + $userfrom = reset($teachers); + } else { // Ok, no teachers, use administrator name. + $userfrom = get_admin(); + } + + $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 = $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 all the issues. + $userfields = get_all_user_name_fields(true, 'u'); + $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"; + $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'); + foreach ($enrolledusers as $enroluser) { + // Check if the user has already been issued. + if (in_array($enroluser->id, array_keys((array) $issuedusers))) { + continue; } - $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 = $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 all the issues. - $userfields = get_all_user_name_fields(true, 'u'); - $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"; - $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'); - foreach ($enrolledusers as $enroluser) { - // Check if the user has already been issued. - if (in_array($enroluser->id, array_keys((array) $issuedusers))) { - continue; - } + // Now check if the certificate is not visible to the current user. + $cm = get_fast_modinfo($customcert->courseid, $enroluser->id)->instances['customcert'][$customcert->id]; + if (!$cm->uservisible) { + continue; + } - // Now check if the certificate is not visible to the current user. - $cm = get_fast_modinfo($customcert->courseid, $enroluser->id)->instances['customcert'][$customcert->id]; - if (!$cm->uservisible) { - continue; - } + // Don't want to email those with the capability to manage the certificate. + if (has_capability('mod/customcert:manage', $context, $enroluser->id)) { + continue; + } - // Don't want to email those with the capability to manage the certificate. - if (has_capability('mod/customcert:manage', $context, $enroluser->id)) { + // Check that they have passed the required time. + if (!empty($customcert->requiredtime)) { + if (\mod_customcert\certificate::get_course_time($customcert->courseid, + $enroluser->id) < ($customcert->requiredtime * 60)) { continue; } + } - // Check that they have passed the required time. - if (!empty($customcert->requiredtime)) { - if (\mod_customcert\certificate::get_course_time($customcert->courseid, - $enroluser->id) < ($customcert->requiredtime * 60)) { - continue; - } - } + // 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); + } - // 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; + } - // 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]); } + } - // 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) { + continue; + } + + foreach ($issuedusers as $user) { + $userfullname = fullname($user); + + // Create a directory to store the PDF we will be sending. + $tempdir = make_temp_directory('certificate/attachment'); + if (!$tempdir) { + return false; } - // Now, email the people we need to. - if ($issuedusers) { - foreach ($issuedusers as $user) { - $userfullname = fullname($user); + // Now, get the PDF. + $template = new \stdClass(); + $template->id = $customcert->templateid; + $template->name = $customcert->templatename; + $template->contextid = $customcert->contextid; + $template = new \mod_customcert\template($template); + $filecontents = $template->generate_pdf(false, $user->id, true); + + // Set the name of the file we are going to send. + $filename = $courseshortname . '_' . $certificatename; + $filename = \core_text::entities_to_utf8($filename); + $filename = strip_tags($filename); + $filename = rtrim($filename, '.'); + $filename = str_replace('&', '_', $filename) . '.pdf'; + + // Create the file we will be sending. + $tempfile = $tempdir . '/' . md5(microtime() . $user->id) . '.pdf'; + file_put_contents($tempfile, $filecontents); + + if ($customcert->emailstudents) { + $renderable = new \mod_customcert\output\email_certificate(true, $userfullname, $courseshortname, + $coursefullname, $certificatename, $customcert->contextid); + + $subject = get_string('emailstudentsubject', 'customcert', $info); + $message = $textrenderer->render($renderable); + $messagehtml = $htmlrenderer->render($renderable); + email_to_user($user, fullname($userfrom), $subject, $message, $messagehtml, $tempfile, $filename); + } - // Create a directory to store the PDF we will be sending. - $tempdir = make_temp_directory('certificate/attachment'); - if (!$tempdir) { - return false; - } + if ($customcert->emailteachers) { + $renderable = new \mod_customcert\output\email_certificate(false, $userfullname, $courseshortname, + $coursefullname, $certificatename, $customcert->contextid); - // Now, get the PDF. - $template = new \stdClass(); - $template->id = $customcert->templateid; - $template->name = $customcert->templatename; - $template->contextid = $customcert->contextid; - $template = new \mod_customcert\template($template); - $filecontents = $template->generate_pdf(false, $user->id, true); - - // Set the name of the file we are going to send. - $filename = $courseshortname . '_' . $certificatename; - $filename = \core_text::entities_to_utf8($filename); - $filename = strip_tags($filename); - $filename = rtrim($filename, '.'); - $filename = str_replace('&', '_', $filename) . '.pdf'; - - // Create the file we will be sending. - $tempfile = $tempdir . '/' . md5(microtime() . $user->id) . '.pdf'; - file_put_contents($tempfile, $filecontents); - - if ($customcert->emailstudents) { - $renderable = new \mod_customcert\output\email_certificate(true, $userfullname, $courseshortname, - $coursefullname, $certificatename, $customcert->contextid); - - $subject = get_string('emailstudentsubject', 'customcert', $info); - $message = $textrenderer->render($renderable); - $messagehtml = $htmlrenderer->render($renderable); - email_to_user($user, fullname($userfrom), $subject, $message, $messagehtml, $tempfile, $filename); - } + $subject = get_string('emailnonstudentsubject', 'customcert', $info); + $message = $textrenderer->render($renderable); + $messagehtml = $htmlrenderer->render($renderable); + foreach ($teachers as $teacher) { + email_to_user($teacher, fullname($userfrom), $subject, $message, $messagehtml, $tempfile, + $filename); + } + } - if ($customcert->emailteachers) { - $renderable = new \mod_customcert\output\email_certificate(false, $userfullname, $courseshortname, - $coursefullname, $certificatename, $customcert->contextid); + if (!empty($customcert->emailothers)) { + $others = explode(',', $customcert->emailothers); + foreach ($others as $email) { + $email = trim($email); + if (validate_email($email)) { + $renderable = new \mod_customcert\output\email_certificate(false, $userfullname, + $courseshortname, $coursefullname, $certificatename, $customcert->contextid); $subject = get_string('emailnonstudentsubject', 'customcert', $info); $message = $textrenderer->render($renderable); $messagehtml = $htmlrenderer->render($renderable); - foreach ($teachers as $teacher) { - email_to_user($teacher, fullname($userfrom), $subject, $message, $messagehtml, $tempfile, - $filename); - } - } - if (!empty($customcert->emailothers)) { - $others = explode(',', $customcert->emailothers); - foreach ($others as $email) { - $email = trim($email); - if (validate_email($email)) { - $renderable = new \mod_customcert\output\email_certificate(false, $userfullname, - $courseshortname, $coursefullname, $certificatename, $customcert->contextid); - - $subject = get_string('emailnonstudentsubject', 'customcert', $info); - $message = $textrenderer->render($renderable); - $messagehtml = $htmlrenderer->render($renderable); - - $emailuser = new \stdClass(); - $emailuser->id = -1; - $emailuser->email = $email; - email_to_user($emailuser, fullname($userfrom), $subject, $message, $messagehtml, $tempfile, - $filename); - } - } + $emailuser = new \stdClass(); + $emailuser->id = -1; + $emailuser->email = $email; + email_to_user($emailuser, fullname($userfrom), $subject, $message, $messagehtml, $tempfile, + $filename); } - - // Set the field so that it is emailed. - $DB->set_field('customcert_issues', 'emailed', 1, array('id' => $user->issueid)); } } + + // Set the field so that it is emailed. + $DB->set_field('customcert_issues', 'emailed', 1, array('id' => $user->issueid)); } } } From 0771ec8a4b6240505931c6754b01357e4ee73a45 Mon Sep 17 00:00:00 2001 From: Mark Nelson Date: Mon, 17 Dec 2018 14:11:11 +0800 Subject: [PATCH 74/93] Removed boolean return and added a comment (#237) --- classes/task/email_certificate_task.php | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/classes/task/email_certificate_task.php b/classes/task/email_certificate_task.php index 40330264c..cf4ec777b 100644 --- a/classes/task/email_certificate_task.php +++ b/classes/task/email_certificate_task.php @@ -62,7 +62,7 @@ public function execute() { OR c.emailteachers = :emailteachers OR $emailotherslengthsql >= 3)"; if (!$customcerts = $DB->get_records_sql($sql, array('emailstudents' => 1, 'emailteachers' => 1))) { - return false; + return; } // The renderers used for sending emails. @@ -149,11 +149,12 @@ public function execute() { } } - // Now, email the people we need to. + // If there are no users to email we can return early. if (!$issuedusers) { continue; } + // Now, email the people we need to. foreach ($issuedusers as $user) { $userfullname = fullname($user); From 3bed3b83ae4d478786bba48d28514bb08981aec1 Mon Sep 17 00:00:00 2001 From: mwithheld Date: Mon, 17 Dec 2018 15:23:28 +0800 Subject: [PATCH 75/93] Move creating the temp directory out of the emailing for loop (#238) --- classes/task/email_certificate_task.php | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/classes/task/email_certificate_task.php b/classes/task/email_certificate_task.php index cf4ec777b..a7a6641f8 100644 --- a/classes/task/email_certificate_task.php +++ b/classes/task/email_certificate_task.php @@ -154,16 +154,16 @@ public function execute() { continue; } + // Create a directory to store the PDF we will be sending. + $tempdir = make_temp_directory('certificate/attachment'); + if (!$tempdir) { + return; + } + // Now, email the people we need to. foreach ($issuedusers as $user) { $userfullname = fullname($user); - // Create a directory to store the PDF we will be sending. - $tempdir = make_temp_directory('certificate/attachment'); - if (!$tempdir) { - return false; - } - // Now, get the PDF. $template = new \stdClass(); $template->id = $customcert->templateid; From d06da0993f815f296e2d291aa7ac19b6d5bea821 Mon Sep 17 00:00:00 2001 From: Mark Nelson Date: Mon, 17 Dec 2018 16:28:16 +0800 Subject: [PATCH 76/93] Hide completion date option if not applicable (#160) --- element/date/classes/element.php | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/element/date/classes/element.php b/element/date/classes/element.php index e03e655f7..c91662e2a 100644 --- a/element/date/classes/element.php +++ b/element/date/classes/element.php @@ -68,12 +68,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; + global $CFG, $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'); + $completionenabled = $CFG->enablecompletion && $COURSE->enablecompletion; + if ($completionenabled) { + $dateoptions[CUSTOMCERT_DATE_COMPLETION] = get_string('completiondate', 'customcertelement_date'); + } $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'); From d9576aac13c694a8a764430836096ab2cac4f183 Mon Sep 17 00:00:00 2001 From: Mark Nelson Date: Mon, 17 Dec 2018 16:41:21 +0800 Subject: [PATCH 77/93] Fixed logic so site templates work as expected (#160) --- element/date/classes/element.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/element/date/classes/element.php b/element/date/classes/element.php index c91662e2a..dcf6a6fb2 100644 --- a/element/date/classes/element.php +++ b/element/date/classes/element.php @@ -73,7 +73,7 @@ public function render_form_elements($mform) { // Get the possible date options. $dateoptions = array(); $dateoptions[CUSTOMCERT_DATE_ISSUE] = get_string('issueddate', 'customcertelement_date'); - $completionenabled = $CFG->enablecompletion && $COURSE->enablecompletion; + $completionenabled = $CFG->enablecompletion && ($COURSE->id == SITEID || $COURSE->enablecompletion); if ($completionenabled) { $dateoptions[CUSTOMCERT_DATE_COMPLETION] = get_string('completiondate', 'customcertelement_date'); } From 1d27bece758b1506748095d19bb2bca57a817120 Mon Sep 17 00:00:00 2001 From: Mark Nelson Date: Tue, 18 Dec 2018 09:43:43 +0800 Subject: [PATCH 78/93] Report now respects the setting 'Show user identity' (#224) --- classes/certificate.php | 3 ++- classes/report_table.php | 26 +++++++++++++++++--------- 2 files changed, 19 insertions(+), 10 deletions(-) diff --git a/classes/certificate.php b/classes/certificate.php index 01e2b8685..0dd842eed 100644 --- a/classes/certificate.php +++ b/classes/certificate.php @@ -260,7 +260,8 @@ public static function get_issues($customcertid, $groupmode, $cm, $limitfrom, $l $allparams = $conditionsparams + array('customcertid' => $customcertid); // Return the issues. - $ufields = \user_picture::fields('u'); + $extrafields = get_extra_user_fields(\context_module::instance($cm->id)); + $ufields = \user_picture::fields('u', $extrafields); $sql = "SELECT $ufields, ci.id as issueid, ci.code, ci.timecreated FROM {user} u INNER JOIN {customcert_issues} ci diff --git a/classes/report_table.php b/classes/report_table.php index 978a6fe50..a1db6bb10 100644 --- a/classes/report_table.php +++ b/classes/report_table.php @@ -65,14 +65,22 @@ class report_table extends \table_sql { public function __construct($customcertid, $cm, $groupmode, $download = null) { parent::__construct('mod_customcert_report_table'); - $columns = array( - 'fullname', - 'timecreated' - ); - $headers = array( - get_string('fullname'), - get_string('receiveddate', 'customcert') - ); + $context = \context_module::instance($cm->id); + $extrafields = get_extra_user_fields($context); + + $columns = []; + $columns[] = 'fullname'; + foreach ($extrafields as $extrafield) { + $columns[] = $extrafield; + } + $columns[] = 'timecreated'; + + $headers = []; + $headers[] = get_string('fullname'); + foreach ($extrafields as $extrafield) { + $headers[] = get_user_field_name($extrafield); + } + $headers[] = get_string('receiveddate', 'customcert'); // Check if we were passed a filename, which means we want to download it. if ($download) { @@ -84,7 +92,7 @@ public function __construct($customcertid, $cm, $groupmode, $download = null) { $headers[] = get_string('file'); } - if (!$this->is_downloading() && has_capability('mod/customcert:manage', \context_module::instance($cm->id))) { + if (!$this->is_downloading() && has_capability('mod/customcert:manage', $context)) { $columns[] = 'actions'; $headers[] = ''; } From 83f3fce127641c3c64e6d3cbba846f7b6762de2c Mon Sep 17 00:00:00 2001 From: Mark Nelson Date: Tue, 18 Dec 2018 11:25:25 +0800 Subject: [PATCH 79/93] Allow verification of deleted users (#159) --- verify_certificate.php | 2 -- 1 file changed, 2 deletions(-) diff --git a/verify_certificate.php b/verify_certificate.php index 4f245be37..6f4b4269e 100644 --- a/verify_certificate.php +++ b/verify_certificate.php @@ -116,8 +116,6 @@ $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, $params)) { $result->success = true; From 74a8a2f06c2bce653460a86ef7f15ef4c5e22b18 Mon Sep 17 00:00:00 2001 From: Mark Nelson Date: Wed, 19 Dec 2018 11:44:30 +0800 Subject: [PATCH 80/93] Make use of the decimal value setting We should use this instead of our own logic. --- classes/element_helper.php | 24 +++--------------------- element/grade/classes/element.php | 16 ++-------------- tests/element_helper_test.php | 19 ++++++++++++++++--- 3 files changed, 21 insertions(+), 38 deletions(-) diff --git a/classes/element_helper.php b/classes/element_helper.php index b5cb893da..8788c7358 100644 --- a/classes/element_helper.php +++ b/classes/element_helper.php @@ -513,18 +513,12 @@ public static function get_course_grade_info($courseid, $gradeformat, $userid) { 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_format_gradevalue($grade->finalgrade, $courseitem, true, $gradeformat), $grade->get_dategraded() ); } @@ -554,12 +548,6 @@ public static function get_mod_grade_info($cmid, $gradeformat, $userid) { 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; @@ -578,7 +566,7 @@ public static function get_mod_grade_info($cmid, $gradeformat, $userid) { return new grade_information( $item->name, $objgrade->grade, - grade_format_gradevalue($objgrade->grade, $item, true, $gradeformat, $decimals), + grade_format_gradevalue($objgrade->grade, $item, true, $gradeformat), $dategraded ); } @@ -596,18 +584,12 @@ public static function get_grade_item_info($gradeitemid, $gradeformat, $userid) 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_format_gradevalue($grade->finalgrade, $gradeitem, true, $gradeformat), $grade->get_dategraded() ); } diff --git a/element/grade/classes/element.php b/element/grade/classes/element.php index e10a6fd33..0c454ea36 100644 --- a/element/grade/classes/element.php +++ b/element/grade/classes/element.php @@ -106,14 +106,8 @@ public function render($pdf, $preview, $user) { // If we are previewing this certificate then just show a demonstration grade. if ($preview) { - // 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); + $grade = grade_format_gradevalue('100', $courseitem, true, $gradeinfo->gradeformat); } else { if ($gradeitem == CUSTOMCERT_GRADE_COURSE) { $grade = \mod_customcert\element_helper::get_course_grade_info( @@ -165,13 +159,7 @@ public function render_html() { $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); + $grade = grade_format_gradevalue('100', $courseitem, true, $gradeinfo->gradeformat); return \mod_customcert\element_helper::render_html_content($this, $grade); } diff --git a/tests/element_helper_test.php b/tests/element_helper_test.php index 5a8065524..1521cf0b2 100644 --- a/tests/element_helper_test.php +++ b/tests/element_helper_test.php @@ -136,6 +136,11 @@ public function test_get_grade_items() { * Test we return the correct grade information for an activity. */ public function test_get_mod_grade_info() { + global $CFG; + + // Set that we want 3 decimals to display. + $CFG->grade_decimalpoints = 3; + // Create a course. $course = $this->getDataGenerator()->create_course(); @@ -181,7 +186,7 @@ public function test_get_mod_grade_info() { $this->assertEquals($assign->name, $grade->get_name()); $this->assertEquals('50.00000', $grade->get_grade()); - $this->assertEquals('50 %', $grade->get_displaygrade()); + $this->assertEquals('50.000 %', $grade->get_displaygrade()); $this->assertEquals($time, $grade->get_dategraded()); // Check that the user we did not grade has no grade. @@ -205,6 +210,9 @@ public function test_get_course_grade_info() { // Including to use constant. require_once($CFG->dirroot . '/mod/customcert/element/grade/classes/element.php'); + // Set that we want 3 decimals to display. + $CFG->grade_decimalpoints = 3; + // Create a course. $course = $this->getDataGenerator()->create_course(); @@ -241,7 +249,7 @@ public function test_get_course_grade_info() { $this->assertEquals(get_string('coursetotal', 'grades'), $grade->get_name()); $this->assertEquals('50.00000', $grade->get_grade()); - $this->assertEquals('50 %', $grade->get_displaygrade()); + $this->assertEquals('50.000 %', $grade->get_displaygrade()); $this->assertEquals($time, $grade->get_dategraded()); // Check that the user we did not grade has no grade. @@ -260,6 +268,11 @@ public function test_get_course_grade_info() { * Test we return the correct grade information for a grade item. */ public function test_get_grade_item_info() { + global $CFG; + + // Set that we want 3 decimals to display. + $CFG->grade_decimalpoints = 3; + // Create a course. $course = $this->getDataGenerator()->create_course(); @@ -298,7 +311,7 @@ public function test_get_grade_item_info() { $this->assertEquals('Grade item yo', $grade->get_name()); $this->assertEquals('50.00000', $grade->get_grade()); - $this->assertEquals('50 %', $grade->get_displaygrade()); + $this->assertEquals('50.000 %', $grade->get_displaygrade()); $this->assertEquals($time, $grade->get_dategraded()); // Check that the user we did not grade has no grade. From 6f7ad60f09b9d5f667c6ce566314c16a88913f0d Mon Sep 17 00:00:00 2001 From: Mark Nelson Date: Wed, 19 Dec 2018 12:08:27 +0800 Subject: [PATCH 81/93] Fixed issue when scales are used (#242) The grade item's type was being hard-coded to GRADE_TYPE_VALUE when this isn't always the case. --- classes/element_helper.php | 39 +++++++++++++++++++++++++------------- 1 file changed, 26 insertions(+), 13 deletions(-) diff --git a/classes/element_helper.php b/classes/element_helper.php index 8788c7358..1113aab61 100644 --- a/classes/element_helper.php +++ b/classes/element_helper.php @@ -542,31 +542,44 @@ public static function get_mod_grade_info($cmid, $gradeformat, $userid) { return false; } - $gradeitem = grade_get_grades($cm->course, 'mod', $module->name, $cm->instance, $userid); + $params = [ + 'itemtype' => 'mod', + 'itemmodule' => $module->name, + 'iteminstance' => $cm->instance, + 'courseid' => $cm->course, + 'itemnumber' => 0 + ]; + $gradeitem = \grade_item::fetch($params); if (empty($gradeitem)) { return false; } - $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 = grade_get_grades( + $cm->course, + 'mod', + $module->name, + $cm->instance, + $userid + ); + + if (!isset($grade->items[0]->grades[$userid])) { + return false; } - $objgrade = $item->grades[$userid]; + $gradebookgrade = $grade->items[0]->grades[$userid]; $dategraded = null; - if (!empty($objgrade->dategraded)) { - $dategraded = $objgrade->dategraded; + if (!empty($gradebookgrade->dategraded)) { + $dategraded = $gradebookgrade->dategraded; } + $displaygrade = grade_format_gradevalue($gradebookgrade->grade, $gradeitem, true, $gradeformat); + return new grade_information( - $item->name, - $objgrade->grade, - grade_format_gradevalue($objgrade->grade, $item, true, $gradeformat), + $gradeitem->get_name(), + $gradebookgrade->grade, + $displaygrade, $dategraded ); } From cddc2c4b4160e8f16fca0171b1b07c2a179acc29 Mon Sep 17 00:00:00 2001 From: Mark Nelson Date: Thu, 20 Dec 2018 09:14:28 +0800 Subject: [PATCH 82/93] Add ability to set transparency on images (#186) --- element/image/classes/element.php | 37 ++++++++++++++++++- .../image/lang/en/customcertelement_image.php | 2 + tests/behat/managing_elements.feature | 10 +++-- 3 files changed, 44 insertions(+), 5 deletions(-) diff --git a/element/image/classes/element.php b/element/image/classes/element.php index 8261bb884..7708dd705 100644 --- a/element/image/classes/element.php +++ b/element/image/classes/element.php @@ -75,6 +75,24 @@ public function render_form_elements($mform) { $mform->setDefault('height', 0); $mform->addHelpButton('height', 'height', 'customcertelement_image'); + $alphachannelvalues = [ + '0' => 0, + '0.1' => 0.1, + '0.2' => 0.2, + '0.3' => 0.3, + '0.4' => 0.4, + '0.5' => 0.5, + '0.6' => 0.6, + '0.7' => 0.7, + '0.8' => 0.8, + '0.9' => 0.9, + '1' => 1 + ]; + $mform->addElement('select', 'alphachannel', get_string('alphachannel', 'customcertelement_image'), $alphachannelvalues); + $mform->setType('alphachannel', PARAM_FLOAT); + $mform->setDefault('alphachannel', 1); + $mform->addHelpButton('alphachannel', 'alphachannel', 'customcertelement_image'); + if (get_config('customcert', 'showposxy')) { \mod_customcert\element_helper::render_form_element_position($mform); } @@ -148,6 +166,10 @@ public function save_unique_data($data) { 'height' => !empty($data->height) ? (int) $data->height : 0 ]; + if (isset($data->alphachannel)) { + $arrtostore['alphachannel'] = (float) $data->alphachannel; + } + if (!empty($data->fileid)) { // Array of data we will be storing in the database. $fs = get_file_storage(); @@ -189,12 +211,20 @@ public function render($pdf, $preview, $user) { $location = make_request_directory() . '/target'; $file->copy_content_to($location); + // Check if the alpha channel is set, if it is, use it. + if (isset($imageinfo->alphachannel)) { + $pdf->SetAlpha($imageinfo->alphachannel); + } + $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); } + + // Restore to full opacity. + $pdf->SetAlpha(1); } } @@ -257,7 +287,7 @@ public function render_html() { public function definition_after_data($mform) { global $COURSE, $SITE; - // Set the image, width and height for this element. + // Set the image, width, height and alpha channel for this element. if (!empty($this->get_data())) { $imageinfo = json_decode($this->get_data()); if (!empty($imageinfo->filename)) { @@ -276,6 +306,11 @@ public function definition_after_data($mform) { $element = $mform->getElement('height'); $element->setValue($imageinfo->height); } + + if (isset($imageinfo->alphachannel) && $mform->elementExists('alphachannel')) { + $element = $mform->getElement('alphachannel'); + $element->setValue($imageinfo->alphachannel); + } } // Set the context. diff --git a/element/image/lang/en/customcertelement_image.php b/element/image/lang/en/customcertelement_image.php index 1422b6b9e..ba3ab252f 100644 --- a/element/image/lang/en/customcertelement_image.php +++ b/element/image/lang/en/customcertelement_image.php @@ -22,6 +22,8 @@ * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later */ +$string['alphachannel'] = 'Alpha channel'; +$string['alphachannel_help'] = 'This value determines how transparent the image is. You can set the alpha channel from 0 (fully transparent) to 1 (fully opaque).'; $string['height'] = 'Height'; $string['height_help'] = 'Height of the image in mm. If equal to zero, it is automatically calculated.'; $string['image'] = 'Image'; diff --git a/tests/behat/managing_elements.feature b/tests/behat/managing_elements.feature index f2fe4b8e2..ccc441b91 100644 --- a/tests/behat/managing_elements.feature +++ b/tests/behat/managing_elements.feature @@ -186,14 +186,16 @@ Feature: Being able to manage elements in a certificate template # 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 | + | Width | 25 | + | Height | 15 | + | Alpha channel | 0.7 | 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 | + | Width | 25 | + | Height | 15 | + | Alpha channel | 0.7 | And I press "Save changes" # Student name. And I add the element "Student name" to page "1" of the "Custom certificate 1" certificate template From af3121f19cd109879ac25375cb48a94dea6c607a Mon Sep 17 00:00:00 2001 From: Mark Nelson Date: Thu, 20 Dec 2018 11:20:06 +0800 Subject: [PATCH 83/93] Updated CHANGES.md --- CHANGES.md | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/CHANGES.md b/CHANGES.md index 0e51ff419..e2d5f70ad 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -4,6 +4,29 @@ 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.4.6] - 2018-12-20 +### Added + +- GDPR: Add support for removal of users from a context (see MDL-62560) (#252). +- Images can be made transparent (#186). +- Set default values of activity instance settings (#180). +- Allow element plugins to control if they can be added to a certificate (#225). +- Allow element plugins to have their own admin settings (#213). +- Added plaintext language variants for email bodies (#231). +- Added possibility to selectively disable activity instance settings (#179). + +### Changed + +- Allow verification of deleted users (#159). +- The 'element' field in the 'customcert_elements' table has been changed from a Text field to varchar(255) (#241). +- The 'Completion date' option in the 'date' element is only displayed when completion is enabled (#160). + +### Fixed + +- Issue with scales not displaying correctly (#242). +- The report now respects the setting 'Show user identity' (#224). +- Removed incorrect course reset logic (#223). + ## [3.4.5] - 2018-07-13 ### Fixed From 9f9ce2a380104d430f4f98cfe097ec9b2d3a7014 Mon Sep 17 00:00:00 2001 From: Mark Nelson Date: Mon, 24 Dec 2018 15:23:01 +0800 Subject: [PATCH 84/93] Bumped version --- version.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/version.php b/version.php index 26350c150..0156ff42c 100644 --- a/version.php +++ b/version.php @@ -24,10 +24,10 @@ defined('MOODLE_INTERNAL') || die('Direct access to this script is forbidden.'); -$plugin->version = 2017111306; // The current module version (Date: YYYYMMDDXX). +$plugin->version = 2017111307; // The current module version (Date: YYYYMMDDXX). $plugin->requires = 2017111300; // Requires this Moodle version (3.4). $plugin->cron = 0; // Period for cron to check this module (secs). $plugin->component = 'mod_customcert'; $plugin->maturity = MATURITY_STABLE; -$plugin->release = "3.4.5"; // User-friendly version number. +$plugin->release = "3.4.6"; // User-friendly version number. From 922389b77066ab6971cbd057c132d00f6ff5609c Mon Sep 17 00:00:00 2001 From: Mark Nelson Date: Wed, 26 Dec 2018 11:34:51 +0800 Subject: [PATCH 85/93] Added missing implementation for privacy provider (#260) --- classes/privacy/provider.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/classes/privacy/provider.php b/classes/privacy/provider.php index b3024d306..29bebc63c 100644 --- a/classes/privacy/provider.php +++ b/classes/privacy/provider.php @@ -42,7 +42,8 @@ */ class provider implements \core_privacy\local\metadata\provider, - \core_privacy\local\request\plugin\provider { + \core_privacy\local\request\plugin\provider, + \core_privacy\local\request\core_userlist_provider { /** * Return the fields which contain personal data. From c85d7e0edc002133839f6f4da7de1bf08014e5ed Mon Sep 17 00:00:00 2001 From: Mark Nelson Date: Thu, 27 Dec 2018 07:40:44 +0800 Subject: [PATCH 86/93] Added missing details to CHANGES.md --- CHANGES.md | 3 +++ 1 file changed, 3 insertions(+) diff --git a/CHANGES.md b/CHANGES.md index e2d5f70ad..8d8a7e206 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -20,12 +20,15 @@ Note - All hash comments refer to the issue number. Eg. #169 refers to https://g - Allow verification of deleted users (#159). - The 'element' field in the 'customcert_elements' table has been changed from a Text field to varchar(255) (#241). - The 'Completion date' option in the 'date' element is only displayed when completion is enabled (#160). +- Instead of assuming 2 decimal points for percentages, we now make use of the decimal value setting, which the + function `grade_format_gradevalue` does by default if no decimal value is passed. ### Fixed - Issue with scales not displaying correctly (#242). - The report now respects the setting 'Show user identity' (#224). - Removed incorrect course reset logic (#223). +- Description strings referring to the wrong setting (#254). ## [3.4.5] - 2018-07-13 ### Fixed From 61e18a647b73a857c9093d93582348c745918d62 Mon Sep 17 00:00:00 2001 From: Mark Nelson Date: Thu, 27 Dec 2018 09:05:45 +0800 Subject: [PATCH 87/93] Prevent exception when adding 'teachername' element to site template (#261) --- element/teachername/classes/element.php | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/element/teachername/classes/element.php b/element/teachername/classes/element.php index c35d474ad..1c18e3030 100644 --- a/element/teachername/classes/element.php +++ b/element/teachername/classes/element.php @@ -102,6 +102,11 @@ public function render_html() { protected function get_list_of_teachers() { global $PAGE; + // Return early if we are in a site template. + if ($PAGE->context->id == \context_system::instance()->id) { + return []; + } + // The list of teachers to return. $teachers = array(); From ff0652e3ac05e70c98664062b9a0d91eb0921881 Mon Sep 17 00:00:00 2001 From: Mark Nelson Date: Thu, 27 Dec 2018 12:15:57 +0800 Subject: [PATCH 88/93] Use course module context when calling format_string/text (#200) --- classes/element_helper.php | 21 ++++++ element/categoryname/classes/element.php | 18 +++-- element/coursename/classes/element.php | 22 +++--- element/gradeitemname/classes/element.php | 44 ++++++------ element/text/classes/element.php | 18 +++-- element/userfield/classes/element.php | 88 ++++++++++------------- tests/element_helper_test.php | 58 +++++++++++++++ 7 files changed, 172 insertions(+), 97 deletions(-) diff --git a/classes/element_helper.php b/classes/element_helper.php index 1113aab61..153dae0c2 100644 --- a/classes/element_helper.php +++ b/classes/element_helper.php @@ -383,6 +383,27 @@ public static function get_courseid($elementid) { } } + /** + * Helper function that returns the context for this element. + * + * @param int $elementid The element id + * @return \context The context + */ + public static function get_context(int $elementid) : \context { + global $DB; + + $sql = "SELECT ct.contextid + FROM {customcert_templates} ct + INNER JOIN {customcert_pages} cp + ON ct.id = cp.templateid + INNER JOIN {customcert_elements} ce + ON cp.id = ce.pageid + WHERE ce.id = :elementid"; + $contextid = $DB->get_field_sql($sql, array('elementid' => $elementid), MUST_EXIST); + + return \context::instance_by_id($contextid); + } + /** * Return the list of possible elements to add. * diff --git a/element/categoryname/classes/element.php b/element/categoryname/classes/element.php index 054a70bff..48d157820 100644 --- a/element/categoryname/classes/element.php +++ b/element/categoryname/classes/element.php @@ -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($this->get_id())); + \mod_customcert\element_helper::render_content($pdf, $this, $this->get_category_name()); } /** @@ -55,30 +55,28 @@ public function render($pdf, $preview, $user) { * @return string the html */ public function render_html() { - global $COURSE; - - $categoryname = format_string($COURSE->fullname, true, ['context' => \context_course::instance($COURSE->id)]); - return \mod_customcert\element_helper::render_html_content($this, $categoryname); + return \mod_customcert\element_helper::render_html_content($this, $this->get_category_name()); } /** * Helper function that returns the category name. * - * @param int $elementid * @return string */ - protected static function get_category_name($elementid) { + protected function get_category_name() : string { global $DB, $SITE; - $courseid = \mod_customcert\element_helper::get_courseid($elementid); + $courseid = \mod_customcert\element_helper::get_courseid($this->get_id()); $course = get_course($courseid); + $context = \mod_customcert\element_helper::get_context($this->get_id()); // Check that there is a course category available. if (!empty($course->category)) { $categoryname = $DB->get_field('course_categories', 'name', array('id' => $course->category), MUST_EXIST); - return format_string($categoryname, true, ['context' => \context_course::instance($courseid)]); } else { // Must be in a site template. - return format_string($SITE->fullname, true, ['context' => \context_system::instance()]); + $categoryname = $SITE->fullname; } + + return format_string($categoryname, true, ['context' => $context]); } } diff --git a/element/coursename/classes/element.php b/element/coursename/classes/element.php index 5b0f78dc2..87a1764f5 100644 --- a/element/coursename/classes/element.php +++ b/element/coursename/classes/element.php @@ -43,11 +43,7 @@ class element extends \mod_customcert\element { * @param \stdClass $user the user we are rendering this for */ public function render($pdf, $preview, $user) { - $courseid = \mod_customcert\element_helper::get_courseid($this->get_id()); - $course = get_course($courseid); - - $coursename = format_string($course->fullname, true, ['context' => \context_course::instance($courseid)]); - \mod_customcert\element_helper::render_content($pdf, $this, $coursename); + \mod_customcert\element_helper::render_content($pdf, $this, $this->get_course_name()); } /** @@ -59,9 +55,19 @@ public function render($pdf, $preview, $user) { * @return string the html */ public function render_html() { - global $COURSE; + return \mod_customcert\element_helper::render_html_content($this, $this->get_course_name()); + } + + /** + * Helper function that returns the category name. + * + * @return string + */ + protected function get_course_name() : string { + $courseid = \mod_customcert\element_helper::get_courseid($this->get_id()); + $course = get_course($courseid); + $context = \mod_customcert\element_helper::get_context($this->get_id()); - $coursename = format_string($COURSE->fullname, true, ['context' => \context_course::instance($COURSE->id)]); - return \mod_customcert\element_helper::render_html_content($this, $coursename); + return format_string($course->fullname, true, ['context' => $context]); } } diff --git a/element/gradeitemname/classes/element.php b/element/gradeitemname/classes/element.php index afa792c6e..401de904a 100644 --- a/element/gradeitemname/classes/element.php +++ b/element/gradeitemname/classes/element.php @@ -73,20 +73,9 @@ public function save_unique_data($data) { * @param \stdClass $user the user we are rendering this for */ public function render($pdf, $preview, $user) { - global $DB; - // Check that the grade item is not empty. if (!empty($this->get_data())) { - // Get the course module information. - $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. - $courseid = \mod_customcert\element_helper::get_courseid($this->get_data()); - $itemname = $DB->get_field($module->name, 'name', array('id' => $cm->instance), MUST_EXIST); - $itemname = format_string($itemname, true, ['context' => \context_course::instance($courseid)]); - - \mod_customcert\element_helper::render_content($pdf, $this, $itemname); + \mod_customcert\element_helper::render_content($pdf, $this, $this->get_grade_item_name()); } } @@ -99,20 +88,9 @@ public function render($pdf, $preview, $user) { * @return string the html */ public function render_html() { - global $DB; - // Check that the grade item is not empty. if (!empty($this->get_data())) { - // Get the course module information. - $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. - $courseid = \mod_customcert\element_helper::get_courseid($this->get_data()); - $itemname = $DB->get_field($module->name, 'name', array('id' => $cm->instance), MUST_EXIST); - $itemname = format_string($itemname, true, ['context' => \context_course::instance($courseid)]); - - return \mod_customcert\element_helper::render_html_content($this, $itemname); + return \mod_customcert\element_helper::render_html_content($this, $this->get_grade_item_name()); } return ''; @@ -130,4 +108,22 @@ public function definition_after_data($mform) { } parent::definition_after_data($mform); } + + /** + * Helper function that returns the category name. + * + * @return string + */ + protected function get_grade_item_name() : string { + global $DB; + + // Get the course module information. + $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. + $itemname = $DB->get_field($module->name, 'name', array('id' => $cm->instance), MUST_EXIST); + + return format_string($itemname, true, ['context' => \mod_customcert\element_helper::get_context($this->get_id())]); + } } diff --git a/element/text/classes/element.php b/element/text/classes/element.php index a2909df20..c2a4f1360 100644 --- a/element/text/classes/element.php +++ b/element/text/classes/element.php @@ -67,9 +67,7 @@ public function save_unique_data($data) { * @param \stdClass $user the user we are rendering this for */ public function render($pdf, $preview, $user) { - $courseid = \mod_customcert\element_helper::get_courseid($this->get_id()); - $text = format_text($this->get_data(), FORMAT_HTML, ['context' => \context_course::instance($courseid)]); - \mod_customcert\element_helper::render_content($pdf, $this, $text); + \mod_customcert\element_helper::render_content($pdf, $this, $this->get_text()); } /** @@ -81,9 +79,7 @@ public function render($pdf, $preview, $user) { * @return string the html */ public function render_html() { - $courseid = \mod_customcert\element_helper::get_courseid($this->get_id()); - $text = format_text($this->get_data(), FORMAT_HTML, ['context' => \context_course::instance($courseid)]); - return \mod_customcert\element_helper::render_html_content($this, $text); + return \mod_customcert\element_helper::render_html_content($this, $this->get_text()); } /** @@ -98,4 +94,14 @@ public function definition_after_data($mform) { } parent::definition_after_data($mform); } + + /** + * Helper function that returns the text. + * + * @return string + */ + protected function get_text() : string { + $context = \mod_customcert\element_helper::get_context($this->get_id()); + return format_text($this->get_data(), FORMAT_HTML, ['context' => $context]); + } } diff --git a/element/userfield/classes/element.php b/element/userfield/classes/element.php index ad9ceff57..84db94ac2 100644 --- a/element/userfield/classes/element.php +++ b/element/userfield/classes/element.php @@ -98,30 +98,7 @@ public function save_unique_data($data) { * @param \stdClass $user the user we are rendering this for */ public function render($pdf, $preview, $user) { - global $CFG, $DB; - - // The user field to display. - $field = $this->get_data(); - // The value to display on the PDF. - $value = ''; - if (is_number($field)) { // Must be a custom user profile field. - if ($field = $DB->get_record('user_info_field', array('id' => $field))) { - $file = $CFG->dirroot . '/user/profile/field/' . $field->datatype . '/field.class.php'; - if (file_exists($file)) { - require_once($CFG->dirroot . '/user/profile/lib.php'); - require_once($file); - $class = "profile_field_{$field->datatype}"; - $field = new $class($field->id, $user->id); - $value = $field->display_data(); - } - } - } else if (!empty($user->$field)) { // Field in the user table. - $value = $user->$field; - } - - $courseid = \mod_customcert\element_helper::get_courseid($this->get_id()); - $value = format_string($value, true, ['context' => \context_course::instance($courseid)]); - \mod_customcert\element_helper::render_content($pdf, $this, $value); + \mod_customcert\element_helper::render_content($pdf, $this, $this->get_user_field_value($user, $preview)); } /** @@ -131,12 +108,42 @@ public function render($pdf, $preview, $user) { * drag and drop interface to position it. */ public function render_html() { - global $CFG, $DB, $USER; + global $USER; + + return \mod_customcert\element_helper::render_html_content($this, $this->get_user_field_value($USER, true)); + } + + /** + * 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) { + if (!empty($this->get_data())) { + $element = $mform->getElement('userfield'); + $element->setValue($this->get_data()); + } + parent::definition_after_data($mform); + } + + /** + * Helper function that returns the text. + * + * @param \stdClass $user the user we are rendering this for + * @param bool $preview Is this a preview? + * @return string + */ + protected function get_user_field_value(\stdClass $user, bool $preview) : string { + global $CFG, $DB; // The user field to display. $field = $this->get_data(); // The value to display - we always want to show a value here so it can be repositioned. - $value = $field; + if ($preview) { + $value = $field; + } else { + $value = ''; + } if (is_number($field)) { // Must be a custom user profile field. if ($field = $DB->get_record('user_info_field', array('id' => $field))) { // Found the field name, let's update the value to display. @@ -146,32 +153,15 @@ public function render_html() { require_once($CFG->dirroot . '/user/profile/lib.php'); require_once($file); $class = "profile_field_{$field->datatype}"; - $field = new $class($field->id, $USER->id); - if ($fieldvalue = $field->display_data()) { - // Ok, found a value for the user, let's show that instead. - $value = $fieldvalue; - } + $field = new $class($field->id, $user->id); + $value = $field->display_data(); } } - } else if (!empty($USER->$field)) { // Field in the user table. - $value = $USER->$field; + } else if (!empty($user->$field)) { // Field in the user table. + $value = $user->$field; } - $courseid = \mod_customcert\element_helper::get_courseid($this->get_id()); - $value = format_string($value, true, ['context' => \context_course::instance($courseid)]); - return \mod_customcert\element_helper::render_html_content($this, $value); - } - - /** - * 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) { - if (!empty($this->get_data())) { - $element = $mform->getElement('userfield'); - $element->setValue($this->get_data()); - } - parent::definition_after_data($mform); + $context = \mod_customcert\element_helper::get_context($this->get_id()); + return format_string($value, true, ['context' => $context]); } } diff --git a/tests/element_helper_test.php b/tests/element_helper_test.php index 1521cf0b2..7ad365159 100644 --- a/tests/element_helper_test.php +++ b/tests/element_helper_test.php @@ -101,6 +101,64 @@ public function test_get_courseid_element_in_site_template() { $this->assertEquals($SITE->id, \mod_customcert\element_helper::get_courseid($element->id)); } + /** + * Tests we are returning the correct course module id for an element in a course customcert activity. + */ + public function test_get_context_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 module id is returned. + $this->assertEquals(context_module::instance($customcert->cmid), + \mod_customcert\element_helper::get_context($element->id)); + } + + /** + * Tests we are returning the correct course module id for an element in a site template. + */ + public function test_get_context_element_in_site_template() { + global $DB; + + // 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 module id is returned. + $this->assertEquals(context_system::instance(), \mod_customcert\element_helper::get_context($element->id)); + } + /** * Test we return the correct grade items in a course. */ From bb5bce94a0f2723441bdb7fde9f7aeff566a14c7 Mon Sep 17 00:00:00 2001 From: Mark Nelson Date: Mon, 31 Dec 2018 09:35:31 +0800 Subject: [PATCH 89/93] Make it clear what element values are just an example (#144) --- element/date/classes/element.php | 7 ++++++- element/grade/classes/element.php | 1 + lang/en/customcert.php | 2 ++ rearrange.php | 3 ++- 4 files changed, 11 insertions(+), 2 deletions(-) diff --git a/element/date/classes/element.php b/element/date/classes/element.php index dcf6a6fb2..30cab73b3 100644 --- a/element/date/classes/element.php +++ b/element/date/classes/element.php @@ -190,7 +190,12 @@ public function render($pdf, $preview, $user) { // Ensure that a date has been set. if (!empty($date)) { - \mod_customcert\element_helper::render_content($pdf, $this, $this->get_date_format_string($date, $dateformat)); + $date = $this->get_date_format_string($date, $dateformat); + // If we are previewing, we want to let the user know it's an example date so they don't get confused. + if ($preview) { + $date = get_string('exampledata', 'customcert', 'date') . ' ' . $date; + } + \mod_customcert\element_helper::render_content($pdf, $this, $date); } } diff --git a/element/grade/classes/element.php b/element/grade/classes/element.php index 0c454ea36..95bc64d8c 100644 --- a/element/grade/classes/element.php +++ b/element/grade/classes/element.php @@ -108,6 +108,7 @@ public function render($pdf, $preview, $user) { if ($preview) { $courseitem = \grade_item::fetch_course_item($courseid); $grade = grade_format_gradevalue('100', $courseitem, true, $gradeinfo->gradeformat); + $grade = get_string('exampledata', 'customcert', 'grade') . ' ' . $grade; } else { if ($gradeitem == CUSTOMCERT_GRADE_COURSE) { $grade = \mod_customcert\element_helper::get_course_grade_info( diff --git a/lang/en/customcert.php b/lang/en/customcert.php index f705c9545..917e159af 100644 --- a/lang/en/customcert.php +++ b/lang/en/customcert.php @@ -87,6 +87,8 @@ $string['emailteachers_help'] = 'If set this will email the teachers a copy of the certificate when it becomes available.'; $string['emailothers'] = 'Email others'; $string['emailothers_help'] = 'If set this will email the email addresses listed here (separated by a comma) with a copy of the certificate when it becomes available.'; +$string['exampledata'] = 'Example {$a}:'; +$string['exampledatawarning'] = 'Some of these values may just be an example to ensure positioning of the elements is possible.'; $string['font'] = 'Font'; $string['font_help'] = 'The font used when generating this element.'; $string['fontcolour'] = 'Colour'; diff --git a/rearrange.php b/rearrange.php index 78f40ade8..7483953c2 100644 --- a/rearrange.php +++ b/rearrange.php @@ -125,7 +125,8 @@ echo $OUTPUT->header(); echo $OUTPUT->heading($heading); -echo $OUTPUT->heading(get_string('rearrangeelementsheading', 'customcert'), 4); +echo $OUTPUT->heading(get_string('rearrangeelementsheading', 'customcert'), 3); +echo $OUTPUT->notification(get_string('exampledatawarning', 'customcert'), \core\output\notification::NOTIFY_WARNING); echo $html; $PAGE->requires->js_call_amd('mod_customcert/rearrange-area', 'init', array('#pdf')); echo $OUTPUT->footer(); From f28b698781b3e3e4710474fc6f15feadad8cb947 Mon Sep 17 00:00:00 2001 From: Mark Nelson Date: Mon, 31 Dec 2018 10:31:20 +0800 Subject: [PATCH 90/93] Updated CHANGES.md --- CHANGES.md | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/CHANGES.md b/CHANGES.md index 8d8a7e206..26e1171b9 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -4,6 +4,18 @@ 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.4.7] - 2018-12-31 + +### Changed + +- Make it clear what element values are just an example when previewing the PDF (#144). + +### Fixed + +- Missing implementation for privacy provider (#260). +- Use course module context when calling format_string/text (#200). +- Exception being thrown when adding the 'teachername' element to site template (#261). + ## [3.4.6] - 2018-12-20 ### Added From d451ed8f010817a215bc6978495014ed159c6a11 Mon Sep 17 00:00:00 2001 From: Mark Nelson Date: Mon, 31 Dec 2018 10:31:42 +0800 Subject: [PATCH 91/93] Bumped version --- version.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/version.php b/version.php index 0156ff42c..96099f8a8 100644 --- a/version.php +++ b/version.php @@ -24,10 +24,10 @@ defined('MOODLE_INTERNAL') || die('Direct access to this script is forbidden.'); -$plugin->version = 2017111307; // The current module version (Date: YYYYMMDDXX). +$plugin->version = 2017111308; // The current module version (Date: YYYYMMDDXX). $plugin->requires = 2017111300; // Requires this Moodle version (3.4). $plugin->cron = 0; // Period for cron to check this module (secs). $plugin->component = 'mod_customcert'; $plugin->maturity = MATURITY_STABLE; -$plugin->release = "3.4.6"; // User-friendly version number. +$plugin->release = "3.4.7"; // User-friendly version number. From cc0d7c343bbfd1faf24cea8ac20ab68a0ea0db30 Mon Sep 17 00:00:00 2001 From: Nicolas Roeser Date: Tue, 6 Nov 2018 14:53:06 +0100 Subject: [PATCH 92/93] Add vertical spacing after certificate download button MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Increase the vertical spacing after the single button for downloading user’s own certificate. This makes the page look better. --- view.php | 1 + 1 file changed, 1 insertion(+) diff --git a/view.php b/view.php index 4c1e01d67..0f94c9f4c 100644 --- a/view.php +++ b/view.php @@ -137,6 +137,7 @@ $linkname = get_string('getcustomcert', 'customcert'); $link = new moodle_url('/mod/customcert/view.php', array('id' => $cm->id, 'downloadown' => true)); $downloadbutton = new single_button($link, $linkname, 'post', true); + $downloadbutton->class .= ' m-b-1'; // Seems a bit hackish, ahem. $downloadbutton = $OUTPUT->render($downloadbutton); // Output all the page data. From 62615cd243b7b69f6cf628a2c089ccd732c31bfc Mon Sep 17 00:00:00 2001 From: Noemie Ariste Date: Fri, 4 Apr 2025 12:49:06 +1300 Subject: [PATCH 93/93] Update test classes for T19 compatibility --- tests/element_helper_test.php | 2 +- tests/email_certificate_task_test.php | 2 +- tests/external_test.php | 4 +++- 3 files changed, 5 insertions(+), 3 deletions(-) diff --git a/tests/element_helper_test.php b/tests/element_helper_test.php index 2fd56c667..adf493ac4 100644 --- a/tests/element_helper_test.php +++ b/tests/element_helper_test.php @@ -35,7 +35,7 @@ * @copyright 2017 Mark Nelson * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later */ -class mod_customcert_element_helper_testcase extends advanced_testcase { +class mod_customcert_element_helper_test extends \core_phpunit\testcase { /** * Test set up. diff --git a/tests/email_certificate_task_test.php b/tests/email_certificate_task_test.php index 1ca2cd161..cfa56c9f5 100644 --- a/tests/email_certificate_task_test.php +++ b/tests/email_certificate_task_test.php @@ -35,7 +35,7 @@ * @copyright 2017 Mark Nelson * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later */ -class mod_customcert_task_email_certificate_task_testcase extends advanced_testcase { +class mod_customcert_task_email_certificate_task_test extends \core_phpunit\testcase { /** * Test set up. diff --git a/tests/external_test.php b/tests/external_test.php index c46f303f1..50615f27f 100644 --- a/tests/external_test.php +++ b/tests/external_test.php @@ -27,6 +27,8 @@ global $CFG; +require_once($CFG->dirroot . '/webservice/tests/helpers.php'); + /** * Unit tests for the webservices. * @@ -35,7 +37,7 @@ * @copyright 2018 Mark Nelson * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later */ -class mod_customcert_external_test_testcase extends advanced_testcase { +class mod_customcert_external_test extends externallib_advanced_testcase { /** * Test set up.