From dd9119453037b6d4b52b086fd2246efb238195f3 Mon Sep 17 00:00:00 2001 From: Mikhail Golenkov Date: Tue, 13 Sep 2022 16:35:08 +1000 Subject: [PATCH] Let filters to be set before running reports --- lang/en/block_configurable_reports.php | 1 + report.class.php | 6 +++++- reports/sql/report.class.php | 2 +- viewreport.php | 2 +- 4 files changed, 8 insertions(+), 3 deletions(-) diff --git a/lang/en/block_configurable_reports.php b/lang/en/block_configurable_reports.php index 4f0d9975..6af37ca8 100644 --- a/lang/en/block_configurable_reports.php +++ b/lang/en/block_configurable_reports.php @@ -65,6 +65,7 @@ $string['field'] = "Field"; // Report form. +$string['applyfilters'] = "Apply filters to run the report"; $string['typeofreport'] = "Type of report"; $string['enablejsordering'] = "Enable JavaScript ordering"; $string['enablejspagination'] = "Enable JavaScript Pagination"; diff --git a/report.class.php b/report.class.php index 97ee2b6a..6f04f8ba 100755 --- a/report.class.php +++ b/report.class.php @@ -1011,7 +1011,11 @@ public function print_report_page(moodle_page $moodlepage) { $this->print_export_options(); } else { - echo '
' . get_string('norecordsfound', 'block_configurable_reports') . '
'; + if (isset($this->filterform) && !$this->filterform->get_data()) { + echo '
'.get_string('applyfilters', 'block_configurable_reports').'
'; + } else { + echo '
'.get_string('norecordsfound', 'block_configurable_reports').'
'; + } } if ($this->config->displayprintbutton) { diff --git a/reports/sql/report.class.php b/reports/sql/report.class.php index 0f7fae26..528ffdec 100644 --- a/reports/sql/report.class.php +++ b/reports/sql/report.class.php @@ -182,7 +182,7 @@ public function create_report(): bool { $sql = $this->prepare_sql($sql); - if ($rs = $this->execute_query($sql)) { + if (isset($this->filterform) && $this->filterform->get_data() && $rs = $this->execute_query($sql)) { foreach ($rs as $row) { if (empty($finaltable)) { foreach ($row as $colname => $value) { diff --git a/viewreport.php b/viewreport.php index aca79fdb..31a8f59f 100755 --- a/viewreport.php +++ b/viewreport.php @@ -75,13 +75,13 @@ if ($download && $report->type === "sql") { $reportclass->set_forexport(true); } +$reportclass->check_filters_request(); $reportclass->create_report(); $action = (!empty($download)) ? 'download' : 'view'; // No download, build navigation header etc.. if (!$download) { - $reportclass->check_filters_request(); $reportname = format_string($report->name); $navlinks = [];