Search moodle.org's
Developer Documentation

See Release Notes

  • Bug fixes for general core bugs in 4.2.x will end 22 April 2024 (12 months).
  • Bug fixes for security issues in 4.2.x will end 7 October 2024 (18 months).
  • PHP version: minimum PHP 8.0.0 Note: minimum PHP version has increased since Moodle 4.1. PHP 8.1.x is supported too.

Differences Between: [Versions 400 and 402] [Versions 401 and 402]

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