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 core\check\result;
  20  use core\output\notification;
  21  use mod_bigbluebuttonbn\instance;
  22  use mod_bigbluebuttonbn\local\config;
  23  use mod_bigbluebuttonbn\local\proxy\bigbluebutton_proxy;
  24  use mod_bigbluebuttonbn\meeting;
  25  use renderable;
  26  use renderer_base;
  27  use stdClass;
  28  use templatable;
  29  use tool_task\check\cronrunning;
  30  
  31  /**
  32   * View Page template renderable.
  33   *
  34   * @package   mod_bigbluebuttonbn
  35   * @copyright 2021 Andrew Lyons <andrew@nicols.co.uk>
  36   * @license   http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
  37   */
  38  class view_page implements renderable, templatable {
  39  
  40      /** @var instance The instance being rendered */
  41      protected $instance;
  42  
  43      /**
  44       * Constructor for the View Page.
  45       *
  46       * @param instance $instance
  47       */
  48      public function __construct(instance $instance) {
  49          $this->instance = $instance;
  50      }
  51  
  52      /**
  53       * Export the content required to render the template.
  54       *
  55       * @param renderer_base $output
  56       * @return stdClass
  57       */
  58      public function export_for_template(renderer_base $output): stdClass {
  59          $pollinterval = bigbluebutton_proxy::get_poll_interval();
  60          $templatedata = (object) [
  61              'instanceid' => $this->instance->get_instance_id(),
  62              'pollinterval' => $pollinterval * 1000, // Javascript poll interval is in miliseconds.
  63              'groupselector' => $output->render_groups_selector($this->instance),
  64              'meetingname' => $this->instance->get_meeting_name(),
  65              'description' => $this->instance->get_meeting_description(true),
  66              'joinurl' => $this->instance->get_join_url(),
  67          ];
  68  
  69          if ($this->show_default_server_warning()) {
  70              $templatedata->serverwarning = (new notification(
  71                  get_string('view_warning_default_server', 'mod_bigbluebuttonbn'),
  72                  notification::NOTIFY_WARNING,
  73                  false
  74              ))->export_for_template($output);
  75          }
  76  
  77          $viewwarningmessage = config::get('general_warning_message');
  78          if ($this->show_view_warning() && !empty($viewwarningmessage)) {
  79              $templatedata->sitenotification = (object) [
  80                  'message' => $viewwarningmessage,
  81                  'type' => config::get('general_warning_box_type'),
  82                  'icon' => [
  83                      'pix' => 'i/bullhorn',
  84                      'component' => 'core',
  85                  ],
  86              ];
  87  
  88              if ($url = config::get('general_warning_button_href')) {
  89                  $templatedata->sitenotification->actions = [[
  90                      'url' => $url,
  91                      'title' => config::get('general_warning_button_text'),
  92                  ]];
  93              }
  94          }
  95  
  96          if ($this->instance->is_feature_enabled('showroom')) {
  97              $roomdata = meeting::get_meeting_info_for_instance($this->instance);
  98              $roomdata->haspresentations = false;
  99              if (!empty($roomdata->presentations)) {
 100                  $roomdata->haspresentations = true;
 101              }
 102              $templatedata->room = $roomdata;
 103          }
 104  
 105          $templatedata->recordingwarnings = [];
 106          $check = new cronrunning();
 107          $result = $check->get_result();
 108          if ($result->status != result::OK && $this->instance->is_moderator()) {
 109              $templatedata->recordingwarnings[] = (new notification(
 110                  get_string('view_message_cron_disabled', 'mod_bigbluebuttonbn',
 111                      $result->get_summary()),
 112                  notification::NOTIFY_ERROR,
 113                  false
 114              ))->export_for_template($output);
 115          }
 116          if ($this->instance->is_feature_enabled('showrecordings') && $this->instance->is_recorded()) {
 117              $recordings = new recordings_session($this->instance);
 118              $templatedata->recordings = $recordings->export_for_template($output);
 119          } else if ($this->instance->is_type_recordings_only()) {
 120              $templatedata->recordingwarnings[] = (new notification(
 121                  get_string('view_message_recordings_disabled', 'mod_bigbluebuttonbn'),
 122                  notification::NOTIFY_WARNING,
 123                  false
 124              ))->export_for_template($output);
 125          }
 126  
 127          return $templatedata;
 128      }
 129  
 130      /**
 131       * Whether to show the default server warning.
 132       *
 133       * @return bool
 134       */
 135      protected function show_default_server_warning(): bool {
 136          if (!$this->instance->is_admin()) {
 137              return false;
 138          }
 139  
 140          if (config::DEFAULT_SERVER_URL != config::get('server_url')) {
 141              return false;
 142          }
 143  
 144          return true;
 145      }
 146  
 147      /**
 148       * Whether to show the view warning.
 149       *
 150       * @return bool
 151       */
 152      protected function show_view_warning(): bool {
 153          if ($this->instance->is_admin()) {
 154              return true;
 155          }
 156  
 157          $generalwarningroles = explode(',', config::get('general_warning_roles'));
 158          $userroles = \mod_bigbluebuttonbn\local\helpers\roles::get_user_roles(
 159              $this->instance->get_context(),
 160              $this->instance->get_user_id()
 161          );
 162  
 163          foreach ($userroles as $userrole) {
 164              if (in_array($userrole->shortname, $generalwarningroles)) {
 165                  return true;
 166              }
 167          }
 168  
 169          return false;
 170      }
 171  
 172  }