Search moodle.org's
Developer Documentation

See Release Notes
Long Term Support Release

  • Bug fixes for general core bugs in 4.1.x will end 13 November 2023 (12 months).
  • Bug fixes for security issues in 4.1.x will end 10 November 2025 (36 months).
  • PHP version: minimum PHP 7.4.0 Note: minimum PHP version has increased since Moodle 4.0. PHP 8.0.x is supported too.

Differences Between: [Versions 401 and 402] [Versions 401 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\exceptions\meeting_join_exception;
  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 create the meeting (if needed), check user limit, and return the join URL when we can join.
  35   *
  36   * This is mainly used by the mobile application.
  37   *
  38   * @package   mod_bigbluebuttonbn
  39   * @category  external
  40   * @copyright 2018 onwards, Blindside Networks Inc
  41   * @license   http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
  42   */
  43  class get_join_url extends external_api {
  44      /**
  45       * Returns description of method parameters
  46       *
  47       * @return external_function_parameters
  48       */
  49      public static function execute_parameters(): external_function_parameters {
  50          return new external_function_parameters([
  51              'cmid' => new external_value(PARAM_INT, 'course module id', VALUE_REQUIRED),
  52              'groupid' => new external_value(PARAM_INT, 'bigbluebuttonbn group id', VALUE_DEFAULT, 0),
  53          ]);
  54      }
  55  
  56      /**
  57       * Updates a recording
  58       *
  59       * @param int $cmid the bigbluebuttonbn course module id
  60       * @param null|int $groupid
  61       * @return array (empty array for now)
  62       */
  63      public static function execute(
  64          int $cmid,
  65          ?int $groupid = 0
  66      ): array {
  67          // Validate the cmid ID.
  68          [
  69              'cmid' => $cmid,
  70              'groupid' => $groupid,
  71          ] = self::validate_parameters(self::execute_parameters(), [
  72              'cmid' => $cmid,
  73              'groupid' => $groupid,
  74          ]);
  75          $result = ['warnings' => []];
  76  
  77          $instance = instance::get_from_cmid($cmid);
  78          if (empty($instance)) {
  79              throw new \moodle_exception('nosuchinstance', 'mod_bigbluebuttonbn', null,
  80                  ['entity' => get_string('module', 'course'), 'id' => $cmid]);
  81          }
  82          // Validate the groupid.
  83          if (!groups_group_visible($groupid, $instance->get_course(), $instance->get_cm())) {
  84              throw new restricted_context_exception();
  85          }
  86          $instance->set_group_id($groupid);
  87  
  88          self::validate_context($instance->get_context());
  89  
  90          try {
  91              $result['join_url'] = meeting::join_meeting($instance);
  92          } catch (meeting_join_exception $e) {
  93              $result['warnings'][] = [
  94                  'item' => 'mod_bigbluebuttonbn',
  95                  'itemid' => $instance->get_instance_id(),
  96                  'warningcode' => $e->errorcode,
  97                  'message' => $e->getMessage()
  98              ];
  99          }
 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.3
 108       */
 109      public static function execute_returns(): external_single_structure {
 110          return new external_single_structure([
 111              'join_url' => new external_value(PARAM_RAW, 'Can join session', VALUE_OPTIONAL),
 112              'warnings' => new \external_warnings()
 113          ]);
 114      }
 115  }