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 mod_bigbluebuttonbn\instance;
25
use mod_bigbluebuttonbn\local\proxy\bigbluebutton_proxy;
26
 
27
/**
28
 * External service to validate completion.
29
 *
30
 * @package   mod_bigbluebuttonbn
31
 * @category  external
32
 * @copyright 2018 onwards, Blindside Networks Inc
33
 * @license   http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
34
 */
35
class completion_validate extends external_api {
36
    /**
37
     * Returns description of method parameters
38
     *
39
     * @return external_function_parameters
40
     */
41
    public static function execute_parameters(): external_function_parameters {
42
        return new external_function_parameters([
43
            'bigbluebuttonbnid' => new external_value(PARAM_INT, 'bigbluebuttonbn instance id'),
44
        ]);
45
    }
46
 
47
    /**
48
     * Mark activity as complete
49
     *
50
     * @param int $bigbluebuttonbnid the bigbluebuttonbn instance id
51
     * @return array (empty array for now)
52
     */
53
    public static function execute(
54
        int $bigbluebuttonbnid
55
    ): array {
56
        // Validate the bigbluebuttonbnid ID.
57
        [
58
            'bigbluebuttonbnid' => $bigbluebuttonbnid,
59
        ] = self::validate_parameters(self::execute_parameters(), [
60
            'bigbluebuttonbnid' => $bigbluebuttonbnid,
61
        ]);
62
        $result = ['warnings' => []];
63
        // Fetch the session, features, and profile.
64
        $instance = instance::get_from_instanceid($bigbluebuttonbnid);
65
        if ($instance) {
66
            $context = $instance->get_context();
67
 
68
            // Validate that the user has access to this activity.
69
            self::validate_context($context);
70
 
71
            // Get list with all the users enrolled in the course.
72
            [$sort, $sqlparams] = users_order_by_sql('u');
73
            if (has_capability('moodle/course:update', $context)) {
74
                $users = get_enrolled_users($context, 'mod/bigbluebuttonbn:view', 0, 'u.*', $sort);
75
                foreach ($users as $user) {
76
                    // Enqueue a task for processing the completion.
77
                    bigbluebutton_proxy::enqueue_completion_event($instance->get_instance_data(), $user->id);
78
                }
79
            } else {
80
                $result['warnings'][] = [
81
                    'item' => 'mod_bigbluebuttonbn',
82
                    'itemid' => $instance->get_instance_id(),
83
                    'warningcode' => 'nopermissions',
84
                    'message' => get_string('nopermissions', 'error', 'completion_validate')
85
                ];
86
            }
87
        } else {
88
            $result['warnings'][] = [
89
                'item' => 'mod_bigbluebuttonbn',
90
                'itemid' => $bigbluebuttonbnid,
91
                'warningcode' => 'indexerrorbbtn',
92
                'message' => get_string('index_error_bbtn', 'mod_bigbluebuttonbn', $bigbluebuttonbnid)
93
            ];
94
        }
95
        // We might want to return a status here or some warnings.
96
        return $result;
97
    }
98
 
99
    /**
100
     * Describe the return structure of the external service.
101
     *
102
     * @return external_single_structure
103
     * @since Moodle 3.0
104
     */
105
    public static function execute_returns(): external_single_structure {
106
        return new external_single_structure([
107
            'warnings' => new external_warnings(),
108
        ]);
109
    }
110
}