From 850ce97425395d2272ae7e45e1b53585fafed226 Mon Sep 17 00:00:00 2001 From: Simey Lameze Date: Thu, 26 Sep 2019 10:30:14 +0800 Subject: [PATCH] MDL-66768 forumreport_summary: add ability to download report --- .../report/summary/classes/summary_table.php | 19 +++++++++- mod/forum/report/summary/index.php | 36 ++++++++++++------- 2 files changed, 41 insertions(+), 14 deletions(-) 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..ca84cc43d1c 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,16 +75,8 @@ $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); @@ -90,10 +84,26 @@ $bulkoperations = !empty($CFG->messaging) && has_capability('moodle/course:bulkm $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')); + } + + + + if ($bulkoperations) { + echo $renderer->render_bulk_action_menu(); + } + + echo $renderer->render_filters_form($cm, $url, $filters); + $table->show_download_buttons_at(array(TABLE_P_BOTTOM)); + echo $renderer->render_summary_table($table, $perpage); + $table->download_buttons(); + + echo $OUTPUT->footer(); } - -echo $OUTPUT->footer();