Skip to content

Commit

Permalink
MDL-29824 improve notification of max number of enrolled users
Browse files Browse the repository at this point in the history
  • Loading branch information
skodak committed Oct 30, 2011
1 parent 38e9a1c commit 78c5042
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 12 deletions.
1 change: 1 addition & 0 deletions enrol/index.php
Expand Up @@ -82,6 +82,7 @@
$PAGE->navbar->add(get_string('enrolmentoptions','enrol'));

echo $OUTPUT->header();
echo $OUTPUT->heading(get_string('enrolmentoptions','enrol'));

//TODO: find if future enrolments present and display some info

Expand Down
1 change: 1 addition & 0 deletions enrol/self/lang/en/enrol_self.php
Expand Up @@ -47,6 +47,7 @@
$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['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.
Expand Down
9 changes: 0 additions & 9 deletions enrol/self/lib.php
Expand Up @@ -189,15 +189,6 @@ public function enrol_page_hook(stdClass $instance) {
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");

Expand Down
26 changes: 23 additions & 3 deletions enrol/self/locallib.php
Expand Up @@ -30,6 +30,7 @@

class enrol_self_enrol_form extends moodleform {
protected $instance;
protected $toomany = false;

/**
* Overriding this function to get unique form id for multiple self enrolments
Expand All @@ -42,19 +43,33 @@ protected function get_form_identifier() {
}

public function definition() {
global $DB;

$mform = $this->_form;
$instance = $this->_customdata;
$this->instance = $instance;
$plugin = enrol_get_plugin('self');

$heading = $plugin->get_instance_name($instance);
$mform->addElement('header', 'selfheader', $heading);

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
$this->toomany = true;
$mform->addElement('static', 'notice', '', get_string('maxenrolledreached', 'enrol_self'));
return;
}
}

if ($instance->password) {
$heading = $plugin->get_instance_name($instance);
$mform->addElement('header', 'selfheader', $heading);
//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"));
} else {
// nothing?
$mform->addElement('static', 'nokey', '', get_string('nopassword', 'enrol_self'));
}

$this->add_action_buttons(false, get_string('enrolme', 'enrol_self'));
Expand All @@ -74,6 +89,11 @@ public function validation($data, $files) {
$errors = parent::validation($data, $files);
$instance = $this->instance;

if ($this->toomany) {
$errors['notice'] = get_string('error');
return $errors;
}

if ($instance->password) {
if ($data['enrolpassword'] !== $instance->password) {
if ($instance->customint1) {
Expand Down

0 comments on commit 78c5042

Please sign in to comment.