2 // This file is part of Moodle - http://moodle.org/
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.
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/>.
18 * shows an analysed view of a feedback on the mainsite
20 * @author Andreas Grabs
21 * @license http://www.gnu.org/copyleft/gpl.html GNU Public License
22 * @package mod_feedback
25 require_once("../../config.php");
26 require_once("lib.php");
28 $current_tab = 'analysis';
30 $id = required_param('id', PARAM_INT
); //the POST dominated the GET
31 $courseitemfilter = optional_param('courseitemfilter', '0', PARAM_INT
);
32 $courseitemfiltertyp = optional_param('courseitemfiltertyp', '0', PARAM_ALPHANUM
);
33 $courseid = optional_param('courseid', false, PARAM_INT
);
35 $url = new moodle_url('/mod/feedback/analysis_course.php', array('id'=>$id));
36 navigation_node
::override_active_url($url);
37 if ($courseid !== false) {
38 $url->param('courseid', $courseid);
40 if ($courseitemfilter !== '0') {
41 $url->param('courseitemfilter', $courseitemfilter);
43 if ($courseitemfiltertyp !== '0') {
44 $url->param('courseitemfiltertyp', $courseitemfiltertyp);
48 list($course, $cm) = get_course_and_cm_from_cmid($id, 'feedback');
49 $context = context_module
::instance($cm->id
);
51 require_course_login($course, true, $cm);
53 $feedback = $PAGE->activityrecord
;
55 if (!($feedback->publish_stats
OR has_capability('mod/feedback:viewreports', $context))) {
59 $feedbackstructure = new mod_feedback_structure($feedback, $PAGE->cm
, $courseid);
61 // Process course select form.
62 $courseselectform = new mod_feedback_course_select_form($url, $feedbackstructure);
63 if ($data = $courseselectform->get_data()) {
64 redirect(new moodle_url($url, ['courseid' => $data->courseid
]));
67 /// Print the page header
68 $strfeedbacks = get_string("modulenameplural", "feedback");
69 $strfeedback = get_string("modulename", "feedback");
71 $PAGE->set_heading($course->fullname
);
72 $PAGE->set_title($feedback->name
);
73 echo $OUTPUT->header();
74 echo $OUTPUT->heading(format_string($feedback->name
));
80 //lstgroupid is the choosen id
83 $courseselectform->display();
85 // Button "Export to excel".
86 if (has_capability('mod/feedback:viewreports', $context) && $feedbackstructure->get_items()) {
87 echo $OUTPUT->container_start('form-buttons');
88 $aurl = new moodle_url('/mod/feedback/analysis_to_excel.php',
89 ['sesskey' => sesskey(), 'id' => $id, 'courseid' => (int)$courseid]);
90 echo $OUTPUT->single_button($aurl, get_string('export_to_excel', 'feedback'));
91 echo $OUTPUT->container_end();
95 $summary = new mod_feedback\output\
summary($feedbackstructure);
96 echo $OUTPUT->render_from_template('mod_feedback/summary', $summary->export_for_template($OUTPUT));
98 // Get the items of the feedback.
99 $items = $feedbackstructure->get_items(true);
101 if ($courseitemfilter > 0) {
102 $sumvalue = 'SUM(' . $DB->sql_cast_char2real('value', true) . ')';
103 $sql = "SELECT fv.course_id, c.shortname, $sumvalue AS sumvalue, COUNT(value) as countvalue
104 FROM {feedback_value} fv, {course} c, {feedback_item} fi
105 WHERE fv.course_id = c.id AND fi.id = fv.item AND fi.typ = ? AND fv.item = ?
106 GROUP BY course_id, shortname
107 ORDER BY sumvalue desc";
109 if ($courses = $DB->get_records_sql($sql, array($courseitemfiltertyp, $courseitemfilter))) {
110 $item = $DB->get_record('feedback_item', array('id'=>$courseitemfilter));
111 echo '<h4>'.$item->name
.'</h4>';
112 echo '<div class="clearfix">';
114 echo '<tr><th>Course</th><th>Average</th></tr>';
116 foreach ($courses as $c) {
117 $coursecontext = context_course
::instance($c->course_id
);
118 $shortname = format_string($c->shortname
, true, array('context' => $coursecontext));
121 echo '<td>'.$shortname.'</td>';
122 echo '<td align="right">';
123 echo format_float(($c->sumvalue
/ $c->countvalue
), 2);
129 echo '<p>'.get_string('noresults').'</p>';
131 echo '<p><a href="analysis_course.php?id=' . $id . '">';
132 echo get_string('back');
136 // Print the items in an analysed form.
137 foreach ($items as $item) {
138 echo '<table class="analysis">';
139 $itemobj = feedback_get_item_class($item->typ
);
140 $printnr = ($feedback->autonumbering
&& $item->itemnr
) ?
($item->itemnr
. '.') : '';
141 $itemobj->print_analysed($item, $printnr, $mygroupid, $feedbackstructure->get_courseid());
142 if (preg_match('/rated$/i', $item->typ
)) {
143 $url = new moodle_url('/mod/feedback/analysis_course.php', array('id' => $id,
144 'courseitemfilter' => $item->id
, 'courseitemfiltertyp' => $item->typ
));
145 $anker = html_writer
::link($url, get_string('sort_by_course', 'feedback'));
147 echo '<tr><td colspan="2">'.$anker.'</td></tr>';
153 echo $OUTPUT->footer();