mirror of
https://github.com/moodle/moodle.git
synced 2025-01-18 22:08:20 +01:00
MDL-15962 implemented a max enrolled users limit in enrol/self plugin
This commit is contained in:
parent
39693a3dba
commit
af41d03d96
@ -70,6 +70,7 @@ if ($mform->is_cancelled()) {
|
||||
$instance->password = $data->password;
|
||||
$instance->customint1 = $data->customint1;
|
||||
$instance->customint2 = $data->customint2;
|
||||
$instance->customint3 = $data->customint3;
|
||||
$instance->roleid = $data->roleid;
|
||||
$instance->enrolperiod = $data->enrolperiod;
|
||||
$instance->enrolstartdate = $data->enrolstartdate;
|
||||
@ -78,7 +79,7 @@ if ($mform->is_cancelled()) {
|
||||
$DB->update_record('enrol', $instance);
|
||||
|
||||
} else {
|
||||
$fields = array('status'=>$data->status, 'name'=>$data->name, 'password'=>$data->password, 'customint1'=>$data->customint1, 'customint2'=>$data->customint2,
|
||||
$fields = array('status'=>$data->status, 'name'=>$data->name, 'password'=>$data->password, 'customint1'=>$data->customint1, 'customint2'=>$data->customint2, 'customint3'=>$data->customint3,
|
||||
'roleid'=>$data->roleid, 'enrolperiod'=>$data->enrolperiod, 'enrolstartdate'=>$data->enrolstartdate, 'enrolenddate'=>$data->enrolenddate);
|
||||
$plugin->add_instance($course, $fields);
|
||||
}
|
||||
|
@ -92,8 +92,15 @@ class enrol_self_edit_form extends moodleform {
|
||||
$mform->setDefault('customint2', $plugin->get_config('longtimenosee'));
|
||||
$mform->addHelpButton('customint2', 'longtimenosee', 'enrol_self');
|
||||
|
||||
$mform->addElement('text', 'customint3', get_string('maxenrolled', 'enrol_self'));
|
||||
$mform->setDefault('customint3', $plugin->get_config('maxenrolled'));
|
||||
$mform->addHelpButton('customint3', 'maxenrolled', 'enrol_self');
|
||||
$mform->setType('customint3', PARAM_INT);
|
||||
|
||||
$mform->addElement('hidden', 'id');
|
||||
$mform->setType('id', PARAM_INT);
|
||||
$mform->addElement('hidden', 'courseid');
|
||||
$mform->setType('courseid', PARAM_INT);
|
||||
|
||||
$this->add_action_buttons(true, ($instance->id ? null : get_string('addinstance', 'enrol')));
|
||||
|
||||
|
@ -39,6 +39,9 @@ $string['groupkey_help'] = 'In addition to restricting access to the course to o
|
||||
To use a group enrolment key, an enrolment key must be specified in the course settings as well as the group enrolment key in the group settings.';
|
||||
$string['longtimenosee'] = 'Unenrol inactive after';
|
||||
$string['longtimenosee_help'] = 'If users haven\'t accessed a course for a long time, then they are automatically unenrolled. This parameter specifies that time limit.';
|
||||
$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['password'] = 'Enrolment key';
|
||||
$string['password_help'] = 'An enrolment key enables access to the course to be restricted to only those who know the key.
|
||||
|
||||
|
@ -162,6 +162,15 @@ class enrol_self_plugin extends enrol_plugin {
|
||||
return null;
|
||||
}
|
||||
|
||||
if ($instance->customint3 > 0) {
|
||||
// max enrol limit specified
|
||||
$count = $DB->count_records('user_enrolments', array('enrolid'=>$instance->id));
|
||||
if ($count >= $instance->customint3) {
|
||||
// bad luck, no more self enrolments here
|
||||
return $OUTPUT->notification(get_string('maxenrolledreached', 'enrol_self'));
|
||||
}
|
||||
}
|
||||
|
||||
require_once("$CFG->dirroot/enrol/self/locallib.php");
|
||||
require_once("$CFG->dirroot/group/lib.php");
|
||||
|
||||
@ -218,6 +227,7 @@ class enrol_self_plugin extends enrol_plugin {
|
||||
|
||||
$fields = array('customint1' => $this->get_config('groupkey'),
|
||||
'customint2' => $this->get_config('longtimenosee'),
|
||||
'customint3' => $this->get_config('maxenrolled'),
|
||||
'enrolperiod' => $this->get_config('enrolperiod', 0),
|
||||
'status' => $this->get_config('status'),
|
||||
'roleid' => $this->get_config('roleid', 0));
|
||||
|
@ -88,4 +88,6 @@ if ($ADMIN->fulltree) {
|
||||
$settings->add(new admin_setting_configselect('enrol_self/longtimenosee',
|
||||
get_string('longtimenosee', 'enrol_self'), get_string('longtimenosee_help', 'enrol_self'), 0, $options));
|
||||
|
||||
$settings->add(new admin_setting_configtext('enrol_self/maxenrolled',
|
||||
get_string('maxenrolled', 'enrol_self'), get_string('maxenrolled_help', 'enrol_self'), 0, PARAM_INT));
|
||||
}
|
||||
|
@ -26,5 +26,5 @@
|
||||
|
||||
defined('MOODLE_INTERNAL') || die();
|
||||
|
||||
$plugin->version = 2010080900;
|
||||
$plugin->version = 2010090500;
|
||||
$plugin->cron = 180;
|
Loading…
x
Reference in New Issue
Block a user