diff --git a/db/access.php b/db/access.php index 7848fed..2fbea48 100644 --- a/db/access.php +++ b/db/access.php @@ -96,4 +96,64 @@ $capabilities = array( '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 91007c6..bbb5215 100644 --- a/lang/en/customcert.php +++ b/lang/en/customcert.php @@ -35,6 +35,12 @@ the certificate.'; $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 89f28ad..93fbae1 100644 --- a/mod_form.php +++ b/mod_form.php @@ -55,33 +55,77 @@ class mod_customcert_mod_form extends moodleform_mod { $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); + } - $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: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('selectyesno', 'verifyany', get_string('verifycertificateanyone', 'customcert')); - $mform->setType('verifyany', 0); - $mform->addHelpButton('verifyany', 'verifycertificateanyone', '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('text', 'requiredtime', get_string('coursetimereq', 'customcert'), array('size' => '3')); - $mform->setType('requiredtime', PARAM_INT); - $mform->addHelpButton('requiredtime', 'coursetimereq', '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('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 (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); + } + + if (!empty($firstoption)) { + $mform->insertElementBefore($optionsheader, $firstoption); + } $this->standard_coursemodule_elements(); diff --git a/version.php b/version.php index af35dbc..0e62c91 100644 --- a/version.php +++ b/version.php @@ -24,7 +24,7 @@ defined('MOODLE_INTERNAL') || die('Direct access to this script is forbidden.'); -$plugin->version = 2018051704; // The current module version (Date: YYYYMMDDXX). +$plugin->version = 2018051705; // The current module version (Date: YYYYMMDDXX). $plugin->requires = 2018051700; // Requires this Moodle version (3.5). $plugin->cron = 0; // Period for cron to check this module (secs). $plugin->component = 'mod_customcert';