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
/**
18
 * Zoom external API
19
 *
20
 * @package    mod_zoom
21
 * @category   external
22
 * @author     Nick Stefanski <nstefanski@escoffier.edu>
23
 * @copyright  2017 Auguste Escoffier School of Culinary Arts {@link https://www.escoffier.edu}
24
 * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
25
 * @since      Moodle 3.1
26
 */
27
 
28
namespace mod_zoom;
29
 
30
defined('MOODLE_INTERNAL') || die;
31
 
32
require_once("$CFG->libdir/externallib.php");
33
 
34
use context_module;
35
use external_api;
36
use external_function_parameters;
37
use external_single_structure;
38
use external_value;
39
use external_warnings;
40
use invalid_response_exception;
41
 
42
/**
43
 * Zoom external functions
44
 */
45
class external extends external_api {
46
    /**
47
     * Returns description of method parameters
48
     *
49
     * @return external_function_parameters
50
     * @since Moodle 3.1
51
     */
52
    public static function get_state_parameters() {
53
        return new external_function_parameters(
54
            [
55
                'zoomid' => new external_value(PARAM_INT, 'zoom course module id'),
56
            ]
57
        );
58
    }
59
 
60
    /**
61
     * Determine if a zoom meeting is available, meeting status, and the start time, duration, and other meeting options.
62
     * This function grabs most of the options to display for users in /mod/zoom/view.php
63
     * Host functions are not currently supported
64
     *
65
     * @param int $zoomid the zoom course module id
66
     * @return array of warnings and status result
67
     * @since Moodle 3.1
68
     * @throws moodle_exception
69
     */
70
    public static function get_state($zoomid) {
71
        global $DB, $CFG;
72
        require_once($CFG->dirroot . "/mod/zoom/locallib.php");
73
 
74
        $params = self::validate_parameters(
75
            self::get_state_parameters(),
76
            [
77
                'zoomid' => $zoomid,
78
            ]
79
        );
80
        $warnings = [];
81
 
82
        // Request and permission validation.
83
        $cm = $DB->get_record('course_modules', ['id' => $params['zoomid']], '*', MUST_EXIST);
84
        $zoom = $DB->get_record('zoom', ['id' => $cm->instance], '*', MUST_EXIST);
85
 
86
        $context = context_module::instance($cm->id);
87
        self::validate_context($context);
88
 
89
        require_capability('mod/zoom:view', $context);
90
 
91
        // Call the zoom/locallib API.
92
        [$inprogress, $available, $finished] = zoom_get_state($zoom);
93
 
94
        $result = [];
95
        $result['available'] = $available;
96
 
97
        if ($zoom->recurring) {
98
            $result['start_time'] = 0;
99
            $result['duration'] = 0;
100
        } else {
101
            $result['start_time'] = $zoom->start_time;
102
            $result['duration'] = $zoom->duration;
103
        }
104
 
105
        $result['haspassword'] = (isset($zoom->password) && $zoom->password !== '');
106
        $result['joinbeforehost'] = $zoom->option_jbh;
107
        $result['startvideohost'] = $zoom->option_host_video;
108
        $result['startvideopart'] = $zoom->option_participants_video;
109
        $result['audioopt'] = $zoom->option_audio;
110
 
111
        if (!$zoom->recurring) {
112
            if ($zoom->exists_on_zoom == ZOOM_MEETING_EXPIRED) {
113
                $status = get_string('meeting_nonexistent_on_zoom', 'mod_zoom');
114
            } else if ($finished) {
115
                $status = get_string('meeting_finished', 'mod_zoom');
116
            } else if ($inprogress) {
117
                $status = get_string('meeting_started', 'mod_zoom');
118
            } else {
119
                $status = get_string('meeting_not_started', 'mod_zoom');
120
            }
121
        } else {
122
            $status = get_string('recurringmeetinglong', 'mod_zoom');
123
        }
124
 
125
        $result['status'] = $status;
126
 
127
        $result['warnings'] = $warnings;
128
        return $result;
129
    }
130
 
131
    /**
132
     * Returns description of method result value
133
     *
134
     * @return external_description
135
     * @since Moodle 3.1
136
     */
137
    public static function get_state_returns() {
138
        return new external_single_structure(
139
            [
140
                'available' => new external_value(PARAM_BOOL, 'if true, run grade_item_update and redirect to meeting url'),
141
 
142
                'start_time' => new external_value(PARAM_INT, 'meeting start time as unix timestamp (0 if recurring)'),
143
                'duration' => new external_value(PARAM_INT, 'meeting duration in seconds (0 if recurring)'),
144
 
145
                'haspassword' => new external_value(PARAM_BOOL, ''),
146
                'joinbeforehost' => new external_value(PARAM_BOOL, ''),
147
                'startvideohost' => new external_value(PARAM_BOOL, ''),
148
                'startvideopart' => new external_value(PARAM_BOOL, ''),
149
                'audioopt' => new external_value(PARAM_TEXT, ''),
150
 
151
                'status' => new external_value(PARAM_TEXT, 'meeting status: not_started, started, finished, expired, recurring'),
152
 
153
                'warnings' => new external_warnings(),
154
            ]
155
        );
156
    }
157
 
158
    /**
159
     * Returns description of method parameters
160
     *
161
     * @return external_function_parameters
162
     * @since Moodle 3.1
163
     */
164
    public static function grade_item_update_parameters() {
165
        return new external_function_parameters(
166
            [
167
                'zoomid' => new external_value(PARAM_INT, 'zoom course module id'),
168
            ]
169
        );
170
    }
171
 
172
    /**
173
     * Creates or updates grade item for the given zoom instance and returns join url.
174
     * This function grabs most of the options to display for users in /mod/zoom/view.php
175
     *
176
     * @param int $zoomid the zoom course module id
177
     * @return array of warnings and status result
178
     * @since Moodle 3.1
179
     * @throws moodle_exception
180
     */
181
    public static function grade_item_update($zoomid) {
182
        global $CFG;
183
        require_once($CFG->dirroot . '/mod/zoom/locallib.php');
184
 
185
        $params = self::validate_parameters(
186
            self::get_state_parameters(),
187
            [
188
                'zoomid' => $zoomid,
189
            ]
190
        );
191
        $warnings = [];
192
 
193
        $context = context_module::instance($params['zoomid']);
194
        self::validate_context($context);
195
 
196
        // Call load meeting function, do not use start url on mobile.
197
        $meetinginfo = zoom_load_meeting($params['zoomid'], $context, $usestarturl = false);
198
 
199
        // Pass url to join zoom meeting in order to redirect user.
200
        $result = [];
201
        if ($meetinginfo['nexturl']) {
202
            $result['status'] = true;
203
            $result['joinurl'] = $meetinginfo['nexturl']->__toString();
204
        } else {
205
            $warningmsg = clean_param($meetinginfo['error'], PARAM_TEXT);
206
            throw new invalid_response_exception($warningmsg);
207
        }
208
 
209
        $result['warnings'] = $warnings;
210
        return $result;
211
    }
212
 
213
    /**
214
     * Returns description of method result value
215
     *
216
     * @return external_description
217
     * @since Moodle 3.1
218
     */
219
    public static function grade_item_update_returns() {
220
        return new external_single_structure(
221
            [
222
                'status' => new external_value(PARAM_BOOL, 'status: true if success'),
223
                'joinurl' => new external_value(PARAM_RAW, 'Zoom meeting join url'),
224
                'warnings' => new external_warnings(),
225
            ]
226
        );
227
    }
228
}