1 |
efrain |
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 |
// This file is part of BasicLTI4Moodle
|
|
|
18 |
//
|
|
|
19 |
// BasicLTI4Moodle is an IMS BasicLTI (Basic Learning Tools for Interoperability)
|
|
|
20 |
// consumer for Moodle 1.9 and Moodle 2.0. BasicLTI is a IMS Standard that allows web
|
|
|
21 |
// based learning tools to be easily integrated in LMS as native ones. The IMS BasicLTI
|
|
|
22 |
// specification is part of the IMS standard Common Cartridge 1.1 Sakai and other main LMS
|
|
|
23 |
// are already supporting or going to support BasicLTI. This project Implements the consumer
|
|
|
24 |
// for Moodle. Moodle is a Free Open source Learning Management System by Martin Dougiamas.
|
|
|
25 |
// BasicLTI4Moodle is a project iniciated and leaded by Ludo(Marc Alier) and Jordi Piguillem
|
|
|
26 |
// at the GESSI research group at UPC.
|
|
|
27 |
// SimpleLTI consumer for Moodle is an implementation of the early specification of LTI
|
|
|
28 |
// by Charles Severance (Dr Chuck) htp://dr-chuck.com , developed by Jordi Piguillem in a
|
|
|
29 |
// Google Summer of Code 2008 project co-mentored by Charles Severance and Marc Alier.
|
|
|
30 |
//
|
|
|
31 |
// BasicLTI4Moodle is copyright 2009 by Marc Alier Forment, Jordi Piguillem and Nikolas Galanis
|
|
|
32 |
// of the Universitat Politecnica de Catalunya http://www.upc.edu
|
|
|
33 |
// Contact info: Marc Alier Forment granludo @ gmail.com or marc.alier @ upc.edu.
|
|
|
34 |
|
|
|
35 |
/**
|
|
|
36 |
* This file defines de main basiclti configuration form
|
|
|
37 |
*
|
|
|
38 |
* @package mod_lti
|
|
|
39 |
* @copyright 2009 Marc Alier, Jordi Piguillem, Nikolas Galanis
|
|
|
40 |
* marc.alier@upc.edu
|
|
|
41 |
* @copyright 2009 Universitat Politecnica de Catalunya http://www.upc.edu
|
|
|
42 |
* @author Marc Alier
|
|
|
43 |
* @author Jordi Piguillem
|
|
|
44 |
* @author Nikolas Galanis
|
|
|
45 |
* @author Charles Severance
|
|
|
46 |
* @author Chris Scribner
|
|
|
47 |
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
|
|
48 |
*/
|
|
|
49 |
|
|
|
50 |
defined('MOODLE_INTERNAL') || die;
|
|
|
51 |
|
|
|
52 |
global $CFG;
|
|
|
53 |
require_once($CFG->libdir.'/formslib.php');
|
|
|
54 |
require_once($CFG->dirroot.'/mod/lti/locallib.php');
|
|
|
55 |
|
|
|
56 |
/**
|
|
|
57 |
* LTI Edit Form
|
|
|
58 |
*
|
|
|
59 |
* @package mod_lti
|
|
|
60 |
* @copyright 2009 Marc Alier, Jordi Piguillem, Nikolas Galanis
|
|
|
61 |
* marc.alier@upc.edu
|
|
|
62 |
* @copyright 2009 Universitat Politecnica de Catalunya http://www.upc.edu
|
|
|
63 |
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
|
|
64 |
*/
|
|
|
65 |
class mod_lti_edit_types_form extends moodleform {
|
|
|
66 |
|
|
|
67 |
/**
|
|
|
68 |
* Define this form.
|
|
|
69 |
*/
|
|
|
70 |
public function definition() {
|
|
|
71 |
global $CFG, $PAGE, $DB, $OUTPUT;
|
|
|
72 |
|
|
|
73 |
$mform =& $this->_form;
|
|
|
74 |
|
|
|
75 |
$istool = $this->_customdata && isset($this->_customdata->istool) && $this->_customdata->istool;
|
|
|
76 |
$typeid = $this->_customdata->id ?? '';
|
|
|
77 |
$clientid = $this->_customdata->clientid ?? '';
|
|
|
78 |
|
|
|
79 |
// Add basiclti elements.
|
|
|
80 |
$mform->addElement('header', 'setup', get_string('tool_settings', 'lti'));
|
|
|
81 |
|
|
|
82 |
$mform->addElement('text', 'lti_typename', get_string('typename', 'lti'));
|
|
|
83 |
$mform->setType('lti_typename', PARAM_TEXT);
|
|
|
84 |
$mform->addHelpButton('lti_typename', 'typename', 'lti');
|
|
|
85 |
$mform->addRule('lti_typename', null, 'required', null, 'client');
|
|
|
86 |
|
|
|
87 |
$mform->addElement('text', 'lti_toolurl', get_string('toolurl', 'lti'), array('size' => '64'));
|
|
|
88 |
$mform->setType('lti_toolurl', PARAM_URL);
|
|
|
89 |
$mform->addHelpButton('lti_toolurl', 'toolurl', 'lti');
|
|
|
90 |
|
|
|
91 |
$mform->addElement('textarea', 'lti_description', get_string('tooldescription', 'lti'), array('rows' => 4, 'cols' => 60));
|
|
|
92 |
$mform->setType('lti_description', PARAM_TEXT);
|
|
|
93 |
$mform->addHelpButton('lti_description', 'tooldescription', 'lti');
|
|
|
94 |
if (!$istool) {
|
|
|
95 |
$mform->addRule('lti_toolurl', null, 'required', null, 'client');
|
|
|
96 |
} else {
|
|
|
97 |
$mform->disabledIf('lti_toolurl', null);
|
|
|
98 |
}
|
|
|
99 |
|
|
|
100 |
if (!$istool) {
|
|
|
101 |
$options = array(
|
|
|
102 |
LTI_VERSION_1 => get_string('oauthsecurity', 'lti'),
|
|
|
103 |
LTI_VERSION_1P3 => get_string('jwtsecurity', 'lti'),
|
|
|
104 |
);
|
|
|
105 |
$mform->addElement('select', 'lti_ltiversion', get_string('ltiversion', 'lti'), $options);
|
|
|
106 |
$mform->setType('lti_ltiversion', PARAM_TEXT);
|
|
|
107 |
$mform->addHelpButton('lti_ltiversion', 'ltiversion', 'lti');
|
|
|
108 |
$mform->setDefault('lti_ltiversion', LTI_VERSION_1);
|
|
|
109 |
|
|
|
110 |
$mform->addElement('text', 'lti_resourcekey', get_string('resourcekey_admin', 'lti'));
|
|
|
111 |
$mform->setType('lti_resourcekey', PARAM_TEXT);
|
|
|
112 |
$mform->addHelpButton('lti_resourcekey', 'resourcekey_admin', 'lti');
|
|
|
113 |
$mform->hideIf('lti_resourcekey', 'lti_ltiversion', 'eq', LTI_VERSION_1P3);
|
|
|
114 |
$mform->setForceLtr('lti_resourcekey');
|
|
|
115 |
|
|
|
116 |
$mform->addElement('passwordunmask', 'lti_password', get_string('password_admin', 'lti'));
|
|
|
117 |
$mform->setType('lti_password', PARAM_RAW);
|
|
|
118 |
$mform->addHelpButton('lti_password', 'password_admin', 'lti');
|
|
|
119 |
$mform->hideIf('lti_password', 'lti_ltiversion', 'eq', LTI_VERSION_1P3);
|
|
|
120 |
|
|
|
121 |
if (!empty($typeid)) {
|
|
|
122 |
$mform->addElement('text', 'lti_clientid_disabled', get_string('clientidadmin', 'lti'));
|
|
|
123 |
$mform->setType('lti_clientid_disabled', PARAM_TEXT);
|
|
|
124 |
$mform->addHelpButton('lti_clientid_disabled', 'clientidadmin', 'lti');
|
|
|
125 |
$mform->hideIf('lti_clientid_disabled', 'lti_ltiversion', 'neq', LTI_VERSION_1P3);
|
|
|
126 |
$mform->disabledIf('lti_clientid_disabled', null);
|
|
|
127 |
$mform->setForceLtr('lti_clientid_disabled');
|
|
|
128 |
$mform->addElement('hidden', 'lti_clientid');
|
|
|
129 |
$mform->setType('lti_clientid', PARAM_TEXT);
|
|
|
130 |
}
|
|
|
131 |
|
|
|
132 |
$keyoptions = [
|
|
|
133 |
LTI_RSA_KEY => get_string('keytype_rsa', 'lti'),
|
|
|
134 |
LTI_JWK_KEYSET => get_string('keytype_keyset', 'lti'),
|
|
|
135 |
];
|
|
|
136 |
$mform->addElement('select', 'lti_keytype', get_string('keytype', 'lti'), $keyoptions);
|
|
|
137 |
$mform->setType('lti_keytype', PARAM_TEXT);
|
|
|
138 |
$mform->addHelpButton('lti_keytype', 'keytype', 'lti');
|
|
|
139 |
$mform->setDefault('lti_keytype', LTI_JWK_KEYSET);
|
|
|
140 |
$mform->hideIf('lti_keytype', 'lti_ltiversion', 'neq', LTI_VERSION_1P3);
|
|
|
141 |
|
|
|
142 |
$mform->addElement('textarea', 'lti_publickey', get_string('publickey', 'lti'), ['rows' => 8, 'cols' => 60]);
|
|
|
143 |
$mform->setType('lti_publickey', PARAM_TEXT);
|
|
|
144 |
$mform->addHelpButton('lti_publickey', 'publickey', 'lti');
|
|
|
145 |
$mform->hideIf('lti_publickey', 'lti_keytype', 'neq', LTI_RSA_KEY);
|
|
|
146 |
$mform->hideIf('lti_publickey', 'lti_ltiversion', 'neq', LTI_VERSION_1P3);
|
|
|
147 |
$mform->setForceLtr('lti_publickey');
|
|
|
148 |
|
|
|
149 |
$mform->addElement('text', 'lti_publickeyset', get_string('publickeyset', 'lti'), ['size' => '64']);
|
|
|
150 |
$mform->setType('lti_publickeyset', PARAM_TEXT);
|
|
|
151 |
$mform->addHelpButton('lti_publickeyset', 'publickeyset', 'lti');
|
|
|
152 |
$mform->hideIf('lti_publickeyset', 'lti_keytype', 'neq', LTI_JWK_KEYSET);
|
|
|
153 |
$mform->hideIf('lti_publickeyset', 'lti_ltiversion', 'neq', LTI_VERSION_1P3);
|
|
|
154 |
$mform->setForceLtr('lti_publickeyset');
|
|
|
155 |
|
|
|
156 |
$mform->addElement('text', 'lti_initiatelogin', get_string('initiatelogin', 'lti'), array('size' => '64'));
|
|
|
157 |
$mform->setType('lti_initiatelogin', PARAM_URL);
|
|
|
158 |
$mform->addHelpButton('lti_initiatelogin', 'initiatelogin', 'lti');
|
|
|
159 |
$mform->hideIf('lti_initiatelogin', 'lti_ltiversion', 'neq', LTI_VERSION_1P3);
|
|
|
160 |
|
|
|
161 |
$mform->addElement('textarea', 'lti_redirectionuris', get_string('redirectionuris', 'lti'),
|
|
|
162 |
array('rows' => 3, 'cols' => 60));
|
|
|
163 |
$mform->setType('lti_redirectionuris', PARAM_TEXT);
|
|
|
164 |
$mform->addHelpButton('lti_redirectionuris', 'redirectionuris', 'lti');
|
|
|
165 |
$mform->hideIf('lti_redirectionuris', 'lti_ltiversion', 'neq', LTI_VERSION_1P3);
|
|
|
166 |
$mform->setForceLtr('lti_redirectionuris');
|
|
|
167 |
}
|
|
|
168 |
|
|
|
169 |
if ($istool) {
|
|
|
170 |
$mform->addElement('textarea', 'lti_parameters', get_string('parameter', 'lti'), array('rows' => 4, 'cols' => 60));
|
|
|
171 |
$mform->setType('lti_parameters', PARAM_TEXT);
|
|
|
172 |
$mform->addHelpButton('lti_parameters', 'parameter', 'lti');
|
|
|
173 |
$mform->disabledIf('lti_parameters', null);
|
|
|
174 |
$mform->setForceLtr('lti_parameters');
|
|
|
175 |
}
|
|
|
176 |
|
|
|
177 |
$mform->addElement('textarea', 'lti_customparameters', get_string('custom', 'lti'), array('rows' => 4, 'cols' => 60));
|
|
|
178 |
$mform->setType('lti_customparameters', PARAM_TEXT);
|
|
|
179 |
$mform->addHelpButton('lti_customparameters', 'custom', 'lti');
|
|
|
180 |
$mform->setForceLtr('lti_customparameters');
|
|
|
181 |
|
|
|
182 |
if (!empty($this->_customdata->isadmin)) {
|
|
|
183 |
// Only site-level preconfigured tools allow the control of course visibility in the site admin tool type form.
|
|
|
184 |
if (empty($this->_customdata->iscoursetool) || !$this->_customdata->iscoursetool) {
|
|
|
185 |
$options = array(
|
|
|
186 |
LTI_COURSEVISIBLE_NO => get_string('show_in_course_no', 'lti'),
|
|
|
187 |
LTI_COURSEVISIBLE_PRECONFIGURED => get_string('show_in_course_preconfigured', 'lti'),
|
|
|
188 |
LTI_COURSEVISIBLE_ACTIVITYCHOOSER => get_string('show_in_course_activity_chooser', 'lti'),
|
|
|
189 |
);
|
|
|
190 |
if ($istool) {
|
|
|
191 |
// LTI2 tools can not be matched by URL, they have to be either in preconfigured tools or in activity chooser.
|
|
|
192 |
unset($options[LTI_COURSEVISIBLE_NO]);
|
|
|
193 |
$stringname = 'show_in_course_lti2';
|
|
|
194 |
} else {
|
|
|
195 |
$stringname = 'show_in_course_lti1';
|
|
|
196 |
}
|
|
|
197 |
$mform->addElement('select', 'lti_coursevisible', get_string($stringname, 'lti'), $options);
|
|
|
198 |
$mform->addHelpButton('lti_coursevisible', $stringname, 'lti');
|
|
|
199 |
$mform->setDefault('lti_coursevisible', '1');
|
|
|
200 |
}
|
|
|
201 |
} else {
|
|
|
202 |
$mform->addElement('hidden', 'lti_coursevisible', LTI_COURSEVISIBLE_ACTIVITYCHOOSER);
|
|
|
203 |
}
|
|
|
204 |
$mform->setType('lti_coursevisible', PARAM_INT);
|
|
|
205 |
|
|
|
206 |
$mform->addElement('hidden', 'typeid');
|
|
|
207 |
$mform->setType('typeid', PARAM_INT);
|
|
|
208 |
|
|
|
209 |
$launchoptions = array();
|
|
|
210 |
$launchoptions[LTI_LAUNCH_CONTAINER_EMBED] = get_string('embed', 'lti');
|
|
|
211 |
$launchoptions[LTI_LAUNCH_CONTAINER_EMBED_NO_BLOCKS] = get_string('embed_no_blocks', 'lti');
|
|
|
212 |
$launchoptions[LTI_LAUNCH_CONTAINER_REPLACE_MOODLE_WINDOW] = get_string('existing_window', 'lti');
|
|
|
213 |
$launchoptions[LTI_LAUNCH_CONTAINER_WINDOW] = get_string('new_window', 'lti');
|
|
|
214 |
|
|
|
215 |
$mform->addElement('select', 'lti_launchcontainer', get_string('default_launch_container', 'lti'), $launchoptions);
|
|
|
216 |
$mform->setDefault('lti_launchcontainer', LTI_LAUNCH_CONTAINER_EMBED_NO_BLOCKS);
|
|
|
217 |
$mform->addHelpButton('lti_launchcontainer', 'default_launch_container', 'lti');
|
|
|
218 |
$mform->setType('lti_launchcontainer', PARAM_INT);
|
|
|
219 |
|
|
|
220 |
$mform->addElement('advcheckbox', 'lti_contentitem', get_string('contentitem_deeplinking', 'lti'));
|
|
|
221 |
$mform->addHelpButton('lti_contentitem', 'contentitem_deeplinking', 'lti');
|
|
|
222 |
if ($istool) {
|
|
|
223 |
$mform->disabledIf('lti_contentitem', null);
|
|
|
224 |
}
|
|
|
225 |
|
|
|
226 |
$mform->addElement('text', 'lti_toolurl_ContentItemSelectionRequest',
|
|
|
227 |
get_string('toolurl_contentitemselectionrequest', 'lti'), array('size' => '64'));
|
|
|
228 |
$mform->setType('lti_toolurl_ContentItemSelectionRequest', PARAM_URL);
|
|
|
229 |
$mform->addHelpButton('lti_toolurl_ContentItemSelectionRequest', 'toolurl_contentitemselectionrequest', 'lti');
|
|
|
230 |
$mform->disabledIf('lti_toolurl_ContentItemSelectionRequest', 'lti_contentitem', 'notchecked');
|
|
|
231 |
if ($istool) {
|
|
|
232 |
$mform->disabledIf('lti_toolurl__ContentItemSelectionRequest', null);
|
|
|
233 |
}
|
|
|
234 |
|
|
|
235 |
$mform->addElement('hidden', 'oldicon');
|
|
|
236 |
$mform->setType('oldicon', PARAM_URL);
|
|
|
237 |
|
|
|
238 |
$mform->addElement('text', 'lti_icon', get_string('icon_url', 'lti'), array('size' => '64'));
|
|
|
239 |
$mform->setType('lti_icon', PARAM_URL);
|
|
|
240 |
$mform->setAdvanced('lti_icon');
|
|
|
241 |
$mform->addHelpButton('lti_icon', 'icon_url', 'lti');
|
|
|
242 |
|
|
|
243 |
$mform->addElement('text', 'lti_secureicon', get_string('secure_icon_url', 'lti'), array('size' => '64'));
|
|
|
244 |
$mform->setType('lti_secureicon', PARAM_URL);
|
|
|
245 |
$mform->setAdvanced('lti_secureicon');
|
|
|
246 |
$mform->addHelpButton('lti_secureicon', 'secure_icon_url', 'lti');
|
|
|
247 |
|
|
|
248 |
// Restrict to course categories.
|
|
|
249 |
if (empty($this->_customdata->iscoursetool) || !$this->_customdata->iscoursetool) {
|
|
|
250 |
$mform->addElement('header', 'coursecategory', get_string('restricttocategory', 'lti'));
|
|
|
251 |
$mform->addHelpButton('coursecategory', 'restricttocategory', 'lti');
|
|
|
252 |
$records = $DB->get_records('course_categories', [], 'sortorder, id', 'id,parent,name');
|
|
|
253 |
// Convert array of objects to two dimentional array.
|
|
|
254 |
$tree = $this->lti_build_category_tree(array_map(fn($record) => (array)$record, $records));
|
|
|
255 |
$mform->addElement('html', $OUTPUT->render_from_template('mod_lti/categorynode', ['nodes' => $tree]));
|
|
|
256 |
$mform->addElement('hidden', 'lti_coursecategories');
|
|
|
257 |
$mform->setType('lti_coursecategories', PARAM_TEXT);
|
|
|
258 |
}
|
|
|
259 |
|
|
|
260 |
if (!$istool) {
|
|
|
261 |
// Display the lti advantage services.
|
|
|
262 |
$this->get_lti_advantage_services($mform);
|
|
|
263 |
}
|
|
|
264 |
|
|
|
265 |
if (!$istool) {
|
|
|
266 |
// Add privacy preferences fieldset where users choose whether to send their data.
|
|
|
267 |
$mform->addElement('header', 'privacy', get_string('privacy', 'lti'));
|
|
|
268 |
|
|
|
269 |
$options = array();
|
|
|
270 |
$options[0] = get_string('never', 'lti');
|
|
|
271 |
$options[1] = get_string('always', 'lti');
|
|
|
272 |
|
|
|
273 |
$mform->addElement('select', 'lti_sendname', get_string('share_name_admin', 'lti'), $options);
|
|
|
274 |
$mform->setType('lti_sendname', PARAM_INT);
|
|
|
275 |
$mform->setDefault('lti_sendname', '0');
|
|
|
276 |
$mform->addHelpButton('lti_sendname', 'share_name_admin', 'lti');
|
|
|
277 |
|
|
|
278 |
$mform->addElement('select', 'lti_sendemailaddr', get_string('share_email_admin', 'lti'), $options);
|
|
|
279 |
$mform->setType('lti_sendemailaddr', PARAM_INT);
|
|
|
280 |
$mform->setDefault('lti_sendemailaddr', '0');
|
|
|
281 |
$mform->addHelpButton('lti_sendemailaddr', 'share_email_admin', 'lti');
|
|
|
282 |
|
|
|
283 |
// LTI Extensions.
|
|
|
284 |
|
|
|
285 |
// Add grading preferences fieldset where the tool is allowed to return grades.
|
|
|
286 |
$gradeoptions = array();
|
|
|
287 |
$gradeoptions[] = get_string('never', 'lti');
|
|
|
288 |
$gradeoptions[] = get_string('always', 'lti');
|
|
|
289 |
$gradeoptions[] = get_string('delegate_tool', 'lti');
|
|
|
290 |
|
|
|
291 |
$mform->addElement('select', 'lti_acceptgrades', get_string('accept_grades_admin', 'lti'), $gradeoptions);
|
|
|
292 |
$mform->setType('lti_acceptgrades', PARAM_INT);
|
|
|
293 |
$mform->setDefault('lti_acceptgrades', '2');
|
|
|
294 |
$mform->addHelpButton('lti_acceptgrades', 'accept_grades_admin', 'lti');
|
|
|
295 |
|
|
|
296 |
$mform->addElement('checkbox', 'lti_forcessl', get_string('force_ssl', 'lti'));
|
|
|
297 |
$mform->setType('lti_forcessl', PARAM_BOOL);
|
|
|
298 |
if (!empty($CFG->mod_lti_forcessl)) {
|
|
|
299 |
$mform->setDefault('lti_forcessl', '1');
|
|
|
300 |
$mform->freeze('lti_forcessl');
|
|
|
301 |
} else {
|
|
|
302 |
$mform->setDefault('lti_forcessl', '0');
|
|
|
303 |
}
|
|
|
304 |
$mform->addHelpButton('lti_forcessl', 'force_ssl', 'lti');
|
|
|
305 |
|
|
|
306 |
if (!empty($this->_customdata->isadmin)) {
|
|
|
307 |
// Add setup parameters fieldset.
|
|
|
308 |
$mform->addElement('header', 'setupoptions', get_string('miscellaneous', 'lti'));
|
|
|
309 |
|
|
|
310 |
$options = array(
|
|
|
311 |
LTI_DEFAULT_ORGID_SITEID => get_string('siteid', 'lti'),
|
|
|
312 |
LTI_DEFAULT_ORGID_SITEHOST => get_string('sitehost', 'lti'),
|
|
|
313 |
);
|
|
|
314 |
|
|
|
315 |
$mform->addElement('select', 'lti_organizationid_default', get_string('organizationid_default', 'lti'), $options);
|
|
|
316 |
$mform->setType('lti_organizationid_default', PARAM_TEXT);
|
|
|
317 |
$mform->setDefault('lti_organizationid_default', LTI_DEFAULT_ORGID_SITEID);
|
|
|
318 |
$mform->addHelpButton('lti_organizationid_default', 'organizationid_default', 'lti');
|
|
|
319 |
|
|
|
320 |
$mform->addElement('text', 'lti_organizationid', get_string('organizationidguid', 'lti'));
|
|
|
321 |
$mform->setType('lti_organizationid', PARAM_TEXT);
|
|
|
322 |
$mform->addHelpButton('lti_organizationid', 'organizationidguid', 'lti');
|
|
|
323 |
|
|
|
324 |
$mform->addElement('text', 'lti_organizationurl', get_string('organizationurl', 'lti'));
|
|
|
325 |
$mform->setType('lti_organizationurl', PARAM_URL);
|
|
|
326 |
$mform->addHelpButton('lti_organizationurl', 'organizationurl', 'lti');
|
|
|
327 |
}
|
|
|
328 |
}
|
|
|
329 |
|
|
|
330 |
/* Suppress this for now - Chuck
|
|
|
331 |
* mform->addElement('text', 'lti_organizationdescr', get_string('organizationdescr', 'lti'))
|
|
|
332 |
* mform->setType('lti_organizationdescr', PARAM_TEXT)
|
|
|
333 |
* mform->addHelpButton('lti_organizationdescr', 'organizationdescr', 'lti')
|
|
|
334 |
*/
|
|
|
335 |
|
|
|
336 |
/*
|
|
|
337 |
// Add a hidden element to signal a tool fixing operation after a problematic backup - restore process
|
|
|
338 |
//$mform->addElement('hidden', 'lti_fix');
|
|
|
339 |
*/
|
|
|
340 |
|
|
|
341 |
$tab = optional_param('tab', '', PARAM_ALPHAEXT);
|
|
|
342 |
$mform->addElement('hidden', 'tab', $tab);
|
|
|
343 |
$mform->setType('tab', PARAM_ALPHAEXT);
|
|
|
344 |
|
|
|
345 |
$courseid = optional_param('course', 1, PARAM_INT);
|
|
|
346 |
$mform->addElement('hidden', 'course', $courseid);
|
|
|
347 |
$mform->setType('course', PARAM_INT);
|
|
|
348 |
|
|
|
349 |
// Add standard buttons, common to all modules.
|
|
|
350 |
$this->add_action_buttons();
|
|
|
351 |
|
|
|
352 |
}
|
|
|
353 |
|
|
|
354 |
/**
|
|
|
355 |
* Retrieves the data of the submitted form.
|
|
|
356 |
*
|
|
|
357 |
* @return stdClass
|
|
|
358 |
*/
|
|
|
359 |
public function get_data() {
|
|
|
360 |
$data = parent::get_data();
|
|
|
361 |
if ($data && !empty($this->_customdata->istool)) {
|
|
|
362 |
// Content item checkbox is disabled in tool settings, so this cannot be edited. Just unset it.
|
|
|
363 |
unset($data->lti_contentitem);
|
|
|
364 |
}
|
|
|
365 |
return $data;
|
|
|
366 |
}
|
|
|
367 |
|
|
|
368 |
/**
|
|
|
369 |
* Generates the lti advantage extra configuration adding it to the mform
|
|
|
370 |
*
|
|
|
371 |
* @param MoodleQuickForm $mform
|
|
|
372 |
*/
|
|
|
373 |
public function get_lti_advantage_services(&$mform) {
|
|
|
374 |
// For each service add the label and get the array of configuration.
|
|
|
375 |
$services = lti_get_services();
|
|
|
376 |
$mform->addElement('header', 'services', get_string('services', 'lti'));
|
|
|
377 |
foreach ($services as $service) {
|
|
|
378 |
/** @var \mod_lti\local\ltiservice\service_base $service */
|
|
|
379 |
$service->get_configuration_options($mform);
|
|
|
380 |
}
|
|
|
381 |
}
|
|
|
382 |
|
|
|
383 |
/**
|
|
|
384 |
* Validate the form data before we allow them to save the tool type.
|
|
|
385 |
*
|
|
|
386 |
* @param array $data
|
|
|
387 |
* @param array $files
|
|
|
388 |
* @return array Error messages
|
|
|
389 |
*/
|
|
|
390 |
public function validation($data, $files) {
|
|
|
391 |
global $CFG;
|
|
|
392 |
|
|
|
393 |
$errors = parent::validation($data, $files);
|
|
|
394 |
|
|
|
395 |
// LTI2 tools do not contain a ltiversion field.
|
|
|
396 |
if (isset($data['lti_ltiversion']) && $data['lti_ltiversion'] == LTI_VERSION_1P3) {
|
|
|
397 |
require_once($CFG->dirroot . '/mod/lti/upgradelib.php');
|
|
|
398 |
|
|
|
399 |
$warning = mod_lti_verify_private_key();
|
|
|
400 |
if (!empty($warning)) {
|
|
|
401 |
$errors['lti_ltiversion'] = $warning;
|
|
|
402 |
return $errors;
|
|
|
403 |
}
|
|
|
404 |
}
|
|
|
405 |
return $errors;
|
|
|
406 |
}
|
|
|
407 |
|
|
|
408 |
/**
|
|
|
409 |
* Build category tree.
|
|
|
410 |
*
|
|
|
411 |
* @param array $elements
|
|
|
412 |
* @param int $parentid
|
|
|
413 |
* @return array category tree
|
|
|
414 |
*/
|
|
|
415 |
public function lti_build_category_tree(array $elements, int $parentid = 0): array {
|
|
|
416 |
$branch = [];
|
|
|
417 |
|
|
|
418 |
foreach ($elements as $element) {
|
|
|
419 |
if ($element['parent'] == $parentid) {
|
|
|
420 |
$children = $this->lti_build_category_tree($elements, $element['id']);
|
|
|
421 |
if ($children) {
|
|
|
422 |
$element['nodes'] = $children;
|
|
|
423 |
$element['haschildren'] = true;
|
|
|
424 |
} else {
|
|
|
425 |
$element['nodes'] = null;
|
|
|
426 |
$element['haschildren'] = false;
|
|
|
427 |
}
|
|
|
428 |
$branch[] = $element;
|
|
|
429 |
}
|
|
|
430 |
}
|
|
|
431 |
return $branch;
|
|
|
432 |
}
|
|
|
433 |
|
|
|
434 |
public function definition_after_data() {
|
|
|
435 |
// Add the deprecated "Delegate to teacher" option to the "Share launcher's name" and "Share launcher's email" fields for
|
|
|
436 |
// existing types which are already using this setting value. This ensures that editing the tool type won't result in a
|
|
|
437 |
// change to the existing value. Add the option as a disabled to make this clear. Once changed, it cannot be set again.
|
|
|
438 |
// This isn't supported from 4.3 onward in the creation of new tool types.
|
|
|
439 |
foreach (['lti_sendname', 'lti_sendemailaddr'] as $elementname) {
|
|
|
440 |
if (!empty($this->_form->_defaultValues[$elementname])
|
|
|
441 |
&& $this->_form->_defaultValues[$elementname] == LTI_SETTING_DELEGATE) {
|
|
|
442 |
|
|
|
443 |
$elementarr = array_filter($this->_form->_elements, function ($element) use($elementname) {
|
|
|
444 |
return !empty($element->_attributes['name']) && $element->_attributes['name'] == $elementname;
|
|
|
445 |
});
|
|
|
446 |
/** @var MoodleQuickForm_select $element */
|
|
|
447 |
$element = array_shift($elementarr);
|
|
|
448 |
|
|
|
449 |
$element->addOption(
|
|
|
450 |
get_string('delegate', 'mod_lti'),
|
|
|
451 |
LTI_SETTING_DELEGATE,
|
|
|
452 |
['disabled' => 'disabled', 'selected' => 'selected']
|
|
|
453 |
);
|
|
|
454 |
}
|
|
|
455 |
}
|
|
|
456 |
}
|
|
|
457 |
}
|