diff --git a/enrol/self/db/access.php b/enrol/self/db/access.php index 9cdd3c3cc91..d2c59726a55 100644 --- a/enrol/self/db/access.php +++ b/enrol/self/db/access.php @@ -48,6 +48,15 @@ $capabilities = array( ) ), + 'enrol/self:holdkey' => array( + + 'captype' => 'write', + 'contextlevel' => CONTEXT_COURSE, + 'archetypes' => array( + 'manager' => CAP_PROHIBIT, + ) + ), + /* Voluntarily unenrol self from course - watch out for data loss. */ 'enrol/self:unenrolself' => array( 'captype' => 'write', diff --git a/enrol/self/lang/en/enrol_self.php b/enrol/self/lang/en/enrol_self.php index a964a9ff82e..87a43f0de7d 100644 --- a/enrol/self/lang/en/enrol_self.php +++ b/enrol/self/lang/en/enrol_self.php @@ -63,6 +63,7 @@ $string['groupkey_desc'] = 'Use group enrolment keys by default.'; $string['groupkey_help'] = 'In addition to restricting access to the course to only those who know the key, use of group enrolment keys means users are automatically added to groups when they enrol in the course. Note: An enrolment key for the course must be specified in the self enrolment settings as well as group enrolment keys in the group settings.'; +$string['keyholder'] = 'You should have received this enrolment key from:'; $string['longtimenosee'] = 'Unenrol inactive after'; $string['longtimenosee_help'] = 'If users haven\'t accessed a course for a long time, then they are automatically unenrolled. This parameter specifies that time limit.'; $string['maxenrolled'] = 'Max enrolled users'; @@ -88,6 +89,7 @@ $string['requirepassword'] = 'Require enrolment key'; $string['requirepassword_desc'] = 'Require enrolment key in new courses and prevent removing of enrolment key from existing courses.'; $string['role'] = 'Default assigned role'; $string['self:config'] = 'Configure self enrol instances'; +$string['self:holdkey'] = 'Appear as the self enrolment key holder'; $string['self:manage'] = 'Manage enrolled users'; $string['self:unenrol'] = 'Unenrol users from course'; $string['self:unenrolself'] = 'Unenrol self from the course'; diff --git a/enrol/self/locallib.php b/enrol/self/locallib.php index cd010eb3fd5..226555df94d 100644 --- a/enrol/self/locallib.php +++ b/enrol/self/locallib.php @@ -41,6 +41,7 @@ class enrol_self_enrol_form extends moodleform { } public function definition() { + global $USER, $OUTPUT, $CFG; $mform = $this->_form; $instance = $this->_customdata; $this->instance = $instance; @@ -53,6 +54,26 @@ class enrol_self_enrol_form extends moodleform { // Change the id of self enrolment key input as there can be multiple self enrolment methods. $mform->addElement('passwordunmask', 'enrolpassword', get_string('password', 'enrol_self'), array('id' => 'enrolpassword_'.$instance->id)); + $context = context_course::instance($this->instance->courseid); + $keyholders = get_users_by_capability($context, 'enrol/self:holdkey', user_picture::fields('u')); + $keyholdercount = 0; + foreach ($keyholders as $keyholder) { + $keyholdercount++; + if ($keyholdercount === 1) { + $mform->addElement('static', 'keyholder', '', get_string('keyholder', 'enrol_self')); + } + $keyholdercontext = context_user::instance($keyholder->id); + if ($USER->id == $keyholder->id || has_capability('moodle/user:viewdetails', context_system::instance()) || + has_coursecontact_role($keyholder->id)) { + $profilelink = '' . fullname($keyholder) . ''; + } else { + $profilelink = fullname($keyholder); + } + $profilepic = $OUTPUT->user_picture($keyholder, array('size' => 35, 'courseid' => $this->instance->courseid)); + $mform->addElement('static', 'keyholder'.$keyholdercount, '', $profilepic . $profilelink); + } + } else { $mform->addElement('static', 'nokey', '', get_string('nopassword', 'enrol_self')); } diff --git a/enrol/self/version.php b/enrol/self/version.php index adc754ed1a1..59c2ca09f6c 100644 --- a/enrol/self/version.php +++ b/enrol/self/version.php @@ -24,7 +24,7 @@ defined('MOODLE_INTERNAL') || die(); -$plugin->version = 2014111000; // The current plugin version (Date: YYYYMMDDXX) +$plugin->version = 2014111001; // The current plugin version (Date: YYYYMMDDXX) $plugin->requires = 2014110400; // Requires this Moodle version $plugin->component = 'enrol_self'; // Full name of the plugin (used for diagnostics) $plugin->cron = 600;