MDL-66768 forumreport_summary: add ability to download report
authorSimey Lameze <simey@moodle.com>
Thu, 26 Sep 2019 02:30:14 +0000 (10:30 +0800)
committerShamim Rezaie <shamim@moodle.com>
Mon, 14 Oct 2019 02:05:04 +0000 (13:05 +1100)
mod/forum/report/summary/classes/summary_table.php
mod/forum/report/summary/index.php

index 2aff436..117351b 100644 (file)
@@ -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);
+    }
 }
index 78ac735..ca84cc4 100644 (file)
@@ -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'));
+    }
 
-echo $OUTPUT->footer();
+
+
+    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();
+}