Moodle

Keyholder role 2.0x

Details

  • Database:
    MySQL
  • Affected Branches:
    MOODLE_20_STABLE, MOODLE_21_STABLE

Description

I can't find the keyholder role option in enrolments. Has this been remove din the enrolment re-factoring or is this a bug?

If it's been removed, suggested improvement is reinstate it.

Activity

Hide
Petr Škoda (skodak) added a comment -

You are right, this was accidentally not implemented yet in the new enrol/self plugin.

Show
Petr Škoda (skodak) added a comment - You are right, this was accidentally not implemented yet in the new enrol/self plugin.
Hide
Ray Lawrence added a comment -

Thanks. Should I do anything or is this already logged for reinstatment?

Show
Ray Lawrence added a comment - Thanks. Should I do anything or is this already logged for reinstatment?
Hide
Mira Vogel added a comment -

Really hoping this will be reinstated. Because of a distinctive interpretation of copyright law here, the scanning service requires password protection on all areas using their scanned chapters, articles, &tc. And with password protection come the inevitable password reminder requests. Thanks in advance.

Show
Mira Vogel added a comment - Really hoping this will be reinstated. Because of a distinctive interpretation of copyright law here, the scanning service requires password protection on all areas using their scanned chapters, articles, &tc. And with password protection come the inevitable password reminder requests. Thanks in advance.
Hide
Mark Drechsler added a comment -

This is having an impact on our clients who are keen to use this function - any idea when it will be scheduled for a fix?

Show
Mark Drechsler added a comment - This is having an impact on our clients who are keen to use this function - any idea when it will be scheduled for a fix?
Hide
Helen Foster added a comment -

Just noting that this issue also affects 2.1.1. Hope it can be fixed soon as it's missing functionality from 1.9.

Show
Helen Foster added a comment - Just noting that this issue also affects 2.1.1. Hope it can be fixed soon as it's missing functionality from 1.9.
Hide
Peter Roberts added a comment -

Did the fix for this make it into 2.2? (I'm guessing not since it's still open).

Show
Peter Roberts added a comment - Did the fix for this make it into 2.2? (I'm guessing not since it's still open).
Hide
Matt Jenner added a comment -

I must admit, we would very much like to see this implemented in 2.2+, if it's possible!

Show
Matt Jenner added a comment - I must admit, we would very much like to see this implemented in 2.2+, if it's possible!
Hide
Nicolas Dunand added a comment - - edited

Just coming up for a solution for this. 2 files need to be modified in the enrol/self plugin directory: locallib.php, db/access.php and lang/en/enrol_self.php (see attached diff file).

The site admin then has to define a key holder role (whatever it's name) and give it the 'enrol/self:holdkey" capability. Last step, this role has to be given to some one on a course/category/site level.

Then the enrollment page for the student (the one asking for the key) displays the additional text : "You should have received this enrolment key from XXX", where XXX is either the Key holder or - if none - the last teacher having accessed the site.

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( // mod_ND
+
+        '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 {
             //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' => $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'));
         }
Show
Nicolas Dunand added a comment - - edited Just coming up for a solution for this. 2 files need to be modified in the enrol/self plugin directory: locallib.php, db/access.php and lang/en/enrol_self.php (see attached diff file). The site admin then has to define a key holder role (whatever it's name) and give it the 'enrol/self:holdkey" capability. Last step, this role has to be given to some one on a course/category/site level. Then the enrollment page for the student (the one asking for the key) displays the additional text : "You should have received this enrolment key from XXX", where XXX is either the Key holder or - if none - the last teacher having accessed the site.
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( // mod_ND
+
+        '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 {
             //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' => $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'));
         }

Dates

  • Created:
    Updated: