weekly release 2.2dev
[moodle.git] / mod / feedback / analysis_course.php
CommitLineData
84973212 1<?php
2
c70ad9f7 3/**
4* shows an analysed view of a feedback on the mainsite
5*
c70ad9f7 6* @author Andreas Grabs
7* @license http://www.gnu.org/copyleft/gpl.html GNU Public License
8* @package feedback
9*/
10
84973212 11require_once("../../config.php");
12require_once("lib.php");
13
14// $SESSION->feedback->current_tab = 'analysis';
15$current_tab = 'analysis';
16
17$id = required_param('id', PARAM_INT); //the POST dominated the GET
18$coursefilter = optional_param('coursefilter', '0', PARAM_INT);
19$courseitemfilter = optional_param('courseitemfilter', '0', PARAM_INT);
20$courseitemfiltertyp = optional_param('courseitemfiltertyp', '0', PARAM_ALPHANUM);
21// $searchcourse = optional_param('searchcourse', '', PARAM_ALPHAEXT);
22$searchcourse = optional_param('searchcourse', '', PARAM_RAW);
23$courseid = optional_param('courseid', false, PARAM_INT);
24
a6855934 25$url = new moodle_url('/mod/feedback/analysis_course.php', array('id'=>$id));
84973212 26if ($courseid !== false) {
27 $url->param('courseid', $courseid);
28}
29if ($coursefilter !== '0') {
30 $url->param('coursefilter', $coursefilter);
31}
32if ($courseitemfilter !== '0') {
33 $url->param('courseitemfilter', $courseitemfilter);
34}
35if ($courseitemfiltertyp !== '0') {
36 $url->param('courseitemfiltertyp', $courseitemfiltertyp);
37}
38if ($searchcourse !== '') {
39 $url->param('searchcourse', $searchcourse);
40}
41$PAGE->set_url($url);
42
43if(($searchcourse OR $courseitemfilter OR $coursefilter) AND !confirm_sesskey()) {
44 print_error('invalidsesskey');
45}
46
b6f26001
AG
47if (! $cm = get_coursemodule_from_id('feedback', $id)) {
48 print_error('invalidcoursemodule');
49}
50
51if (! $course = $DB->get_record("course", array("id"=>$cm->course))) {
52 print_error('coursemisconf');
53}
54
55if (! $feedback = $DB->get_record("feedback", array("id"=>$cm->instance))) {
56 print_error('invalidcoursemodule');
84973212 57}
c987dbad
AG
58
59if (!$context = get_context_instance(CONTEXT_MODULE, $cm->id)) {
60 print_error('badcontext');
61}
84973212 62
63require_login($course->id, true, $cm);
64
c987dbad 65if( !( (intval($feedback->publish_stats) == 1) OR has_capability('mod/feedback:viewreports', $context))) {
84973212 66 print_error('error');
67}
68
69/// Print the page header
70$strfeedbacks = get_string("modulenameplural", "feedback");
71$strfeedback = get_string("modulename", "feedback");
72
9d092aa9 73$PAGE->set_heading(format_string($course->fullname));
84973212 74$PAGE->set_title(format_string($feedback->name));
84973212 75echo $OUTPUT->header();
76
77/// print the tabs
78include('tabs.php');
79
80//print the analysed items
81echo $OUTPUT->box_start('generalbox boxaligncenter boxwidthwide');
82
c987dbad 83if( has_capability('mod/feedback:viewreports', $context) ) {
84973212 84 //button "export to excel"
85 echo $OUTPUT->container_start('mdl-align');
5c2ed7e2
PS
86 $aurl = new moodle_url('analysis_to_excel.php', array('sesskey'=>sesskey(), 'id'=>$id, 'coursefilter'=>$coursefilter));
87 echo $OUTPUT->single_button($aurl, get_string('export_to_excel', 'feedback'));
84973212 88 echo $OUTPUT->container_end();
89}
90
91//get the groupid
92//lstgroupid is the choosen id
93$mygroupid = false;
94//get completed feedbacks
95$completedscount = feedback_get_completeds_group_count($feedback, $mygroupid, $coursefilter);
96
97//show the count
98echo '<b>'.get_string('completed_feedbacks', 'feedback').': '.$completedscount. '</b><br />';
99
100// get the items of the feedback
101$items = $DB->get_records('feedback_item', array('feedback'=>$feedback->id, 'hasvalue'=>1), 'position');
102//show the count
103if(is_array($items)){
104 echo '<b>'.get_string('questions', 'feedback').': ' .sizeof($items). ' </b><hr />';
105 echo '<a href="analysis_course.php?id=' . $id . '&courseid='.$courseid.'">'.get_string('show_all', 'feedback').'</a>';
106} else {
107 $items=array();
108}
109
110echo '<form name="report" method="post" id="analysis-form">';
111echo '<div class="mdl-align"><table width="80%" cellpadding="10">';
112if ($courseitemfilter > 0) {
113 $avgvalue = 'avg(value)';
114 if ($DB->get_dbfamily() == 'postgres') { // TODO: this should be moved to standard sql DML function ;-)
115 $avgvalue = 'avg(cast (value as integer))';
c70ad9f7 116 }
84973212 117 if ($courses = $DB->get_records_sql ("SELECT fv.course_id, c.shortname, $avgvalue AS avgvalue
118 FROM {feedback_value} fv, {course} c, {feedback_item} fi
119 WHERE fv.course_id = c.id AND fi.id = fv.item AND fi.typ = ? AND fv.item = ?
120 GROUP BY course_id, shortname
121 ORDER BY avgvalue desc",
122 array($courseitemfiltertyp, $courseitemfilter))) {
123 $item = $DB->get_record('feedback_item', array('id'=>$courseitemfilter));
124 echo '<tr><th colspan="2">'.$item->name.'</th></tr>';
125 echo '<tr><td><table align="left">';
126 echo '<tr><th>Course</th><th>Average</th></tr>';
127 $sep_dec = get_string('separator_decimal', 'feedback');
128 $sep_thous = get_string('separator_thousand', 'feedback');
129
130 foreach ($courses as $c) {
131 echo '<tr><td>'.$c->shortname.'</td><td align="right">'.number_format(($c->avgvalue), 2, $sep_dec, $sep_thous).'</td></tr>';
132 }
133 echo '</table></td></tr>';
c70ad9f7 134 } else {
84973212 135 echo '<tr><td>'.get_string('noresults').'</td></tr>';
c70ad9f7 136 }
84973212 137} else {
138
139 echo get_string('search_course', 'feedback') . ': ';
140 echo '<input type="text" name="searchcourse" value="'.s($searchcourse).'"/> <input type="submit" value="'.get_string('search').'"/>';
141 echo '<input type="hidden" name="sesskey" value="'.sesskey().'" />';
142 echo '<input type="hidden" name="id" value="'.$id.'" />';
143 echo '<input type="hidden" name="courseitemfilter" value="'.$courseitemfilter.'" />';
144 echo '<input type="hidden" name="courseitemfiltertyp" value="'.$courseitemfiltertyp.'" />';
145 echo '<input type="hidden" name="courseid" value="'.$courseid.'" />';
c17f05fb 146 echo html_writer::script('', $CFG->wwwroot.'/mod/feedback/feedback.js');
31c0fa53 147 $sql = 'select DISTINCT c.id, c.shortname from {course} c, '.
84973212 148 '{feedback_value} fv, {feedback_item} fi '.
149 'where c.id = fv.course_id and fv.item = fi.id '.
31c0fa53 150 'and fi.feedback = ? '.
84973212 151 'and
0f1b6a5e
PS
152 ('.$DB->sql_like('c.shortname', '?', false).'
153 OR '.$DB->sql_like('c.fullname', '?', false).')';
84973212 154 $params = array($feedback->id, "%$searchcourse%", "%$searchcourse%");
155
156 if ($courses = $DB->get_records_sql_menu($sql, $params)) {
157
158 echo ' ' . get_string('filter_by_course', 'feedback') . ': ';
0f1b6a5e 159
18300e6b 160 echo html_writer::select($courses, 'coursefilter', $coursefilter, null, array('id'=>'coursefilterid'));
edc28287 161 $PAGE->requires->js_init_call('M.util.init_select_autosubmit', array('analysis-form', 'coursefilterid', false));
84973212 162 }
163 echo '<hr />';
164 $itemnr = 0;
165 //print the items in an analysed form
166 echo '<tr><td>';
167 foreach($items as $item) {
168 if($item->hasvalue == 0) continue;
169 echo '<table width="100%" class="generalbox">';
170 //get the class from item-typ
6cc1599e 171 $itemobj = feedback_get_item_class($item->typ);
84973212 172 $itemnr++;
173 if($feedback->autonumbering) {
174 $printnr = $itemnr.'.';
c70ad9f7 175 } else {
84973212 176 $printnr = '';
c70ad9f7 177 }
84973212 178 $itemobj->print_analysed($item, $printnr, $mygroupid, $coursefilter);
179 if (preg_match('/rated$/i', $item->typ)) {
180 echo '<tr><td colspan="2"><a href="#" onclick="setcourseitemfilter('.$item->id.',\''.$item->typ.'\'); return false;">'.
181 get_string('sort_by_course', 'feedback').'</a></td></tr>';
c70ad9f7 182 }
84973212 183 echo '</table>';
c70ad9f7 184 }
84973212 185 echo '</td></tr>';
186}
187echo '</table></div>';
188echo '</form>';
189echo $OUTPUT->box_end();
d4b1d58c 190
84973212 191echo $OUTPUT->footer();
c70ad9f7 192