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