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_multiple_structure;
  22  use external_single_structure;
  23  use external_value;
  24  use external_warnings;
  25  use mod_bigbluebuttonbn\instance;
  26  use mod_bigbluebuttonbn\local\bigbluebutton\recordings\recording_data;
  27  use mod_bigbluebuttonbn\local\proxy\bigbluebutton_proxy;
  28  use restricted_context_exception;
  29  
  30  defined('MOODLE_INTERNAL') || die();
  31  
  32  global $CFG;
  33  require_once($CFG->libdir . '/externallib.php');
  34  
  35  /**
  36   * External service to fetch a list of recordings from the BBB service.
  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_recordings 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              'bigbluebuttonbnid' => new external_value(PARAM_INT, 'bigbluebuttonbn instance id'),
  52              'tools' => new external_value(PARAM_RAW, 'a set of enabled tools', VALUE_DEFAULT,
  53                  'protect,unprotect,publish,unpublish,delete'),
  54              'groupid' => new external_value(PARAM_INT, 'Group ID', VALUE_DEFAULT, null),
  55          ]);
  56      }
  57  
  58      /**
  59       * Get a list of recordings
  60       *
  61       * @param int $bigbluebuttonbnid the bigbluebuttonbn instance id to which the recordings are referred.
  62       * @param string|null $tools
  63       * @param int|null $groupid
  64       * @return array of warnings and status result
  65       * @throws \invalid_parameter_exception
  66       * @throws restricted_context_exception
  67       */
  68      public static function execute(
  69          int $bigbluebuttonbnid = 0,
  70          ?string $tools = 'protect,unprotect,publish,unpublish,delete',
  71          ?int $groupid = null
  72      ): array {
  73          global $USER;
  74  
  75          $returnval = [
  76              'status' => false,
  77              'warnings' => [],
  78          ];
  79  
  80          // Validate the bigbluebuttonbnid ID.
  81          [
  82              'bigbluebuttonbnid' => $bigbluebuttonbnid,
  83              'tools' => $tools,
  84              'groupid' => $groupid,
  85          ] = self::validate_parameters(self::execute_parameters(), [
  86              'bigbluebuttonbnid' => $bigbluebuttonbnid,
  87              'tools' => $tools,
  88              'groupid' => $groupid,
  89          ]);
  90  
  91          $tools = explode(',', $tools ?? 'protect,unprotect,publish,unpublish,delete');
  92  
  93          // Fetch the session, features, and profile.
  94          $instance = instance::get_from_instanceid($bigbluebuttonbnid);
  95          if (!$instance) {
  96              $returnval['warnings'][] = [
  97                  'item' => $bigbluebuttonbnid,
  98                  'warningcode' => 'nosuchinstance',
  99                  'message' => get_string('nosuchinstance', 'mod_bigbluebuttonbn',
 100                      (object) ['id' => $bigbluebuttonbnid, 'entity' => 'bigbluebuttonbn'])
 101              ];
 102          } else {
 103              $typeprofiles = bigbluebutton_proxy::get_instance_type_profiles();
 104              $profilefeature = $typeprofiles[$instance->get_type()]['features'];
 105              $showrecordings = in_array('all', $profilefeature) || in_array('showrecordings', $profilefeature);
 106              if ($showrecordings) {
 107                  $context = $instance->get_context();
 108                  // Validate that the user has access to this activity.
 109                  self::validate_context($context);
 110                  if (!$instance->user_has_group_access($USER, $groupid)) {
 111                      new restricted_context_exception();
 112                  }
 113                  if ($groupid) {
 114                      $instance->set_group_id($groupid);
 115                  }
 116                  $recordings = $instance->get_recordings([], $instance->get_instance_var('recordings_deleted') ?? false);
 117                  $tabledata = recording_data::get_recording_table($recordings, $tools, $instance);
 118  
 119                  $returnval['tabledata'] = $tabledata;
 120                  $returnval['status'] = true;
 121              } else {
 122                  $returnval['warnings'][] = [
 123                      'item' => $bigbluebuttonbnid,
 124                      'warningcode' => 'instanceprofilewithoutrecordings',
 125                      'message' => get_string('instanceprofilewithoutrecordings', 'mod_bigbluebuttonbn')
 126                  ];
 127              }
 128          }
 129          return $returnval;
 130      }
 131  
 132      /**
 133       * Describe the return structure of the external service.
 134       *
 135       * @return external_single_structure
 136       * @since Moodle 3.0
 137       */
 138      public static function execute_returns(): external_single_structure {
 139          return new external_single_structure([
 140              'status' => new external_value(PARAM_BOOL, 'Whether the fetch was successful'),
 141              'tabledata' => new external_single_structure([
 142                  'activity' => new external_value(PARAM_ALPHANUMEXT),
 143                  'ping_interval' => new external_value(PARAM_INT),
 144                  'locale' => new external_value(PARAM_TEXT),
 145                  'profile_features' => new external_multiple_structure(new external_value(PARAM_TEXT)),
 146                  'columns' => new external_multiple_structure(new external_single_structure([
 147                      'key' => new external_value(PARAM_ALPHA),
 148                      'label' => new external_value(PARAM_TEXT),
 149                      'width' => new external_value(PARAM_ALPHANUMEXT),
 150                      // See https://datatables.net/reference/option/columns.type .
 151                      'type' => new external_value(PARAM_ALPHANUMEXT, 'Column type', VALUE_OPTIONAL),
 152                      'sortable' => new external_value(PARAM_BOOL, 'Whether this column is sortable', VALUE_OPTIONAL, false),
 153                      'allowHTML' => new external_value(PARAM_BOOL, 'Whether this column contains HTML', VALUE_OPTIONAL, false),
 154                      'formatter' => new external_value(PARAM_ALPHANUMEXT, 'Formatter name', VALUE_OPTIONAL),
 155                  ])),
 156                  'data' => new external_value(PARAM_RAW), // For now it will be json encoded.
 157              ], '', VALUE_OPTIONAL),
 158              'warnings' => new external_warnings()
 159          ]);
 160      }
 161  }