MDL-73184 reportbuilder: preserve pagesize property between requests.
Given that custom reports can now have defined pagesize properties, we need to preserve that value in the table filterset so that it's always available after AJAX requests.
This commit is contained in:
committed by
Mikel Martín
parent
0908a1bdeb
commit
6b6a040084
@@ -30,6 +30,7 @@ use core_reportbuilder\table\custom_report_table_filterset;
|
||||
use core_reportbuilder\table\custom_report_table_view;
|
||||
use core_reportbuilder\table\custom_report_table_view_filterset;
|
||||
use core_reportbuilder\local\helpers\report as report_helper;
|
||||
use core_table\local\filter\integer_filter;
|
||||
|
||||
/**
|
||||
* Custom report exporter class
|
||||
@@ -78,6 +79,7 @@ class custom_report_exporter extends persistent_exporter {
|
||||
*/
|
||||
protected static function define_related(): array {
|
||||
return [
|
||||
'pagesize' => 'int?',
|
||||
];
|
||||
}
|
||||
|
||||
@@ -119,8 +121,12 @@ class custom_report_exporter extends persistent_exporter {
|
||||
$table = custom_report_table::create($this->persistent->get('id'));
|
||||
$table->set_filterset(new custom_report_table_filterset());
|
||||
} else {
|
||||
// We store the pagesize within the table filterset so that it's available between AJAX requests.
|
||||
$filterset = new custom_report_table_view_filterset();
|
||||
$filterset->add_filter(new integer_filter('pagesize', null, [$this->related['pagesize']]));
|
||||
|
||||
$table = custom_report_table_view::create($this->persistent->get('id'), $this->download);
|
||||
$table->set_filterset(new custom_report_table_view_filterset());
|
||||
$table->set_filterset($filterset);
|
||||
|
||||
// Generate filters form if report contains any filters.
|
||||
$source = $this->persistent->get('source');
|
||||
|
||||
@@ -18,6 +18,7 @@ declare(strict_types=1);
|
||||
|
||||
namespace core_reportbuilder\output;
|
||||
|
||||
use core_reportbuilder\manager;
|
||||
use core_reportbuilder\external\custom_report_exporter;
|
||||
use core_reportbuilder\local\models\report;
|
||||
use renderable;
|
||||
@@ -63,7 +64,11 @@ class custom_report implements renderable, templatable {
|
||||
* @return stdClass
|
||||
*/
|
||||
public function export_for_template(renderer_base $output): stdClass {
|
||||
$exporter = new custom_report_exporter($this->persistent, [], $this->editmode, $this->download);
|
||||
$report = manager::get_report_from_persistent($this->persistent);
|
||||
|
||||
$exporter = new custom_report_exporter($this->persistent, [
|
||||
'pagesize' => $report->get_default_per_page(),
|
||||
], $this->editmode, $this->download);
|
||||
|
||||
return $exporter->export($output);
|
||||
}
|
||||
|
||||
@@ -44,6 +44,17 @@ class custom_report_table_view extends custom_report_table {
|
||||
base_report_table::print_headers();
|
||||
}
|
||||
|
||||
/**
|
||||
* Override base implementation, return pagesize as defined in table filterset
|
||||
*
|
||||
* @return int
|
||||
*/
|
||||
public function get_default_per_page(): int {
|
||||
$filterset = $this->get_filterset();
|
||||
|
||||
return $filterset->get_filter('pagesize')->current();
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the html for the download buttons
|
||||
*
|
||||
|
||||
@@ -18,6 +18,9 @@ declare(strict_types=1);
|
||||
|
||||
namespace core_reportbuilder\table;
|
||||
|
||||
use core_table\local\filter\filterset;
|
||||
use core_table\local\filter\integer_filter;
|
||||
|
||||
/**
|
||||
* Custom report dynamic table filterset class
|
||||
*
|
||||
@@ -25,5 +28,16 @@ namespace core_reportbuilder\table;
|
||||
* @copyright 2021 Paul Holden <[email protected]>
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
*/
|
||||
class custom_report_table_view_filterset extends custom_report_table_filterset {
|
||||
class custom_report_table_view_filterset extends filterset {
|
||||
|
||||
/**
|
||||
* Get the required filters
|
||||
*
|
||||
* @return array.
|
||||
*/
|
||||
public function get_required_filters(): array {
|
||||
return [
|
||||
'pagesize' => integer_filter::class,
|
||||
];
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user