-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathmod_form.php
203 lines (176 loc) · 7.37 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
191
192
193
194
195
196
197
198
199
200
201
202
203
<?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 ONLYOFFICE DocSpace 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_onlyofficedocspace
* @copyright 2025 Ascensio System SIA <[email protected]>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
use mod_onlyofficedocspace\local\docspace\docspace_settings;
use mod_onlyofficedocspace\local\moodle\moodle_docspace_user_manager;
defined('MOODLE_INTERNAL') || die();
require_once($CFG->dirroot . '/course/moodleform_mod.php');
/**
* New ONLYOFFICE DocSpace module 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_onlyofficedocspace
* @copyright 2025 Ascensio System SIA <[email protected]>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class mod_onlyofficedocspace_mod_form extends moodleform_mod {
/**
* Defines forms elements
*/
public function definition() {
global $CFG, $PAGE, $OUTPUT, $USER, $DB;
$mform = $this->_form;
$docspacesettings = new docspace_settings();
try {
$docspacesettings->healthCheck();
} catch (Exception) {
$mform->addElement('html', $OUTPUT->notification(get_string('docspaceunreachable', 'onlyofficedocspace'), 'error'));
$this->standard_hidden_coursemodule_elements();
return;
}
$moodledocspaceusermanager = new moodle_docspace_user_manager();
$docspaceuser = $moodledocspaceusermanager->get($USER->email);
if (!$docspaceuser) {
$mform->addElement('html', $OUTPUT->notification(get_string('docspaceusernotfound', 'onlyofficedocspace'), 'error'));
$this->standard_hidden_coursemodule_elements();
return;
}
// 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('activityname', 'onlyofficedocspace'), ['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');
// Adding the standard "intro" and "introformat" fields.
$this->standard_intro_elements();
$element = $mform->getElement('introeditor');
$attributes = $element->getAttributes();
$attributes['rows'] = 5;
$element->setAttributes($attributes);
$selectelements = [];
$onlyofficedocspaceactivity = null;
if ($this->_instance) {
$onlyofficedocspaceid = $this->_instance;
$onlyofficedocspaceactivity = $DB->get_record(
'onlyofficedocspace',
['id' => $onlyofficedocspaceid],
'docspaceitemid, docspaceitemtype, docspacerequesttoken, docspaceitemname, docspaceitemicon',
MUST_EXIST
);
}
$selectelements[] = &$mform->createElement(
'hidden',
'docspaceitemtype',
$onlyofficedocspaceactivity ? $onlyofficedocspaceactivity->docspaceitemtype : ''
);
$selectelements[] = &$mform->createElement(
'hidden',
'docspaceitemid',
$onlyofficedocspaceactivity ? $onlyofficedocspaceactivity->docspaceitemid : ''
);
$selectelements[] = &$mform->createElement(
'hidden',
'docspacerequesttoken',
$onlyofficedocspaceactivity ? $onlyofficedocspaceactivity->docspacerequesttoken : ''
);
$selectelements[] = &$mform->createElement(
'hidden',
'docspaceitemname',
$onlyofficedocspaceactivity ? $onlyofficedocspaceactivity->docspaceitemname : ''
);
$selectelements[] = &$mform->createElement(
'hidden',
'docspaceitemicon',
$onlyofficedocspaceactivity ? $onlyofficedocspaceactivity->docspaceitemicon : ''
);
$mform->setType('docspaceitemtype', PARAM_TEXT);
$mform->setType('docspaceitemid', PARAM_TEXT);
$mform->setType('docspacerequesttoken', PARAM_TEXT);
$mform->setType('docspaceitemname', PARAM_TEXT);
$mform->setType('docspaceitemicon', PARAM_TEXT);
$selectelements[] = &$mform->createElement('html', $OUTPUT->render_from_template('onlyofficedocspace/select_element', [
'docspaceurl' => $docspacesettings->url(),
]));
$PAGE->requires->js_call_amd(
'mod_onlyofficedocspace/select_element',
'init',
[
'docspaceUrl' => $docspacesettings->url(),
'user' => ['email' => $docspaceuser->email, 'hash' => $docspaceuser->password],
'activity' => $onlyofficedocspaceactivity,
],
);
$mform->addGroup(
$selectelements,
'select_element',
get_string('selectelement:room', 'onlyofficedocspace'),
'',
false
);
$mform->addRule(
'select_element',
get_string('required'),
'required',
null,
'client'
);
// Add standard grading elements.
// Add grading capability. need use case for grading.
// $this->standard_grading_coursemodule_elements();
// Add standard elements, common to all modules.
$this->standard_coursemodule_elements();
// Add standard buttons, common to all modules.
$this->add_action_buttons();
}
/**
* Form verification.
*
* @param array $data form data.
* @param array $files uploaded file.
* @return mixed of "element_name"=>"error_description" if there are errors,
* or an empty array if everything is OK (true allowed for backwards compatibility too).
*/
public function validation($data, $files) {
$errors = [];
$errors = parent::validation($data, $files);
if (
empty($data['docspaceitemtype'])
|| empty($data['docspaceitemid'])
|| empty($data['docspacerequesttoken'])
|| empty($data['docspaceitemname'])
|| empty($data['docspaceitemicon'])
) {
$errors['select_element'] = get_string('required');
}
return $errors;
}
}