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 core\notification;
  20  use external_api;
  21  use external_function_parameters;
  22  use external_single_structure;
  23  use external_value;
  24  use mod_bigbluebuttonbn\instance;
  25  use mod_bigbluebuttonbn\local\bigbluebutton;
  26  use mod_bigbluebuttonbn\local\exceptions\bigbluebutton_exception;
  27  use mod_bigbluebuttonbn\logger;
  28  use mod_bigbluebuttonbn\meeting;
  29  use restricted_context_exception;
  30  
  31  defined('MOODLE_INTERNAL') || die();
  32  
  33  global $CFG;
  34  require_once($CFG->libdir . '/externallib.php');
  35  
  36  /**
  37   * External service to end a meeting.
  38   *
  39   * @package   mod_bigbluebuttonbn
  40   * @category  external
  41   * @copyright 2018 onwards, Blindside Networks Inc
  42   * @license   http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
  43   */
  44  class end_meeting extends external_api {
  45      /**
  46       * Returns description of method parameters
  47       *
  48       * @return external_function_parameters
  49       */
  50      public static function execute_parameters(): external_function_parameters {
  51          return new external_function_parameters([
  52              'bigbluebuttonbnid' => new external_value(PARAM_INT, 'bigbluebuttonbn instance id'),
  53              'groupid' => new external_value(PARAM_INT, 'bigbluebuttonbn group id', VALUE_DEFAULT, 0),
  54          ]);
  55      }
  56  
  57      /**
  58       * Updates a recording
  59       *
  60       * @param int $bigbluebuttonbnid the bigbluebuttonbn instance id
  61       * @param int $groupid the groupid (either 0 or the groupid)
  62       * @return array (empty array for now)
  63       * @throws \invalid_parameter_exception
  64       * @throws \moodle_exception
  65       * @throws restricted_context_exception
  66       */
  67      public static function execute(
  68          int $bigbluebuttonbnid,
  69          int $groupid
  70      ): array {
  71          // Validate the bigbluebuttonbnid ID.
  72          [
  73              'bigbluebuttonbnid' => $bigbluebuttonbnid,
  74              'groupid' => $groupid,
  75          ] = self::validate_parameters(self::execute_parameters(), [
  76              'bigbluebuttonbnid' => $bigbluebuttonbnid,
  77              'groupid' => $groupid,
  78          ]);
  79  
  80          // Fetch the session, features, and profile.
  81          $instance = instance::get_from_instanceid($bigbluebuttonbnid);
  82          if (empty($instance)) {
  83              throw new \moodle_exception('Unknown Instance');
  84          }
  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          $context = $instance->get_context();
  90  
  91          // Validate that the user has access to this activity and to manage recordings.
  92          self::validate_context($context);
  93  
  94          if (!$instance->user_can_end_meeting()) {
  95              throw new restricted_context_exception();
  96          }
  97          // Execute the end command.
  98          $meeting = new meeting($instance);
  99          try {
 100              $meeting->end_meeting();
 101          } catch (bigbluebutton_exception $e) {
 102              return [
 103                  'warnings' => [
 104                      [
 105                          'item' => $instance->get_meeting_name(),
 106                          'itemid' => $instance->get_instance_id(),
 107                          'warningcode' => 'notFound',
 108                          'message' => $e->getMessage()
 109                      ]
 110                  ]
 111              ];
 112          }
 113          logger::log_meeting_ended_event($instance);
 114          // Update the cache.
 115          $meeting->update_cache();
 116          notification::add(get_string('end_session_notification', 'mod_bigbluebuttonbn'), notification::INFO);
 117          return [];
 118      }
 119  
 120      /**
 121       * Describe the return structure of the external service.
 122       *
 123       * @return external_single_structure
 124       * @since Moodle 3.0
 125       */
 126      public static function execute_returns(): external_single_structure {
 127          return new external_single_structure([
 128              'warnings' => new \external_warnings()
 129          ]);
 130      }
 131  }