MDL-36514 add new option to prevent only new self enrolments

Hopefully this will resolve all confusion around the enrol->status flag in this plugin.
This commit is contained in:
Petr Škoda 2012-11-11 16:49:16 +01:00
parent ca48fe5f97
commit e1fa177cf9
7 changed files with 45 additions and 4 deletions

View file

@ -38,6 +38,12 @@ function xmldb_enrol_self_upgrade($oldversion) {
upgrade_plugin_savepoint(true, 2012101400, 'enrol', 'self'); upgrade_plugin_savepoint(true, 2012101400, 'enrol', 'self');
} }
if ($oldversion < 2012120600) {
// Enable new self enrolments everywhere.
$DB->execute("UPDATE {enrol} SET customint6 = 1 WHERE enrol = 'self'");
upgrade_plugin_savepoint(true, 2012120600, 'enrol', 'self');
}
// Moodle v2.4.0 release upgrade line // Moodle v2.4.0 release upgrade line
// Put any upgrade step following this // Put any upgrade step following this

View file

@ -82,6 +82,11 @@ if ($mform->is_cancelled()) {
// Keep previous/default value of disabled expirythreshold option. // Keep previous/default value of disabled expirythreshold option.
$data->expirythreshold = $instance->expirythreshold; $data->expirythreshold = $instance->expirythreshold;
} }
if (!isset($data->customint6)) {
// Add previous value of newenrols if disabled.
$data->customint6 = $instance->customint6;
}
if ($instance->id) { if ($instance->id) {
$reset = ($instance->status != $data->status); $reset = ($instance->status != $data->status);
@ -93,6 +98,7 @@ if ($mform->is_cancelled()) {
$instance->customint3 = $data->customint3; $instance->customint3 = $data->customint3;
$instance->customint4 = $data->customint4; $instance->customint4 = $data->customint4;
$instance->customint5 = $data->customint5; $instance->customint5 = $data->customint5;
$instance->customint6 = $data->customint6;
$instance->customtext1 = $data->customtext1; $instance->customtext1 = $data->customtext1;
$instance->roleid = $data->roleid; $instance->roleid = $data->roleid;
$instance->enrolperiod = $data->enrolperiod; $instance->enrolperiod = $data->enrolperiod;
@ -118,6 +124,7 @@ if ($mform->is_cancelled()) {
'customint3' => $data->customint3, 'customint3' => $data->customint3,
'customint4' => $data->customint4, 'customint4' => $data->customint4,
'customint5' => $data->customint5, 'customint5' => $data->customint5,
'customint6' => $data->customint6,
'customtext1' => $data->customtext1, 'customtext1' => $data->customtext1,
'roleid' => $data->roleid, 'roleid' => $data->roleid,
'enrolperiod' => $data->enrolperiod, 'enrolperiod' => $data->enrolperiod,

View file

@ -45,6 +45,11 @@ class enrol_self_edit_form extends moodleform {
$mform->addElement('select', 'status', get_string('status', 'enrol_self'), $options); $mform->addElement('select', 'status', get_string('status', 'enrol_self'), $options);
$mform->addHelpButton('status', 'status', 'enrol_self'); $mform->addHelpButton('status', 'status', 'enrol_self');
$options = array(1 => get_string('yes'), 0 => get_string('no'));
$mform->addElement('select', 'customint6', get_string('newenrols', 'enrol_self'), $options);
$mform->addHelpButton('customint6', 'newenrols', 'enrol_self');
$mform->disabledIf('customint6', 'status', 'eq', ENROL_INSTANCE_DISABLED);
$mform->addElement('passwordunmask', 'password', get_string('password', 'enrol_self')); $mform->addElement('passwordunmask', 'password', get_string('password', 'enrol_self'));
$mform->addHelpButton('password', 'password', 'enrol_self'); $mform->addHelpButton('password', 'password', 'enrol_self');
if (empty($instance->id) and $plugin->get_config('requirepassword')) { if (empty($instance->id) and $plugin->get_config('requirepassword')) {

View file

@ -69,6 +69,9 @@ $string['maxenrolled'] = 'Max enrolled users';
$string['maxenrolled_help'] = 'Specifies the maximum number of users that can self enrol. 0 means no limit.'; $string['maxenrolled_help'] = 'Specifies the maximum number of users that can self enrol. 0 means no limit.';
$string['maxenrolledreached'] = 'Maximum number of users allowed to self-enrol was already reached.'; $string['maxenrolledreached'] = 'Maximum number of users allowed to self-enrol was already reached.';
$string['messageprovider:expiry_notification'] = 'Self enrolment expiry notifications'; $string['messageprovider:expiry_notification'] = 'Self enrolment expiry notifications';
$string['newenrols'] = 'Allow new enrolments';
$string['newenrols_desc'] = 'Allow users to self enrol into new courses by default.';
$string['newenrols_help'] = 'This setting determines whether a user can enrol into this course.';
$string['nopassword'] = 'No enrolment key required.'; $string['nopassword'] = 'No enrolment key required.';
$string['password'] = 'Enrolment key'; $string['password'] = 'Enrolment key';
$string['password_help'] = 'An enrolment key enables access to the course to be restricted to only those who know the key. $string['password_help'] = 'An enrolment key enables access to the course to be restricted to only those who know the key.
@ -92,9 +95,9 @@ $string['sendcoursewelcomemessage'] = 'Send course welcome message';
$string['sendcoursewelcomemessage_help'] = 'If enabled, users receive a welcome message via email when they self-enrol in a course.'; $string['sendcoursewelcomemessage_help'] = 'If enabled, users receive a welcome message via email when they self-enrol in a course.';
$string['showhint'] = 'Show hint'; $string['showhint'] = 'Show hint';
$string['showhint_desc'] = 'Show first letter of the guest access key.'; $string['showhint_desc'] = 'Show first letter of the guest access key.';
$string['status'] = 'Allow self enrolments'; $string['status'] = 'Enable existing enrolments';
$string['status_desc'] = 'Allow users to self enrol into course by default.'; $string['status_desc'] = 'Enable self enrolment method in new courses.';
$string['status_help'] = 'This setting determines whether a user can enrol (and also unenrol if they have the appropriate permission) themselves from the course.'; $string['status_help'] = 'If disabled all existing self enrolments are suspended and new users can not enrol.';
$string['unenrol'] = 'Unenrol user'; $string['unenrol'] = 'Unenrol user';
$string['unenrolselfconfirm'] = 'Do you really want to unenrol yourself from course "{$a}"?'; $string['unenrolselfconfirm'] = 'Do you really want to unenrol yourself from course "{$a}"?';
$string['unenroluser'] = 'Do you really want to unenrol "{$a->user}" from course "{$a->course}"?'; $string['unenroluser'] = 'Do you really want to unenrol "{$a->user}" from course "{$a->course}"?';

View file

@ -48,6 +48,10 @@ class enrol_self_plugin extends enrol_plugin {
$key = false; $key = false;
$nokey = false; $nokey = false;
foreach ($instances as $instance) { foreach ($instances as $instance) {
if (!$instance->customint6) {
// New enrols not allowed.
continue;
}
if ($instance->password or $instance->customint1) { if ($instance->password or $instance->customint1) {
$key = true; $key = true;
} else { } else {
@ -107,6 +111,12 @@ class enrol_self_plugin extends enrol_plugin {
if ($instance->status != ENROL_INSTANCE_ENABLED) { if ($instance->status != ENROL_INSTANCE_ENABLED) {
return false; return false;
} }
if (!$instance->customint6) {
// New enrols not allowed.
return false;
}
if ($instance->customint5) { if ($instance->customint5) {
require_once("$CFG->dirroot/cohort/lib.php"); require_once("$CFG->dirroot/cohort/lib.php");
return cohort_is_member($instance->customint5, $USER->id); return cohort_is_member($instance->customint5, $USER->id);
@ -200,6 +210,11 @@ class enrol_self_plugin extends enrol_plugin {
return null; return null;
} }
if (!$instance->customint6) {
// New enrols not allowed.
return null;
}
if ($instance->customint5) { if ($instance->customint5) {
require_once("$CFG->dirroot/cohort/lib.php"); require_once("$CFG->dirroot/cohort/lib.php");
if (!cohort_is_member($instance->customint5, $USER->id)) { if (!cohort_is_member($instance->customint5, $USER->id)) {
@ -298,6 +313,7 @@ class enrol_self_plugin extends enrol_plugin {
$fields['customint3'] = $this->get_config('maxenrolled'); $fields['customint3'] = $this->get_config('maxenrolled');
$fields['customint4'] = $this->get_config('sendcoursewelcomemessage'); $fields['customint4'] = $this->get_config('sendcoursewelcomemessage');
$fields['customint5'] = 0; $fields['customint5'] = 0;
$fields['customint6'] = $this->get_config('newenrols');
return $fields; return $fields;
} }

View file

@ -65,6 +65,10 @@ if ($ADMIN->fulltree) {
$settings->add(new admin_setting_configselect('enrol_self/status', $settings->add(new admin_setting_configselect('enrol_self/status',
get_string('status', 'enrol_self'), get_string('status_desc', 'enrol_self'), ENROL_INSTANCE_DISABLED, $options)); get_string('status', 'enrol_self'), get_string('status_desc', 'enrol_self'), ENROL_INSTANCE_DISABLED, $options));
$options = array(1 => get_string('yes'), 0 => get_string('no'));
$settings->add(new admin_setting_configselect('enrol_self/newenrols',
get_string('newenrols', 'enrol_self'), get_string('newenrols_desc', 'enrol_self'), 1, $options));
$options = array(1 => get_string('yes'), $options = array(1 => get_string('yes'),
0 => get_string('no')); 0 => get_string('no'));
$settings->add(new admin_setting_configselect('enrol_self/groupkey', $settings->add(new admin_setting_configselect('enrol_self/groupkey',

View file

@ -24,7 +24,7 @@
defined('MOODLE_INTERNAL') || die(); defined('MOODLE_INTERNAL') || die();
$plugin->version = 2012112900; // The current plugin version (Date: YYYYMMDDXX) $plugin->version = 2012120600; // The current plugin version (Date: YYYYMMDDXX)
$plugin->requires = 2012112900; // Requires this Moodle version $plugin->requires = 2012112900; // Requires this Moodle version
$plugin->component = 'enrol_self'; // Full name of the plugin (used for diagnostics) $plugin->component = 'enrol_self'; // Full name of the plugin (used for diagnostics)
$plugin->cron = 600; $plugin->cron = 600;