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 feedback
20 * @copyright 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 $courseid = optional_param('courseid', false, PARAM_INT
);
33 $url = new moodle_url('/mod/feedback/analysis.php', array('id'=>$id));
34 if ($courseid !== false) {
35 $url->param('courseid', $courseid);
39 if (! $cm = get_coursemodule_from_id('feedback', $id)) {
40 print_error('invalidcoursemodule');
43 if (! $course = $DB->get_record("course", array("id"=>$cm->course
))) {
44 print_error('coursemisconf');
47 if (! $feedback = $DB->get_record("feedback", array("id"=>$cm->instance
))) {
48 print_error('invalidcoursemodule');
51 $context = context_module
::instance($cm->id
);
53 if ($course->id
== SITEID
) {
54 require_login($course, true);
56 require_login($course, true, $cm);
59 //check whether the given courseid exists
60 if ($courseid AND $courseid != SITEID
) {
61 if ($course2 = $DB->get_record('course', array('id'=>$courseid))) {
62 require_course_login($course2); //this overwrites the object $course :-(
63 $course = $DB->get_record("course", array("id"=>$cm->course
)); // the workaround
65 print_error('invalidcourseid');
69 if ( !( ((intval($feedback->publish_stats
) == 1) AND
70 has_capability('mod/feedback:viewanalysepage', $context)) OR
71 has_capability('mod/feedback:viewreports', $context))) {
75 /// Print the page header
76 $strfeedbacks = get_string("modulenameplural", "feedback");
77 $strfeedback = get_string("modulename", "feedback");
79 $PAGE->navbar
->add(get_string('analysis', 'feedback'));
80 $PAGE->set_heading($course->fullname
);
81 $PAGE->set_title($feedback->name
);
82 echo $OUTPUT->header();
83 echo $OUTPUT->heading(format_string($feedback->name
));
89 //print analysed items
90 echo $OUTPUT->box_start('generalbox boxaligncenter boxwidthwide');
93 $myurl = $CFG->wwwroot
.'/mod/feedback/analysis.php?id='.$cm->id
.'&do_show=analysis';
94 $groupselect = groups_print_activity_menu($cm, $myurl, true);
95 $mygroupid = groups_get_activity_group($cm);
97 if ( has_capability('mod/feedback:viewreports', $context) ) {
99 echo isset($groupselect) ?
$groupselect : '';
100 echo '<div class="clearer"></div>';
102 //button "export to excel"
103 echo $OUTPUT->container_start('form-buttons');
104 $aurl = new moodle_url('analysis_to_excel.php', array('sesskey'=>sesskey(), 'id'=>$id));
105 echo $OUTPUT->single_button($aurl, get_string('export_to_excel', 'feedback'));
106 echo $OUTPUT->container_end();
109 //get completed feedbacks
110 $completedscount = feedback_get_completeds_group_count($feedback, $mygroupid);
112 //show the group, if available
113 if ($mygroupid and $group = $DB->get_record('groups', array('id'=>$mygroupid))) {
114 echo '<b>'.get_string('group').': '.$group->name
. '</b><br />';
117 echo '<b>'.get_string('completed_feedbacks', 'feedback').': '.$completedscount. '</b><br />';
119 // get the items of the feedback
120 $items = $DB->get_records('feedback_item',
121 array('feedback'=>$feedback->id
, 'hasvalue'=>1),
124 if (is_array($items)) {
125 echo '<b>'.get_string('questions', 'feedback').': ' .count($items). ' </b><hr />';
129 $check_anonymously = true;
130 if ($mygroupid > 0 AND $feedback->anonymous
== FEEDBACK_ANONYMOUS_YES
) {
131 if ($completedscount < FEEDBACK_MIN_ANONYMOUS_COUNT_IN_GROUP
) {
132 $check_anonymously = false;
136 echo '<div><table width="80%" cellpadding="10"><tr><td>';
137 if ($check_anonymously) {
139 //print the items in an analysed form
140 foreach ($items as $item) {
141 if ($item->hasvalue
== 0) {
144 echo '<table width="100%" class="generalbox">';
146 //get the class of item-typ
147 $itemobj = feedback_get_item_class($item->typ
);
150 if ($feedback->autonumbering
) {
151 $printnr = $itemnr.'.';
155 $itemobj->print_analysed($item, $printnr, $mygroupid);
159 echo $OUTPUT->heading_with_help(get_string('insufficient_responses_for_this_group', 'feedback'),
160 'insufficient_responses',
161 'feedback', '', '', 3);
163 echo '</td></tr></table></div>';
164 echo $OUTPUT->box_end();
166 echo $OUTPUT->footer();