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\notification;
20
use core_external\external_api;
21
use core_external\external_function_parameters;
22
use core_external\external_single_structure;
23
use core_external\external_value;
24
use core_external\external_warnings;
25
use core_external\restricted_context_exception;
26
use mod_bigbluebuttonbn\instance;
27
use mod_bigbluebuttonbn\local\exceptions\bigbluebutton_exception;
28
use mod_bigbluebuttonbn\logger;
29
use mod_bigbluebuttonbn\meeting;
30
 
31
/**
32
 * External service to end a meeting.
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 end_meeting 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
            'bigbluebuttonbnid' => new external_value(PARAM_INT, 'bigbluebuttonbn instance id'),
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 $bigbluebuttonbnid the bigbluebuttonbn instance id
56
     * @param int $groupid the groupid (either 0 or the groupid)
57
     * @return array (empty array for now)
58
     * @throws \invalid_parameter_exception
59
     * @throws \moodle_exception
60
     * @throws restricted_context_exception
61
     */
62
    public static function execute(
63
        int $bigbluebuttonbnid,
64
        int $groupid
65
    ): array {
66
        // Validate the bigbluebuttonbnid ID.
67
        [
68
            'bigbluebuttonbnid' => $bigbluebuttonbnid,
69
            'groupid' => $groupid,
70
        ] = self::validate_parameters(self::execute_parameters(), [
71
            'bigbluebuttonbnid' => $bigbluebuttonbnid,
72
            'groupid' => $groupid,
73
        ]);
74
 
75
        // Fetch the session, features, and profile.
76
        $instance = instance::get_from_instanceid($bigbluebuttonbnid);
77
        if (empty($instance)) {
78
            throw new \moodle_exception('Unknown Instance');
79
        }
80
        if (!groups_group_visible($groupid, $instance->get_course(), $instance->get_cm())) {
81
            throw new restricted_context_exception();
82
        }
83
        $instance->set_group_id($groupid);
84
        $context = $instance->get_context();
85
 
86
        // Validate that the user has access to this activity and to manage recordings.
87
        self::validate_context($context);
88
 
89
        if (!$instance->user_can_end_meeting()) {
90
            throw new restricted_context_exception();
91
        }
92
        // Execute the end command.
93
        $meeting = new meeting($instance);
94
        try {
95
            $meeting->end_meeting();
96
        } catch (bigbluebutton_exception $e) {
97
            return [
98
                'warnings' => [
99
                    [
100
                        'item' => $instance->get_meeting_name(),
101
                        'itemid' => $instance->get_instance_id(),
102
                        'warningcode' => 'notFound',
103
                        'message' => $e->getMessage()
104
                    ]
105
                ]
106
            ];
107
        }
108
        logger::log_meeting_ended_event($instance);
109
        // Update the cache.
110
        $meeting->update_cache();
111
        notification::add(get_string('end_session_notification', 'mod_bigbluebuttonbn'), notification::INFO);
112
        return [];
113
    }
114
 
115
    /**
116
     * Describe the return structure of the external service.
117
     *
118
     * @return external_single_structure
119
     * @since Moodle 3.0
120
     */
121
    public static function execute_returns(): external_single_structure {
122
        return new external_single_structure([
123
            'warnings' => new external_warnings(),
124
        ]);
125
    }
126
}