weekly release 3.7.1+
[moodle.git] / mod / feedback / index.php
blob44d84c5430a2e87231f971ff11b6e4910d07ad4f
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 * prints the overview of all feedbacks included into the current course
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 $id = required_param('id', PARAM_INT);
30 $url = new moodle_url('/mod/feedback/index.php', array('id'=>$id));
32 $PAGE->set_url($url);
34 if (!$course = $DB->get_record('course', array('id'=>$id))) {
35 print_error('invalidcourseid');
38 $context = context_course::instance($course->id);
40 require_login($course);
41 $PAGE->set_pagelayout('incourse');
43 // Trigger instances list viewed event.
44 $event = \mod_feedback\event\course_module_instance_list_viewed::create(array('context' => $context));
45 $event->add_record_snapshot('course', $course);
46 $event->trigger();
48 /// Print the page header
49 $strfeedbacks = get_string("modulenameplural", "feedback");
50 $strfeedback = get_string("modulename", "feedback");
52 $PAGE->navbar->add($strfeedbacks);
53 $PAGE->set_heading($course->fullname);
54 $PAGE->set_title(get_string('modulename', 'feedback').' '.get_string('activities'));
55 echo $OUTPUT->header();
56 echo $OUTPUT->heading($strfeedbacks);
58 /// Get all the appropriate data
60 if (! $feedbacks = get_all_instances_in_course("feedback", $course)) {
61 $url = new moodle_url('/course/view.php', array('id'=>$course->id));
62 notice(get_string('thereareno', 'moodle', $strfeedbacks), $url);
63 die;
66 $usesections = course_format_uses_sections($course->format);
68 /// Print the list of instances (your module will probably extend this)
70 $timenow = time();
71 $strname = get_string("name");
72 $strresponses = get_string('responses', 'feedback');
74 $table = new html_table();
76 if ($usesections) {
77 $strsectionname = get_string('sectionname', 'format_'.$course->format);
78 if (has_capability('mod/feedback:viewreports', $context)) {
79 $table->head = array ($strsectionname, $strname, $strresponses);
80 $table->align = array ("center", "left", 'center');
81 } else {
82 $table->head = array ($strsectionname, $strname);
83 $table->align = array ("center", "left");
85 } else {
86 if (has_capability('mod/feedback:viewreports', $context)) {
87 $table->head = array ($strname, $strresponses);
88 $table->align = array ("left", "center");
89 } else {
90 $table->head = array ($strname);
91 $table->align = array ("left");
96 foreach ($feedbacks as $feedback) {
97 //get the responses of each feedback
98 $viewurl = new moodle_url('/mod/feedback/view.php', array('id'=>$feedback->coursemodule));
100 if (has_capability('mod/feedback:viewreports', $context)) {
101 $completed_feedback_count = intval(feedback_get_completeds_group_count($feedback));
104 $dimmedclass = $feedback->visible ? '' : 'class="dimmed"';
105 $link = '<a '.$dimmedclass.' href="'.$viewurl->out().'">'.$feedback->name.'</a>';
107 if ($usesections) {
108 $tabledata = array (get_section_name($course, $feedback->section), $link);
109 } else {
110 $tabledata = array ($link);
112 if (has_capability('mod/feedback:viewreports', $context)) {
113 $tabledata[] = $completed_feedback_count;
116 $table->data[] = $tabledata;
120 echo "<br />";
122 echo html_writer::table($table);
124 /// Finish the page
126 echo $OUTPUT->footer();