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 context_module;
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 mod_bigbluebuttonbn\instance;
26
 
27
/**
28
 * External service to trigger the course module viewed event and update the module completion status
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 view_bigbluebuttonbn extends external_api {
38
    /**
39
     * Returns description of method parameters
40
     *
41
     * @return external_function_parameters
42
     * @since Moodle 3.0
43
     */
44
    public static function execute_parameters() {
45
        return new external_function_parameters([
46
                'bigbluebuttonbnid' => new external_value(PARAM_INT, 'bigbluebuttonbn instance id'),
47
            ]
48
        );
49
    }
50
 
51
    /**
52
     * Trigger the course module viewed event and update the module completion status.
53
     *
54
     * @param int $instanceid the bigbluebuttonbn instance id
55
     * @return array of warnings and status result
56
     * @since Moodle 3.0
57
     */
58
    public static function execute($instanceid) {
59
        global $CFG;
60
        require_once($CFG->dirroot . "/mod/bigbluebuttonbn/lib.php");
61
 
62
        ['bigbluebuttonbnid' => $instanceid] = self::validate_parameters(
63
            self::execute_parameters(),
64
            ['bigbluebuttonbnid' => $instanceid]
65
        );
66
 
67
        $instance = instance::get_from_instanceid($instanceid);
68
 
69
        if (empty($instance)) {
70
            return [
71
                'status' => false,
72
                'warnings' => [
73
                    [
74
                        'item' => 'mod_bigbluebuttonbn',
75
                        'itemid' => 0,
76
                        'warningcode' => 'nosuchinstance',
77
                        'message' => get_string('nosuchinstance', 'mod_bigbluebuttonbn',
78
                            (object) ['id' => $instanceid, 'entity' => 'bigbluebuttonbn'])
79
                    ]
80
                ]
81
            ];
82
        }
83
        $context = context_module::instance($instance->get_cm_id());
84
        self::validate_context($context);
85
 
86
        require_capability('mod/bigbluebuttonbn:view', $context);
87
        // Call the bigbluebuttonbn/lib API.
88
        bigbluebuttonbn_view($instance->get_instance_data(), $instance->get_course(), $instance->get_cm(), $context);
89
        return [
90
            'status' => true,
91
            'warnings' => []
92
        ];
93
    }
94
 
95
    /**
96
     * Returns description of method result value
97
     *
98
     * @return \core_external\external_description
99
     * @since Moodle 3.0
100
     */
101
    public static function execute_returns() {
102
        return new external_single_structure([
103
                'status' => new external_value(PARAM_BOOL, 'status: true if success'),
104
                'warnings' => new external_warnings()
105
            ]
106
        );
107
    }
108
}