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.
   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\config;
  21  use mod_bigbluebuttonbn\local\helpers\roles;
  22  use renderable;
  23  use renderer_base;
  24  use stdClass;
  25  use templatable;
  26  
  27  /**
  28   * Renderable for the import 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   * @author    Darko Miletic  (darko.miletic [at] gmail [dt] com)
  34   */
  35  class import_view implements renderable, templatable {
  36      /**
  37       * @var instance $destinationinstance
  38       */
  39      protected $destinationinstance;
  40  
  41      /**
  42       * @var int|null $sourceinstanceid the source instance id or null if it is not yet set.
  43       */
  44      protected $sourceinstanceid;
  45  
  46      /**
  47       * @var int|null $sourcecourseid the source instance id or null if it is not yet set.
  48       */
  49      protected $sourcecourseid;
  50  
  51      /**
  52       * import_view constructor.
  53       *
  54       * @param instance $destinationinstance
  55       * @param int $sourcecourseid
  56       * @param int $sourceinstanceid
  57       */
  58      public function __construct(instance $destinationinstance, int $sourcecourseid, int $sourceinstanceid) {
  59          $this->destinationinstance = $destinationinstance;
  60          $this->sourcecourseid = $sourcecourseid >= 0 ? $sourcecourseid : null;
  61          $this->sourceinstanceid = $sourceinstanceid >= 0 ? $sourceinstanceid : null;
  62      }
  63  
  64      /**
  65       * Defer to template.
  66       *
  67       * @param renderer_base $output
  68       * @return stdClass
  69       */
  70      public function export_for_template(renderer_base $output): stdClass {
  71          $courses = roles::import_get_courses_for_select($this->destinationinstance);
  72          if (config::get('importrecordings_from_deleted_enabled')) {
  73              $courses[0] = get_string('recordings_from_deleted_activities', 'mod_bigbluebuttonbn');
  74              ksort($courses);
  75          }
  76          $context = (object) [
  77              'bbbid' => $this->destinationinstance->get_instance_id(),
  78              'has_recordings' => true,
  79              'bbbsourceid' => 0
  80          ];
  81  
  82          if (!empty($this->sourceinstanceid)) {
  83              $context->sourceid = $this->sourceinstanceid;
  84              $context->search = [
  85                  'value' => ''
  86              ];
  87              $sourceinstance = instance::get_from_instanceid($this->sourceinstanceid);
  88              if ($sourceinstance->is_type_room_only()) {
  89                  $context->has_recordings = false;
  90              }
  91              $context->bbbsourceid = $sourceinstance->get_instance_id();
  92          }
  93  
  94          // Now the selects.
  95          if (!empty($this->sourcecourseid)) {
  96              $selectrecords = [];
  97  
  98              $cms = get_fast_modinfo($this->sourcecourseid)->instances['bigbluebuttonbn'];
  99              foreach ($cms as $cm) {
 100                  if ($cm->id == $this->destinationinstance->get_cm_id()) {
 101                      // Skip the target instance.
 102                      continue;
 103                  }
 104  
 105                  if ($cm->deletioninprogress) {
 106                      // Check if the BBB is not currently scheduled for deletion.
 107                      continue;
 108                  }
 109  
 110                  $selectrecords[$cm->instance] = $cm->name;
 111              }
 112              if (config::get('importrecordings_from_deleted_enabled')) {
 113                  $selectrecords[0] =
 114                      get_string('recordings_from_deleted_activities', 'mod_bigbluebuttonbn');
 115              }
 116              $actionurl = $this->destinationinstance->get_import_url();
 117              $actionurl->param('sourcecourseid', $this->sourcecourseid);
 118  
 119              $select = new \single_select(
 120                  $actionurl,
 121                  'sourcebn',
 122                  $selectrecords,
 123                  $this->sourceinstanceid ?? ""
 124              );
 125              $context->bbb_select = $select->export_for_template($output);
 126          }
 127          $context->sourcecourseid = $this->sourcecourseid ?? 0;
 128  
 129          // Course selector.
 130          $context->course_select = (new \single_select(
 131              $this->destinationinstance->get_import_url(),
 132              'sourcecourseid',
 133              $courses,
 134              $this->sourcecourseid ?? ""
 135          ))->export_for_template($output);
 136  
 137          if (!is_null($this->sourcecourseid)) {
 138              $context->has_selected_course = true;
 139          }
 140  
 141          // Back button.
 142          $context->back_button = (new \single_button(
 143              $this->destinationinstance->get_view_url(),
 144              get_string('view_recording_button_return', 'mod_bigbluebuttonbn')
 145          ))->export_for_template($output);
 146  
 147          return $context;
 148      }
 149  }