This repository has been archived by the owner on Nov 15, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2
/
mod_form.php
190 lines (156 loc) · 8.49 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
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
<?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 openwebinar 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
*
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*
* @package mod_openwebinar
* @copyright 2015 MoodleFreak.com
* @author Luuk Verhoeven
*/
defined('MOODLE_INTERNAL') || die();
require_once($CFG->dirroot . '/course/moodleform_mod.php');
/**
* Module instance settings form
*
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*
* @package mod_openwebinar
* @copyright 2015 MoodleFreak.com
* @author Luuk Verhoeven
*/
class mod_openwebinar_mod_form extends moodleform_mod {
/** @var array options to be used with date_time_selector fields in the openwebinar. */
public static $datefieldoptions = array('optional' => false, 'step' => 1);
/**
* Defines forms elements
*/
public function definition() {
global $CFG , $COURSE;
$mform = $this->_form;
// Load default config.
$config = get_config('openwebinar');
// 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('openwebinarname', 'openwebinar'), array('size' => '64'));
if (!empty($CFG->formatstringstriptags)) {
$mform->setType('name', PARAM_TEXT);
} else {
$mform->setType('name', PARAM_CLEAN);
}
$mform->addRule('name', null, 'required', null, 'client');
$mform->addRule('name', get_string('maximumchars', '', 255), 'maxlength', 255, 'client');
$mform->addHelpButton('name', 'openwebinarname', 'openwebinar');
// Adding the standard "intro" and "introformat" fields.
$this->standard_intro_elements();
$mform->addElement('header', 'timing', get_string('mod_setting:timing', 'openwebinar'));
// Open and close dates.
$mform->addElement('date_time_selector', 'timeopen', get_string('mod_setting:timeopen', 'openwebinar'),
self::$datefieldoptions);
$mform->addHelpButton('timeopen', 'mod_setting:timeopenhelp', 'openwebinar');
$mform->setDefault('timeopen', strtotime('+5 minutes'));
$mform->addElement('duration', 'duration', get_string('mod_setting:duration', 'openwebinar'),
array('defaultunit' => 3600, 'optional' => false));
$mform->addHelpButton('duration', 'mod_setting:durationhelp', 'openwebinar');
$mform->setDefault('duration', 3600);
$mform->addElement('header', 'settings', get_string('mod_setting:settings', 'openwebinar'));
$mform->addElement('selectyesno', 'stream', get_string('setting:stream', 'openwebinar'));
$mform->setDefault('stream', $config->stream);
$mform->addElement('selectyesno', 'chat', get_string('setting:chat', 'openwebinar'));
$mform->setDefault('chat', $config->chat);
$mform->addElement('selectyesno', 'filesharing', get_string('setting:filesharing', 'openwebinar'));
$mform->setDefault('filesharing', $config->filesharing);
$mform->addElement('selectyesno', 'filesharing_student', get_string('setting:filesharing_student', 'openwebinar'));
$mform->setDefault('filesharing_student', $config->filesharing_student);
$mform->addElement('selectyesno', 'showuserpicture', get_string('setting:showuserpicture', 'openwebinar'));
$mform->setDefault('showuserpicture', $config->showuserpicture);
$mform->addElement('selectyesno', 'userlist', get_string('setting:userlist', 'openwebinar'));
$mform->setDefault('userlist', $config->userlist);
$mform->addElement('selectyesno', 'ajax_timer', get_string('setting:ajax_timer', 'openwebinar'));
$mform->setDefault('ajax_timer', $config->ajax_timer);
$mform->addElement('selectyesno', 'emoticons', get_string('setting:emoticons', 'openwebinar'));
$mform->setDefault('emoticons', $config->emoticons);
$mform->addElement('selectyesno', 'hls', get_string('setting:hls', 'openwebinar'));
$mform->setDefault('hls', $config->hls);
$mform->addElement('header', 'broadcasterheader', get_string('mod_setting:broadcaster', 'openwebinar'));
$this->add_openwebinar_user_selector();
// Add broadcastkey.
if (empty($this->current->instance)) {
$key = \mod_openwebinar\helper::generate_key();
$obj = new stdClass();
$obj->broadcastkey = $key;
$mform->addElement('static', 'html_broadcastkey', get_string('mod_setting:broadcastkey', 'openwebinar'),
get_string('mod_setting:broadcastkey_desc', 'openwebinar', $obj));
// Add value to the form.
$mform->addElement('hidden', 'broadcastkey');
$mform->setType('broadcastkey', PARAM_TEXT);
$mform->setDefault('broadcastkey', $key);
} else {
$obj = new stdClass();
$obj->broadcastkey = $this->current->broadcastkey;
$mform->addElement('static', 'html_broadcastkey', get_string('mod_setting:broadcastkey', 'openwebinar'),
get_string('mod_setting:broadcastkey_desc', 'openwebinar', $obj));
}
$mform->addElement('header', 'reminders', get_string('mod_setting:reminders', 'openwebinar'));
$mform->addElement('duration', 'reminder_1', get_string('setting:reminder_1', 'openwebinar'));
$mform->setDefault('reminder_1', $config->reminder_1);
$mform->addElement('duration', 'reminder_2', get_string('setting:reminder_2', 'openwebinar'));
$mform->setDefault('reminder_2', $config->reminder_2);
$mform->addElement('duration', 'reminder_3', get_string('setting:reminder_3', 'openwebinar'));
$mform->setDefault('reminder_3', $config->reminder_3);
$mform->addElement('duration', 'reminder_4', get_string('setting:reminder_4', 'openwebinar'));
$mform->setDefault('reminder_4', $config->reminder_4);
// Feedback selector.
$array = \mod_openwebinar\helper::get_feedbacks_by_courseid($COURSE->id);
if(!empty($array)){
$mform->addElement('header', 'feedback', get_string('mod_setting:feedback', 'openwebinar'));
$mform->addElement('select', 'feedback_id', get_string('mod_setting:feedback_field', 'openwebinar'), $array);
}
// Add standard elements, common to all modules.
$this->standard_coursemodule_elements();
$mform->setDefault('completion', COMPLETION_TRACKING_AUTOMATIC);
$mform->setDefault('completionview', true);
// Add standard buttons, common to all modules.
$this->add_action_buttons();
}
/**
* add a select element for a broadcaster
*/
protected function add_openwebinar_user_selector() {
global $DB, $USER;
$array = array('' => get_string('mod_setting:make_a_selection', 'openwebinar'));
$rs = $DB->get_recordset_sql('SELECT {user}.id , {user}.firstname ,{user}.lastname
FROM {user}
WHERE {user}.deleted = 0
ORDER BY {user}.firstname ASC');
foreach ($rs as $user) {
$array[$user->id] = $user->firstname . " " . $user->lastname . " ({$user->id})";
}
$rs->close();
$this->_form->addElement('select', 'broadcaster', get_string('mod_setting:broadcaster', 'openwebinar'), $array);
$this->_form->addRule('broadcaster', null, 'required', null, 'client');
$this->_form->setDefault('broadcaster', $USER->id);
}
public function validation($data, $files) {
$errors = parent::validation($data, $files);
return $errors;
}
}