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  use external_api;
  19  use external_function_parameters;
  20  use external_single_structure;
  21  use external_value;
  22  use mod_bigbluebuttonbn\instance;
  23  use mod_bigbluebuttonbn\meeting;
  24  use restricted_context_exception;
  25  
  26  defined('MOODLE_INTERNAL') || die();
  27  
  28  global $CFG;
  29  require_once($CFG->libdir . '/externallib.php');
  30  
  31  /**
  32   * External service to check whether a user can join a meeting.
  33   *
  34   * This is mainly used by the mobile application.
  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 can_join extends external_api {
  42      /**
  43       * Returns description of method parameters
  44       *
  45       * @return external_function_parameters
  46       */
  47      public static function execute_parameters(): external_function_parameters {
  48          return new external_function_parameters([
  49              'cmid' => new external_value(PARAM_INT, 'course module id', VALUE_REQUIRED),
  50              'groupid' => new external_value(PARAM_INT, 'bigbluebuttonbn group id', VALUE_DEFAULT, 0),
  51          ]);
  52      }
  53  
  54      /**
  55       * Updates a recording
  56       *
  57       * @param int $cmid the bigbluebuttonbn course module id
  58       * @param null|int $groupid
  59       * @return array (empty array for now)
  60       * @throws \restricted_context_exception
  61       */
  62      public static function execute(
  63          int $cmid,
  64          ?int $groupid = 0
  65      ): array {
  66          // Validate the cmid ID.
  67          [
  68              'cmid' => $cmid,
  69              'groupid' => $groupid,
  70          ] = self::validate_parameters(self::execute_parameters(), [
  71              'cmid' => $cmid,
  72              'groupid' => $groupid,
  73          ]);
  74  
  75          $result = [
  76              'can_join' => false,
  77              'cmid' => $cmid,
  78          ];
  79  
  80          $instance = instance::get_from_cmid($cmid);
  81          if (empty($instance)) {
  82              return $result;
  83          }
  84          // Validate the groupid.
  85          if (!groups_group_visible($groupid, $instance->get_course(), $instance->get_cm())) {
  86              throw new restricted_context_exception();
  87          }
  88          $instance->set_group_id($groupid);
  89  
  90          self::validate_context($instance->get_context());
  91  
  92          $meeting = new meeting($instance);
  93  
  94          $result['can_join'] = $meeting->can_join();
  95  
  96          return $result;
  97      }
  98  
  99      /**
 100       * Describe the return structure of the external service.
 101       *
 102       * @return external_single_structure
 103       * @since Moodle 3.3
 104       */
 105      public static function execute_returns(): external_single_structure {
 106          return new external_single_structure([
 107              'can_join' => new external_value(PARAM_BOOL, 'Can join session'),
 108              'cmid' => new external_value(PARAM_INT, 'course module id', VALUE_REQUIRED),
 109          ]);
 110      }
 111  }