From e1fa177cf90ca1f8f487bb21c25248b41b73dbba Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Petr=20S=CC=8Ckoda?= Date: Sun, 11 Nov 2012 16:49:16 +0100 Subject: [PATCH] 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. --- enrol/self/db/upgrade.php | 6 ++++++ enrol/self/edit.php | 7 +++++++ enrol/self/edit_form.php | 5 +++++ enrol/self/lang/en/enrol_self.php | 9 ++++++--- enrol/self/lib.php | 16 ++++++++++++++++ enrol/self/settings.php | 4 ++++ enrol/self/version.php | 2 +- 7 files changed, 45 insertions(+), 4 deletions(-) diff --git a/enrol/self/db/upgrade.php b/enrol/self/db/upgrade.php index fda0d853a8f..625ba828ca5 100644 --- a/enrol/self/db/upgrade.php +++ b/enrol/self/db/upgrade.php @@ -38,6 +38,12 @@ function xmldb_enrol_self_upgrade($oldversion) { 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 // Put any upgrade step following this diff --git a/enrol/self/edit.php b/enrol/self/edit.php index e683d18c58f..a339b8e4b1b 100644 --- a/enrol/self/edit.php +++ b/enrol/self/edit.php @@ -82,6 +82,11 @@ if ($mform->is_cancelled()) { // Keep previous/default value of disabled expirythreshold option. $data->expirythreshold = $instance->expirythreshold; } + if (!isset($data->customint6)) { + // Add previous value of newenrols if disabled. + $data->customint6 = $instance->customint6; + } + if ($instance->id) { $reset = ($instance->status != $data->status); @@ -93,6 +98,7 @@ if ($mform->is_cancelled()) { $instance->customint3 = $data->customint3; $instance->customint4 = $data->customint4; $instance->customint5 = $data->customint5; + $instance->customint6 = $data->customint6; $instance->customtext1 = $data->customtext1; $instance->roleid = $data->roleid; $instance->enrolperiod = $data->enrolperiod; @@ -118,6 +124,7 @@ if ($mform->is_cancelled()) { 'customint3' => $data->customint3, 'customint4' => $data->customint4, 'customint5' => $data->customint5, + 'customint6' => $data->customint6, 'customtext1' => $data->customtext1, 'roleid' => $data->roleid, 'enrolperiod' => $data->enrolperiod, diff --git a/enrol/self/edit_form.php b/enrol/self/edit_form.php index 94287df2c25..04bc13d6883 100644 --- a/enrol/self/edit_form.php +++ b/enrol/self/edit_form.php @@ -45,6 +45,11 @@ class enrol_self_edit_form extends moodleform { $mform->addElement('select', 'status', get_string('status', 'enrol_self'), $options); $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->addHelpButton('password', 'password', 'enrol_self'); if (empty($instance->id) and $plugin->get_config('requirepassword')) { diff --git a/enrol/self/lang/en/enrol_self.php b/enrol/self/lang/en/enrol_self.php index 10e41ccc0ed..92c7aa44f4a 100644 --- a/enrol/self/lang/en/enrol_self.php +++ b/enrol/self/lang/en/enrol_self.php @@ -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['maxenrolledreached'] = 'Maximum number of users allowed to self-enrol was already reached.'; $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['password'] = 'Enrolment 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['showhint'] = 'Show hint'; $string['showhint_desc'] = 'Show first letter of the guest access key.'; -$string['status'] = 'Allow self enrolments'; -$string['status_desc'] = 'Allow users to self enrol into course by default.'; -$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'] = 'Enable existing enrolments'; +$string['status_desc'] = 'Enable self enrolment method in new courses.'; +$string['status_help'] = 'If disabled all existing self enrolments are suspended and new users can not enrol.'; $string['unenrol'] = 'Unenrol user'; $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}"?'; diff --git a/enrol/self/lib.php b/enrol/self/lib.php index 14930b9281f..0ab4f7c9a8a 100644 --- a/enrol/self/lib.php +++ b/enrol/self/lib.php @@ -48,6 +48,10 @@ class enrol_self_plugin extends enrol_plugin { $key = false; $nokey = false; foreach ($instances as $instance) { + if (!$instance->customint6) { + // New enrols not allowed. + continue; + } if ($instance->password or $instance->customint1) { $key = true; } else { @@ -107,6 +111,12 @@ class enrol_self_plugin extends enrol_plugin { if ($instance->status != ENROL_INSTANCE_ENABLED) { return false; } + + if (!$instance->customint6) { + // New enrols not allowed. + return false; + } + if ($instance->customint5) { require_once("$CFG->dirroot/cohort/lib.php"); return cohort_is_member($instance->customint5, $USER->id); @@ -200,6 +210,11 @@ class enrol_self_plugin extends enrol_plugin { return null; } + if (!$instance->customint6) { + // New enrols not allowed. + return null; + } + if ($instance->customint5) { require_once("$CFG->dirroot/cohort/lib.php"); 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['customint4'] = $this->get_config('sendcoursewelcomemessage'); $fields['customint5'] = 0; + $fields['customint6'] = $this->get_config('newenrols'); return $fields; } diff --git a/enrol/self/settings.php b/enrol/self/settings.php index 8401283bb1e..497c27edc53 100644 --- a/enrol/self/settings.php +++ b/enrol/self/settings.php @@ -65,6 +65,10 @@ if ($ADMIN->fulltree) { $settings->add(new admin_setting_configselect('enrol_self/status', 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'), 0 => get_string('no')); $settings->add(new admin_setting_configselect('enrol_self/groupkey', diff --git a/enrol/self/version.php b/enrol/self/version.php index 722b1ca9a89..3eb1046482c 100644 --- a/enrol/self/version.php +++ b/enrol/self/version.php @@ -24,7 +24,7 @@ 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->component = 'enrol_self'; // Full name of the plugin (used for diagnostics) $plugin->cron = 600;