Browse Source

Add info about max enrolled users on enrol screen

Konstantin (CMD): Add info about max enrolled users on enrol screen.
SABERES_37_STABLE 3.1-c
Flotter Totte 8 years ago
parent
commit
372f6d7caf
  1. 9
      apply_form.php
  2. 10
      db/upgrade.php
  3. 2
      edit.php
  4. 4
      edit_form.php
  5. 8
      lang/en/enrol_apply.php
  6. 9
      lib.php
  7. 4
      version.php

9
apply_form.php

@ -42,7 +42,7 @@ class enrol_apply_apply_form extends moodleform {
}
public function definition() {
global $USER;
global $USER, $DB;
$mform = $this->_form;
$instance = $this->_customdata;
@ -52,6 +52,13 @@ class enrol_apply_apply_form extends moodleform {
$heading = $plugin->get_instance_name($instance);
$mform->addElement('header', 'selfheader', $heading);
if ($instance->customint3 > 0) {
$count = $DB->count_records('user_enrolments', array('enrolid' => $instance->id));
if ($count < $instance->customint3) {
$mform->addElement('html', '<div class="alert alert-info">'.$count.' '.get_string('maxenrolled_tip_1', 'enrol_apply').' '.$instance->customint3.' '.get_string('maxenrolled_tip_2', 'enrol_apply').'</div>');
}
}
$mform->addElement('html', '<p>'.$instance->customtext1.'</p>');
$mform->addElement('textarea', 'applydescription', get_string('comment', 'enrol_apply'), 'cols="80"');
$mform->setType('applydescription', PARAM_TEXT);

10
db/upgrade.php

@ -92,6 +92,16 @@ function xmldb_enrol_apply_upgrade($oldversion) {
}
}
if ($oldversion < 2017032400) {
$enrolapply = enrol_get_plugin('apply');
$instances = $DB->get_records('enrol', array('enrol' => 'apply'));
foreach ($instances as $instance) {
$instance->customint3 = 0;
$DB->update_record('enrol', $instance, true);
}
}
return true;
}

2
edit.php

@ -94,6 +94,7 @@ if ($mform->is_cancelled()) {
$instance->customtext2 = $data->customtext2;
$instance->customint1 = $data->customint1;
$instance->customint2 = $data->customint2;
$instance->customint3 = $data->customint3;
$instance->roleid = $data->roleid;
$instance->timemodified = time();
$DB->update_record('enrol', $instance);
@ -105,6 +106,7 @@ if ($mform->is_cancelled()) {
'roleid' => $data->roleid,
'customint1' => $data->customint1,
'customint2' => $data->customint2,
'customint3' => $data->customint3,
'customtext1' => $data->customtext1,
'customtext2' => $data->customtext2);
$plugin->add_instance($course, $fields);

4
edit_form.php

@ -73,6 +73,10 @@ class enrol_apply_edit_form extends moodleform {
$select = $mform->addElement('select', 'notify', get_string('notify_desc', 'enrol_apply'), $choices);
$select->setMultiple(true);
$mform->addElement('text', 'customint3', get_string('maxenrolled', 'enrol_apply'));
$mform->setType('customint3', PARAM_INT);
$mform->setDefault('customint3', $plugin->get_config('customint3'));
$mform->addElement('hidden', 'id');
$mform->setType('id', PARAM_INT);
$mform->addElement('hidden', 'courseid');

8
lang/en/enrol_apply.php

@ -97,3 +97,11 @@ $string['user_profile'] = 'User Profile';
$string['show_standard_user_profile'] = 'Show standard user profile fields on enrolment screen';
$string['show_extra_user_profile'] = 'Show extra user profile fields on enrolment screen';
$string['maxenrolled'] = 'Max enrolled users';
$string['maxenrolled_help'] = 'Specifies the maximum number of users that can self enrol. 0 means no limit.';
$string['maxenrolledreached_left'] = 'Maximum number of users allowed';
$string['maxenrolledreached_right'] = 'has already been reached.';
$string['maxenrolled_tip_1'] = 'out of';
$string['maxenrolled_tip_2'] = 'seats already booked.';

9
lib.php

@ -68,6 +68,15 @@ class enrol_apply_plugin extends enrol_plugin {
return $OUTPUT->notification(get_string('notification', 'enrol_apply'), 'notifysuccess');
}
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 '<div class="alert alert-error">'.get_string('maxenrolledreached_left', 'enrol_apply')." (".$count.") ".get_string('maxenrolledreached_right', 'enrol_apply').'</div>';
}
}
require_once("$CFG->dirroot/enrol/apply/apply_form.php");
$form = new enrol_apply_apply_form(null, $instance);

4
version.php

@ -24,8 +24,8 @@
defined('MOODLE_INTERNAL') || die();
$plugin->version = 2017020300;
$plugin->version = 2017032900;
$plugin->requires = 2011080100;
$plugin->maturity = MATURITY_STABLE;
$plugin->release = 'Enrolment upon approval plugin Version 3.1-b.3';
$plugin->release = 'Enrolment upon approval plugin Version 3.1-c';
$plugin->component = 'enrol_apply';

Loading…
Cancel
Save