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 |
* View H5P Content
|
|
|
18 |
*
|
|
|
19 |
* @package mod_hvp
|
|
|
20 |
* @copyright 2016 Joubel AS <contact@joubel.com>
|
|
|
21 |
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
|
|
22 |
*/
|
|
|
23 |
require_once("../../config.php");
|
|
|
24 |
require_once("locallib.php");
|
|
|
25 |
|
|
|
26 |
global $PAGE, $DB, $CFG, $OUTPUT;
|
|
|
27 |
|
|
|
28 |
$id = required_param('id', PARAM_INT);
|
|
|
29 |
|
|
|
30 |
// Verify course context.
|
|
|
31 |
$cm = get_coursemodule_from_id('hvp', $id);
|
|
|
32 |
if (!$cm) {
|
|
|
33 |
print_error('invalidcoursemodule');
|
|
|
34 |
}
|
|
|
35 |
$course = $DB->get_record('course', array('id' => $cm->course));
|
|
|
36 |
if (!$course) {
|
|
|
37 |
print_error('coursemisconf');
|
|
|
38 |
}
|
|
|
39 |
require_course_login($course, true, $cm);
|
|
|
40 |
$context = context_module::instance($cm->id);
|
|
|
41 |
require_capability('mod/hvp:view', $context);
|
|
|
42 |
|
|
|
43 |
// Set up view assets.
|
|
|
44 |
$view = new \mod_hvp\view_assets($cm, $course);
|
|
|
45 |
$content = $view->getcontent();
|
|
|
46 |
$view->validatecontent();
|
|
|
47 |
|
|
|
48 |
// Configure page.
|
|
|
49 |
$PAGE->set_url(new \moodle_url('/mod/hvp/view.php', array('id' => $id)));
|
|
|
50 |
$PAGE->set_title(format_string($content['title']));
|
|
|
51 |
$PAGE->set_heading($course->fullname);
|
|
|
52 |
|
|
|
53 |
// Add H5P assets to page.
|
|
|
54 |
$view->addassetstopage();
|
|
|
55 |
$view->logviewed();
|
|
|
56 |
|
|
|
57 |
$PAGE->requires->css(new moodle_url(\mod_hvp\view_assets::getsiteroot() . '/mod/hvp/view.css'));
|
|
|
58 |
|
|
|
59 |
// Print page HTML.
|
|
|
60 |
echo $OUTPUT->header();
|
|
|
61 |
if ($CFG->branch < 400) {
|
|
|
62 |
echo $OUTPUT->heading(format_string($content['title']));
|
|
|
63 |
echo '<div class="clearer"></div>';
|
|
|
64 |
|
|
|
65 |
// Output introduction.
|
|
|
66 |
if (trim(strip_tags($content['intro'], '<img>'))) {
|
|
|
67 |
echo $OUTPUT->box_start('mod_introbox', 'hvpintro');
|
|
|
68 |
echo format_module_intro('hvp', (object) array(
|
|
|
69 |
'intro' => $content['intro'],
|
|
|
70 |
'introformat' => $content['introformat'],
|
|
|
71 |
), $cm->id);
|
|
|
72 |
echo $OUTPUT->box_end();
|
|
|
73 |
}
|
|
|
74 |
}
|
|
|
75 |
|
|
|
76 |
$hashub = (has_capability('mod/hvp:share', $context) && !empty(get_config('mod_hvp', 'site_uuid')) && !empty(get_config('mod_hvp', 'hub_secret')));
|
|
|
77 |
$isshared = $content['shared'] === '1';
|
|
|
78 |
$huboptionsdata = array(
|
|
|
79 |
'id' => $id,
|
|
|
80 |
'isshared' => $isshared
|
|
|
81 |
);
|
|
|
82 |
|
|
|
83 |
// Update Hub status for content before printing out messages.
|
|
|
84 |
if ($hashub && $isshared) {
|
|
|
85 |
$newstate = hvp_update_hub_status($content);
|
|
|
86 |
$synced = $newstate !== false ? $newstate : intval($content['synced']);
|
|
|
87 |
$huboptionsdata['canbesynced'] = $synced !== \H5PContentHubSyncStatus::SYNCED && $synced !== \H5PContentHubSyncStatus::WAITING;
|
|
|
88 |
$huboptionsdata['waitingclass'] = $synced === \H5PContentHubSyncStatus::WAITING ? '' : ' hidden';
|
|
|
89 |
$huboptionsdata['token'] = \H5PCore::createToken('share_' . $id);
|
|
|
90 |
}
|
|
|
91 |
|
|
|
92 |
// Print any messages.
|
|
|
93 |
\mod_hvp\framework::printMessages('info', \mod_hvp\framework::messages('info'));
|
|
|
94 |
\mod_hvp\framework::printMessages('error', \mod_hvp\framework::messages('error'));
|
|
|
95 |
|
|
|
96 |
if ($hashub) {
|
|
|
97 |
echo $OUTPUT->render_from_template('mod_hvp/hub_options', $huboptionsdata);
|
|
|
98 |
}
|
|
|
99 |
|
|
|
100 |
$view->outputview();
|
|
|
101 |
echo $OUTPUT->footer();
|