From 9a8091d550e6c7ee1f58bdd98ebd92e1df4acb30 Mon Sep 17 00:00:00 2001 From: David Matamoros Date: Tue, 19 Apr 2022 15:33:52 +0200 Subject: [PATCH] MDL-74497 reportbuilder: Add all columns/filters/conditions at once --- reportbuilder/classes/datasource.php | 20 ++++++++++++++++++++ reportbuilder/classes/local/report/base.php | 9 +++++++++ reportbuilder/upgrade.txt | 8 ++++++++ 3 files changed, 37 insertions(+) create mode 100644 reportbuilder/upgrade.txt diff --git a/reportbuilder/classes/datasource.php b/reportbuilder/classes/datasource.php index d852ebbab32..cddbcf465dc 100644 --- a/reportbuilder/classes/datasource.php +++ b/reportbuilder/classes/datasource.php @@ -266,4 +266,24 @@ abstract class datasource extends base { return $conditions; } + + /** + * Adds all columns/filters/conditions from the given entity to the report at once + * + * @param string $entityname + */ + final protected function add_all_from_entity(string $entityname): void { + $this->add_columns_from_entity($entityname); + $this->add_filters_from_entity($entityname); + $this->add_conditions_from_entity($entityname); + } + + /** + * Adds all columns/filters/conditions from all the entities added to the report at once + */ + final protected function add_all_from_entities(): void { + foreach ($this->get_entities() as $entity) { + $this->add_all_from_entity($entity->get_entity_name()); + } + } } diff --git a/reportbuilder/classes/local/report/base.php b/reportbuilder/classes/local/report/base.php index 5366ba63942..5aebe7957d9 100644 --- a/reportbuilder/classes/local/report/base.php +++ b/reportbuilder/classes/local/report/base.php @@ -269,6 +269,15 @@ abstract class base { return $this->entities[$name]; } + /** + * Returns the list of all the entities added to the report + * + * @return entity_base[] + */ + final protected function get_entities(): array { + return $this->entities; + } + /** * Define a new entity for the report * diff --git a/reportbuilder/upgrade.txt b/reportbuilder/upgrade.txt new file mode 100644 index 00000000000..be2d3683385 --- /dev/null +++ b/reportbuilder/upgrade.txt @@ -0,0 +1,8 @@ +This file describes API changes in /reportbuilder/* +Information provided here is intended especially for developers. + +=== 4.1 === + +* Added two new methods in the datasource class: + - add_all_from_entity() to add all columns/filters/conditions from the given entity to the report at once + - add_all_from_entities() to add all columns/filters/conditions from all the entities added to the report at once \ No newline at end of file -- 2.43.0