-
Notifications
You must be signed in to change notification settings - Fork 12
/
editengine.php
95 lines (81 loc) · 3.43 KB
/
editengine.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
<?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/>.
/**
* Page for editing the configuration of a particular Opaque engine.
*
* @package qtype_opaque
* @copyright 2006 The Open University
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
require_once(dirname(__FILE__) . '/../../../config.php');
require_once($CFG->libdir . '/adminlib.php');
require_once($CFG->dirroot . '/question/type/opaque/enginemanager.php');
require_once($CFG->dirroot . '/question/type/opaque/edit_engine_form.php');
$engineid = optional_param('engineid', 0, PARAM_INT);
// Check the user is logged in.
require_login();
$context = context_system::instance();
require_capability('moodle/question:config', $context);
admin_externalpage_setup('qtypesettingopaque', '', null,
new moodle_url('/question/type/opaque/editengine.php', array('engineid' => $engineid)));
$PAGE->set_title(get_string('editquestionengine', 'qtype_opaque'));
$PAGE->navbar->add(get_string('editquestionengineshort', 'qtype_opaque'));
// Create form.
$mform = new qtype_opaque_engine_edit_form('editengine.php');
if ($mform->is_cancelled()) {
redirect(new moodle_url('/question/type/opaque/engines.php'));
} else if ($data = $mform->get_data()) {
$engine = new stdClass();
if (!empty($data->engineid)) {
$engine->id = $data->engineid;
}
$engine->name = $data->enginename;
$engine->passkey = trim($data->passkey);
$engine->questionengines = $mform->extracturllist($data, 'questionengineurls');
$engine->questionbanks = $mform->extracturllist($data, 'questionbankurls');
$engine->timeout = $data->timeout;
qtype_opaque_engine_manager::get()->save($engine);
if (!empty($data->engineid)) {
\qtype_opaque\event\engine_edited::create(array(
'objectid' => $engine->id,
'context' => $context,
))->trigger();
} else {
\qtype_opaque\event\engine_created::create(array(
'objectid' => $engine->id,
'context' => $context,
))->trigger();
}
redirect(new moodle_url('/question/type/opaque/engines.php'));
}
// Prepare defaults.
$defaults = new stdClass();
$defaults->engineid = $engineid;
if ($engineid) {
$engine = qtype_opaque_engine_manager::get()->load($engineid);
$defaults->enginename = $engine->name;
$defaults->questionengineurls = implode("\n", $engine->questionengines);
$defaults->questionbankurls = implode("\n", $engine->questionbanks);
$defaults->passkey = $engine->passkey;
$defaults->timeout = $engine->timeout;
}
$mform->set_data($defaults);
// Display the form.
echo $OUTPUT->header();
echo $OUTPUT->heading_with_help(get_string('editquestionengine', 'qtype_opaque'),
'editquestionengine', 'qtype_opaque');
$mform->display();
echo $OUTPUT->footer();