Merge branch 'MDL-74441-400' of https://github.com/cameron1729/moodle into MOODLE_400...
[moodle.git] / mod / h5pactivity / view.php
blob012fedb661682d791b6adeebe8ef558934138d50
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.
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/>.
17 /**
18 * Prints an instance of mod_h5pactivity.
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
25 use mod_h5pactivity\local\manager;
26 use core_h5p\factory;
27 use core_h5p\player;
28 use core_h5p\helper;
30 require(__DIR__.'/../../config.php');
31 require_once(__DIR__.'/lib.php');
33 $id = required_param('id', PARAM_INT);
35 list ($course, $cm) = get_course_and_cm_from_cmid($id, 'h5pactivity');
37 require_login($course, true, $cm);
39 $manager = manager::create_from_coursemodule($cm);
41 $moduleinstance = $manager->get_instance();
43 $context = $manager->get_context();
45 // Trigger module viewed event and completion.
46 $manager->set_module_viewed($course);
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);
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);
61 $PAGE->set_url('/mod/h5pactivity/view.php', ['id' => $cm->id]);
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));
67 $PAGE->set_heading(format_string($course->fullname));
68 $PAGE->set_context($context);
70 echo $OUTPUT->header();
72 $instance = $manager->get_instance();
74 if (!$manager->is_tracking_enabled()) {
75 $message = get_string('previewmode', 'mod_h5pactivity');
76 echo $OUTPUT->notification($message, \core\output\notification::NOTIFY_WARNING);
79 echo player::display($fileurl, $config, true, 'mod_h5pactivity', true);
81 echo $OUTPUT->footer();