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 310 and 401] [Versions 311 and 401] [Versions 39 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  
  17  /**
  18   * Prints an instance of mod_h5pactivity.
  19   *
  20   * @package     mod_h5pactivity
  21   * @copyright   2020 Ferran Recio <ferran@moodle.com>
  22   * @license     http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
  23   */
  24  
  25  use mod_h5pactivity\local\manager;
  26  use core_h5p\factory;
  27  use core_h5p\player;
  28  use core_h5p\helper;
  29  
  30  require(__DIR__.'/../../config.php');
  31  require_once (__DIR__.'/lib.php');
  32  
  33  $id = required_param('id', PARAM_INT);
  34  
  35  list ($course, $cm) = get_course_and_cm_from_cmid($id, 'h5pactivity');
  36  
  37  require_login($course, true, $cm);
  38  
  39  $manager = manager::create_from_coursemodule($cm);
  40  
  41  $moduleinstance = $manager->get_instance();
  42  
  43  $context = $manager->get_context();
  44  
  45  // Trigger module viewed event and completion.
  46  $manager->set_module_viewed($course);
  47  
  48  // Convert display options to a valid object.
  49  $factory = new factory();
  50  $core = $factory->get_core();
  51  $config = core_h5p\helper::decode_display_options($core, $moduleinstance->displayoptions);
  52  
  53  // Instantiate player.
  54  $fs = get_file_storage();
  55  $files = $fs->get_area_files($context->id, 'mod_h5pactivity', 'package', 0, 'id', false);
  56  $file = reset($files);
  57  $fileurl = moodle_url::make_pluginfile_url($file->get_contextid(), $file->get_component(),
  58                      $file->get_filearea(), $file->get_itemid(), $file->get_filepath(),
  59                      $file->get_filename(), false);
  60  
  61  $PAGE->set_url('/mod/h5pactivity/view.php', ['id' => $cm->id]);
  62  
  63  $shortname = format_string($course->shortname, true, ['context' => $context]);
  64  $pagetitle = strip_tags($shortname.': '.format_string($moduleinstance->name));
  65  $PAGE->set_title(format_string($pagetitle));
  66  
  67  $PAGE->set_heading(format_string($course->fullname));
  68  $PAGE->set_context($context);
  69  
  70  echo $OUTPUT->header();
  71  
  72  $instance = $manager->get_instance();
  73  
  74  if (!$manager->is_tracking_enabled()) {
  75      $message = get_string('previewmode', 'mod_h5pactivity');
  76      echo $OUTPUT->notification($message, \core\output\notification::NOTIFY_WARNING);
  77  }
  78  
  79  echo player::display($fileurl, $config, true, 'mod_h5pactivity', true);
  80  
  81  echo $OUTPUT->footer();