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 |
/**
|
|
|
18 |
* Configure communication for a given instance.
|
|
|
19 |
*
|
|
|
20 |
* @package core_communication
|
|
|
21 |
* @copyright 2023 David Woloszyn <david.woloszyn@moodle.com>
|
|
|
22 |
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
|
|
23 |
*/
|
|
|
24 |
|
|
|
25 |
require_once('../config.php');
|
|
|
26 |
require_once('lib.php');
|
|
|
27 |
|
|
|
28 |
require_login();
|
|
|
29 |
|
|
|
30 |
$contextid = required_param('contextid', PARAM_INT);
|
|
|
31 |
$instanceid = required_param('instanceid', PARAM_INT);
|
|
|
32 |
$instancetype = required_param('instancetype', PARAM_TEXT);
|
|
|
33 |
$component = required_param('component', PARAM_COMPONENT);
|
|
|
34 |
$selectedcommunication = optional_param('selectedcommunication', null, PARAM_PLUGIN);
|
|
|
35 |
|
|
|
36 |
$context = \core\context::instance_by_id($contextid);
|
|
|
37 |
$instanceinfo = [
|
|
|
38 |
'contextid' => $context->id,
|
|
|
39 |
'instanceid' => $instanceid,
|
|
|
40 |
'instancetype' => $instancetype,
|
|
|
41 |
'component' => $component,
|
|
|
42 |
];
|
|
|
43 |
|
|
|
44 |
// Requires communication to be enabled.
|
|
|
45 |
if (!core_communication\api::is_available()) {
|
|
|
46 |
throw new \moodle_exception('communicationdisabled', 'communication');
|
|
|
47 |
}
|
|
|
48 |
|
|
|
49 |
// Attempt to load the communication instance with the provided params.
|
|
|
50 |
$communication = \core_communication\api::load_by_instance(
|
|
|
51 |
context: $context,
|
|
|
52 |
component: $component,
|
|
|
53 |
instancetype: $instancetype,
|
|
|
54 |
instanceid: $instanceid,
|
|
|
55 |
provider: $selectedcommunication,
|
|
|
56 |
);
|
|
|
57 |
|
|
|
58 |
// No communication, no way this form can be used.
|
|
|
59 |
if (!$communication) {
|
|
|
60 |
throw new \moodle_exception('nocommunicationinstance', 'communication');
|
|
|
61 |
}
|
|
|
62 |
|
|
|
63 |
// Set variables according to the component callback and use them on the page.
|
|
|
64 |
[$instance, $context, $heading, $returnurl] = component_callback(
|
|
|
65 |
$component,
|
|
|
66 |
'get_communication_instance_data',
|
|
|
67 |
[$instanceid]
|
|
|
68 |
);
|
|
|
69 |
|
|
|
70 |
// Set up the page.
|
|
|
71 |
$PAGE->set_context($context);
|
|
|
72 |
$PAGE->set_url('/communication/configure.php', $instanceinfo);
|
|
|
73 |
$PAGE->set_title(get_string('communication', 'communication'));
|
|
|
74 |
$PAGE->set_heading($heading);
|
|
|
75 |
$PAGE->add_body_class('limitedwidth');
|
|
|
76 |
|
|
|
77 |
// Append the instance data before passing to form object.
|
|
|
78 |
$instanceinfo['instancedata'] = $instance;
|
|
|
79 |
|
|
|
80 |
// Get our form definitions.
|
|
|
81 |
$form = new \core_communication\form\configure_form(
|
|
|
82 |
context: $context,
|
|
|
83 |
instanceid: $instanceinfo['instanceid'],
|
|
|
84 |
instancetype: $instanceinfo['instancetype'],
|
|
|
85 |
component: $instanceinfo['component'],
|
|
|
86 |
selectedcommunication: $selectedcommunication,
|
|
|
87 |
instancedata: $instanceinfo['instancedata'],
|
|
|
88 |
);
|
|
|
89 |
|
|
|
90 |
|
|
|
91 |
if ($form->is_cancelled()) {
|
|
|
92 |
redirect($returnurl);
|
|
|
93 |
} else if ($data = $form->get_data()) {
|
|
|
94 |
component_callback($component, 'update_communication_instance_data', [$data]);
|
|
|
95 |
redirect($returnurl);
|
|
|
96 |
}
|
|
|
97 |
|
|
|
98 |
// Display the page contents.
|
|
|
99 |
echo $OUTPUT->header();
|
|
|
100 |
echo $OUTPUT->heading(get_string('communication', 'communication'), 2);
|
|
|
101 |
$form->display();
|
|
|
102 |
echo $OUTPUT->footer();
|