MDL-66372 forumreport_summary: Tidy up per page and bulk ops handling
[moodle.git] / mod / forum / report / summary / renderer.php
CommitLineData
b29de56d
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 * Provides rendering functionality for the forum summary report subplugin.
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
25defined('MOODLE_INTERNAL') || die();
26
cc970382
SR
27use forumreport_summary\summary_table;
28
b29de56d
MH
29/**
30 * Renderer for the forum summary report.
31 *
32 * @copyright 2019 Michael Hawkins <michaelh@moodle.com>
33 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
34 */
35class forumreport_summary_renderer extends plugin_renderer_base {
36
37 /**
38 * Render the filters available for the forum summary report.
39 *
40 * @param stdClass $cm The course module object.
41 * @param moodle_url $actionurl The form action URL.
42 * @param array $filters Optional array of currently applied filter values.
43 * @return string The filter form HTML.
44 */
45 public function render_filters_form(stdClass $cm, moodle_url $actionurl, array $filters = []): string {
46 $renderable = new \forumreport_summary\output\filters($cm, $actionurl, $filters);
47 $templatecontext = $renderable->export_for_template($this);
48
49 return $this->render_from_template('forumreport_summary/filters', $templatecontext);
50 }
51
52 /**
53 * Render the summary report table.
54 *
cc970382 55 * @param summary_table $table The summary table to be rendered.
b29de56d
MH
56 * @return string The report table HTML.
57 */
cf8393be 58 public function render_summary_table(summary_table $table): string {
b29de56d
MH
59 // Buffer so calling script can output the report as required.
60 ob_start();
61
62 // Render table.
20b064be 63 $table->out($table->get_perpage(), false);
b29de56d
MH
64
65 $tablehtml = ob_get_contents();
66
67 ob_end_clean();
68
20b064be 69 return $this->render_from_template('forumreport_summary/report', ['tablehtml' => $tablehtml]);
0942e58c 70 }
b29de56d 71}