diff --git a/enrol/self/db/access.php b/enrol/self/db/access.php
index 54fa9d8..3ff23e3 100644
--- a/enrol/self/db/access.php
+++ b/enrol/self/db/access.php
@@ -38,6 +38,14 @@ $capabilities = array(
)
),
+ 'enrol/self:holdkey' => array( +
+ 'captype' => 'write',
+ 'contextlevel' => CONTEXT_COURSE,
+ 'archetypes' => array(
+ )
+ ),
+
'enrol/self:manage' => array(
'captype' => 'write',
diff --git a/enrol/self/lang/en/enrol_self.php b/enrol/self/lang/en/enrol_self.php
index af2c54c..2988f06 100644
--- a/enrol/self/lang/en/enrol_self.php
+++ b/enrol/self/lang/en/enrol_self.php
@@ -42,6 +42,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 a group enro
To use a group enrolment key, an enrolment key must be specified in the course settings as well as the group enrolment key in t
+$string['keyholder'] = 'You should have received this enrolment key from {$a}';
$string['longtimenosee'] = 'Unenrol inactive after';
$string['longtimenosee_help'] = 'If users haven\'t accessed a course for a long time, then they are automatically unenrolled. T
$string['maxenrolled'] = 'Max enrolled users';
@@ -63,6 +64,7 @@ $string['requirepassword'] = 'Require enrolment key';
$string['requirepassword_desc'] = 'Require enrolment key in new courses and prevent removing of enrolment key from existing cou
$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 1742339..63bc15d 100644
--- a/enrol/self/locallib.php
+++ b/enrol/self/locallib.php
@@ -68,6 +68,18 @@ class enrol_self_enrol_form extends moodleform {
$mform->addElement('passwordunmask', 'enrolpassword', get_string('password', 'enrol_self'),
array('id' => $instance->id."_enrolpassword"));
+ global $course;
+ $context = get_context_instance(CONTEXT_COURSE, $course->id);
+ $keyholders = get_users_by_capability($context, 'enrol/self:holdkey', 'u.id, u.firstname, u.lastname, u.email');
+ if (count($keyholders) == 0) {
+ $keyholders = get_users_by_capability($context, 'enrol/self:manage', 'u.id, u.firstname, u.lastname, u.email');
+ }
+ foreach ($keyholders as $user) {
+ $keyholder = $user;
+ break;
+ }
+ $mform->addElement('static', 'keyholder', '', get_string('keyholder', 'enrol_self', $keyholder->firstname.' '.$keyh
+
} else {
$mform->addElement('static', 'nokey', '', get_string('nopassword', 'enrol_self'));
}
You are right, this was accidentally not implemented yet in the new enrol/self plugin.