Search moodle.org's
Developer Documentation

See Release Notes

  • Bug fixes for general core bugs in 4.0.x will end 8 May 2023 (12 months).
  • Bug fixes for security issues in 4.0.x will end 13 November 2023 (18 months).
  • PHP version: minimum PHP 7.3.0 Note: the minimum PHP version has increased since Moodle 3.10. PHP 7.4.x is also supported.
   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  namespace mod_bigbluebuttonbn\output;
  17  
  18  use lang_string;
  19  use mod_bigbluebuttonbn\local\bigbluebutton;
  20  use moodle_exception;
  21  use core\output\inplace_editable;
  22  use mod_bigbluebuttonbn\instance;
  23  use mod_bigbluebuttonbn\local\proxy\bigbluebutton_proxy;
  24  use mod_bigbluebuttonbn\local\proxy\recording_proxy;
  25  use mod_bigbluebuttonbn\recording;
  26  use stdClass;
  27  
  28  /**
  29   * Renderer for recording in place editable.
  30   *
  31   * Generic class
  32   *
  33   * @package   mod_bigbluebuttonbn
  34   * @copyright 2010 onwards, Blindside Networks Inc
  35   * @license   http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
  36   * @author    Laurent David  (laurent.david [at] call-learning [dt] fr)
  37   */
  38  abstract class recording_editable extends \core\output\inplace_editable {
  39  
  40      /** @var instance The bbb instance */
  41      protected $instance;
  42  
  43      /**
  44       * Constructor.
  45       *
  46       * @param recording $rec
  47       * @param instance $instance
  48       * @param string $edithint
  49       * @param string $editlabel
  50       */
  51      public function __construct(recording $rec, instance $instance, string $edithint, string $editlabel) {
  52          $this->instance = $instance;
  53  
  54          $editable = $this->check_capability();
  55          $displayvalue = format_string(
  56              $this->get_recording_value($rec),
  57              true,
  58              [
  59                  'context' => $instance->get_context(),
  60              ]
  61          );
  62  
  63          // Hack here: the ID is the recordID and the meeting ID.
  64          parent::__construct(
  65              'mod_bigbluebuttonbn',
  66              static::get_type(),
  67              $rec->get('id'),
  68              $editable,
  69              $displayvalue,
  70              $displayvalue,
  71              $edithint,
  72              $editlabel
  73          );
  74      }
  75  
  76      /**
  77       * Check user can access and or modify this item.
  78       *
  79       * @return bool
  80       * @throws \moodle_exception
  81       */
  82      protected function check_capability() {
  83          global $USER;
  84  
  85          if (!can_access_course($this->instance->get_course(), $USER)) {
  86              throw new moodle_exception('noaccess', 'mod_bigbluebuttonbn');
  87          }
  88  
  89          return $this->instance->can_manage_recordings();
  90      }
  91  
  92      /**
  93       *  Get the type of editable
  94       */
  95      protected static function get_type() {
  96          return '';
  97      }
  98  
  99      /**
 100       * Get the real recording value
 101       *
 102       * @param recording $rec
 103       * @return mixed
 104       */
 105      abstract public function get_recording_value(recording $rec): string;
 106  
 107      /**
 108       * Update the recording with the new value
 109       *
 110       * @param int $itemid
 111       * @param mixed $value
 112       * @return recording_editable
 113       */
 114      public static function update($itemid, $value) {
 115          $recording = recording::get_record(['id' => $itemid]);
 116          $instance = instance::get_from_instanceid($recording->get('bigbluebuttonbnid'));
 117  
 118          require_login($instance->get_course(), true, $instance->get_cm());
 119          require_capability('mod/bigbluebuttonbn:managerecordings', $instance->get_context());
 120  
 121          $recording->set(static::get_type(), $value);
 122          $recording->update();
 123  
 124          return new static($recording, $instance);
 125      }
 126  
 127      /**
 128       * Helper function evaluates if a row for the data used by the recording table is editable.
 129       *
 130       * @return bool
 131       */
 132      protected function row_editable() {
 133          // Since the request to BBB are cached, it is safe to use the wrapper to check the server version.
 134          return $this->instance->can_manage_recordings()
 135              && (bigbluebutton_proxy::get_server_version() >= 1.0 || $this->instance->is_blindside_network_server());
 136      }
 137  }