MDL-22789 addding forgotten group enrol option
This commit is contained in:
@@ -158,6 +158,8 @@ class enrol_self_plugin extends enrol_plugin {
|
||||
}
|
||||
|
||||
require_once("$CFG->dirroot/enrol/self/locallib.php");
|
||||
require_once("$CFG->dirroot/group/lib.php");
|
||||
|
||||
$form = new enrol_self_enrol_form(NULL, $instance);
|
||||
$instanceid = optional_param('instance', 0, PARAM_INT);
|
||||
|
||||
@@ -173,6 +175,20 @@ class enrol_self_plugin extends enrol_plugin {
|
||||
|
||||
$this->enrol_user($instance, $USER->id, $instance->roleid, $timestart, $tineend);
|
||||
add_to_log($instance->courseid, 'course', 'enrol', '../enrol/users.php?id='.$instance->courseid, $instance->courseid); //there should be userid somewhere!
|
||||
|
||||
if ($instance->password and $instance->customint1 and $data->enrolpassword !== $instance->password) {
|
||||
// it must be a group enrolment, let's assign group too
|
||||
$groups = $DB->get_records('groups', array('courseid'=>$instance->courseid), 'id', 'id, enrolmentkey');
|
||||
foreach ($groups as $group) {
|
||||
if (empty($group->enrolmentkey)) {
|
||||
continue;
|
||||
}
|
||||
if ($group->enrolmentkey === $data->enrolpassword) {
|
||||
groups_add_member($group->id, $USER->id);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
// send welcome
|
||||
if ($this->get_config('sendcoursewelcomemessage')) {
|
||||
$this->email_welcome_message($instance, $USER);
|
||||
|
||||
+15
-1
@@ -65,7 +65,21 @@ class enrol_self_enrol_form extends moodleform {
|
||||
if ($instance->password) {
|
||||
if ($data['enrolpassword'] !== $instance->password) {
|
||||
if ($instance->customint1) {
|
||||
//TODO: check groups
|
||||
$groups = $DB->get_records('groups', array('courseid'=>$instance->courseid), 'id ASC', 'id, enrolmentkey');
|
||||
$found = false;
|
||||
foreach ($groups as $group) {
|
||||
if (empty($group->enrolmentkey)) {
|
||||
continue;
|
||||
}
|
||||
if ($group->enrolmentkey === $data['enrolpassword']) {
|
||||
$found = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (!$found) {
|
||||
// we can not hint because there are probably multiple passwords
|
||||
$errors['enrolpassword'] = get_string('passwordinvalid', 'enrol_self');
|
||||
}
|
||||
|
||||
} else {
|
||||
$plugin = enrol_get_plugin('self');
|
||||
|
||||
Reference in New Issue
Block a user