-
Notifications
You must be signed in to change notification settings - Fork 0
/
report.php
executable file
·108 lines (94 loc) · 3.98 KB
/
report.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
<?php
// This file is part of Moodle - http://moodle.org/
//
// Moodle is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// Moodle is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
use mod_feedbackbox\feedbackbox;
require_once('./../../config.php');
$instance = optional_param('instance', false, PARAM_INT); // Feedbackbox ID.
$action = optional_param('action', null, PARAM_ALPHA);
$turnus = optional_param('turnus', null, PARAM_INT);
$userid = $USER->id;
if ($instance === false) {
if (!empty($SESSION->instance)) {
$instance = $SESSION->instance;
} else {
throw new \moodle_exception('requiredparameter', 'error');
}
}
$SESSION->instance = $instance;
if (!$feedbackbox = $DB->get_record('feedbackbox', ['id' => $instance])) {
throw new \moodle_exception('incorrectfeedbackbox', 'error');
}
if (!$course = $DB->get_record('course', ['id' => $feedbackbox->course])) {
throw new \moodle_exception('coursemisconf', 'error');
}
if (!$cm = get_coursemodule_from_instance('feedbackbox', $feedbackbox->id, $course->id)) {
throw new \moodle_exception('invalidcoursemodule', 'error');
}
require_course_login($course, true, $cm);
$feedbackbox = new feedbackbox(0, $feedbackbox, $course, $cm);
$context = context_module::instance($cm->id);
if (!has_capability('mod/feedbackbox:manage', $context)) {
// Should never happen, unless called directly by a snoop...
throw new \moodle_exception('nopermissions', 'moodle', $CFG->wwwroot . '/mod/feedbackbox/view.php?id=' . $cm->id,
get_string('viewallresponses', 'mod_feedbackbox'));
}
$sid = $feedbackbox->survey->id;
$url = new moodle_url($CFG->wwwroot . '/mod/feedbackbox/report.php');
if ($instance) {
$url->param('instance', $instance);
}
if ($action) {
$url->param('action', $action);
}
if ($turnus) {
$url->param('turnus', $turnus);
}
$PAGE->set_url($url);
$PAGE->set_context($context);
$feedbackbox->add_renderer($PAGE->get_renderer('mod_feedbackbox'));
$currentturnus = $feedbackbox->get_current_turnus();
if ($currentturnus != false) {
$currentturnus = $currentturnus->id;
} else {
$currentturnus = 1;
}
$navbarelements = [
(object) ['url' => new moodle_url('/mod/feedbackbox/report.php',
['instance' => $instance]), 'name' => get_string('viewstats', 'mod_feedbackbox')],
(object) ['url' => new moodle_url('/mod/feedbackbox/report.php',
['instance' => $instance, 'action' => 'single']), 'name' => get_string('viewsingle', 'mod_feedbackbox')],
];
$turnus = $turnus === null ? $currentturnus : intval($turnus);
if ($action == 'single') {
$data = $feedbackbox->get_turnus_responses($turnus);
$data->single = true;
$PAGE->requires->js_call_amd('mod_feedbackbox/chartview',
'init',
[$feedbackbox->id, 'single', $turnus, get_string('round', 'mod_feedbackbox')]);
$navbarelements[1]->active = true;
} else {
$data = $feedbackbox->get_feedback_responses();
$PAGE->requires->js_call_amd('mod_feedbackbox/chartview',
'init',
[$feedbackbox->id, 'all', $data->totalparticipants, get_string('round', 'mod_feedbackbox')]);
$data->all = true;
$navbarelements[0]->active = true;
}
$data->downloadcsv = moodle_url::make_pluginfile_url($context->id, 'mod_feedbackbox', 'csv', 0, '/download', '/csv');
$data->navbarelements = $navbarelements;
$PAGE->requires->css('/mod/feedbackbox/style/chart.css');
echo $feedbackbox->renderer->header();
echo $feedbackbox->renderer->render_from_template('mod_feedbackbox/report', $data);
echo $feedbackbox->renderer->footer($course);