Proyectos de Subversion Moodle

Rev

| Ultima modificación | Ver Log |

Rev Autor Línea Nro. Línea
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\external_warnings;
24
use core_external\restricted_context_exception;
25
use mod_bigbluebuttonbn\instance;
26
use mod_bigbluebuttonbn\local\exceptions\meeting_join_exception;
27
use mod_bigbluebuttonbn\meeting;
28
 
29
/**
30
 * External service to create the meeting (if needed), check user limit, and return the join URL when we can join.
31
 *
32
 * This is mainly used by the mobile application.
33
 *
34
 * @package   mod_bigbluebuttonbn
35
 * @category  external
36
 * @copyright 2018 onwards, Blindside Networks Inc
37
 * @license   http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
38
 */
39
class get_join_url extends external_api {
40
    /**
41
     * Returns description of method parameters
42
     *
43
     * @return external_function_parameters
44
     */
45
    public static function execute_parameters(): external_function_parameters {
46
        return new external_function_parameters([
47
            'cmid' => new external_value(PARAM_INT, 'course module id', VALUE_REQUIRED),
48
            'groupid' => new external_value(PARAM_INT, 'bigbluebuttonbn group id', VALUE_DEFAULT, 0),
49
        ]);
50
    }
51
 
52
    /**
53
     * Updates a recording
54
     *
55
     * @param int $cmid the bigbluebuttonbn course module id
56
     * @param null|int $groupid
57
     * @return array (empty array for now)
58
     *
59
     * @throws restricted_context_exception
60
     */
61
    public static function execute(
62
        int $cmid,
63
        ?int $groupid = 0
64
    ): array {
65
        // Validate the cmid ID.
66
        [
67
            'cmid' => $cmid,
68
            'groupid' => $groupid,
69
        ] = self::validate_parameters(self::execute_parameters(), [
70
            'cmid' => $cmid,
71
            'groupid' => $groupid,
72
        ]);
73
        $result = ['warnings' => []];
74
 
75
        $instance = instance::get_from_cmid($cmid);
76
        if (empty($instance)) {
77
            throw new \moodle_exception('nosuchinstance', 'mod_bigbluebuttonbn', null,
78
                ['entity' => get_string('module', 'course'), 'id' => $cmid]);
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
        // Validate that the user has access to this activity and to join the meeting.
87
        self::validate_context($instance->get_context());
88
        if (!$instance->can_join()) {
89
            throw new restricted_context_exception();
90
        }
91
 
92
        try {
93
            $result['join_url'] = meeting::join_meeting($instance);
94
        } catch (meeting_join_exception $e) {
95
            $result['warnings'][] = [
96
                'item' => 'mod_bigbluebuttonbn',
97
                'itemid' => $instance->get_instance_id(),
98
                'warningcode' => $e->errorcode,
99
                'message' => $e->getMessage()
100
            ];
101
        }
102
        return $result;
103
    }
104
 
105
    /**
106
     * Describe the return structure of the external service.
107
     *
108
     * @return external_single_structure
109
     * @since Moodle 3.3
110
     */
111
    public static function execute_returns(): external_single_structure {
112
        return new external_single_structure([
113
            'join_url' => new external_value(PARAM_RAW, 'Can join session', VALUE_OPTIONAL),
114
            'warnings' => new external_warnings(),
115
        ]);
116
    }
117
}