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
|
|
|
* BigBlueButtonBN external API |
19
|
|
|
* |
20
|
|
|
* @package mod_bigbluebuttonbn |
21
|
|
|
* @category external |
22
|
|
|
* @copyright 2018 onwards, Blindside Networks Inc |
23
|
|
|
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later |
24
|
|
|
*/ |
25
|
|
|
|
26
|
|
|
defined('MOODLE_INTERNAL') || die; |
27
|
|
|
|
28
|
|
|
require_once("$CFG->libdir/externallib.php"); |
29
|
|
|
|
30
|
|
|
/** |
31
|
|
|
* BigBlueButtonBN external functions |
32
|
|
|
* |
33
|
|
|
* @package mod_bigbluebuttonbn |
34
|
|
|
* @category external |
35
|
|
|
* @copyright 2018 onwards, Blindside Networks Inc |
36
|
|
|
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later |
37
|
|
|
*/ |
38
|
|
|
class mod_bigbluebuttonbn_external extends external_api { |
39
|
|
|
|
40
|
|
|
/** |
41
|
|
|
* Returns description of method parameters |
42
|
|
|
* |
43
|
|
|
* @return external_function_parameters |
44
|
|
|
* @since Moodle 3.0 |
45
|
|
|
*/ |
46
|
|
|
public static function view_bigbluebuttonbn_parameters() { |
47
|
|
|
return new external_function_parameters( |
48
|
|
|
array( |
49
|
|
|
'bigbluebuttonbnid' => new external_value(PARAM_INT, 'bigbluebuttonbn instance id') |
50
|
|
|
) |
51
|
|
|
); |
52
|
|
|
} |
53
|
|
|
|
54
|
|
|
/** |
55
|
|
|
* Trigger the course module viewed event and update the module completion status. |
56
|
|
|
* |
57
|
|
|
* @param int $bigbluebuttonbnid the bigbluebuttonbn instance id |
58
|
|
|
* @return array of warnings and status result |
59
|
|
|
* @since Moodle 3.0 |
60
|
|
|
* @throws moodle_exception |
61
|
|
|
*/ |
62
|
|
|
public static function view_bigbluebuttonbn($bigbluebuttonbnid) { |
63
|
|
|
global $DB, $CFG; |
64
|
|
|
require_once($CFG->dirroot . "/mod/bigbluebuttonbn/lib.php"); |
65
|
|
|
|
66
|
|
|
$params = self::validate_parameters(self::view_bigbluebuttonbn_parameters(), |
67
|
|
|
array( |
68
|
|
|
'bigbluebuttonbnid' => $bigbluebuttonbnid |
69
|
|
|
)); |
70
|
|
|
$warnings = array(); |
71
|
|
|
|
72
|
|
|
// Request and permission validation. |
73
|
|
|
$bigbluebuttonbn = $DB->get_record('bigbluebuttonbn', array('id' => $params['bigbluebuttonbnid']), '*', MUST_EXIST); |
74
|
|
|
list($course, $cm) = get_course_and_cm_from_instance($bigbluebuttonbn, 'bigbluebuttonbn'); |
75
|
|
|
|
76
|
|
|
$context = context_module::instance($cm->id); |
77
|
|
|
self::validate_context($context); |
78
|
|
|
|
79
|
|
|
require_capability('mod/bigbluebuttonbn:view', $context); |
80
|
|
|
|
81
|
|
|
// Call the bigbluebuttonbn/lib API. |
82
|
|
|
bigbluebuttonbn_view($bigbluebuttonbn, $course, $cm, $context); |
83
|
|
|
|
84
|
|
|
$result = array(); |
85
|
|
|
$result['status'] = true; |
86
|
|
|
$result['warnings'] = $warnings; |
87
|
|
|
return $result; |
88
|
|
|
} |
89
|
|
|
|
90
|
|
|
/** |
91
|
|
|
* Returns description of method result value |
92
|
|
|
* |
93
|
|
|
* @return external_description |
94
|
|
|
* @since Moodle 3.0 |
95
|
|
|
*/ |
96
|
|
|
public static function view_bigbluebuttonbn_returns() { |
97
|
|
|
return new external_single_structure( |
98
|
|
|
array( |
99
|
|
|
'status' => new external_value(PARAM_BOOL, 'status: true if success'), |
100
|
|
|
'warnings' => new external_warnings() |
101
|
|
|
) |
102
|
|
|
); |
103
|
|
|
} |
104
|
|
|
|
105
|
|
|
/** |
106
|
|
|
* Describes the parameters for get_bigbluebuttonbns_by_courses. |
107
|
|
|
* |
108
|
|
|
* @return external_function_parameters |
109
|
|
|
* @since Moodle 3.3 |
110
|
|
|
*/ |
111
|
|
|
public static function get_bigbluebuttonbns_by_courses_parameters() { |
112
|
|
|
return new external_function_parameters ( |
113
|
|
|
array( |
114
|
|
|
'courseids' => new external_multiple_structure( |
115
|
|
|
new external_value(PARAM_INT, 'Course id'), 'Array of course ids', VALUE_DEFAULT, array() |
116
|
|
|
), |
117
|
|
|
) |
118
|
|
|
); |
119
|
|
|
} |
120
|
|
|
|
121
|
|
|
/** |
122
|
|
|
* Returns a list of bigbluebuttonbns in a provided list of courses. |
123
|
|
|
* If no list is provided all bigbluebuttonbns that the user can view will be returned. |
124
|
|
|
* |
125
|
|
|
* @param array $courseids course ids |
126
|
|
|
* @return array of warnings and bigbluebuttonbns |
127
|
|
|
* @since Moodle 3.3 |
128
|
|
|
*/ |
129
|
|
|
public static function get_bigbluebuttonbns_by_courses($courseids = array()) { |
130
|
|
|
|
131
|
|
|
$warnings = array(); |
132
|
|
|
$returnedbigbluebuttonbns = array(); |
133
|
|
|
|
134
|
|
|
$params = array( |
135
|
|
|
'courseids' => $courseids, |
136
|
|
|
); |
137
|
|
|
$params = self::validate_parameters(self::get_bigbluebuttonbns_by_courses_parameters(), $params); |
138
|
|
|
|
139
|
|
|
$mycourses = array(); |
140
|
|
|
if (empty($params['courseids'])) { |
141
|
|
|
$mycourses = enrol_get_my_courses(); |
142
|
|
|
$params['courseids'] = array_keys($mycourses); |
143
|
|
|
} |
144
|
|
|
|
145
|
|
|
// Ensure there are courseids to loop through. |
146
|
|
|
if (!empty($params['courseids'])) { |
147
|
|
|
|
148
|
|
|
list($courses, $warnings) = external_util::validate_courses($params['courseids'], $mycourses); |
149
|
|
|
|
150
|
|
|
// Get the bigbluebuttonbns in this course, this function checks users visibility permissions. |
151
|
|
|
// We can avoid then additional validate_context calls. |
152
|
|
|
$bigbluebuttonbns = get_all_instances_in_courses("bigbluebuttonbn", $courses); |
153
|
|
|
foreach ($bigbluebuttonbns as $bigbluebuttonbn) { |
154
|
|
|
$context = context_module::instance($bigbluebuttonbn->coursemodule); |
155
|
|
|
// Entry to return. |
156
|
|
|
$bigbluebuttonbn->name = external_format_string($bigbluebuttonbn->name, $context->id); |
157
|
|
|
|
158
|
|
|
list($bigbluebuttonbn->intro, $bigbluebuttonbn->introformat) = external_format_text($bigbluebuttonbn->intro, |
159
|
|
|
$bigbluebuttonbn->introformat, $context->id, 'mod_bigbluebuttonbn', 'intro', null); |
160
|
|
|
$bigbluebuttonbn->introfiles = external_util::get_area_files($context->id, |
161
|
|
|
'mod_bigbluebuttonbn', 'intro', false, false); |
162
|
|
|
|
163
|
|
|
$returnedbigbluebuttonbns[] = $bigbluebuttonbn; |
164
|
|
|
} |
165
|
|
|
} |
166
|
|
|
|
167
|
|
|
$result = array( |
168
|
|
|
'bigbluebuttonbns' => $returnedbigbluebuttonbns, |
169
|
|
|
'warnings' => $warnings |
170
|
|
|
); |
171
|
|
|
return $result; |
172
|
|
|
} |
173
|
|
|
|
174
|
|
|
/** |
175
|
|
|
* Describes the get_bigbluebuttonbns_by_courses return value. |
176
|
|
|
* |
177
|
|
|
* @return external_single_structure |
178
|
|
|
* @since Moodle 3.3 |
179
|
|
|
*/ |
180
|
|
|
public static function get_bigbluebuttonbns_by_courses_returns() { |
181
|
|
|
return new external_single_structure( |
182
|
|
|
array( |
183
|
|
|
'bigbluebuttonbns' => new external_multiple_structure( |
184
|
|
|
new external_single_structure( |
185
|
|
|
array( |
186
|
|
|
'id' => new external_value(PARAM_INT, 'Module id'), |
187
|
|
|
'coursemodule' => new external_value(PARAM_INT, 'Course module id'), |
188
|
|
|
'course' => new external_value(PARAM_INT, 'Course id'), |
189
|
|
|
'name' => new external_value(PARAM_RAW, 'Name'), |
190
|
|
|
'intro' => new external_value(PARAM_RAW, 'Description'), |
191
|
|
|
'introformat' => new external_format_value('intro', 'Summary format'), |
192
|
|
|
'introfiles' => new external_files('Files in the introduction text'), |
193
|
|
|
'timemodified' => new external_value(PARAM_INT, 'Last time the instance was modified'), |
194
|
|
|
'section' => new external_value(PARAM_INT, 'Course section id'), |
195
|
|
|
'visible' => new external_value(PARAM_INT, 'Module visibility'), |
196
|
|
|
'groupmode' => new external_value(PARAM_INT, 'Group mode'), |
197
|
|
|
'groupingid' => new external_value(PARAM_INT, 'Grouping id'), |
198
|
|
|
) |
199
|
|
|
) |
200
|
|
|
), |
201
|
|
|
'warnings' => new external_warnings(), |
202
|
|
|
) |
203
|
|
|
); |
204
|
|
|
} |
205
|
|
|
|
206
|
|
|
/** |
207
|
|
|
* Returns description of method parameters |
208
|
|
|
* |
209
|
|
|
* @return external_function_parameters |
210
|
|
|
* @since Moodle 3.0 |
211
|
|
|
*/ |
212
|
|
|
public static function can_join_parameters() { |
213
|
|
|
return new external_function_parameters( |
214
|
|
|
array( |
215
|
|
|
'cmid' => new external_value(PARAM_INT, 'course module id', VALUE_REQUIRED) |
216
|
|
|
) |
217
|
|
|
); |
218
|
|
|
} |
219
|
|
|
|
220
|
|
|
/** |
221
|
|
|
* This will check if current user can join the session from this module |
222
|
|
|
* @param int $cmid |
223
|
|
|
* @throws coding_exception |
224
|
|
|
* @throws dml_exception |
225
|
|
|
*/ |
226
|
|
|
public static function can_join($cmid) { |
227
|
|
|
global $SESSION, $CFG; |
228
|
|
|
require_once($CFG->dirroot . "/mod/bigbluebuttonbn/locallib.php"); |
229
|
|
|
|
230
|
|
|
$params = self::validate_parameters(self::can_join_parameters(), |
|
|
|
|
231
|
|
|
array( |
232
|
|
|
'cmid' => $cmid |
233
|
|
|
)); |
234
|
|
|
$canjoin = \mod_bigbluebuttonbn\locallib\bigbluebutton::can_join_meeting($cmid); |
235
|
|
|
$canjoin['cmid'] = $cmid; |
236
|
|
|
return $canjoin; |
237
|
|
|
} |
238
|
|
|
|
239
|
|
|
/** |
240
|
|
|
* Return value for can join function |
241
|
|
|
* |
242
|
|
|
* @return external_single_structure |
243
|
|
|
* @since Moodle 3.3 |
244
|
|
|
*/ |
245
|
|
|
public static function can_join_returns() { |
246
|
|
|
return new external_single_structure( |
247
|
|
|
array( |
248
|
|
|
'can_join' => new external_value(PARAM_BOOL, 'Can join session'), |
249
|
|
|
'message' => new external_value(PARAM_RAW, 'Message if we cannot join', VALUE_OPTIONAL), |
250
|
|
|
'cmid' => new external_value(PARAM_INT, 'course module id', VALUE_REQUIRED) |
251
|
|
|
) |
252
|
|
|
); |
253
|
|
|
} |
254
|
|
|
} |
255
|
|
|
|
This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.
Both the
$myVar
assignment in line 1 and the$higher
assignment in line 2 are dead. The first because$myVar
is never used and the second because$higher
is always overwritten for every possible time line.