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 all results for 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 |
|
|
|
24 |
require_once(dirname(__FILE__) . '/../../config.php');
|
|
|
25 |
require_once("locallib.php");
|
|
|
26 |
|
|
|
27 |
global $DB, $PAGE, $USER, $COURSE;
|
|
|
28 |
|
|
|
29 |
$id = required_param('id', PARAM_INT);
|
|
|
30 |
$userid = optional_param('userid', 0, PARAM_INT);
|
|
|
31 |
|
|
|
32 |
if (! $cm = get_coursemodule_from_id('hvp', $id)) {
|
|
|
33 |
print_error('invalidcoursemodule');
|
|
|
34 |
}
|
|
|
35 |
if (! $course = $DB->get_record('course', array('id' => $cm->course))) {
|
|
|
36 |
print_error('coursemisconf');
|
|
|
37 |
}
|
|
|
38 |
require_course_login($course, false, $cm);
|
|
|
39 |
|
|
|
40 |
// Check permission.
|
|
|
41 |
$context = \context_module::instance($cm->id);
|
|
|
42 |
|
|
|
43 |
// Load H5P Content.
|
|
|
44 |
$hvp = $DB->get_record_sql(
|
|
|
45 |
"SELECT h.id,
|
|
|
46 |
h.name AS title,
|
|
|
47 |
hl.machine_name,
|
|
|
48 |
hl.major_version,
|
|
|
49 |
hl.minor_version
|
|
|
50 |
FROM {hvp} h
|
|
|
51 |
JOIN {hvp_libraries} hl ON hl.id = h.main_library_id
|
|
|
52 |
WHERE h.id = ?",
|
|
|
53 |
array($cm->instance));
|
|
|
54 |
|
|
|
55 |
if ($hvp === false) {
|
|
|
56 |
print_error('invalidhvp', 'mod_hvp');
|
|
|
57 |
}
|
|
|
58 |
|
|
|
59 |
// Redirect to report if a specific user is chosen.
|
|
|
60 |
if ($userid) {
|
|
|
61 |
redirect(new moodle_url('/mod/hvp/review.php',
|
|
|
62 |
array(
|
|
|
63 |
'id' => $hvp->id,
|
|
|
64 |
'course' => $course->id,
|
|
|
65 |
'user' => $userid
|
|
|
66 |
))
|
|
|
67 |
);
|
|
|
68 |
}
|
|
|
69 |
hvp_require_view_results_permission((int)$USER->id, $context, $cm->id);
|
|
|
70 |
|
|
|
71 |
// Log content result view.
|
|
|
72 |
new \mod_hvp\event(
|
|
|
73 |
'results', 'content',
|
|
|
74 |
$hvp->id, $hvp->title,
|
|
|
75 |
$hvp->machine_name, "{$hvp->major_version}.{$hvp->minor_version}"
|
|
|
76 |
);
|
|
|
77 |
|
|
|
78 |
// Set page properties.
|
|
|
79 |
$pageurl = new moodle_url('/mod/hvp/grade.php', array('id' => $hvp->id));
|
|
|
80 |
$PAGE->set_url($pageurl);
|
|
|
81 |
$title = get_string('gradeheading', 'hvp', $hvp->title);
|
|
|
82 |
$PAGE->set_title($title);
|
|
|
83 |
$PAGE->set_heading($course->fullname);
|
|
|
84 |
|
|
|
85 |
// List all results for specific content.
|
|
|
86 |
$dataviewid = 'h5p-results';
|
|
|
87 |
|
|
|
88 |
// Add required assets for data views.
|
|
|
89 |
$root = \mod_hvp\view_assets::getsiteroot();
|
|
|
90 |
$PAGE->requires->js(new moodle_url($root . '/mod/hvp/library/js/jquery.js'), true);
|
|
|
91 |
$PAGE->requires->js(new moodle_url($root . '/mod/hvp/library/js/h5p-utils.js'), true);
|
|
|
92 |
$PAGE->requires->js(new moodle_url($root . '/mod/hvp/library/js/h5p-data-view.js'), true);
|
|
|
93 |
$PAGE->requires->js(new moodle_url($root . '/mod/hvp/dataviews.js'), true);
|
|
|
94 |
$PAGE->requires->css(new moodle_url($root . '/mod/hvp/styles.css'));
|
|
|
95 |
|
|
|
96 |
// Add JavaScript settings to data views.
|
|
|
97 |
$settings = array(
|
|
|
98 |
'dataViews' => array(
|
|
|
99 |
"{$dataviewid}" => array(
|
|
|
100 |
'source' => "{$root}/mod/hvp/ajax.php?action=results&content_id={$hvp->id}",
|
|
|
101 |
'headers' => array(
|
|
|
102 |
(object) array(
|
|
|
103 |
'text' => get_string('user', 'hvp'),
|
|
|
104 |
'sortable' => true
|
|
|
105 |
),
|
|
|
106 |
(object) array(
|
|
|
107 |
'text' => get_string('score', 'hvp'),
|
|
|
108 |
'sortable' => true
|
|
|
109 |
),
|
|
|
110 |
(object) array(
|
|
|
111 |
'text' => get_string('maxscore', 'hvp'),
|
|
|
112 |
'sortable' => true
|
|
|
113 |
),
|
|
|
114 |
(object) array(
|
|
|
115 |
'text' => get_string('finished', 'hvp'),
|
|
|
116 |
'sortable' => true
|
|
|
117 |
),
|
|
|
118 |
(object) array(
|
|
|
119 |
'text' => get_string('dataviewreportlabel', 'hvp')
|
|
|
120 |
)
|
|
|
121 |
),
|
|
|
122 |
'filters' => array(true),
|
|
|
123 |
'order' => (object) array(
|
|
|
124 |
'by' => 3,
|
|
|
125 |
'dir' => 0
|
|
|
126 |
),
|
|
|
127 |
'l10n' => array(
|
|
|
128 |
'loading' => get_string('loadingdata', 'hvp'),
|
|
|
129 |
'ajaxFailed' => get_string('ajaxfailed', 'hvp'),
|
|
|
130 |
'noData' => get_string('nodata', 'hvp'),
|
|
|
131 |
'currentPage' => get_string('currentpage', 'hvp'),
|
|
|
132 |
'nextPage' => get_string('nextpage', 'hvp'),
|
|
|
133 |
'previousPage' => get_string('previouspage', 'hvp'),
|
|
|
134 |
'search' => get_string('search', 'hvp'),
|
|
|
135 |
'empty' => get_string('empty', 'hvp')
|
|
|
136 |
)
|
|
|
137 |
)
|
|
|
138 |
)
|
|
|
139 |
);
|
|
|
140 |
$PAGE->requires->data_for_js('H5PIntegration', $settings, true);
|
|
|
141 |
|
|
|
142 |
// Print page HTML.
|
|
|
143 |
echo $OUTPUT->header();
|
|
|
144 |
echo '<div class="clearer"></div>';
|
|
|
145 |
|
|
|
146 |
// Print H5P Content.
|
|
|
147 |
echo "<h2>{$title}</h2>";
|
|
|
148 |
echo '<div id="h5p-results">' . get_string('javascriptloading', 'hvp') . '</div>';
|
|
|
149 |
|
|
|
150 |
echo $OUTPUT->footer();
|