MDL-66372 forumreport_summary: Tidy up per page and bulk ops handling
[moodle.git] / mod / forum / report / summary / index.php
CommitLineData
6388b657
MH
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.
13//
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/>.
16
17/**
18 * This script displays the forum summary report for the given parameters, within a user's capabilities.
19 *
20 * @package forumreport_summary
21 * @copyright 2019 Michael Hawkins <michaelh@moodle.com>
22 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
23 */
24
25require_once("../../../../config.php");
26
27if (isguestuser()) {
28 print_error('noguest');
29}
30
31$courseid = required_param('courseid', PARAM_INT);
32$forumid = required_param('forumid', PARAM_INT);
cf8393be 33$perpage = optional_param('perpage', \forumreport_summary\summary_table::DEFAULT_PER_PAGE, PARAM_INT);
b29de56d
MH
34$filters = [];
35
36// Establish filter values.
37$filters['forums'] = [$forumid];
38$filters['groups'] = optional_param_array('filtergroups', [], PARAM_INT);
a9496531
MH
39$filters['datefrom'] = optional_param_array('datefrom', ['enabled' => 0], PARAM_INT);
40$filters['dateto'] = optional_param_array('dateto', ['enabled' => 0], PARAM_INT);
b29de56d 41
850ce974
SL
42$download = optional_param('download', '', PARAM_ALPHA);
43
6388b657
MH
44$cm = null;
45$modinfo = get_fast_modinfo($courseid);
46
14f92164 47if (!isset($modinfo->instances['forum'][$forumid])) {
6388b657
MH
48 throw new \moodle_exception("A valid forum ID is required to generate a summary report.");
49}
50
14f92164
SR
51$foruminfo = $modinfo->instances['forum'][$forumid];
52$forumname = $foruminfo->name;
53$cm = $foruminfo->get_course_module_record();
54
6388b657 55require_login($courseid, false, $cm);
b29de56d 56$context = \context_module::instance($cm->id);
6388b657
MH
57
58// This capability is required to view any version of the report.
6388b657
MH
59if (!has_capability("forumreport/summary:view", $context)) {
60 $redirecturl = new moodle_url("/mod/forum/view.php");
61 $redirecturl->param('id', $forumid);
62 redirect($redirecturl);
63}
64
65$course = $modinfo->get_course();
66
67$urlparams = [
68 'courseid' => $courseid,
69 'forumid' => $forumid,
70 'perpage' => $perpage,
71];
72$url = new moodle_url("/mod/forum/report/summary/index.php", $urlparams);
73
74$PAGE->set_url($url);
75$PAGE->set_pagelayout('report');
76$PAGE->set_title($forumname);
77$PAGE->set_heading($course->fullname);
14f92164 78$PAGE->navbar->add(get_string('nodetitle', "forumreport_summary"));
6388b657 79
b29de56d 80// Prepare and display the report.
cf8393be 81$allowbulkoperations = !$download && !empty($CFG->messaging) && has_capability('moodle/course:bulkmessaging', $context);
354cbf48 82$canseeprivatereplies = has_capability('mod/forum:readprivatereplies', $context);
0942e58c 83
cf8393be 84$table = new \forumreport_summary\summary_table($courseid, $filters, $allowbulkoperations, $canseeprivatereplies, $perpage);
cc970382 85$table->baseurl = $url;
0942e58c 86
850ce974
SL
87if ($download) {
88 $table->download($download);
89} else {
90 echo $OUTPUT->header();
91 echo $OUTPUT->heading(get_string('summarytitle', 'forumreport_summary', $forumname), 2, 'p-b-2');
b29de56d 92
850ce974
SL
93 if (!empty($filters['groups'])) {
94 \core\notification::info(get_string('viewsdisclaimer', 'forumreport_summary'));
95 }
0942e58c 96
a90b8056
SR
97 // Render the report filters form.
98 $renderer = $PAGE->get_renderer('forumreport_summary');
850ce974 99
a90b8056
SR
100 echo $renderer->render_filters_form($cm, $url, $filters);
101 $table->show_download_buttons_at(array(TABLE_P_BOTTOM));
cf8393be 102 echo $renderer->render_summary_table($table);
850ce974
SL
103 echo $OUTPUT->footer();
104}