MDL-63683 enrol: Fix plugin settings when no role has student archetype
[moodle.git] / enrol / fee / settings.php
CommitLineData
d3432a88
SR
1<?php
2// This file is part of Moodle - http://moodle.org/
3//
4// Moodle is free software: you can redistribute it and/or modify
5// it under the terms of the GNU General Public License as published by
6// the Free Software Foundation, either version 3 of the License, or
7// (at your option) any later version.
8//
9// Moodle is distributed in the hope that it will be useful,
10// but WITHOUT ANY WARRANTY; without even the implied warranty of
11// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12// GNU General Public License for more details.
13//
14// You should have received a copy of the GNU General Public License
15// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
16
17/**
18 * Settings for the Fee enrolment plugin
19 *
20 * @package enrol_fee
21 * @copyright 2019 Shamim Rezaie <shamim@moodle.com>
22 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
23 */
24
25defined('MOODLE_INTERNAL') || die();
26
27if ($ADMIN->fulltree) {
28
acd1c824
SR
29 $currencies = enrol_get_plugin('fee')->get_possible_currencies();
30
31 if (empty($currencies)) {
32 $notify = new \core\output\notification(
33 get_string('nocurrencysupported', 'core_payment'),
34 \core\output\notification::NOTIFY_WARNING
35 );
36 $settings->add(new admin_setting_heading('enrol_fee_nocurrency', '', $OUTPUT->render($notify)));
37 }
38
d3432a88
SR
39 $settings->add(new admin_setting_heading('enrol_fee_settings', '', get_string('pluginname_desc', 'enrol_fee')));
40
41 // Note: let's reuse the ext sync constants and strings here, internally it is very similar,
42 // it describes what should happen when users are not supposed to be enrolled any more.
43 $options = array(
44 ENROL_EXT_REMOVED_KEEP => get_string('extremovedkeep', 'enrol'),
45 ENROL_EXT_REMOVED_SUSPENDNOROLES => get_string('extremovedsuspendnoroles', 'enrol'),
46 ENROL_EXT_REMOVED_UNENROL => get_string('extremovedunenrol', 'enrol'),
47 );
48 $settings->add(new admin_setting_configselect(
acd1c824
SR
49 'enrol_fee/expiredaction',
50 get_string('expiredaction', 'enrol_fee'),
51 get_string('expiredaction_help', 'enrol_fee'),
52 ENROL_EXT_REMOVED_SUSPENDNOROLES,
53 $options));
d3432a88
SR
54
55 $settings->add(new admin_setting_heading('enrol_fee_defaults',
56 get_string('enrolinstancedefaults', 'admin'), get_string('enrolinstancedefaults_desc', 'admin')));
57
58 $options = array(ENROL_INSTANCE_ENABLED => get_string('yes'),
59 ENROL_INSTANCE_DISABLED => get_string('no'));
60 $settings->add(new admin_setting_configselect('enrol_fee/status',
61 get_string('status', 'enrol_fee'), get_string('status_desc', 'enrol_fee'), ENROL_INSTANCE_DISABLED, $options));
62
acd1c824
SR
63 if (!empty($currencies)) {
64 $settings->add(new admin_setting_configtext('enrol_fee/cost', get_string('cost', 'enrol_fee'), '', 0, PARAM_FLOAT, 4));
da4b94e0 65 $settings->add(new admin_setting_configselect('enrol_fee/currency', get_string('currency', 'enrol_fee'), '', 'USD',
acd1c824
SR
66 $currencies));
67 }
d3432a88
SR
68
69 if (!during_initial_install()) {
70 $options = get_default_enrol_roles(context_system::instance());
71 $student = get_archetype_roles('student');
72 $student = reset($student);
73 $settings->add(new admin_setting_configselect('enrol_fee/roleid',
12b9c605 74 get_string('defaultrole', 'enrol_fee'), get_string('defaultrole_desc', 'enrol_fee'), $student->id ?? null, $options));
d3432a88
SR
75 }
76
77 $settings->add(new admin_setting_configduration('enrol_fee/enrolperiod',
78 get_string('enrolperiod', 'enrol_fee'), get_string('enrolperiod_desc', 'enrol_fee'), 0));
79}