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]

   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 html_table;
  19  use html_writer;
  20  use mod_bigbluebuttonbn\instance;
  21  use mod_bigbluebuttonbn\meeting;
  22  use mod_bigbluebuttonbn\plugin;
  23  use renderable;
  24  use renderer_base;
  25  use stdClass;
  26  
  27  /**
  28   * Renderer for the Index page.
  29   *
  30   * @package   mod_bigbluebuttonbn
  31   * @copyright 2010 onwards, Blindside Networks Inc
  32   * @license   http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
  33   */
  34  class index implements renderable {
  35  
  36      /** @var stdClass */
  37      protected $course;
  38  
  39      /** @var stdClass[] */
  40      protected $instances;
  41  
  42      /**
  43       * Constructor for the index renderable.
  44       *
  45       * @param stdClass $course
  46       * @param instance[] List of bbbbn instances
  47       */
  48      public function __construct(stdClass $course, array $instances) {
  49          $this->course = $course;
  50          $this->instances = $instances;
  51      }
  52  
  53      /**
  54       * Get the table for the index page.
  55       *
  56       * @param renderer_base $output
  57       * @return html_table
  58       */
  59      public function get_table(renderer_base $output): html_table {
  60          // Print the list of instances.
  61          $table = new html_table();
  62  
  63          if (course_format_uses_sections($this->course->format)) {
  64              $sectionheading = get_string('sectionname', "format_{$this->course->format}");
  65          } else {
  66              $sectionheading = '';
  67          }
  68  
  69          $table->head = [
  70              $sectionheading,
  71              get_string('index_heading_name', plugin::COMPONENT),
  72              get_string('index_heading_group', plugin::COMPONENT),
  73              get_string('index_heading_users', plugin::COMPONENT),
  74              get_string('index_heading_viewer', plugin::COMPONENT),
  75              get_string('index_heading_moderator', plugin::COMPONENT),
  76              get_string('index_heading_recording', plugin::COMPONENT),
  77              get_string('index_heading_actions', plugin::COMPONENT),
  78          ];
  79          $table->align = ['center', 'left', 'center', 'center', 'center', 'center', 'center'];
  80  
  81          foreach ($this->instances as $instance) {
  82              $this->add_instance_to_table($output, $table, $instance);
  83          }
  84  
  85          return $table;
  86      }
  87  
  88      /**
  89       * Add details of the bigbluebuttonbn instance to the table.
  90       *
  91       * @param renderer_base $output
  92       * @param html_table $table
  93       * @param instance $instance
  94       */
  95      protected function add_instance_to_table(renderer_base $output, html_table $table, instance $instance): void {
  96          $cm = $instance->get_cm();
  97          if (!$cm->uservisible) {
  98              return;
  99          }
 100          if (groups_get_activity_groupmode($cm) == 0) {
 101              $table->data[] = $this->add_room_row_to_table($output, $instance);
 102          } else {
 103              // Add 'All participants' room information.
 104              $table->data[] = $this->add_room_row_to_table($output, $instance, 0);
 105  
 106              // Add data for the groups belonging to the bbb instance, if any.
 107              $groups = groups_get_activity_allowed_groups($cm);
 108              foreach ($groups as $group) {
 109                  $table->data[] = $this->add_room_row_to_table($output, $instance, $group->id);
 110              }
 111          }
 112      }
 113  
 114      /**
 115       * Displays the general view.
 116       *
 117       * @param renderer_base $output
 118       * @param instance $instance
 119       * @param int|null $group
 120       * @return array
 121       */
 122      protected function add_room_row_to_table(renderer_base $output, instance $instance, ?int $group = null): array {
 123          if ($group) {
 124              $instance = instance::get_group_instance_from_instance($instance, $group);
 125          }
 126          $meeting = new meeting($instance);
 127  
 128          if (course_format_uses_sections($this->course->format)) {
 129              $sectionname = get_section_name($this->course, $instance->get_cm()->sectionnum);
 130          } else {
 131              $sectionname = '';
 132          }
 133  
 134          $viewurl = $instance->get_view_url();
 135          if ($groupid = $instance->get_group_id()) {
 136              $viewurl->param('group', $groupid);
 137          }
 138  
 139          $joinurl = html_writer::link($viewurl, format_string($instance->get_meeting_name()));
 140  
 141          // The meeting info was returned.
 142          if ($meeting->is_running()) {
 143              return [
 144                  $sectionname,
 145                  $joinurl,
 146                  $instance->get_group_name(),
 147                  $this->get_room_usercount($meeting),
 148                  $this->get_room_attendee_list($meeting, 'VIEWER'),
 149                  $this->get_room_attendee_list($meeting, 'MODERATOR'),
 150                  $this->get_room_record_info($output, $instance),
 151                  $this->get_room_actions($output, $instance, $meeting),
 152              ];
 153          }
 154  
 155          return [$sectionname, $joinurl, $instance->get_group_name(), '', '', '', '', ''];
 156      }
 157  
 158      /**
 159       * Count the number of users in the meeting.
 160       *
 161       * @param meeting $meeting
 162       * @return int
 163       */
 164      protected function get_room_usercount(meeting $meeting): int {
 165          return count($meeting->get_attendees());
 166      }
 167  
 168      /**
 169       * Returns attendee list.
 170       *
 171       * @param meeting $meeting
 172       * @param string $role
 173       * @return string
 174       */
 175      protected function get_room_attendee_list(meeting $meeting, string $role): string {
 176          $attendees = [];
 177  
 178          // Iterate attendees, matching by their "role" property.
 179          foreach ($meeting->get_attendees() as $attendee) {
 180              if (strcmp((string) $attendee['role'], $role) === 0) {
 181                  $attendees[] = $attendee['fullName'];
 182              }
 183          }
 184  
 185          return implode(', ', $attendees);
 186      }
 187  
 188      /**
 189       * Returns indication of recording enabled.
 190       *
 191       * @param renderer_base $output
 192       * @param instance $instance
 193       * @return string
 194       */
 195      protected function get_room_record_info(renderer_base $output, instance $instance): string {
 196          if ($instance->is_recorded()) {
 197              // If it has been set when meeting created, set the variable on/off.
 198              return get_string('index_enabled', 'bigbluebuttonbn');
 199          }
 200          return '';
 201      }
 202  
 203      /**
 204       * Returns room actions.
 205       *
 206       * @param renderer_base $output
 207       * @param instance $instance
 208       * @param meeting $meeting
 209       * @return string
 210       */
 211      protected function get_room_actions(renderer_base $output, instance $instance, meeting $meeting): string {
 212          if ($instance->is_moderator()) {
 213              return $output->render_from_template('mod_bigbluebuttonbn/end_session_button', (object) [
 214                  'bigbluebuttonbnid' => $instance->get_instance_id(),
 215                  'groupid' => $instance->get_group_id(),
 216                  'statusrunning' => $meeting->is_running(),
 217              ]);
 218          }
 219  
 220          return '';
 221      }
 222  }