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\output;
  18  
  19  use mod_bigbluebuttonbn\instance;
  20  use mod_bigbluebuttonbn\local\bigbluebutton\recordings\recording_data;
  21  use mod_bigbluebuttonbn\local\config;
  22  use mod_bigbluebuttonbn\local\helpers\roles;
  23  use mod_bigbluebuttonbn\recording;
  24  use renderable;
  25  use renderer_base;
  26  use stdClass;
  27  use templatable;
  28  
  29  /**
  30   * Renderer for recording row playback column
  31   *
  32   * @package   mod_bigbluebuttonbn
  33   * @copyright 2010 onwards, Blindside Networks Inc
  34   * @license   http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
  35   * @author    Laurent David  (laurent.david [at] call-learning [dt] fr)
  36   */
  37  class recording_row_playback implements renderable, templatable {
  38  
  39      /**
  40       * @var $instance
  41       */
  42      protected $instance;
  43  
  44      /**
  45       * @var $recording
  46       */
  47      protected $recording;
  48  
  49      /**
  50       * recording_row_playback constructor.
  51       *
  52       * @param recording $rec
  53       * @param instance|null $instance $instance
  54       */
  55      public function __construct(recording $rec, ?instance $instance) {
  56          $this->instance = $instance ?? null;
  57          $this->recording = $rec;
  58      }
  59  
  60      /**
  61       * Export for template
  62       *
  63       * @param renderer_base $output
  64       * @return stdClass
  65       */
  66      public function export_for_template(renderer_base $output): stdClass {
  67          $ispublished = $this->recording->get('published');
  68          $recordingid = $this->recording->get('id');
  69          $context = (object) [
  70              'dataimported' => $this->recording->get('imported'),
  71              'id' => 'playbacks-' . $this->recording->get('id'),
  72              'recordingid' => $recordingid,
  73              'additionaloptions' => '',
  74              'playbacks' => [],
  75          ];
  76  
  77          $playbacks = $this->recording->get('playbacks');
  78          if ($ispublished && $playbacks) {
  79              foreach ($playbacks as $playback) {
  80                  if ($this->should_be_included($playback)) {
  81                      $linkattributes = [
  82                          'id' => "recording-play-{$playback['type']}-{$recordingid}",
  83                          'class' => 'btn btn-sm btn-default',
  84                          'data-action' => 'play',
  85                          'data-target' => $playback['type'],
  86                      ];
  87                      $actionlink = new \action_link(
  88                          $playback['url'],
  89                          recording_data::type_text($playback['type']),
  90                          null,
  91                          $linkattributes
  92                      );
  93                      $context->playbacks[] = $actionlink->export_for_template($output);
  94                  }
  95              }
  96          }
  97          return $context;
  98      }
  99      /**
 100       * Helper function renders the link used for recording type in row for the data used by the recording table.
 101       *
 102       * @param array $playback
 103       * @return bool
 104       */
 105      protected function should_be_included(array $playback): bool {
 106          // All types that are not restricted are included.
 107          if (array_key_exists('restricted', $playback) && strtolower($playback['restricted']) == 'false') {
 108              return true;
 109          }
 110  
 111          $canmanagerecordings = roles::has_capability_in_course(
 112              $this->recording->get('courseid'), 'mod/bigbluebuttonbn:managerecordings');
 113          $canviewallformats = roles::has_capability_in_course(
 114              $this->recording->get('courseid'), 'mod/bigbluebuttonbn:viewallrecordingformats');
 115          $issafeformat = false;
 116          // Now check the list of safe formats.
 117          if ($safeformats = config::get('recording_safe_formats')) {
 118              $safeformatarray = str_getcsv($safeformats);
 119              $issafeformat = in_array($playback['type'], $safeformatarray);
 120          }
 121          return ($canmanagerecordings && $canviewallformats) || $issafeformat;
 122      }
 123  }