Search moodle.org's
Developer Documentation

See Release Notes

  • Bug fixes for general core bugs in 3.10.x will end 8 November 2021 (12 months).
  • Bug fixes for security issues in 3.10.x will end 9 May 2022 (18 months).
  • PHP version: minimum PHP 7.2.0 Note: minimum PHP version has increased since Moodle 3.8. PHP 7.3.x and 7.4.x are supported too.

Differences Between: [Versions 310 and 311] [Versions 310 and 400] [Versions 310 and 401] [Versions 310 and 402] [Versions 310 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  /**
  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  echo $OUTPUT->heading(format_string($moduleinstance->name));
  72  
  73  $instance = $manager->get_instance();
  74  if (!empty($instance->intro)) {
  75      echo $OUTPUT->box(format_module_intro('h5pactivity', $instance, $cm->id), 'generalbox', 'intro');
  76  }
  77  
  78  // Attempts review.
  79  if ($manager->can_view_all_attempts()) {
  80      $reviewurl = new moodle_url('report.php', ['a' => $cm->instance]);
  81      $reviewmessage = get_string('review_all_attempts', 'mod_h5pactivity', $manager->count_attempts());
  82  } else if ($manager->can_view_own_attempts() && $manager->count_attempts($USER->id)) {
  83      $reviewurl = new moodle_url('report.php', ['a' => $cm->instance, 'userid' => $USER->id]);
  84      $reviewmessage = get_string('review_my_attempts', 'mod_h5pactivity');
  85  }
  86  if (isset($reviewurl)) {
  87      $widget = new mod_h5pactivity\output\reportlink($reviewurl, $reviewmessage);
  88      echo $OUTPUT->render($widget);
  89  }
  90  
  91  if (!$manager->is_tracking_enabled()) {
  92      $message = get_string('previewmode', 'mod_h5pactivity');
  93      echo $OUTPUT->notification($message, \core\output\notification::NOTIFY_WARNING);
  94  }
  95  
  96  echo player::display($fileurl, $config, true, 'mod_h5pactivity');
  97  
  98  echo $OUTPUT->footer();