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.
   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\recording;
  20  use pix_icon;
  21  use renderable;
  22  use renderer_base;
  23  use stdClass;
  24  use templatable;
  25  
  26  /**
  27   * Renderer for recording row actionbar column
  28   *
  29   * @package   mod_bigbluebuttonbn
  30   * @copyright 2010 onwards, Blindside Networks Inc
  31   * @license   http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
  32   * @author    Laurent David  (laurent.david [at] call-learning [dt] fr)
  33   */
  34  class recording_row_actionbar implements renderable, templatable {
  35      /**
  36       * @var $recording
  37       */
  38      protected $recording;
  39  
  40      /**
  41       * @var $tools
  42       */
  43      protected $tools;
  44  
  45      /**
  46       * @var array TOOLS_DEFINITION a list of definition for the the specific tools
  47       */
  48      const TOOL_ACTION_DEFINITIONS = [
  49          'protect' => [
  50              'action' => 'unprotect',
  51              'icon' => 'lock',
  52              'hidewhen' => '!protected',
  53              'requireconfirmation' => true,
  54              'disablewhen' => 'imported'
  55          ],
  56          'unprotect' => [
  57              'action' => 'protect',
  58              'icon' => 'unlock',
  59              'hidewhen' => 'protected',
  60              'requireconfirmation' => true,
  61              'disablewhen' => 'imported'
  62          ],
  63          'publish' => [
  64              'action' => 'publish',
  65              'icon' => 'show',
  66              'hidewhen' => 'published',
  67              'requireconfirmation' => true,
  68              'disablewhen' => 'imported'
  69          ],
  70          'unpublish' => [
  71              'action' => 'unpublish',
  72              'icon' => 'hide',
  73              'hidewhen' => '!published',
  74              'requireconfirmation' => true,
  75              'disablewhen' => 'imported'
  76          ],
  77          'delete' => [
  78              'action' => 'delete',
  79              'icon' => 'trash',
  80              'requireconfirmation' => true
  81          ],
  82          'import' => [
  83              'action' => 'import',
  84              'icon' => 'import',
  85          ]
  86      ];
  87  
  88      /**
  89       * recording_row_actionbar constructor.
  90       *
  91       * @param recording $recording
  92       * @param array $tools
  93       */
  94      public function __construct(recording $recording, array $tools) {
  95          $this->recording = $recording;
  96          $this->tools = $tools;
  97      }
  98  
  99      /**
 100       * Export for template
 101       *
 102       * @param renderer_base $output
 103       * @return stdClass
 104       */
 105      public function export_for_template(renderer_base $output): stdClass {
 106          $context = new stdClass();
 107          $context->id = 'recording-actionbar-' . $this->recording->get('id');
 108          $context->recordingid = $this->recording->get('id');
 109          $context->tools = [];
 110          foreach ($this->tools as $tool) {
 111              if (!empty(self::TOOL_ACTION_DEFINITIONS[$tool])) {
 112                  $buttonpayload = self::TOOL_ACTION_DEFINITIONS[$tool];
 113                  $conditionalhiding = $buttonpayload['hidewhen'] ?? null;
 114                  $disabledwhen = $buttonpayload['disablewhen'] ?? null;
 115                  $this->actionbar_update_diplay($buttonpayload, $disabledwhen, $this->recording, 'disabled');
 116                  $this->actionbar_update_diplay($buttonpayload, $conditionalhiding, $this->recording);
 117                  if (!empty($buttonpayload)) {
 118                      $iconortext = '';
 119                      $target = $buttonpayload['action'];
 120                      if (isset($buttonpayload['target'])) {
 121                          $target .= '-' . $buttonpayload['target'];
 122                      }
 123                      $id = 'recording-' . $target . '-' . $this->recording->get('recordingid');
 124                      $iconattributes = [
 125                          'id' => $id,
 126                          'class' => 'iconsmall',
 127                      ];
 128                      $linkattributes = [
 129                          'id' => $id,
 130                          'data-action' => $buttonpayload['action'],
 131                          'data-require-confirmation' => !empty($buttonpayload['requireconfirmation']),
 132                          'class' => 'action-icon'
 133                      ];
 134                      if ($this->recording->get('imported')) {
 135                          $linkattributes['data-links'] = recording::count_records(
 136                              [
 137                                  'recordingid' => $this->recording->get('recordingid'),
 138                                  'imported' => true,
 139                              ]
 140                          );
 141                      }
 142                      if (isset($buttonpayload['disabled'])) {
 143                          $iconattributes['class'] .= ' fa-' . $buttonpayload['disabled'];
 144                          $linkattributes['class'] .= ' disabled';
 145                      }
 146                      $icon = new pix_icon(
 147                          'i/' . $buttonpayload['icon'],
 148                          get_string('view_recording_list_actionbar_' . $buttonpayload['action'], 'bigbluebuttonbn'),
 149                          'moodle',
 150                          $iconattributes
 151                      );
 152                      $iconortext = $output->render($icon);
 153                      $actionlink = new \action_link(new \moodle_url('#'), $iconortext, null, $linkattributes);
 154                      $context->tools[] = $actionlink->export_for_template($output);
 155                  }
 156  
 157              }
 158          }
 159          return $context;
 160      }
 161  
 162      /**
 163       * Read the settings for this action and disable or hide the tool from the toolbar
 164       *
 165       * @param array $buttonpayload
 166       * @param string $condition
 167       * @param recording $rec
 168       * @param string $value
 169       */
 170      private function actionbar_update_diplay(&$buttonpayload, $condition, $rec, $value = 'invisible') {
 171          if ($condition) {
 172              $negates = $condition[0] === '!';
 173              $conditionalvariable = ltrim($condition, '!');
 174              if ($rec->get($conditionalvariable) xor $negates) {
 175                  $buttonpayload['disabled'] = $value;
 176              }
 177          }
 178      }
 179  }