Differences Between: [Versions 400 and 402] [Versions 400 and 403]
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 external_api; 20 use external_function_parameters; 21 use external_single_structure; 22 use external_value; 23 use mod_bigbluebuttonbn\instance; 24 use mod_bigbluebuttonbn\local\proxy\bigbluebutton_proxy; 25 26 defined('MOODLE_INTERNAL') || die(); 27 28 global $CFG; 29 require_once($CFG->libdir . '/externallib.php'); 30 31 /** 32 * External service to validate completion. 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 completion_validate 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 ]); 49 } 50 51 /** 52 * Mark activity as complete 53 * 54 * @param int $bigbluebuttonbnid the bigbluebuttonbn instance id 55 * @return array (empty array for now) 56 */ 57 public static function execute( 58 int $bigbluebuttonbnid 59 ): array { 60 // Validate the bigbluebuttonbnid ID. 61 [ 62 'bigbluebuttonbnid' => $bigbluebuttonbnid, 63 ] = self::validate_parameters(self::execute_parameters(), [ 64 'bigbluebuttonbnid' => $bigbluebuttonbnid, 65 ]); 66 $result = ['warnings' => []]; 67 // Fetch the session, features, and profile. 68 $instance = instance::get_from_instanceid($bigbluebuttonbnid); 69 if ($instance) { 70 $context = $instance->get_context(); 71 72 // Validate that the user has access to this activity. 73 self::validate_context($context); 74 75 // Get list with all the users enrolled in the course. 76 [$sort, $sqlparams] = users_order_by_sql('u'); 77 if (has_capability('moodle/course:update', $context)) { 78 $users = get_enrolled_users($context, 'mod/bigbluebuttonbn:view', 0, 'u.*', $sort); 79 foreach ($users as $user) { 80 // Enqueue a task for processing the completion. 81 bigbluebutton_proxy::enqueue_completion_event($instance->get_instance_data(), $user->id); 82 } 83 } else { 84 $result['warnings'][] = [ 85 'item' => 'mod_bigbluebuttonbn', 86 'itemid' => $instance->get_instance_id(), 87 'warningcode' => 'nopermissions', 88 'message' => get_string('nopermissions', 'error', 'completion_validate') 89 ]; 90 } 91 } else { 92 $result['warnings'][] = [ 93 'item' => 'mod_bigbluebuttonbn', 94 'itemid' => $bigbluebuttonbnid, 95 'warningcode' => 'indexerrorbbtn', 96 'message' => get_string('index_error_bbtn', 'mod_bigbluebuttonbn', $bigbluebuttonbnid) 97 ]; 98 } 99 // We might want to return a status here or some warnings. 100 return $result; 101 } 102 103 /** 104 * Describe the return structure of the external service. 105 * 106 * @return external_single_structure 107 * @since Moodle 3.0 108 */ 109 public static function execute_returns(): external_single_structure { 110 return new external_single_structure([ 111 'warnings' => new \external_warnings() 112 ] 113 ); 114 } 115 }
title
Description
Body
title
Description
Body
title
Description
Body
title
Body