MDL-62543 mod_forum: Add RSS Unit tests
[moodle.git] / mod / feedback / show_entries.php
blob0f0cfe96e6cd06b118f52c19143f1936313e1950
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 * print the single entries
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 ////////////////////////////////////////////////////////
29 //get the params
30 ////////////////////////////////////////////////////////
31 $id = required_param('id', PARAM_INT);
32 $userid = optional_param('userid', false, PARAM_INT);
33 $showcompleted = optional_param('showcompleted', false, PARAM_INT);
34 $deleteid = optional_param('delete', null, PARAM_INT);
35 $courseid = optional_param('courseid', null, PARAM_INT);
37 ////////////////////////////////////////////////////////
38 //get the objects
39 ////////////////////////////////////////////////////////
41 list($course, $cm) = get_course_and_cm_from_cmid($id, 'feedback');
43 $baseurl = new moodle_url('/mod/feedback/show_entries.php', array('id' => $cm->id));
44 $PAGE->set_url(new moodle_url($baseurl, array('userid' => $userid, 'showcompleted' => $showcompleted,
45 'delete' => $deleteid)));
47 $context = context_module::instance($cm->id);
49 require_login($course, true, $cm);
50 $feedback = $PAGE->activityrecord;
52 require_capability('mod/feedback:viewreports', $context);
54 if ($deleteid) {
55 // This is a request to delete a reponse.
56 require_capability('mod/feedback:deletesubmissions', $context);
57 require_sesskey();
58 $feedbackstructure = new mod_feedback_completion($feedback, $cm, 0, true, $deleteid);
59 feedback_delete_completed($feedbackstructure->get_completed(), $feedback, $cm);
60 redirect($baseurl);
61 } else if ($showcompleted || $userid) {
62 // Viewing individual response.
63 $feedbackstructure = new mod_feedback_completion($feedback, $cm, 0, true, $showcompleted, $userid);
64 } else {
65 // Viewing list of reponses.
66 $feedbackstructure = new mod_feedback_structure($feedback, $cm, $courseid);
69 $responsestable = new mod_feedback_responses_table($feedbackstructure);
70 $anonresponsestable = new mod_feedback_responses_anon_table($feedbackstructure);
72 if ($responsestable->is_downloading()) {
73 $responsestable->download();
75 if ($anonresponsestable->is_downloading()) {
76 $anonresponsestable->download();
79 // Process course select form.
80 $courseselectform = new mod_feedback_course_select_form($baseurl, $feedbackstructure, $feedback->course == SITEID);
81 if ($data = $courseselectform->get_data()) {
82 redirect(new moodle_url($baseurl, ['courseid' => $data->courseid]));
84 // Print the page header.
85 navigation_node::override_active_url($baseurl);
86 $PAGE->set_heading($course->fullname);
87 $PAGE->set_title($feedback->name);
88 echo $OUTPUT->header();
89 echo $OUTPUT->heading(format_string($feedback->name));
91 $current_tab = 'showentries';
92 require('tabs.php');
94 /// Print the main part of the page
95 ///////////////////////////////////////////////////////////////////////////
96 ///////////////////////////////////////////////////////////////////////////
97 ///////////////////////////////////////////////////////////////////////////
99 if ($userid || $showcompleted) {
100 // Print the response of the given user.
101 $completedrecord = $feedbackstructure->get_completed();
103 if ($userid) {
104 $usr = $DB->get_record('user', array('id' => $userid), '*', MUST_EXIST);
105 $responsetitle = userdate($completedrecord->timemodified) . ' (' . fullname($usr) . ')';
106 } else {
107 $responsetitle = get_string('response_nr', 'feedback') . ': ' .
108 $completedrecord->random_response . ' (' . get_string('anonymous', 'feedback') . ')';
111 echo $OUTPUT->heading($responsetitle, 4);
113 $form = new mod_feedback_complete_form(mod_feedback_complete_form::MODE_VIEW_RESPONSE,
114 $feedbackstructure, 'feedback_viewresponse_form');
115 $form->display();
117 list($prevresponseurl, $returnurl, $nextresponseurl) = $userid ?
118 $responsestable->get_reponse_navigation_links($completedrecord) :
119 $anonresponsestable->get_reponse_navigation_links($completedrecord);
121 echo html_writer::start_div('response_navigation');
123 $responsenavigation = [
124 'col1content' => '',
125 'col2content' => html_writer::link($returnurl, get_string('back'), ['class' => 'back_to_list']),
126 'col3content' => '',
129 if ($prevresponseurl) {
130 $responsenavigation['col1content'] = html_writer::link($prevresponseurl, get_string('prev'), ['class' => 'prev_response']);
133 if ($nextresponseurl) {
134 $responsenavigation['col3content'] = html_writer::link($nextresponseurl, get_string('next'), ['class' => 'next_response']);
137 echo $OUTPUT->render_from_template('core/columns-1to1to1', $responsenavigation);
138 echo html_writer::end_div();
140 } else {
141 // Print the list of responses.
142 $courseselectform->display();
144 // Show non-anonymous responses (always retrieve them even if current feedback is anonymous).
145 $totalrows = $responsestable->get_total_responses_count();
146 if (!$feedbackstructure->is_anonymous() || $totalrows) {
147 echo $OUTPUT->heading(get_string('non_anonymous_entries', 'feedback', $totalrows), 4);
148 $responsestable->display();
151 // Show anonymous responses (always retrieve them even if current feedback is not anonymous).
152 $feedbackstructure->shuffle_anonym_responses();
153 $totalrows = $anonresponsestable->get_total_responses_count();
154 if ($feedbackstructure->is_anonymous() || $totalrows) {
155 echo $OUTPUT->heading(get_string('anonymous_entries', 'feedback', $totalrows), 4);
156 $anonresponsestable->display();
161 // Finish the page.
162 echo $OUTPUT->footer();