Skip to content

Commit

Permalink
Merge pull request #85 from andil-elearning/disablenewenrols
Browse files Browse the repository at this point in the history
Disable new enrols
  • Loading branch information
Flottertotte authored Dec 24, 2018
2 parents 947d1ec + 7495eb6 commit 20a62fb
Show file tree
Hide file tree
Showing 7 changed files with 41 additions and 1 deletion.
8 changes: 8 additions & 0 deletions db/upgrade.php
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,14 @@ function xmldb_enrol_apply_upgrade($oldversion) {
}
}

if ($oldversion < 2018112603) {
$instances = $DB->get_records('enrol', array('enrol' => 'apply'));
foreach ($instances as $instance) {
$instance->customint6 = 1;
$DB->update_record('enrol', $instance, true);
}
}

return true;

}
2 changes: 2 additions & 0 deletions edit.php
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,7 @@
$instance->customint1 = $data->customint1;
$instance->customint2 = $data->customint2;
$instance->customint3 = $data->customint3;
$instance->customint6 = $data->customint6;
$instance->roleid = $data->roleid;
$instance->enrolperiod = $data->enrolperiod;
$instance->timemodified = time();
Expand All @@ -107,6 +108,7 @@
'customint1' => $data->customint1,
'customint2' => $data->customint2,
'customint3' => $data->customint3,
'customint6' => $data->customint6,
'customtext1' => $data->customtext1,
'customtext2' => $data->customtext2,
'enrolperiod' => $data->enrolperiod
Expand Down
6 changes: 6 additions & 0 deletions edit_form.php
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,12 @@ protected function definition() {
// $mform->addHelpButton('status', 'status', 'enrol_apply');
$mform->setDefault('status', $plugin->get_config('status'));

$mform->addElement('select', 'customint6', get_string('newenrols', 'enrol_apply'), array(
1 => get_string('yes'),
0 => get_string('no')
));
$mform->setDefault('newenrols', $plugin->get_config('newenrols'));

if ($instance->id) {
$roles = get_default_enrol_roles($context, $instance->roleid);
} else {
Expand Down
3 changes: 3 additions & 0 deletions lang/en/enrol_apply.php
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@
$string['enrolusers'] = 'Enrol users';

$string['status'] = 'Allow Course enrol confirmation';
$string['newenrols'] = 'Allow new course enrol request';
$string['confirmenrol'] = 'Manage application';

$string['apply:config'] = 'Configure apply enrol instances';
Expand All @@ -104,6 +105,8 @@
$string['maxenrolledreached_left'] = 'Maximum number of users allowed';
$string['maxenrolledreached_right'] = 'has already been reached.';

$string['cantenrol'] = 'Enrolment is disabled or inactive';

$string['maxenrolled_tip_1'] = 'out of';
$string['maxenrolled_tip_2'] = 'seats already booked.';

Expand Down
17 changes: 17 additions & 0 deletions lib.php
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,17 @@ public function roles_protected() {
// Users may tweak the roles later.
return false;
}

public function allow_apply(stdClass $instance) {
if ($instance->status != ENROL_INSTANCE_ENABLED) {
return get_string('cantenrol', 'enrol_apply');
}
if (!$instance->customint6) {
// New enrols not allowed.
return get_string('cantenrol', 'enrol_apply');
}
return true;
}
/**
* Prevent to unenrol an user with a pending application
*
Expand Down Expand Up @@ -85,6 +96,12 @@ public function enrol_page_hook(stdClass $instance) {
// Can not enrol guest!
return null;
}

$allowapply = $this->allow_apply($instance);
if ($allowapply !== true) {
return '<div class="alert alert-error">' . $allowapply . '</div>';
}

if ($DB->record_exists('user_enrolments', array('userid' => $USER->id, 'enrolid' => $instance->id))) {
return $OUTPUT->notification(get_string('notification', 'enrol_apply'), 'notifysuccess');
}
Expand Down
4 changes: 4 additions & 0 deletions settings.php
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,10 @@
$settings->add(new admin_setting_configselect('enrol_apply/status',
get_string('status', 'enrol_apply'), get_string('status_desc', 'enrol_apply'), ENROL_INSTANCE_ENABLED, $options));

$options = array(1 => get_string('yes'), 0 => get_string('no'));
$settings->add(new admin_setting_configselect('enrol_apply/newenrols',
get_string('status', 'enrol_apply'), get_string('status_desc', 'enrol_apply'), 1, $options));

$options = array(1 => get_string('yes'),
0 => get_string('no'));
$settings->add(new admin_setting_configselect('enrol_apply/show_standard_user_profile',
Expand Down
2 changes: 1 addition & 1 deletion version.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@

defined('MOODLE_INTERNAL') || die();

$plugin->version = 2018051500;
$plugin->version = 2018112603;
$plugin->requires = 2011080100;
$plugin->maturity = MATURITY_STABLE;
$plugin->release = 'Enrolment upon approval plugin Version 3.5-a';
Expand Down

0 comments on commit 20a62fb

Please sign in to comment.