-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmod_form.php
162 lines (139 loc) · 6.18 KB
/
mod_form.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
<?php
// This file is part of Moodle - http://moodle.org/
//
// Moodle is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// Moodle is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
/**
* The main vitero configuration form
*
* It uses the standard core Moodle formslib. For more info about them, please
* visit: http://docs.moodle.org/en/Development:lib/formslib.php
*
* @package mod_vitero
* @copyright 2016 Synergy Learning
* @author Yair Spielmann <[email protected]>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
defined('MOODLE_INTERNAL') || die();
global $CFG;
require_once($CFG->dirroot . '/course/moodleform_mod.php');
/**
* Module instance settings form
*/
class mod_vitero_mod_form extends moodleform_mod {
/**
* Defines forms elements.
*/
public function definition() {
global $CFG;
$mform = $this->_form;
// Adding the "general" fieldset, where all the common settings are showed.
$mform->addElement('header', 'general', get_string('general', 'form'));
// Adding the standard "name" field.
$mform->addElement('text', 'name', get_string('viteroname', 'vitero'), ['size' => '64']);
if (!empty($CFG->formatstringstriptags)) {
$mform->setType('name', PARAM_TEXT);
} else {
$mform->setType('name', PARAM_CLEANHTML);
}
$mform->addRule('name', null, 'required', null, 'client');
$mform->addRule('name', get_string('maximumchars', '', 255), 'maxlength', 255, 'client');
$mform->addHelpButton('name', 'viteroname', 'vitero');
// Adding the standard "intro" and "introformat" fields.
$this->standard_intro_elements();
// Adding the rest of vitero settings, spreeading all them into this fieldset
// or adding more fieldsets ('header' elements) if needed for better logic.
$mform->addElement('header', 'appointmentfields', get_string('appointmentfields', 'vitero'));
$mform->addElement('date_time_selector', 'starttime', get_string('starttime', 'vitero'),
['step' => 15, 'optional' => 0]);
$mform->setDefault('starttime', time() + 3600);
$mform->addElement('date_time_selector', 'endtime', get_string('endtime', 'vitero'), ['step' => 15, 'optional' => 0]);
$mform->setDefault('endtime', time() + 7200);
$mform->addElement('text', 'startbuffer', get_string('startbuffer', 'vitero'), ['size' => '2']);
$mform->setDefault('startbuffer', 15);
$mform->setType('startbuffer', PARAM_INT);
$mform->addElement('text', 'endbuffer', get_string('endbuffer', 'vitero'), ['size' => '2']);
$mform->setDefault('endbuffer', 15);
$mform->setType('endbuffer', PARAM_INT);
$mform->addElement('select', 'roomsize', get_string('roomsize', 'vitero'));
$mform->addElement('text', 'teamname', get_string('teamname', 'vitero'));
$mform->addRule('teamname', null, 'required', null, 'client');
$mform->setType('teamname', PARAM_TEXT);
// Direct login.
$mform->addElement('header', 'adminloginarea', get_string('adminlogin', 'vitero'));
$mform->addElement('button', 'adminlogin', get_string('adminlogin', 'vitero'));
$mform->addElement('static', 'nologinhint', '', nl2br(s(get_string('nologinhint', 'vitero'))));
// Add standard elements, common to all modules.
$this->standard_coursemodule_elements();
// Add standard buttons, common to all modules.
$this->add_action_buttons();
}
/**
* Set the form data.
*
* @param object $default data.
*/
public function set_data($default) {
global $CFG;
$mform = $this->_form;
// Load or freeze room size.
if ($default->instance) {
$roomsizes = [];
$roomsizes[$default->roomsize] = $default->roomsize;
$roomsize = &$mform->getElement('roomsize');
$roomsize->loadArray($roomsizes);
$mform->freeze(['roomsize']);
} else {
$roomsizes = vitero_get_available_roomsizes();
$roomsize = &$mform->getElement('roomsize');
$roomsize->loadArray($roomsizes);
}
// Freeze entire form if meeting is in the past.
if (isset($default->endtime, $default->endbuffer) && $default->endtime > 0) {
if ($default->endtime + (int)$default->endbuffer * 60 < time()) {
$mform->freeze();
}
}
// Give id to administration button (or hide if activity hasn't been created yet).
if ($default->coursemodule) {
$adminbutton = $mform->getElement('adminlogin');
$url = $CFG->wwwroot . '/mod/vitero/adminlogin.php?cm=' . $default->coursemodule;
$url = htmlentities($url);
$btnstr = 'onclick="window.open(\'' . $url . '\', \'\', \'\');"';
$adminbutton->updateAttributes($btnstr);
$mform->removeElement('nologinhint');
} else {
$mform->removeElement('adminlogin');
}
parent::set_data($default);
}
/**
* Validation
*
* @param array $data
* @param array $files
* @return array $errors
*/
public function validation($data, $files) {
$errors = parent::validation($data, $files);
// Validate times.
if (!$data['instance']) {
if ($data['starttime'] >= $data['endtime']) {
$errors['starttime'] = get_string('greaterstarttime', 'vitero');
} else if ($data['starttime'] <= time()) {
$errors['starttime'] = get_string('paststarttime', 'vitero');
}
}
return $errors;
}
}