Proyectos de Subversion Moodle

Rev

| Ultima modificación | Ver Log |

Rev Autor Línea Nro. Línea
1 efrain 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
// Only users without permission to submit can see the warning messages.
75
if (!$manager->can_submit()) {
76
    // Show preview mode message.
77
    $message = get_string('previewmode', 'mod_h5pactivity');
78
    echo $OUTPUT->notification($message, \core\output\notification::NOTIFY_INFO, false);
79
 
80
    // If tracking is disabled, show a warning.
81
    if (!$manager->is_tracking_enabled()) {
82
        if (has_capability('moodle/course:manageactivities', $context)) {
83
            $url = new moodle_url('/course/modedit.php', ['update' => $cm->id]);
84
            $message = get_string('trackingdisabled_enable', 'mod_h5pactivity', $url->out());
85
        } else {
86
            $message = get_string('trackingdisabled', 'mod_h5pactivity');
87
        }
88
        echo $OUTPUT->notification($message, \core\output\notification::NOTIFY_WARNING);
89
    }
90
}
91
 
92
$extraactions = [];
93
 
94
if ($manager->can_view_all_attempts() && $manager->is_tracking_enabled()) {
95
    $extraactions[] = new action_link(
96
        new moodle_url('/mod/h5pactivity/report.php', ['id' => $cm->id]),
97
        get_string('viewattempts', 'mod_h5pactivity', $manager->count_attempts()),
98
        null,
99
        null,
100
        new pix_icon('i/chartbar', '', 'core')
101
    );
102
}
103
 
104
echo player::display($fileurl, $config, true, 'mod_h5pactivity', true, $extraactions);
105
 
106
echo $OUTPUT->footer();