From e006f5b39d28a804fa08923b68f5bff6a5c96d79 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 6ea212a4..3e402ec6 100644 --- a/lang/en/block_configurable_reports.php +++ b/lang/en/block_configurable_reports.php @@ -54,6 +54,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 5b0323f7..fd5687c6 100755 --- a/report.class.php +++ b/report.class.php @@ -779,7 +779,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').'
'; + } } echo '

'; diff --git a/reports/sql/report.class.php b/reports/sql/report.class.php index 8de6ea1e..dfb665d8 100644 --- a/reports/sql/report.class.php +++ b/reports/sql/report.class.php @@ -129,7 +129,7 @@ public function create_report() { $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 e4f1a665..0492fa2a 100755 --- a/viewreport.php +++ b/viewreport.php @@ -71,6 +71,7 @@ $download = ($download && $format && strpos($report->export, $format.',') !== false) ? true : false; if ($download && $report->type == "sql") $reportclass->setForExport(true); +$reportclass->check_filters_request(); $reportclass->create_report(); $action = (!empty($download)) ? 'download' : 'view'; @@ -78,7 +79,6 @@ // No download, build navigation header etc.. if (!$download) { - $reportclass->check_filters_request(); $reportname = format_string($report->name); $navlinks = array();