Differences Between: [Versions 400 and 401] [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 context_module; 20 use external_api; 21 use external_files; 22 use external_format_value; 23 use external_function_parameters; 24 use external_multiple_structure; 25 use external_single_structure; 26 use external_util; 27 use external_value; 28 use external_warnings; 29 30 defined('MOODLE_INTERNAL') || die(); 31 32 global $CFG; 33 require_once($CFG->libdir . '/externallib.php'); 34 35 /** 36 * External service to get activity per course 37 * 38 * This is mainly used by the mobile application. 39 * 40 * @package mod_bigbluebuttonbn 41 * @category external 42 * @copyright 2018 onwards, Blindside Networks Inc 43 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later 44 */ 45 class get_bigbluebuttonbns_by_courses extends external_api { 46 /** 47 * Describes the parameters for get_bigbluebuttonbns_by_courses. 48 * 49 * @return external_function_parameters 50 * @since Moodle 3.11 51 */ 52 public static function execute_parameters() { 53 return new external_function_parameters([ 54 'courseids' => new external_multiple_structure( 55 new external_value(PARAM_INT, 'Course id'), 'Array of course ids', VALUE_DEFAULT, [] 56 ), 57 ] 58 ); 59 } 60 61 /** 62 * Returns a list of bigbluebuttonbns in a provided list of courses. 63 * If no list is provided all bigbluebuttonbns that the user can view will be returned. 64 * 65 * @param array $courseids course ids 66 * @return array of warnings and bigbluebuttonbns 67 * @since Moodle 3.11 68 */ 69 public static function execute($courseids = []) { 70 global $USER; 71 $warnings = []; 72 $returnedbigbluebuttonbns = []; 73 74 ['courseids' => $courseids] = self::validate_parameters(self::execute_parameters(), ['courseids' => $courseids]); 75 $mycourses = []; 76 if (empty($courseids)) { 77 $mycourses = enrol_get_my_courses(); 78 $courseids = array_keys($mycourses); 79 } 80 81 // Ensure there are courseids to loop through. 82 if (!empty($courseids)) { 83 [$courses, $warnings] = external_util::validate_courses($courseids, $mycourses); 84 85 // Get the bigbluebuttonbns in this course, this function checks users visibility permissions. 86 // We can avoid then additional validate_context calls. 87 $bigbluebuttonbns = get_all_instances_in_courses("bigbluebuttonbn", $courses, $USER->id); 88 foreach ($bigbluebuttonbns as $bigbluebuttonbn) { 89 $context = context_module::instance($bigbluebuttonbn->coursemodule); 90 // Entry to return. 91 $bigbluebuttonbn->name = external_format_string($bigbluebuttonbn->name, $context->id); 92 93 [$bigbluebuttonbn->intro, $bigbluebuttonbn->introformat] = external_format_text($bigbluebuttonbn->intro, 94 $bigbluebuttonbn->introformat, $context->id, 'mod_bigbluebuttonbn', 'intro', null); 95 $bigbluebuttonbn->introfiles = external_util::get_area_files($context->id, 96 'mod_bigbluebuttonbn', 'intro', false, false); 97 98 $returnedbigbluebuttonbns[] = $bigbluebuttonbn; 99 } 100 } 101 102 $result = [ 103 'bigbluebuttonbns' => $returnedbigbluebuttonbns, 104 'warnings' => $warnings 105 ]; 106 return $result; 107 } 108 109 /** 110 * Describes the get_bigbluebuttonbns_by_courses return value. 111 * 112 * @return external_single_structure 113 * @since Moodle 3.11 114 */ 115 public static function execute_returns() { 116 return new external_single_structure([ 117 'bigbluebuttonbns' => new external_multiple_structure( 118 new external_single_structure([ 119 'id' => new external_value(PARAM_INT, 'Module id'), 120 'coursemodule' => new external_value(PARAM_INT, 'Course module id'), 121 'course' => new external_value(PARAM_INT, 'Course id'), 122 'name' => new external_value(PARAM_RAW, 'Name'), 123 'intro' => new external_value(PARAM_RAW, 'Description'), 124 'meetingid' => new external_value(PARAM_RAW, 'Meeting id'), 125 'introformat' => new external_format_value('intro', VALUE_REQUIRED, 'Summary format'), 126 'introfiles' => new external_files('Files in the introduction text'), 127 'timemodified' => new external_value(PARAM_INT, 'Last time the instance was modified'), 128 'section' => new external_value(PARAM_INT, 'Course section id'), 129 'visible' => new external_value(PARAM_INT, 'Module visibility'), 130 'groupmode' => new external_value(PARAM_INT, 'Group mode'), 131 'groupingid' => new external_value(PARAM_INT, 'Grouping id'), 132 ] 133 ) 134 ), 135 'warnings' => new external_warnings(), 136 ] 137 ); 138 } 139 }
title
Description
Body
title
Description
Body
title
Description
Body
title
Body