diff --git a/mod/forum/report/summary/classes/summary_table.php b/mod/forum/report/summary/classes/summary_table.php index 2aff4369826..117351bffc1 100644 --- a/mod/forum/report/summary/classes/summary_table.php +++ b/mod/forum/report/summary/classes/summary_table.php @@ -179,8 +179,11 @@ class summary_table extends table_sql { * @return string User's full name. */ public function col_fullname($data): string { - global $OUTPUT; + if ($this->is_downloading()) { + return fullname($data); + } + global $OUTPUT; return $OUTPUT->user_picture($data, array('size' => 35, 'courseid' => $this->cm->course, 'includefullname' => true)); } @@ -384,6 +387,7 @@ class summary_table extends table_sql { $this->collapsible(false); $this->sortable(true, 'firstname', SORT_ASC); $this->pageable(true); + $this->is_downloadable(true); $this->no_sorting('select'); $this->set_attribute('id', 'forumreport_summary_table'); } @@ -646,4 +650,17 @@ class summary_table extends table_sql { return (count($groups) < $groupsavailablecount); } + + /** + * Download the summary report in the selected format. + * + * @param string $format The format to download the report. + */ + public function download($format) { + $filename = 'summary_report_' . userdate(time(), get_string('backupnameformat', 'langconfig'), + 99, false); + + $this->is_downloading($format, $filename); + $this->out($this->perpage, false); + } } diff --git a/mod/forum/report/summary/index.php b/mod/forum/report/summary/index.php index 78ac7354b1a..61f407b1e03 100644 --- a/mod/forum/report/summary/index.php +++ b/mod/forum/report/summary/index.php @@ -37,6 +37,8 @@ $filters = []; $filters['forums'] = [$forumid]; $filters['groups'] = optional_param_array('filtergroups', [], PARAM_INT); +$download = optional_param('download', '', PARAM_ALPHA); + $cm = null; $modinfo = get_fast_modinfo($courseid); @@ -73,27 +75,32 @@ $PAGE->set_title($forumname); $PAGE->set_heading($course->fullname); $PAGE->navbar->add(get_string('nodetitle', "forumreport_summary")); -echo $OUTPUT->header(); -echo $OUTPUT->heading(get_string('summarytitle', 'forumreport_summary', $forumname), 2, 'p-b-2'); - -if (!empty($filters['groups'])) { - \core\notification::info(get_string('viewsdisclaimer', 'forumreport_summary')); -} - -// Render the report filters form. -$renderer = $PAGE->get_renderer('forumreport_summary'); -echo $renderer->render_filters_form($cm, $url, $filters); - // Prepare and display the report. -$bulkoperations = !empty($CFG->messaging) && has_capability('moodle/course:bulkmessaging', $context); +$bulkoperations = !$download && !empty($CFG->messaging) && has_capability('moodle/course:bulkmessaging', $context); $table = new \forumreport_summary\summary_table($courseid, $filters, $bulkoperations); $table->baseurl = $url; -echo $renderer->render_summary_table($table, $perpage); +if ($download) { + $table->download($download); +} else { + echo $OUTPUT->header(); + echo $OUTPUT->heading(get_string('summarytitle', 'forumreport_summary', $forumname), 2, 'p-b-2'); -if ($bulkoperations) { - echo $renderer->render_bulk_action_menu(); + if (!empty($filters['groups'])) { + \core\notification::info(get_string('viewsdisclaimer', 'forumreport_summary')); + } + + // Render the report filters form. + $renderer = $PAGE->get_renderer('forumreport_summary'); + + echo $renderer->render_filters_form($cm, $url, $filters); + $table->show_download_buttons_at(array(TABLE_P_BOTTOM)); + echo $renderer->render_summary_table($table, $perpage); + + if ($bulkoperations) { + echo $renderer->render_bulk_action_menu(); + } + + echo $OUTPUT->footer(); } - -echo $OUTPUT->footer();