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_external\external_api;
|
|
|
20 |
use core_external\external_function_parameters;
|
|
|
21 |
use core_external\external_single_structure;
|
|
|
22 |
use core_external\external_value;
|
|
|
23 |
use core_external\restricted_context_exception;
|
|
|
24 |
use mod_bigbluebuttonbn\instance;
|
|
|
25 |
use mod_bigbluebuttonbn\meeting;
|
|
|
26 |
|
|
|
27 |
/**
|
|
|
28 |
* External service to check whether a user can join a meeting.
|
|
|
29 |
*
|
|
|
30 |
* This is mainly used by the mobile application.
|
|
|
31 |
*
|
|
|
32 |
* @package mod_bigbluebuttonbn
|
|
|
33 |
* @category external
|
|
|
34 |
* @copyright 2018 onwards, Blindside Networks Inc
|
|
|
35 |
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
|
|
36 |
*/
|
|
|
37 |
class can_join extends external_api {
|
|
|
38 |
/**
|
|
|
39 |
* Returns description of method parameters
|
|
|
40 |
*
|
|
|
41 |
* @return external_function_parameters
|
|
|
42 |
*/
|
|
|
43 |
public static function execute_parameters(): external_function_parameters {
|
|
|
44 |
return new external_function_parameters([
|
|
|
45 |
'cmid' => new external_value(PARAM_INT, 'course module id', VALUE_REQUIRED),
|
|
|
46 |
'groupid' => new external_value(PARAM_INT, 'bigbluebuttonbn group id', VALUE_DEFAULT, 0),
|
|
|
47 |
]);
|
|
|
48 |
}
|
|
|
49 |
|
|
|
50 |
/**
|
|
|
51 |
* Updates a recording
|
|
|
52 |
*
|
|
|
53 |
* @param int $cmid the bigbluebuttonbn course module id
|
|
|
54 |
* @param null|int $groupid
|
|
|
55 |
* @return array (empty array for now)
|
|
|
56 |
* @throws \restricted_context_exception
|
|
|
57 |
*/
|
|
|
58 |
public static function execute(
|
|
|
59 |
int $cmid,
|
|
|
60 |
?int $groupid = 0
|
|
|
61 |
): array {
|
|
|
62 |
// Validate the cmid ID.
|
|
|
63 |
[
|
|
|
64 |
'cmid' => $cmid,
|
|
|
65 |
'groupid' => $groupid,
|
|
|
66 |
] = self::validate_parameters(self::execute_parameters(), [
|
|
|
67 |
'cmid' => $cmid,
|
|
|
68 |
'groupid' => $groupid,
|
|
|
69 |
]);
|
|
|
70 |
|
|
|
71 |
$result = [
|
|
|
72 |
'can_join' => false,
|
|
|
73 |
'cmid' => $cmid,
|
|
|
74 |
];
|
|
|
75 |
|
|
|
76 |
$instance = instance::get_from_cmid($cmid);
|
|
|
77 |
if (empty($instance)) {
|
|
|
78 |
return $result;
|
|
|
79 |
}
|
|
|
80 |
// Validate the groupid.
|
|
|
81 |
if (!groups_group_visible($groupid, $instance->get_course(), $instance->get_cm())) {
|
|
|
82 |
throw new restricted_context_exception();
|
|
|
83 |
}
|
|
|
84 |
$instance->set_group_id($groupid);
|
|
|
85 |
|
|
|
86 |
self::validate_context($instance->get_context());
|
|
|
87 |
|
|
|
88 |
$meeting = new meeting($instance);
|
|
|
89 |
|
|
|
90 |
$result['can_join'] = $meeting->can_join();
|
|
|
91 |
|
|
|
92 |
return $result;
|
|
|
93 |
}
|
|
|
94 |
|
|
|
95 |
/**
|
|
|
96 |
* Describe the return structure of the external service.
|
|
|
97 |
*
|
|
|
98 |
* @return external_single_structure
|
|
|
99 |
* @since Moodle 3.3
|
|
|
100 |
*/
|
|
|
101 |
public static function execute_returns(): external_single_structure {
|
|
|
102 |
return new external_single_structure([
|
|
|
103 |
'can_join' => new external_value(PARAM_BOOL, 'Can join session'),
|
|
|
104 |
'cmid' => new external_value(PARAM_INT, 'course module id', VALUE_REQUIRED),
|
|
|
105 |
]);
|
|
|
106 |
}
|
|
|
107 |
}
|