MDL-73912 templates: Proper type value for back to user menu button
[moodle.git] / mod / feedback / analysis_course.php
blob7f5e3da27aebf7915fd039c6f02586bbfd8d8511
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.
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/>.
17 /**
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);
46 $PAGE->set_url($url);
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))) {
56 print_error('error');
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 if (!$PAGE->has_secondary_navigation()) {
75 echo $OUTPUT->heading(format_string($feedback->name));
78 //get the groupid
79 //lstgroupid is the choosen id
80 $mygroupid = false;
82 $courseselectform->display();
84 // Button "Export to excel".
85 if (has_capability('mod/feedback:viewreports', $context) && $feedbackstructure->get_items()) {
86 echo $OUTPUT->container_start('form-buttons');
87 $aurl = new moodle_url('/mod/feedback/analysis_to_excel.php',
88 ['sesskey' => sesskey(), 'id' => $id, 'courseid' => (int)$courseid]);
89 echo $OUTPUT->single_button($aurl, get_string('export_to_excel', 'feedback'));
90 echo $OUTPUT->container_end();
93 // Show the summary.
94 $summary = new mod_feedback\output\summary($feedbackstructure);
95 echo $OUTPUT->render_from_template('mod_feedback/summary', $summary->export_for_template($OUTPUT));
97 // Get the items of the feedback.
98 $items = $feedbackstructure->get_items(true);
100 if ($courseitemfilter > 0) {
101 $sumvalue = 'SUM(' . $DB->sql_cast_char2real('value', true) . ')';
102 $sql = "SELECT fv.course_id, c.shortname, $sumvalue AS sumvalue, COUNT(value) as countvalue
103 FROM {feedback_value} fv, {course} c, {feedback_item} fi
104 WHERE fv.course_id = c.id AND fi.id = fv.item AND fi.typ = ? AND fv.item = ?
105 GROUP BY course_id, shortname
106 ORDER BY sumvalue desc";
108 if ($courses = $DB->get_records_sql($sql, array($courseitemfiltertyp, $courseitemfilter))) {
109 $item = $DB->get_record('feedback_item', array('id'=>$courseitemfilter));
110 echo '<h4>'.$item->name.'</h4>';
111 echo '<div class="clearfix">';
112 echo '<table>';
113 echo '<tr><th>Course</th><th>Average</th></tr>';
115 foreach ($courses as $c) {
116 $coursecontext = context_course::instance($c->course_id);
117 $shortname = format_string($c->shortname, true, array('context' => $coursecontext));
119 echo '<tr>';
120 echo '<td>'.$shortname.'</td>';
121 echo '<td align="right">';
122 echo format_float(($c->sumvalue / $c->countvalue), 2);
123 echo '</td>';
124 echo '</tr>';
126 echo '</table>';
127 } else {
128 echo '<p>'.get_string('noresults').'</p>';
130 echo '<p><a href="analysis_course.php?id=' . $id . '">';
131 echo get_string('back');
132 echo '</a></p>';
133 } else {
135 // Print the items in an analysed form.
136 foreach ($items as $item) {
137 echo '<table class="analysis">';
138 $itemobj = feedback_get_item_class($item->typ);
139 $printnr = ($feedback->autonumbering && $item->itemnr) ? ($item->itemnr . '.') : '';
140 $itemobj->print_analysed($item, $printnr, $mygroupid, $feedbackstructure->get_courseid());
141 if (preg_match('/rated$/i', $item->typ)) {
142 $url = new moodle_url('/mod/feedback/analysis_course.php', array('id' => $id,
143 'courseitemfilter' => $item->id, 'courseitemfiltertyp' => $item->typ));
144 $anker = html_writer::link($url, get_string('sort_by_course', 'feedback'));
146 echo '<tr><td colspan="2">'.$anker.'</td></tr>';
148 echo '</table>';
152 echo $OUTPUT->footer();