Search moodle.org's
Developer Documentation

See Release Notes

  • Bug fixes for general core bugs in 4.0.x will end 8 May 2023 (12 months).
  • Bug fixes for security issues in 4.0.x will end 13 November 2023 (18 months).
  • PHP version: minimum PHP 7.3.0 Note: the minimum PHP version has increased since Moodle 3.10. PHP 7.4.x is also supported.

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 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  use mod_bigbluebuttonbn\meeting;
  26  use restricted_context_exception;
  27  
  28  defined('MOODLE_INTERNAL') || die();
  29  
  30  global $CFG;
  31  require_once($CFG->libdir . '/externallib.php');
  32  
  33  /**
  34   * External service to fetch meeting information.
  35   *
  36   * @package   mod_bigbluebuttonbn
  37   * @category  external
  38   * @copyright 2018 onwards, Blindside Networks Inc
  39   * @license   http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
  40   */
  41  class meeting_info extends external_api {
  42  
  43      /**
  44       * Returns description of method parameters.
  45       *
  46       * @return external_function_parameters
  47       */
  48      public static function execute_parameters(): external_function_parameters {
  49          return new external_function_parameters([
  50              'bigbluebuttonbnid' => new external_value(PARAM_INT, 'bigbluebuttonbn instance id'),
  51              'groupid' => new external_value(PARAM_INT, 'bigbluebuttonbn group id', VALUE_DEFAULT, 0),
  52              'updatecache' => new external_value(PARAM_BOOL, 'update cache ?', VALUE_DEFAULT, false),
  53          ]);
  54      }
  55  
  56      /**
  57       * Fetch meeting information.
  58       *
  59       * @param int $bigbluebuttonbnid the bigbluebuttonbn instance id
  60       * @param int $groupid
  61       * @param bool $updatecache
  62       * @return array
  63       * @throws \moodle_exception
  64       * @throws restricted_context_exception
  65       */
  66      public static function execute(
  67          int $bigbluebuttonbnid,
  68          int $groupid,
  69          bool $updatecache = false
  70      ): array {
  71          // Validate the bigbluebuttonbnid ID.
  72          [
  73              'bigbluebuttonbnid' => $bigbluebuttonbnid,
  74              'groupid' => $groupid,
  75              'updatecache' => $updatecache,
  76          ] = self::validate_parameters(self::execute_parameters(), [
  77              'bigbluebuttonbnid' => $bigbluebuttonbnid,
  78              'groupid' => $groupid,
  79              'updatecache' => $updatecache,
  80          ]);
  81  
  82          // Fetch the session, features, and profile.
  83          $instance = instance::get_from_instanceid($bigbluebuttonbnid);
  84          $instance->set_group_id($groupid);
  85          if (!groups_group_visible($groupid, $instance->get_course(), $instance->get_cm())) {
  86              throw new restricted_context_exception();
  87          }
  88          $context = $instance->get_context();
  89  
  90          // Validate that the user has access to this activity and to manage recordings.
  91          self::validate_context($context);
  92  
  93          // Check if the BBB server is working.
  94          $serverversion = bigbluebutton_proxy::get_server_version();
  95          if ($serverversion === null) {
  96              throw new \moodle_exception('general_error_no_answer', 'mod_bigbluebuttonbn',
  97                  bigbluebutton_proxy::get_server_not_available_url($instance),
  98                  bigbluebutton_proxy::get_server_not_available_message($instance));
  99          }
 100          return (array) meeting::get_meeting_info_for_instance($instance, $updatecache);
 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                  'cmid' => new external_value(PARAM_INT, 'CM id'),
 112                  'userlimit' => new external_value(PARAM_INT, 'User limit'),
 113                  'bigbluebuttonbnid' => new external_value(PARAM_RAW, 'bigbluebuttonbn instance id'),
 114                  'meetingid' => new external_value(PARAM_RAW, 'Meeting id'),
 115                  'openingtime' => new external_value(PARAM_INT, 'Opening time', VALUE_OPTIONAL),
 116                  'closingtime' => new external_value(PARAM_INT, 'Closing time', VALUE_OPTIONAL),
 117                  'statusrunning' => new external_value(PARAM_BOOL, 'Status running', VALUE_OPTIONAL),
 118                  'statusclosed' => new external_value(PARAM_BOOL, 'Status closed', VALUE_OPTIONAL),
 119                  'statusopen' => new external_value(PARAM_BOOL, 'Status open', VALUE_OPTIONAL),
 120                  'statusmessage' => new external_value(PARAM_TEXT, 'Status message', VALUE_OPTIONAL),
 121                  'startedat' => new external_value(PARAM_INT, 'Started at', VALUE_OPTIONAL),
 122                  'moderatorcount' => new external_value(PARAM_INT, 'Moderator count', VALUE_OPTIONAL),
 123                  'participantcount' => new external_value(PARAM_INT, 'Participant count', VALUE_OPTIONAL),
 124                  'moderatorplural' => new external_value(PARAM_BOOL, 'Several moderators ?', VALUE_OPTIONAL),
 125                  'participantplural' => new external_value(PARAM_BOOL, 'Several participants ?', VALUE_OPTIONAL),
 126                  'canjoin' => new external_value(PARAM_BOOL, 'Can join'),
 127                  'ismoderator' => new external_value(PARAM_BOOL, 'Is moderator'),
 128                  'presentations' => new \external_multiple_structure(
 129                      new external_single_structure([
 130                          'url' => new external_value(PARAM_URL, 'presentation URL'),
 131                          'iconname' => new external_value(PARAM_RAW, 'icon name'),
 132                          'icondesc' => new external_value(PARAM_TEXT, 'icon text'),
 133                          'name' => new external_value(PARAM_TEXT, 'presentation name'),
 134                      ])
 135                  ),
 136                  'joinurl' => new external_value(PARAM_URL, 'Join URL'),
 137              ]
 138          );
 139      }
 140  }