MDL-43175 events: Base event unit tests for JSON encoding / decoding comparison.
[moodle.git] / enrol / manual / edit_form.php
blobbfc09a7848f1e7916a15a5cd052fc093244aba79
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.
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/>.
17 /**
18 * Adds new instance of enrol_manual to specified course
19 * or edits current instance.
21 * @package enrol_manual
22 * @copyright 2010 Petr Skoda {@link http://skodak.org}
23 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
26 defined('MOODLE_INTERNAL') || die();
28 require_once($CFG->libdir.'/formslib.php');
30 class enrol_manual_edit_form extends moodleform {
32 function definition() {
33 $mform = $this->_form;
35 list($instance, $plugin, $context) = $this->_customdata;
37 $mform->addElement('header', 'header', get_string('pluginname', 'enrol_manual'));
39 $options = array(ENROL_INSTANCE_ENABLED => get_string('yes'),
40 ENROL_INSTANCE_DISABLED => get_string('no'));
41 $mform->addElement('select', 'status', get_string('status', 'enrol_manual'), $options);
42 $mform->addHelpButton('status', 'status', 'enrol_manual');
43 $mform->setDefault('status', $plugin->get_config('status'));
45 if ($instance->id) {
46 $roles = get_default_enrol_roles($context, $instance->roleid);
47 } else {
48 $roles = get_default_enrol_roles($context, $plugin->get_config('roleid'));
50 $mform->addElement('select', 'roleid', get_string('defaultrole', 'role'), $roles);
51 $mform->setDefault('roleid', $plugin->get_config('roleid'));
53 $mform->addElement('duration', 'enrolperiod', get_string('defaultperiod', 'enrol_manual'), array('optional' => true, 'defaultunit' => 86400));
54 $mform->setDefault('enrolperiod', $plugin->get_config('enrolperiod'));
55 $mform->addHelpButton('enrolperiod', 'defaultperiod', 'enrol_manual');
57 $options = array(0 => get_string('no'), 1 => get_string('expirynotifyenroller', 'core_enrol'), 2 => get_string('expirynotifyall', 'core_enrol'));
58 $mform->addElement('select', 'expirynotify', get_string('expirynotify', 'core_enrol'), $options);
59 $mform->addHelpButton('expirynotify', 'expirynotify', 'core_enrol');
61 $mform->addElement('duration', 'expirythreshold', get_string('expirythreshold', 'core_enrol'), array('optional' => false, 'defaultunit' => 86400));
62 $mform->addHelpButton('expirythreshold', 'expirythreshold', 'core_enrol');
63 $mform->disabledIf('expirythreshold', 'expirynotify', 'eq', 0);
65 $mform->addElement('hidden', 'courseid');
66 $mform->setType('courseid', PARAM_INT);
68 if (enrol_accessing_via_instance($instance)) {
69 $mform->addElement('static', 'selfwarn', get_string('instanceeditselfwarning', 'core_enrol'), get_string('instanceeditselfwarningtext', 'core_enrol'));
72 $this->add_action_buttons(true, ($instance->id ? null : get_string('addinstance', 'enrol')));
74 $this->set_data($instance);
77 function validation($data, $files) {
78 global $DB;
80 $errors = parent::validation($data, $files);
82 if ($data['expirynotify'] > 0 and $data['expirythreshold'] < 86400) {
83 $errors['expirythreshold'] = get_string('errorthresholdlow', 'core_enrol');
86 return $errors;