Differences Between: [Versions 400 and 402] [Versions 401 and 402]
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_multiple_structure; 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\bigbluebutton\recordings\recording_data; 28 use mod_bigbluebuttonbn\local\proxy\bigbluebutton_proxy; 29 30 /** 31 * External service to fetch a list of recordings from the BBB service. 32 * 33 * @package mod_bigbluebuttonbn 34 * @category external 35 * @copyright 2018 onwards, Blindside Networks Inc 36 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later 37 */ 38 class get_recordings extends external_api { 39 /** 40 * Returns description of method parameters 41 * 42 * @return external_function_parameters 43 */ 44 public static function execute_parameters(): external_function_parameters { 45 return new external_function_parameters([ 46 'bigbluebuttonbnid' => new external_value(PARAM_INT, 'bigbluebuttonbn instance id'), 47 'tools' => new external_value(PARAM_RAW, 'a set of enabled tools', VALUE_DEFAULT, 48 'protect,unprotect,publish,unpublish,delete'), 49 'groupid' => new external_value(PARAM_INT, 'Group ID', VALUE_DEFAULT, null), 50 ]); 51 } 52 53 /** 54 * Get a list of recordings 55 * 56 * @param int $bigbluebuttonbnid the bigbluebuttonbn instance id to which the recordings are referred. 57 * @param string|null $tools 58 * @param int|null $groupid 59 * @return array of warnings and status result 60 * @throws \invalid_parameter_exception 61 * @throws restricted_context_exception 62 */ 63 public static function execute( 64 int $bigbluebuttonbnid = 0, 65 ?string $tools = 'protect,unprotect,publish,unpublish,delete', 66 ?int $groupid = null 67 ): array { 68 global $USER; 69 70 $returnval = [ 71 'status' => false, 72 'warnings' => [], 73 ]; 74 75 // Validate the bigbluebuttonbnid ID. 76 [ 77 'bigbluebuttonbnid' => $bigbluebuttonbnid, 78 'tools' => $tools, 79 'groupid' => $groupid, 80 ] = self::validate_parameters(self::execute_parameters(), [ 81 'bigbluebuttonbnid' => $bigbluebuttonbnid, 82 'tools' => $tools, 83 'groupid' => $groupid, 84 ]); 85 86 $tools = explode(',', $tools ?? 'protect,unprotect,publish,unpublish,delete'); 87 88 // Fetch the session, features, and profile. 89 $instance = instance::get_from_instanceid($bigbluebuttonbnid); 90 if (!$instance) { 91 $returnval['warnings'][] = [ 92 'item' => $bigbluebuttonbnid, 93 'warningcode' => 'nosuchinstance', 94 'message' => get_string('nosuchinstance', 'mod_bigbluebuttonbn', 95 (object) ['id' => $bigbluebuttonbnid, 'entity' => 'bigbluebuttonbn']) 96 ]; 97 } else { 98 $typeprofiles = bigbluebutton_proxy::get_instance_type_profiles(); 99 $profilefeature = $typeprofiles[$instance->get_type()]['features']; 100 $showrecordings = in_array('all', $profilefeature) || in_array('showrecordings', $profilefeature); 101 if ($showrecordings) { 102 $context = $instance->get_context(); 103 // Validate that the user has access to this activity. 104 self::validate_context($context); 105 if (!$instance->user_has_group_access($USER, $groupid)) { 106 new restricted_context_exception(); 107 } 108 if ($groupid) { 109 $instance->set_group_id($groupid); 110 } 111 $recordings = $instance->get_recordings([], $instance->get_instance_var('recordings_deleted') ?? false); 112 $tabledata = recording_data::get_recording_table($recordings, $tools, $instance); 113 114 $returnval['tabledata'] = $tabledata; 115 $returnval['status'] = true; 116 } else { 117 $returnval['warnings'][] = [ 118 'item' => $bigbluebuttonbnid, 119 'warningcode' => 'instanceprofilewithoutrecordings', 120 'message' => get_string('instanceprofilewithoutrecordings', 'mod_bigbluebuttonbn') 121 ]; 122 } 123 } 124 return $returnval; 125 } 126 127 /** 128 * Describe the return structure of the external service. 129 * 130 * @return external_single_structure 131 * @since Moodle 3.0 132 */ 133 public static function execute_returns(): external_single_structure { 134 return new external_single_structure([ 135 'status' => new external_value(PARAM_BOOL, 'Whether the fetch was successful'), 136 'tabledata' => new external_single_structure([ 137 'activity' => new external_value(PARAM_ALPHANUMEXT), 138 'ping_interval' => new external_value(PARAM_INT), 139 'locale' => new external_value(PARAM_TEXT), 140 'profile_features' => new external_multiple_structure(new external_value(PARAM_TEXT)), 141 'columns' => new external_multiple_structure(new external_single_structure([ 142 'key' => new external_value(PARAM_ALPHA), 143 'label' => new external_value(PARAM_TEXT), 144 'width' => new external_value(PARAM_ALPHANUMEXT), 145 // See https://datatables.net/reference/option/columns.type . 146 'type' => new external_value(PARAM_ALPHANUMEXT, 'Column type', VALUE_OPTIONAL), 147 'sortable' => new external_value(PARAM_BOOL, 'Whether this column is sortable', VALUE_OPTIONAL, false), 148 'allowHTML' => new external_value(PARAM_BOOL, 'Whether this column contains HTML', VALUE_OPTIONAL, false), 149 'formatter' => new external_value(PARAM_ALPHANUMEXT, 'Formatter name', VALUE_OPTIONAL), 150 ])), 151 'data' => new external_value(PARAM_RAW), // For now it will be json encoded. 152 ], '', VALUE_OPTIONAL), 153 'warnings' => new external_warnings() 154 ]); 155 } 156 }
title
Description
Body
title
Description
Body
title
Description
Body
title
Body