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 coding_exception;
  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\recordings\recording_action;
  26  use mod_bigbluebuttonbn\local\bigbluebutton\recordings\recording_helper;
  27  use mod_bigbluebuttonbn\recording;
  28  
  29  defined('MOODLE_INTERNAL') || die();
  30  
  31  global $CFG;
  32  require_once($CFG->libdir . '/externallib.php');
  33  
  34  /**
  35   * External service to update the details of one recording.
  36   *
  37   * @package   mod_bigbluebuttonbn
  38   * @category  external
  39   * @copyright 2018 onwards, Blindside Networks Inc
  40   * @license   http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
  41   */
  42  class update_recording extends external_api {
  43      /**
  44       * Updates a recording
  45       *
  46       * @param int $bigbluebuttonbnid the bigbluebuttonbn instance id, either the same as the one set in the recording or a new
  47       * instance to import the recording into.
  48       * @param int $recordingid
  49       * @param string $action
  50       * @param string|null $additionaloptions
  51       * @return array (empty array for now)
  52       */
  53      public static function execute(
  54          int $bigbluebuttonbnid,
  55          int $recordingid,
  56          string $action,
  57          string $additionaloptions = null
  58      ): array {
  59          // Validate the bigbluebuttonbnid ID.
  60          [
  61              'bigbluebuttonbnid' => $bigbluebuttonbnid,
  62              'recordingid' => $recordingid,
  63              'action' => $action,
  64              'additionaloptions' => $additionaloptions,
  65          ] = self::validate_parameters(self::execute_parameters(), [
  66              'bigbluebuttonbnid' => $bigbluebuttonbnid,
  67              'recordingid' => $recordingid,
  68              'action' => $action,
  69              'additionaloptions' => $additionaloptions,
  70          ]);
  71  
  72          switch ($action) {
  73              case 'delete':
  74              case 'edit':
  75              case 'protect':
  76              case 'publish':
  77              case 'unprotect':
  78              case 'unpublish':
  79              case 'import':
  80                  break;
  81              default:
  82                  throw new coding_exception("Unknown action '{$action}'");
  83          }
  84          $instance = instance::get_from_instanceid($bigbluebuttonbnid);
  85          $recordingcontext = $instance->get_context();
  86          self::validate_context($recordingcontext);
  87          require_capability('mod/bigbluebuttonbn:managerecordings', $recordingcontext);
  88          require_capability("mod/bigbluebuttonbn:{$action}recordings", $recordingcontext);
  89  
  90          // Fetch the session, features, and profile.
  91          $recording = new recording($recordingid);
  92          // Check both the recording instance context and the bbb context.
  93          $relatedinstance = instance::get_from_instanceid($recording->get('bigbluebuttonbnid'));
  94          if ($relatedinstance) {
  95              $recordingcontext = $relatedinstance->get_context();
  96              // Validate that the user has access to this activity and to manage recordings.
  97              self::validate_context($recordingcontext);
  98              require_capability('mod/bigbluebuttonbn:managerecordings', $recordingcontext);
  99              require_capability("mod/bigbluebuttonbn:{$action}recordings", $recordingcontext);
 100          }
 101          $additionaloptionsobject = $additionaloptions ? json_decode($additionaloptions) : null;
 102          // Specific action such as import, delete, publish, unpublish, edit,....
 103          if (method_exists(recording_action::class, "$action")) {
 104              forward_static_call(
 105                  ['\mod_bigbluebuttonbn\local\bigbluebutton\recordings\recording_action', "$action"],
 106                  $recording,
 107                  $instance,
 108                  $additionaloptionsobject
 109              );
 110          }
 111          return [];
 112      }
 113  
 114      /**
 115       * Returns description of method parameters
 116       *
 117       * @return external_function_parameters
 118       */
 119      public static function execute_parameters(): external_function_parameters {
 120          return new external_function_parameters([
 121              'bigbluebuttonbnid' => new external_value(
 122                  PARAM_INT,
 123                  'bigbluebuttonbn instance id, this might be a different one from the one set in recordingid in case of importing'
 124              ),
 125              'recordingid' => new external_value(PARAM_INT, 'The moodle internal recording ID'),
 126              'action' => new external_value(PARAM_ALPHANUMEXT, 'The action to perform'),
 127              'additionaloptions' => new external_value(PARAM_RAW, 'Additional options', VALUE_REQUIRED, null),
 128          ]);
 129      }
 130  
 131      /**
 132       * Describe the return structure of the external service.
 133       *
 134       * @return external_single_structure
 135       * @since Moodle 3.0
 136       */
 137      public static function execute_returns(): external_single_structure {
 138          return new external_single_structure([]);
 139      }
 140  }