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 |
namespace mod_bigbluebuttonbn\external;
|
|
|
18 |
|
|
|
19 |
use core_course\external\helper_for_get_mods_by_courses;
|
|
|
20 |
use core_external\external_api;
|
|
|
21 |
use core_external\external_function_parameters;
|
|
|
22 |
use core_external\external_multiple_structure;
|
|
|
23 |
use core_external\external_single_structure;
|
|
|
24 |
use core_external\external_value;
|
|
|
25 |
use core_external\external_warnings;
|
|
|
26 |
use core_external\util as external_util;
|
|
|
27 |
|
|
|
28 |
/**
|
|
|
29 |
* External service to get activity per course
|
|
|
30 |
*
|
|
|
31 |
* This is mainly used by the mobile application.
|
|
|
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 get_bigbluebuttonbns_by_courses extends external_api {
|
|
|
39 |
/**
|
|
|
40 |
* Describes the parameters for get_bigbluebuttonbns_by_courses.
|
|
|
41 |
*
|
|
|
42 |
* @return external_function_parameters
|
|
|
43 |
* @since Moodle 3.11
|
|
|
44 |
*/
|
|
|
45 |
public static function execute_parameters() {
|
|
|
46 |
return new external_function_parameters([
|
|
|
47 |
'courseids' => new external_multiple_structure(
|
|
|
48 |
new external_value(PARAM_INT, 'Course id'), 'Array of course ids', VALUE_DEFAULT, []
|
|
|
49 |
),
|
|
|
50 |
]
|
|
|
51 |
);
|
|
|
52 |
}
|
|
|
53 |
|
|
|
54 |
/**
|
|
|
55 |
* Returns a list of bigbluebuttonbns in a provided list of courses.
|
|
|
56 |
* If no list is provided all bigbluebuttonbns that the user can view will be returned.
|
|
|
57 |
*
|
|
|
58 |
* @param array $courseids course ids
|
|
|
59 |
* @return array of warnings and bigbluebuttonbns
|
|
|
60 |
* @since Moodle 3.11
|
|
|
61 |
*/
|
|
|
62 |
public static function execute($courseids = []) {
|
|
|
63 |
global $USER;
|
|
|
64 |
$warnings = [];
|
|
|
65 |
$returnedbigbluebuttonbns = [];
|
|
|
66 |
|
|
|
67 |
['courseids' => $courseids] = self::validate_parameters(self::execute_parameters(), ['courseids' => $courseids]);
|
|
|
68 |
$mycourses = [];
|
|
|
69 |
if (empty($courseids)) {
|
|
|
70 |
$mycourses = enrol_get_my_courses();
|
|
|
71 |
$courseids = array_keys($mycourses);
|
|
|
72 |
}
|
|
|
73 |
|
|
|
74 |
// Ensure there are courseids to loop through.
|
|
|
75 |
if (!empty($courseids)) {
|
|
|
76 |
[$courses, $warnings] = external_util::validate_courses($courseids, $mycourses);
|
|
|
77 |
|
|
|
78 |
// Get the bigbluebuttonbns in this course, this function checks users visibility permissions.
|
|
|
79 |
// We can avoid then additional validate_context calls.
|
|
|
80 |
$bigbluebuttonbns = get_all_instances_in_courses("bigbluebuttonbn", $courses, $USER->id);
|
|
|
81 |
foreach ($bigbluebuttonbns as $bigbluebuttonbn) {
|
|
|
82 |
helper_for_get_mods_by_courses::format_name_and_intro($bigbluebuttonbn, 'mod_bigbluebuttonbn');
|
|
|
83 |
$returnedbigbluebuttonbns[] = $bigbluebuttonbn;
|
|
|
84 |
}
|
|
|
85 |
}
|
|
|
86 |
|
|
|
87 |
$result = [
|
|
|
88 |
'bigbluebuttonbns' => $returnedbigbluebuttonbns,
|
|
|
89 |
'warnings' => $warnings
|
|
|
90 |
];
|
|
|
91 |
return $result;
|
|
|
92 |
}
|
|
|
93 |
|
|
|
94 |
/**
|
|
|
95 |
* Describes the get_bigbluebuttonbns_by_courses return value.
|
|
|
96 |
*
|
|
|
97 |
* @return external_single_structure
|
|
|
98 |
* @since Moodle 3.11
|
|
|
99 |
*/
|
|
|
100 |
public static function execute_returns() {
|
|
|
101 |
return new external_single_structure([
|
|
|
102 |
'bigbluebuttonbns' => new external_multiple_structure(
|
|
|
103 |
new external_single_structure(array_merge(
|
|
|
104 |
helper_for_get_mods_by_courses::standard_coursemodule_elements_returns(),
|
|
|
105 |
[
|
|
|
106 |
'meetingid' => new external_value(PARAM_RAW, 'Meeting id'),
|
|
|
107 |
'timemodified' => new external_value(PARAM_INT, 'Last time the instance was modified'),
|
|
|
108 |
]
|
|
|
109 |
))
|
|
|
110 |
),
|
|
|
111 |
'warnings' => new external_warnings(),
|
|
|
112 |
]
|
|
|
113 |
);
|
|
|
114 |
}
|
|
|
115 |
}
|