From 6bdbbe8dbed6be69aa2d89304da19f56a0df61be Mon Sep 17 00:00:00 2001 From: Paul Holden Date: Tue, 9 Sep 2025 07:25:19 +0100 Subject: [PATCH 1/2] MDL-86678 reportbuilder: implement default base entity initialising. Move boilerplate present across all entity classes to the base class itself, defining only the minimum number of methods that extending classes should implement to load entity report data. --- .upgradenotes/MDL-86678-2025091208515445.yml | 19 ++++ .../classes/local/entities/base.php | 96 +++++++++++++------ 2 files changed, 88 insertions(+), 27 deletions(-) create mode 100644 .upgradenotes/MDL-86678-2025091208515445.yml diff --git a/.upgradenotes/MDL-86678-2025091208515445.yml b/.upgradenotes/MDL-86678-2025091208515445.yml new file mode 100644 index 00000000000..54074a04aa4 --- /dev/null +++ b/.upgradenotes/MDL-86678-2025091208515445.yml @@ -0,0 +1,19 @@ +issueNumber: MDL-86678 +notes: + core_reportbuilder: + - message: >- + The base entity class now implements a default `initialise` method, that + will automatically call each of the following methods to load entity + report data: + + + * `get_available_columns()` + + * `get_available_filters()` + + * `get_available_conditions()` + + + This change allows for a lot of boilerplate to be removed from report + entity classes + type: improved diff --git a/public/reportbuilder/classes/local/entities/base.php b/public/reportbuilder/classes/local/entities/base.php index e465efef0d8..298e41d3a58 100644 --- a/public/reportbuilder/classes/local/entities/base.php +++ b/public/reportbuilder/classes/local/entities/base.php @@ -18,11 +18,10 @@ declare(strict_types=1); namespace core_reportbuilder\local\entities; -use coding_exception; +use core\exception\coding_exception; +use core\lang_string; use core_reportbuilder\local\helpers\{database, join_trait}; -use core_reportbuilder\local\report\column; -use core_reportbuilder\local\report\filter; -use lang_string; +use core_reportbuilder\local\report\{column, filter}; /** * Base class for all report entities @@ -35,26 +34,26 @@ abstract class base { use join_trait; - /** @var string $entityname Internal reference to name of entity */ - private $entityname = null; + /** @var string|null $entityname Internal reference to name of entity */ + private string|null $entityname = null; - /** @var lang_string $entitytitle Used as a title for the entity in reports */ - private $entitytitle = null; + /** @var lang_string|null $entitytitle Used as a title for the entity in reports */ + private lang_string|null $entitytitle = null; - /** @var array $tablealiases Database tables that this entity uses and their aliases */ - private $tablealiases = []; + /** @var string[] $tablealiases Database tables that this entity uses and their aliases */ + private array $tablealiases = []; - /** @var array $tablejoinaliases Database tables that have already been joined to the report and their aliases */ - private $tablejoinaliases = []; + /** @var string[] $tablejoinaliases Database tables that have already been joined to the report and their aliases */ + private array $tablejoinaliases = []; /** @var column[] $columns List of columns for the entity */ - private $columns = []; + private array $columns = []; /** @var filter[] $filters List of filters for the entity */ - private $filters = []; + private array $filters = []; /** @var filter[] $conditions List of conditions for the entity */ - private $conditions = []; + private array $conditions = []; /** * Database tables that the entity expects to be present in the main SQL or in JOINs added to it @@ -96,13 +95,27 @@ abstract class base { * Initialise the entity, called automatically when it is added to a report * * This is where entity defines all its columns and filters by calling: - * - {@see add_column} - * - {@see add_filter} - * - etc + * - {@see get_available_columns} + * - {@see get_available_filters} + * - {@see get_available_conditions} * * @return self */ - abstract public function initialise(): self; + public function initialise(): self { + foreach ($this->get_available_columns() as $column) { + $this->add_column($column); + } + + foreach ($this->get_available_filters() as $filter) { + $this->add_filter($filter); + } + + foreach ($this->get_available_conditions() as $condition) { + $this->add_condition($condition); + } + + return $this; + } /** * The default machine-readable name for this entity that will be used in the internal names of the columns/filters @@ -289,6 +302,15 @@ abstract class base { ]; } + /** + * Columns available from this entity + * + * @return column[] + */ + protected function get_available_columns(): array { + return []; + } + /** * Add a column to the entity * @@ -317,11 +339,20 @@ abstract class base { * @throws coding_exception For invalid column name */ final public function get_column(string $name): column { - if (!array_key_exists($name, $this->columns)) { + $columns = $this->get_columns(); + if (!array_key_exists($name, $columns)) { throw new coding_exception('Invalid column name', $name); } + return $columns[$name]; + } - return $this->columns[$name]; + /** + * Filters available from this entity + * + * @return filter[] + */ + protected function get_available_filters(): array { + return []; } /** @@ -352,18 +383,29 @@ abstract class base { * @throws coding_exception For invalid filter name */ final public function get_filter(string $name): filter { - if (!array_key_exists($name, $this->filters)) { + $filters = $this->get_filters(); + if (!array_key_exists($name, $filters)) { throw new coding_exception('Invalid filter name', $name); } + return $filters[$name]; + } - return $this->filters[$name]; + /** + * Conditions available from this entity + * + * By default, all the filters defined by the entity can also be used as conditions + * + * @return filter[] + */ + protected function get_available_conditions(): array { + return $this->get_filters(); } /** * Add a condition to the entity * * @param filter $condition - * @return $this + * @return self */ final protected function add_condition(filter $condition): self { $this->conditions[$condition->get_name()] = $condition; @@ -387,10 +429,10 @@ abstract class base { * @throws coding_exception For invalid condition name */ final public function get_condition(string $name): filter { - if (!array_key_exists($name, $this->conditions)) { + $conditions = $this->get_conditions(); + if (!array_key_exists($name, $conditions)) { throw new coding_exception('Invalid condition name', $name); } - - return $this->conditions[$name]; + return $conditions[$name]; } } From 5cfa19b5a71649bf5da97abee592c74d7c9e5e52 Mon Sep 17 00:00:00 2001 From: Paul Holden Date: Fri, 12 Sep 2025 10:15:55 +0100 Subject: [PATCH 2/2] MDL-86678 reportbuilder: simpler report entity class implementations. Remove boilerplate, switch to newer API for loading entity report data. --- .../reportbuilder/local/entities/task_log.php | 26 ++-------------- .../reportbuilder/local/entities/role.php | 26 ++-------------- .../local/entities/role_assignment.php | 26 ++-------------- .../local/entities/admin_preset.php | 26 ++-------------- .../local/entities/ai_action_register.php | 22 ++------------ .../local/entities/ai_policy_register.php | 22 ++------------ .../reportbuilder/local/entities/badge.php | 26 ++-------------- .../local/entities/badge_issued.php | 26 ++-------------- .../reportbuilder/local/entities/blog.php | 26 ++-------------- .../reportbuilder/local/entities/cohort.php | 30 +++++++------------ .../local/entities/cohort_member.php | 26 ++-------------- .../reportbuilder/local/entities/comment.php | 26 ++-------------- .../local/entities/competency.php | 26 ++-------------- .../local/entities/framework.php | 26 ++-------------- .../local/entities/usercompetency.php | 26 ++-------------- .../reportbuilder/local/entities/access.php | 24 ++------------- .../local/entities/completion.php | 24 ++------------- .../local/entities/course_category.php | 26 ++-------------- .../local/entities/enrolment.php | 24 ++------------- .../reportbuilder/local/entities/enrol.php | 26 ++-------------- .../reportbuilder/local/entities/file.php | 26 ++-------------- .../classes/local/entities/grade_items.php | 16 ++-------- .../reportbuilder/local/entities/group.php | 30 +++++++------------ .../local/entities/group_member.php | 26 ++-------------- .../reportbuilder/local/entities/grouping.php | 30 +++++++------------ .../reportbuilder/local/entities/context.php | 26 ++-------------- .../local/entities/conversation.php | 26 ++-------------- .../reportbuilder/local/entities/message.php | 26 ++-------------- .../local/entities/discussion.php | 26 ++-------------- .../reportbuilder/local/entities/forum.php | 26 ++-------------- .../reportbuilder/local/entities/post.php | 26 ++-------------- .../local/entities/tool_types.php | 23 ++------------ .../reportbuilder/local/entities/note.php | 26 ++-------------- .../local/entities/config_change.php | 23 ++------------ .../reportbuilder/local/entities/theme.php | 16 +--------- .../classes/local/entities/course.php | 30 +++++++------------ .../classes/local/entities/user.php | 30 +++++++------------ .../tests/local/entities/base_test.php | 24 +++++++++------ .../local/entities/collection.php | 26 ++-------------- .../reportbuilder/local/entities/instance.php | 26 ++-------------- .../reportbuilder/local/entities/tag.php | 26 ++-------------- .../reportbuilder/local/entities/service.php | 27 ++--------------- .../reportbuilder/local/entities/token.php | 28 ++--------------- 43 files changed, 144 insertions(+), 955 deletions(-) diff --git a/public/admin/classes/reportbuilder/local/entities/task_log.php b/public/admin/classes/reportbuilder/local/entities/task_log.php index 9adb3ee9b53..79f2e7d44ba 100644 --- a/public/admin/classes/reportbuilder/local/entities/task_log.php +++ b/public/admin/classes/reportbuilder/local/entities/task_log.php @@ -65,34 +65,12 @@ class task_log extends base { return new lang_string('entitytasklog', 'admin'); } - /** - * Initialise the entity - * - * @return base - */ - public function initialise(): base { - $columns = $this->get_all_columns(); - foreach ($columns as $column) { - $this->add_column($column); - } - - // All the filters defined by the entity can also be used as conditions. - $filters = $this->get_all_filters(); - foreach ($filters as $filter) { - $this - ->add_filter($filter) - ->add_condition($filter); - } - - return $this; - } - /** * Returns list of all available columns * * @return column[] */ - protected function get_all_columns(): array { + protected function get_available_columns(): array { global $DB; $tablealias = $this->get_table_alias('task_log'); @@ -270,7 +248,7 @@ class task_log extends base { * * @return filter[] */ - protected function get_all_filters(): array { + protected function get_available_filters(): array { $tablealias = $this->get_table_alias('task_log'); // Name filter (Filter by classname). diff --git a/public/admin/roles/classes/reportbuilder/local/entities/role.php b/public/admin/roles/classes/reportbuilder/local/entities/role.php index c714a526c29..b18f8105021 100644 --- a/public/admin/roles/classes/reportbuilder/local/entities/role.php +++ b/public/admin/roles/classes/reportbuilder/local/entities/role.php @@ -55,34 +55,12 @@ class role extends base { return new lang_string('role'); } - /** - * Initialise the entity - * - * @return base - */ - public function initialise(): base { - $columns = $this->get_all_columns(); - foreach ($columns as $column) { - $this->add_column($column); - } - - // All the filters defined by the entity can also be used as conditions. - $filters = $this->get_all_filters(); - foreach ($filters as $filter) { - $this - ->add_filter($filter) - ->add_condition($filter); - } - - return $this; - } - /** * Returns list of all available columns * * @return column[] */ - protected function get_all_columns(): array { + protected function get_available_columns(): array { $contextalias = $this->get_table_alias('context'); $rolealias = $this->get_table_alias('role'); @@ -181,7 +159,7 @@ class role extends base { * * @return filter[] */ - protected function get_all_filters(): array { + protected function get_available_filters(): array { $rolealias = $this->get_table_alias('role'); // Name filter. diff --git a/public/admin/roles/classes/reportbuilder/local/entities/role_assignment.php b/public/admin/roles/classes/reportbuilder/local/entities/role_assignment.php index 55eda7c9f61..486ea069c44 100644 --- a/public/admin/roles/classes/reportbuilder/local/entities/role_assignment.php +++ b/public/admin/roles/classes/reportbuilder/local/entities/role_assignment.php @@ -53,34 +53,12 @@ class role_assignment extends base { return new lang_string('roleassignment', 'core_role'); } - /** - * Initialise the entity - * - * @return base - */ - public function initialise(): base { - $columns = $this->get_all_columns(); - foreach ($columns as $column) { - $this->add_column($column); - } - - // All the filters defined by the entity can also be used as conditions. - $filters = $this->get_all_filters(); - foreach ($filters as $filter) { - $this - ->add_filter($filter) - ->add_condition($filter); - } - - return $this; - } - /** * Returns list of all available columns * * @return column[] */ - protected function get_all_columns(): array { + protected function get_available_columns(): array { $raalias = $this->get_table_alias('role_assignments'); // Time modified column. @@ -123,7 +101,7 @@ class role_assignment extends base { * * @return filter[] */ - protected function get_all_filters(): array { + protected function get_available_filters(): array { $raalias = $this->get_table_alias('role_assignments'); // Time modified filter. diff --git a/public/admin/tool/admin_presets/classes/reportbuilder/local/entities/admin_preset.php b/public/admin/tool/admin_presets/classes/reportbuilder/local/entities/admin_preset.php index 74203b20877..17696e89d45 100644 --- a/public/admin/tool/admin_presets/classes/reportbuilder/local/entities/admin_preset.php +++ b/public/admin/tool/admin_presets/classes/reportbuilder/local/entities/admin_preset.php @@ -53,34 +53,12 @@ class admin_preset extends base { return new lang_string('pluginname', 'tool_admin_presets'); } - /** - * Initialise the entity - * - * @return base - */ - public function initialise(): base { - $columns = $this->get_all_columns(); - foreach ($columns as $column) { - $this->add_column($column); - } - - // All the filters defined by the entity can also be used as conditions. - $filters = $this->get_all_filters(); - foreach ($filters as $filter) { - $this - ->add_filter($filter) - ->add_condition($filter); - } - - return $this; - } - /** * Returns list of all available columns * * @return column[] */ - protected function get_all_columns(): array { + protected function get_available_columns(): array { $apalias = $this->get_table_alias('adminpresets'); // Name. @@ -126,7 +104,7 @@ class admin_preset extends base { * * @return filter[] */ - protected function get_all_filters(): array { + protected function get_available_filters(): array { $apalias = $this->get_table_alias('adminpresets'); // Name. diff --git a/public/ai/classes/reportbuilder/local/entities/ai_action_register.php b/public/ai/classes/reportbuilder/local/entities/ai_action_register.php index 996d7d00600..4c02c5c090e 100644 --- a/public/ai/classes/reportbuilder/local/entities/ai_action_register.php +++ b/public/ai/classes/reportbuilder/local/entities/ai_action_register.php @@ -53,30 +53,12 @@ class ai_action_register extends base { return new lang_string('aiactionregister', 'core_ai'); } - #[\Override] - public function initialise(): base { - $columns = $this->get_all_columns(); - foreach ($columns as $column) { - $this->add_column($column); - } - - // All the filters defined by the entity can also be used as conditions. - $filters = $this->get_all_filters(); - foreach ($filters as $filter) { - $this - ->add_filter($filter) - ->add_condition($filter); - } - - return $this; - } - /** * Returns list of all available columns. * * @return column[] */ - protected function get_all_columns(): array { + protected function get_available_columns(): array { $mainalias = $this->get_table_alias('ai_action_register'); $generatetextalias = 'aagt'; $summarisetextalias = 'aast'; @@ -205,7 +187,7 @@ class ai_action_register extends base { * * @return filter[] */ - protected function get_all_filters(): array { + protected function get_available_filters(): array { $mainalias = $this->get_table_alias('ai_action_register'); $generatetextalias = 'aagt'; $summarisetextalias = 'aast'; diff --git a/public/ai/classes/reportbuilder/local/entities/ai_policy_register.php b/public/ai/classes/reportbuilder/local/entities/ai_policy_register.php index a71abb00a44..64aa1c1be65 100644 --- a/public/ai/classes/reportbuilder/local/entities/ai_policy_register.php +++ b/public/ai/classes/reportbuilder/local/entities/ai_policy_register.php @@ -46,30 +46,12 @@ class ai_policy_register extends base { return new lang_string('aipolicyregister', 'core_ai'); } - #[\Override] - public function initialise(): base { - $columns = $this->get_all_columns(); - foreach ($columns as $column) { - $this->add_column($column); - } - - // All the filters defined by the entity can also be used as conditions. - $filters = $this->get_all_filters(); - foreach ($filters as $filter) { - $this - ->add_filter($filter) - ->add_condition($filter); - } - - return $this; - } - /** * Returns list of all available columns. * * @return column[] */ - protected function get_all_columns(): array { + protected function get_available_columns(): array { $tablealias = $this->get_table_alias('ai_policy_register'); // Time accepted column. @@ -92,7 +74,7 @@ class ai_policy_register extends base { * * @return filter[] */ - protected function get_all_filters(): array { + protected function get_available_filters(): array { $tablealias = $this->get_table_alias('ai_policy_register'); // Time accepted filter. diff --git a/public/badges/classes/reportbuilder/local/entities/badge.php b/public/badges/classes/reportbuilder/local/entities/badge.php index 742a473f2ed..a518f78ad29 100644 --- a/public/badges/classes/reportbuilder/local/entities/badge.php +++ b/public/badges/classes/reportbuilder/local/entities/badge.php @@ -66,34 +66,12 @@ class badge extends base { return new lang_string('badgedetails', 'core_badges'); } - /** - * Initialise the entity - * - * @return base - */ - public function initialise(): base { - $columns = $this->get_all_columns(); - foreach ($columns as $column) { - $this->add_column($column); - } - - // All the filters defined by the entity can also be used as conditions. - $filters = $this->get_all_filters(); - foreach ($filters as $filter) { - $this - ->add_filter($filter) - ->add_condition($filter); - } - - return $this; - } - /** * Returns list of all available columns * * @return column[] */ - protected function get_all_columns(): array { + protected function get_available_columns(): array { $badgealias = $this->get_table_alias('badge'); $contextalias = $this->get_table_alias('context'); @@ -296,7 +274,7 @@ class badge extends base { * * @return filter[] */ - protected function get_all_filters(): array { + protected function get_available_filters(): array { $badgealias = $this->get_table_alias('badge'); // Name. diff --git a/public/badges/classes/reportbuilder/local/entities/badge_issued.php b/public/badges/classes/reportbuilder/local/entities/badge_issued.php index af57c319d9e..bc1bdc933a2 100644 --- a/public/badges/classes/reportbuilder/local/entities/badge_issued.php +++ b/public/badges/classes/reportbuilder/local/entities/badge_issued.php @@ -53,34 +53,12 @@ class badge_issued extends base { return new lang_string('badgeissued', 'core_badges'); } - /** - * Initialise the entity - * - * @return base - */ - public function initialise(): base { - $columns = $this->get_all_columns(); - foreach ($columns as $column) { - $this->add_column($column); - } - - // All the filters defined by the entity can also be used as conditions. - $filters = $this->get_all_filters(); - foreach ($filters as $filter) { - $this - ->add_filter($filter) - ->add_condition($filter); - } - - return $this; - } - /** * Returns list of all available columns * * @return column[] */ - protected function get_all_columns(): array { + protected function get_available_columns(): array { $badgeissuedalias = $this->get_table_alias('badge_issued'); // Date issued. @@ -127,7 +105,7 @@ class badge_issued extends base { * * @return filter[] */ - protected function get_all_filters(): array { + protected function get_available_filters(): array { $badgealias = $this->get_table_alias('badge_issued'); // Date issued. diff --git a/public/blog/classes/reportbuilder/local/entities/blog.php b/public/blog/classes/reportbuilder/local/entities/blog.php index bdcd2889d67..a4be9fb2954 100644 --- a/public/blog/classes/reportbuilder/local/entities/blog.php +++ b/public/blog/classes/reportbuilder/local/entities/blog.php @@ -61,34 +61,12 @@ class blog extends base { return new lang_string('blog', 'core_blog'); } - /** - * Initialise the entity - * - * @return base - */ - public function initialise(): base { - $columns = $this->get_all_columns(); - foreach ($columns as $column) { - $this->add_column($column); - } - - // All the filters defined by the entity can also be used as conditions. - $filters = $this->get_all_filters(); - foreach ($filters as $filter) { - $this - ->add_filter($filter) - ->add_condition($filter); - } - - return $this; - } - /** * Returns list of all available columns * * @return column[] */ - protected function get_all_columns(): array { + protected function get_available_columns(): array { $postalias = $this->get_table_alias('post'); // Title. @@ -231,7 +209,7 @@ class blog extends base { * * @return filter[] */ - protected function get_all_filters(): array { + protected function get_available_filters(): array { global $DB; $postalias = $this->get_table_alias('post'); diff --git a/public/cohort/classes/reportbuilder/local/entities/cohort.php b/public/cohort/classes/reportbuilder/local/entities/cohort.php index 37ea472262f..4c80df690f5 100644 --- a/public/cohort/classes/reportbuilder/local/entities/cohort.php +++ b/public/cohort/classes/reportbuilder/local/entities/cohort.php @@ -42,6 +42,9 @@ use core_reportbuilder\local\report\filter; */ class cohort extends base { + /** @var custom_fields $customfields */ + private custom_fields $customfields; + /** * Database tables that this entity uses * @@ -71,7 +74,7 @@ class cohort extends base { public function initialise(): base { $tablealias = $this->get_table_alias('cohort'); - $customfields = (new custom_fields( + $this->customfields = (new custom_fields( "{$tablealias}.id", $this->get_entity_name(), 'core_cohort', @@ -79,20 +82,7 @@ class cohort extends base { )) ->add_joins($this->get_joins()); - $columns = array_merge($this->get_all_columns(), $customfields->get_columns()); - foreach ($columns as $column) { - $this->add_column($column); - } - - // All the filters defined by the entity can also be used as conditions. - $filters = array_merge($this->get_all_filters(), $customfields->get_filters()); - foreach ($filters as $filter) { - $this - ->add_filter($filter) - ->add_condition($filter); - } - - return $this; + return parent::initialise(); } /** @@ -100,7 +90,7 @@ class cohort extends base { * * @return column[] */ - protected function get_all_columns(): array { + protected function get_available_columns(): array { $tablealias = $this->get_table_alias('cohort'); $contextalias = $this->get_table_alias('context'); @@ -246,7 +236,8 @@ class cohort extends base { }; }); - return $columns; + // Merge with custom field columns. + return array_merge($columns, $this->customfields->get_columns()); } /** @@ -254,7 +245,7 @@ class cohort extends base { * * @return filter[] */ - protected function get_all_filters(): array { + protected function get_available_filters(): array { $tablealias = $this->get_table_alias('cohort'); // Cohort select filter. @@ -361,7 +352,8 @@ class cohort extends base { )) ->add_joins($this->get_joins()); - return $filters; + // Merge with custom field filters. + return array_merge($filters, $this->customfields->get_filters()); } /** diff --git a/public/cohort/classes/reportbuilder/local/entities/cohort_member.php b/public/cohort/classes/reportbuilder/local/entities/cohort_member.php index 3e16e994420..75fec336bfb 100644 --- a/public/cohort/classes/reportbuilder/local/entities/cohort_member.php +++ b/public/cohort/classes/reportbuilder/local/entities/cohort_member.php @@ -54,34 +54,12 @@ class cohort_member extends base { return new lang_string('cohortmember', 'core_cohort'); } - /** - * Initialise the entity - * - * @return base - */ - public function initialise(): base { - $columns = $this->get_all_columns(); - foreach ($columns as $column) { - $this->add_column($column); - } - - // All the filters defined by the entity can also be used as conditions. - $filters = $this->get_all_filters(); - foreach ($filters as $filter) { - $this - ->add_filter($filter) - ->add_condition($filter); - } - - return $this; - } - /** * Returns list of all available columns * * @return column[] */ - protected function get_all_columns(): array { + protected function get_available_columns(): array { $tablealias = $this->get_table_alias('cohort_members'); // Time added column. @@ -104,7 +82,7 @@ class cohort_member extends base { * * @return filter[] */ - protected function get_all_filters(): array { + protected function get_available_filters(): array { $tablealias = $this->get_table_alias('cohort_members'); // Time added filter. diff --git a/public/comment/classes/reportbuilder/local/entities/comment.php b/public/comment/classes/reportbuilder/local/entities/comment.php index fddea34577f..55ee7dac503 100644 --- a/public/comment/classes/reportbuilder/local/entities/comment.php +++ b/public/comment/classes/reportbuilder/local/entities/comment.php @@ -56,34 +56,12 @@ class comment extends base { return new lang_string('comment', 'core_comment'); } - /** - * Initialise the entity - * - * @return base - */ - public function initialise(): base { - $columns = $this->get_all_columns(); - foreach ($columns as $column) { - $this->add_column($column); - } - - // All the filters defined by the entity can also be used as conditions. - $filters = $this->get_all_filters(); - foreach ($filters as $filter) { - $this - ->add_filter($filter) - ->add_condition($filter); - } - - return $this; - } - /** * Returns list of all available columns * * @return column[] */ - protected function get_all_columns(): array { + protected function get_available_columns(): array { $commentalias = $this->get_table_alias('comments'); $contextalias = $this->get_table_alias('context'); @@ -160,7 +138,7 @@ class comment extends base { * * @return filter[] */ - protected function get_all_filters(): array { + protected function get_available_filters(): array { $commentalias = $this->get_table_alias('comments'); // Content. diff --git a/public/competency/classes/reportbuilder/local/entities/competency.php b/public/competency/classes/reportbuilder/local/entities/competency.php index 7932fb5ef49..7d65b341fcd 100644 --- a/public/competency/classes/reportbuilder/local/entities/competency.php +++ b/public/competency/classes/reportbuilder/local/entities/competency.php @@ -56,34 +56,12 @@ class competency extends base { return new lang_string('competency', 'core_competency'); } - /** - * Initialise the entity - * - * @return base - */ - public function initialise(): base { - $columns = $this->get_all_columns(); - foreach ($columns as $column) { - $this->add_column($column); - } - - // All the filters defined by the entity can also be used as conditions. - $filters = $this->get_all_filters(); - foreach ($filters as $filter) { - $this - ->add_filter($filter) - ->add_condition($filter); - } - - return $this; - } - /** * Returns list of all available columns * * @return column[] */ - protected function get_all_columns(): array { + protected function get_available_columns(): array { $contextalias = $this->get_table_alias('context'); $competencyalias = $this->get_table_alias('competency'); @@ -162,7 +140,7 @@ class competency extends base { * * @return filter[] */ - protected function get_all_filters(): array { + protected function get_available_filters(): array { $competencyalias = $this->get_table_alias('competency'); // Name. diff --git a/public/competency/classes/reportbuilder/local/entities/framework.php b/public/competency/classes/reportbuilder/local/entities/framework.php index d41c704ee6f..3eae3b7617d 100644 --- a/public/competency/classes/reportbuilder/local/entities/framework.php +++ b/public/competency/classes/reportbuilder/local/entities/framework.php @@ -56,34 +56,12 @@ class framework extends base { return new lang_string('competencyframework', 'core_competency'); } - /** - * Initialise the entity - * - * @return base - */ - public function initialise(): base { - $columns = $this->get_all_columns(); - foreach ($columns as $column) { - $this->add_column($column); - } - - // All the filters defined by the entity can also be used as conditions. - $filters = $this->get_all_filters(); - foreach ($filters as $filter) { - $this - ->add_filter($filter) - ->add_condition($filter); - } - - return $this; - } - /** * Returns list of all available columns * * @return column[] */ - protected function get_all_columns(): array { + protected function get_available_columns(): array { $frameworkalias = $this->get_table_alias('competency_framework'); $contextalias = $this->get_table_alias('context'); @@ -187,7 +165,7 @@ class framework extends base { * * @return filter[] */ - protected function get_all_filters(): array { + protected function get_available_filters(): array { $frameworkalias = $this->get_table_alias('competency_framework'); // Name. diff --git a/public/competency/classes/reportbuilder/local/entities/usercompetency.php b/public/competency/classes/reportbuilder/local/entities/usercompetency.php index d381d571fc1..992f666d907 100644 --- a/public/competency/classes/reportbuilder/local/entities/usercompetency.php +++ b/public/competency/classes/reportbuilder/local/entities/usercompetency.php @@ -55,34 +55,12 @@ class usercompetency extends base { return new lang_string('usercompetency', 'core_competency'); } - /** - * Initialise the entity - * - * @return base - */ - public function initialise(): base { - $columns = $this->get_all_columns(); - foreach ($columns as $column) { - $this->add_column($column); - } - - // All the filters defined by the entity can also be used as conditions. - $filters = $this->get_all_filters(); - foreach ($filters as $filter) { - $this - ->add_filter($filter) - ->add_condition($filter); - } - - return $this; - } - /** * Returns list of all available columns * * @return column[] */ - protected function get_all_columns(): array { + protected function get_available_columns(): array { $usercompetencyalias = $this->get_table_alias('competency_usercomp'); // Status. @@ -142,7 +120,7 @@ class usercompetency extends base { * * @return filter[] */ - protected function get_all_filters(): array { + protected function get_available_filters(): array { $usercompetencyalias = $this->get_table_alias('competency_usercomp'); // Status. diff --git a/public/course/classes/reportbuilder/local/entities/access.php b/public/course/classes/reportbuilder/local/entities/access.php index 47708272f63..33079e190f4 100644 --- a/public/course/classes/reportbuilder/local/entities/access.php +++ b/public/course/classes/reportbuilder/local/entities/access.php @@ -56,32 +56,12 @@ class access extends base { return new lang_string('courseaccess', 'course'); } - /** - * Initialise the entity - * - * @return base - */ - public function initialise(): base { - foreach ($this->get_all_columns() as $column) { - $this->add_column($column); - } - - // All the filters defined by the entity can also be used as conditions. - foreach ($this->get_all_filters() as $filter) { - $this - ->add_filter($filter) - ->add_condition($filter); - } - - return $this; - } - /** * Returns list of all available columns * * @return column[] */ - protected function get_all_columns(): array { + protected function get_available_columns(): array { $tablealias = $this->get_table_alias('user_lastaccess'); $user = $this->get_table_alias('user'); @@ -113,7 +93,7 @@ class access extends base { * * @return filter[] */ - protected function get_all_filters(): array { + protected function get_available_filters(): array { $tablealias = $this->get_table_alias('user_lastaccess'); // Last course access filter. diff --git a/public/course/classes/reportbuilder/local/entities/completion.php b/public/course/classes/reportbuilder/local/entities/completion.php index 922d16adff1..478b47ca7c2 100644 --- a/public/course/classes/reportbuilder/local/entities/completion.php +++ b/public/course/classes/reportbuilder/local/entities/completion.php @@ -76,32 +76,12 @@ class completion extends base { return new lang_string('coursecompletion', 'completion'); } - /** - * Initialise the entity - * - * @return base - */ - public function initialise(): base { - foreach ($this->get_all_columns() as $column) { - $this->add_column($column); - } - - // All the filters defined by the entity can also be used as conditions. - foreach ($this->get_all_filters() as $filter) { - $this - ->add_filter($filter) - ->add_condition($filter); - } - - return $this; - } - /** * Returns list of all available columns * * @return column[] */ - protected function get_all_columns(): array { + protected function get_available_columns(): array { [ 'course' => $course, 'course_completions' => $coursecompletion, @@ -305,7 +285,7 @@ class completion extends base { * * @return filter[] */ - protected function get_all_filters(): array { + protected function get_available_filters(): array { $coursecompletion = $this->get_table_alias('course_completions'); // Completed status filter. diff --git a/public/course/classes/reportbuilder/local/entities/course_category.php b/public/course/classes/reportbuilder/local/entities/course_category.php index b103df578f2..01cfad77bd4 100644 --- a/public/course/classes/reportbuilder/local/entities/course_category.php +++ b/public/course/classes/reportbuilder/local/entities/course_category.php @@ -60,34 +60,12 @@ class course_category extends base { return new lang_string('coursecategory'); } - /** - * Initialise the entity - * - * @return base - */ - public function initialise(): base { - $columns = $this->get_all_columns(); - foreach ($columns as $column) { - $this->add_column($column); - } - - // All the filters defined by the entity can also be used as conditions. - $filters = $this->get_all_filters(); - foreach ($filters as $filter) { - $this - ->add_filter($filter) - ->add_condition($filter); - } - - return $this; - } - /** * Returns list of all available columns * * @return column[] */ - protected function get_all_columns(): array { + protected function get_available_columns(): array { $tablealias = $this->get_table_alias('course_categories'); $tablealiascontext = $this->get_table_alias('context'); @@ -231,7 +209,7 @@ class course_category extends base { * * @return filter[] */ - protected function get_all_filters(): array { + protected function get_available_filters(): array { $tablealias = $this->get_table_alias('course_categories'); // Select category filter. diff --git a/public/course/classes/reportbuilder/local/entities/enrolment.php b/public/course/classes/reportbuilder/local/entities/enrolment.php index c1db0ac2e54..c96e0b61607 100644 --- a/public/course/classes/reportbuilder/local/entities/enrolment.php +++ b/public/course/classes/reportbuilder/local/entities/enrolment.php @@ -62,32 +62,12 @@ class enrolment extends base { return new lang_string('enrolment', 'enrol'); } - /** - * Initialise the entity - * - * @return base - */ - public function initialise(): base { - foreach ($this->get_all_columns() as $column) { - $this->add_column($column); - } - - // All the filters defined by the entity can also be used as conditions. - foreach ($this->get_all_filters() as $filter) { - $this - ->add_filter($filter) - ->add_condition($filter); - } - - return $this; - } - /** * Returns list of all available columns * * @return column[] */ - protected function get_all_columns(): array { + protected function get_available_columns(): array { $userenrolments = $this->get_table_alias('user_enrolments'); // Enrolment time created. @@ -172,7 +152,7 @@ class enrolment extends base { * * @return filter[] */ - protected function get_all_filters(): array { + protected function get_available_filters(): array { $userenrolments = $this->get_table_alias('user_enrolments'); // Enrolment time created. diff --git a/public/enrol/classes/reportbuilder/local/entities/enrol.php b/public/enrol/classes/reportbuilder/local/entities/enrol.php index f34f16c5ba3..1b8a2e9303b 100644 --- a/public/enrol/classes/reportbuilder/local/entities/enrol.php +++ b/public/enrol/classes/reportbuilder/local/entities/enrol.php @@ -53,34 +53,12 @@ class enrol extends base { return new lang_string('enrolmentmethod', 'core_enrol'); } - /** - * Initialise the entity - * - * @return base - */ - public function initialise(): base { - $columns = $this->get_all_columns(); - foreach ($columns as $column) { - $this->add_column($column); - } - - // All the filters defined by the entity can also be used as conditions. - $filters = $this->get_all_filters(); - foreach ($filters as $filter) { - $this - ->add_filter($filter) - ->add_condition($filter); - } - - return $this; - } - /** * Returns list of all available columns * * @return column[] */ - protected function get_all_columns(): array { + protected function get_available_columns(): array { global $DB; $enrolalias = $this->get_table_alias('enrol'); @@ -184,7 +162,7 @@ class enrol extends base { * * @return filter[] */ - protected function get_all_filters(): array { + protected function get_available_filters(): array { global $DB; $enrolalias = $this->get_table_alias('enrol'); diff --git a/public/files/classes/reportbuilder/local/entities/file.php b/public/files/classes/reportbuilder/local/entities/file.php index d8b8bbb4998..342cdb64c4f 100644 --- a/public/files/classes/reportbuilder/local/entities/file.php +++ b/public/files/classes/reportbuilder/local/entities/file.php @@ -68,34 +68,12 @@ class file extends base { return new lang_string('file'); } - /** - * Initialise the entity - * - * @return base - */ - public function initialise(): base { - $columns = $this->get_all_columns(); - foreach ($columns as $column) { - $this->add_column($column); - } - - // All the filters defined by the entity can also be used as conditions. - $filters = $this->get_all_filters(); - foreach ($filters as $filter) { - $this - ->add_filter($filter) - ->add_condition($filter); - } - - return $this; - } - /** * Returns list of all available columns * * @return column[] */ - protected function get_all_columns(): array { + protected function get_available_columns(): array { $filesalias = $this->get_table_alias('files'); // Name. @@ -289,7 +267,7 @@ class file extends base { * * @return filter[] */ - protected function get_all_filters(): array { + protected function get_available_filters(): array { $filesalias = $this->get_table_alias('files'); // Directory. diff --git a/public/grade/report/summary/classes/local/entities/grade_items.php b/public/grade/report/summary/classes/local/entities/grade_items.php index 38c7951f625..9b1fcebfd3d 100644 --- a/public/grade/report/summary/classes/local/entities/grade_items.php +++ b/public/grade/report/summary/classes/local/entities/grade_items.php @@ -98,17 +98,7 @@ class grade_items extends base { $showonlyactiveenrol = $this->report->show_only_active(); $this->ungradedcounts = $this->report->ungraded_counts(false, false, $showonlyactiveenrol); - $columns = $this->get_all_columns(); - foreach ($columns as $column) { - $this->add_column($column); - } - - $filters = $this->get_all_filters(); - foreach ($filters as $filter) { - $this->add_filter($filter); - } - - return $this; + return parent::initialise(); } /** @@ -116,7 +106,7 @@ class grade_items extends base { * * @return column[] */ - protected function get_all_columns(): array { + protected function get_available_columns(): array { $tablealias = $this->get_table_alias('grade_items'); $selectsql = "$tablealias.id, $tablealias.itemname, $tablealias.iteminstance, $tablealias.calculation, @@ -221,7 +211,7 @@ class grade_items extends base { * * @return filter[] */ - protected function get_all_filters(): array { + protected function get_available_filters(): array { $tablealias = $this->get_table_alias('grade_items'); // Activity type filter (for performance only load options on demand). diff --git a/public/group/classes/reportbuilder/local/entities/group.php b/public/group/classes/reportbuilder/local/entities/group.php index 3adfc37305c..7cadc14ea0b 100644 --- a/public/group/classes/reportbuilder/local/entities/group.php +++ b/public/group/classes/reportbuilder/local/entities/group.php @@ -42,6 +42,9 @@ require_once("{$CFG->libdir}/grouplib.php"); */ class group extends base { + /** @var custom_fields $customfields */ + private custom_fields $customfields; + /** * Database tables that this entity uses * @@ -71,7 +74,7 @@ class group extends base { public function initialise(): base { $groupsalias = $this->get_table_alias('groups'); - $customfields = (new custom_fields( + $this->customfields = (new custom_fields( "{$groupsalias}.id", $this->get_entity_name(), 'core_group', @@ -79,20 +82,7 @@ class group extends base { )) ->add_joins($this->get_joins()); - $columns = array_merge($this->get_all_columns(), $customfields->get_columns()); - foreach ($columns as $column) { - $this->add_column($column); - } - - // All the filters defined by the entity can also be used as conditions. - $filters = array_merge($this->get_all_filters(), $customfields->get_filters()); - foreach ($filters as $filter) { - $this - ->add_filter($filter) - ->add_condition($filter); - } - - return $this; + return parent::initialise(); } /** @@ -100,7 +90,7 @@ class group extends base { * * @return column[] */ - protected function get_all_columns(): array { + protected function get_available_columns(): array { $contextalias = $this->get_table_alias('context'); $groupsalias = $this->get_table_alias('groups'); @@ -254,7 +244,8 @@ class group extends base { ->set_is_sortable(true) ->set_callback([format::class, 'userdate']); - return $columns; + // Merge with custom field columns. + return array_merge($columns, $this->customfields->get_columns()); } /** @@ -262,7 +253,7 @@ class group extends base { * * @return filter[] */ - protected function get_all_filters(): array { + protected function get_available_filters(): array { $groupsalias = $this->get_table_alias('groups'); // Name filter. @@ -321,6 +312,7 @@ class group extends base { )) ->add_joins($this->get_joins()); - return $filters; + // Merge with custom field filters. + return array_merge($filters, $this->customfields->get_filters()); } } diff --git a/public/group/classes/reportbuilder/local/entities/group_member.php b/public/group/classes/reportbuilder/local/entities/group_member.php index 7db5bd34c67..af0d4292cee 100644 --- a/public/group/classes/reportbuilder/local/entities/group_member.php +++ b/public/group/classes/reportbuilder/local/entities/group_member.php @@ -53,34 +53,12 @@ class group_member extends base { return new lang_string('groupmember', 'core_group'); } - /** - * Initialise the entity - * - * @return base - */ - public function initialise(): base { - $columns = $this->get_all_columns(); - foreach ($columns as $column) { - $this->add_column($column); - } - - // All the filters defined by the entity can also be used as conditions. - $filters = $this->get_all_filters(); - foreach ($filters as $filter) { - $this - ->add_filter($filter) - ->add_condition($filter); - } - - return $this; - } - /** * Returns list of all available columns * * @return column[] */ - protected function get_all_columns(): array { + protected function get_available_columns(): array { $groupsmembersalias = $this->get_table_alias('groups_members'); // Time added column. @@ -114,7 +92,7 @@ class group_member extends base { * * @return filter[] */ - protected function get_all_filters(): array { + protected function get_available_filters(): array { $groupsmembersalias = $this->get_table_alias('groups_members'); // Time added filter. diff --git a/public/group/classes/reportbuilder/local/entities/grouping.php b/public/group/classes/reportbuilder/local/entities/grouping.php index f6e00ccca2d..13c6c99bd2f 100644 --- a/public/group/classes/reportbuilder/local/entities/grouping.php +++ b/public/group/classes/reportbuilder/local/entities/grouping.php @@ -35,6 +35,9 @@ use core_reportbuilder\local\report\{column, filter}; */ class grouping extends base { + /** @var custom_fields $customfields */ + private custom_fields $customfields; + /** * Database tables that this entity uses * @@ -64,7 +67,7 @@ class grouping extends base { public function initialise(): base { $groupingsalias = $this->get_table_alias('groupings'); - $customfields = (new custom_fields( + $this->customfields = (new custom_fields( "{$groupingsalias}.id", $this->get_entity_name(), 'core_group', @@ -72,20 +75,7 @@ class grouping extends base { )) ->add_joins($this->get_joins()); - $columns = array_merge($this->get_all_columns(), $customfields->get_columns()); - foreach ($columns as $column) { - $this->add_column($column); - } - - // All the filters defined by the entity can also be used as conditions. - $filters = array_merge($this->get_all_filters(), $customfields->get_filters()); - foreach ($filters as $filter) { - $this - ->add_filter($filter) - ->add_condition($filter); - } - - return $this; + return parent::initialise(); } /** @@ -93,7 +83,7 @@ class grouping extends base { * * @return column[] */ - protected function get_all_columns(): array { + protected function get_available_columns(): array { $contextalias = $this->get_table_alias('context'); $groupingsalias = $this->get_table_alias('groupings'); @@ -181,7 +171,8 @@ class grouping extends base { ->set_is_sortable(true) ->set_callback([format::class, 'userdate']); - return $columns; + // Merge with custom field columns. + return array_merge($columns, $this->customfields->get_columns()); } /** @@ -189,7 +180,7 @@ class grouping extends base { * * @return filter[] */ - protected function get_all_filters(): array { + protected function get_available_filters(): array { $groupingsalias = $this->get_table_alias('groupings'); // Name filter. @@ -222,6 +213,7 @@ class grouping extends base { )) ->add_joins($this->get_joins()); - return $filters; + // Merge with custom field filters. + return array_merge($filters, $this->customfields->get_filters()); } } diff --git a/public/lib/classes/reportbuilder/local/entities/context.php b/public/lib/classes/reportbuilder/local/entities/context.php index aea22e08fb3..98703c31b98 100644 --- a/public/lib/classes/reportbuilder/local/entities/context.php +++ b/public/lib/classes/reportbuilder/local/entities/context.php @@ -55,34 +55,12 @@ class context extends base { return new lang_string('context'); } - /** - * Initialise the entity - * - * @return base - */ - public function initialise(): base { - $columns = $this->get_all_columns(); - foreach ($columns as $column) { - $this->add_column($column); - } - - // All the filters defined by the entity can also be used as conditions. - $filters = $this->get_all_filters(); - foreach ($filters as $filter) { - $this - ->add_filter($filter) - ->add_condition($filter); - } - - return $this; - } - /** * Returns list of all available columns * * @return column[] */ - protected function get_all_columns(): array { + protected function get_available_columns(): array { global $DB; $contextalias = $this->get_table_alias('context'); @@ -195,7 +173,7 @@ class context extends base { * * @return filter[] */ - protected function get_all_filters(): array { + protected function get_available_filters(): array { $contextalias = $this->get_table_alias('context'); // Level. diff --git a/public/message/classes/reportbuilder/local/entities/conversation.php b/public/message/classes/reportbuilder/local/entities/conversation.php index 06aed8ef1e7..c73a20479b8 100644 --- a/public/message/classes/reportbuilder/local/entities/conversation.php +++ b/public/message/classes/reportbuilder/local/entities/conversation.php @@ -53,34 +53,12 @@ class conversation extends base { return new lang_string('conversation', 'core_message'); } - /** - * Initialise the entity - * - * @return base - */ - public function initialise(): base { - $columns = $this->get_all_columns(); - foreach ($columns as $column) { - $this->add_column($column); - } - - // All the filters defined by the entity can also be used as conditions. - $filters = $this->get_all_filters(); - foreach ($filters as $filter) { - $this - ->add_filter($filter) - ->add_condition($filter); - } - - return $this; - } - /** * Returns list of all available columns * * @return column[] */ - protected function get_all_columns(): array { + protected function get_available_columns(): array { $conversationalias = $this->get_table_alias('message_conversations'); // Type. @@ -152,7 +130,7 @@ class conversation extends base { * * @return filter[] */ - protected function get_all_filters(): array { + protected function get_available_filters(): array { $conversationalias = $this->get_table_alias('message_conversations'); // Type. diff --git a/public/message/classes/reportbuilder/local/entities/message.php b/public/message/classes/reportbuilder/local/entities/message.php index 28dad806a4d..bd050493972 100644 --- a/public/message/classes/reportbuilder/local/entities/message.php +++ b/public/message/classes/reportbuilder/local/entities/message.php @@ -53,34 +53,12 @@ class message extends base { return new lang_string('message', 'core_message'); } - /** - * Initialise the entity - * - * @return base - */ - public function initialise(): base { - $columns = $this->get_all_columns(); - foreach ($columns as $column) { - $this->add_column($column); - } - - // All the filters defined by the entity can also be used as conditions. - $filters = $this->get_all_filters(); - foreach ($filters as $filter) { - $this - ->add_filter($filter) - ->add_condition($filter); - } - - return $this; - } - /** * Returns list of all available columns * * @return column[] */ - protected function get_all_columns(): array { + protected function get_available_columns(): array { $messagealias = $this->get_table_alias('messages'); // Subject. @@ -135,7 +113,7 @@ class message extends base { * * @return filter[] */ - protected function get_all_filters(): array { + protected function get_available_filters(): array { $messagealias = $this->get_table_alias('messages'); // Subject. diff --git a/public/mod/forum/classes/reportbuilder/local/entities/discussion.php b/public/mod/forum/classes/reportbuilder/local/entities/discussion.php index 3cfa147d337..a4a39df45bd 100644 --- a/public/mod/forum/classes/reportbuilder/local/entities/discussion.php +++ b/public/mod/forum/classes/reportbuilder/local/entities/discussion.php @@ -55,34 +55,12 @@ class discussion extends base { return new lang_string('discussion', 'mod_forum'); } - /** - * Initialise the entity - * - * @return base - */ - public function initialise(): base { - $columns = $this->get_all_columns(); - foreach ($columns as $column) { - $this->add_column($column); - } - - // All the filters defined by the entity can also be used as conditions. - $filters = $this->get_all_filters(); - foreach ($filters as $filter) { - $this - ->add_filter($filter) - ->add_condition($filter); - } - - return $this; - } - /** * Returns list of all available columns * * @return column[] */ - protected function get_all_columns(): array { + protected function get_available_columns(): array { [ 'context' => $contextalias, 'forum_discussions' => $discussionalias, @@ -153,7 +131,7 @@ class discussion extends base { * * @return filter[] */ - protected function get_all_filters(): array { + protected function get_available_filters(): array { $discussionalias = $this->get_table_alias('forum_discussions'); // Name. diff --git a/public/mod/forum/classes/reportbuilder/local/entities/forum.php b/public/mod/forum/classes/reportbuilder/local/entities/forum.php index 0b947b3757f..fe091a0d5f9 100644 --- a/public/mod/forum/classes/reportbuilder/local/entities/forum.php +++ b/public/mod/forum/classes/reportbuilder/local/entities/forum.php @@ -55,34 +55,12 @@ class forum extends base { return new lang_string('forum', 'mod_forum'); } - /** - * Initialise the entity - * - * @return base - */ - public function initialise(): base { - $columns = $this->get_all_columns(); - foreach ($columns as $column) { - $this->add_column($column); - } - - // All the filters defined by the entity can also be used as conditions. - $filters = $this->get_all_filters(); - foreach ($filters as $filter) { - $this - ->add_filter($filter) - ->add_condition($filter); - } - - return $this; - } - /** * Returns list of all available columns * * @return column[] */ - protected function get_all_columns(): array { + protected function get_available_columns(): array { [ 'context' => $contextalias, 'forum' => $forumalias, @@ -184,7 +162,7 @@ class forum extends base { * * @return filter[] */ - protected function get_all_filters(): array { + protected function get_available_filters(): array { $forumalias = $this->get_table_alias('forum'); // Name. diff --git a/public/mod/forum/classes/reportbuilder/local/entities/post.php b/public/mod/forum/classes/reportbuilder/local/entities/post.php index 56732a0bedf..78d992a0789 100644 --- a/public/mod/forum/classes/reportbuilder/local/entities/post.php +++ b/public/mod/forum/classes/reportbuilder/local/entities/post.php @@ -55,34 +55,12 @@ class post extends base { return new lang_string('post', 'mod_forum'); } - /** - * Initialise the entity - * - * @return base - */ - public function initialise(): base { - $columns = $this->get_all_columns(); - foreach ($columns as $column) { - $this->add_column($column); - } - - // All the filters defined by the entity can also be used as conditions. - $filters = $this->get_all_filters(); - foreach ($filters as $filter) { - $this - ->add_filter($filter) - ->add_condition($filter); - } - - return $this; - } - /** * Returns list of all available columns * * @return column[] */ - protected function get_all_columns(): array { + protected function get_available_columns(): array { [ 'context' => $contextalias, 'forum_posts' => $postalias, @@ -189,7 +167,7 @@ class post extends base { * * @return filter[] */ - protected function get_all_filters(): array { + protected function get_available_filters(): array { $postalias = $this->get_table_alias('forum_posts'); // Subject. diff --git a/public/mod/lti/classes/reportbuilder/local/entities/tool_types.php b/public/mod/lti/classes/reportbuilder/local/entities/tool_types.php index f5c24174038..2f28d0e28a6 100644 --- a/public/mod/lti/classes/reportbuilder/local/entities/tool_types.php +++ b/public/mod/lti/classes/reportbuilder/local/entities/tool_types.php @@ -55,31 +55,12 @@ class tool_types extends base { return new lang_string('entitycourseexternaltools', 'mod_lti'); } - /** - * Initialize the entity - * - * @return base - */ - public function initialise(): base { - $columns = $this->get_all_columns(); - foreach ($columns as $column) { - $this->add_column($column); - } - - $filters = $this->get_all_filters(); - foreach ($filters as $filter) { - $this->add_filter($filter); - } - - return $this; - } - /** * Returns list of all available columns * * @return column[] */ - protected function get_all_columns(): array { + protected function get_available_columns(): array { $tablealias = $this->get_table_alias('lti_types'); // Name column. @@ -146,7 +127,7 @@ class tool_types extends base { * * @return filter[] */ - protected function get_all_filters(): array { + protected function get_available_filters(): array { $tablealias = $this->get_table_alias('lti_types'); return [ diff --git a/public/notes/classes/reportbuilder/local/entities/note.php b/public/notes/classes/reportbuilder/local/entities/note.php index 830ea1e73c1..8c595e77872 100644 --- a/public/notes/classes/reportbuilder/local/entities/note.php +++ b/public/notes/classes/reportbuilder/local/entities/note.php @@ -59,34 +59,12 @@ class note extends base { return new lang_string('note', 'core_notes'); } - /** - * Initialise the entity - * - * @return base - */ - public function initialise(): base { - $columns = $this->get_all_columns(); - foreach ($columns as $column) { - $this->add_column($column); - } - - // All the filters defined by the entity can also be used as conditions. - $filters = $this->get_all_filters(); - foreach ($filters as $filter) { - $this - ->add_filter($filter) - ->add_condition($filter); - } - - return $this; - } - /** * Returns list of all available columns * * @return column[] */ - protected function get_all_columns(): array { + protected function get_available_columns(): array { $postalias = $this->get_table_alias('post'); // Content. @@ -158,7 +136,7 @@ class note extends base { * * @return filter[] */ - protected function get_all_filters(): array { + protected function get_available_filters(): array { $postalias = $this->get_table_alias('post'); // Content. diff --git a/public/report/configlog/classes/reportbuilder/local/entities/config_change.php b/public/report/configlog/classes/reportbuilder/local/entities/config_change.php index adfcc9870e9..54c2594937e 100644 --- a/public/report/configlog/classes/reportbuilder/local/entities/config_change.php +++ b/public/report/configlog/classes/reportbuilder/local/entities/config_change.php @@ -55,31 +55,12 @@ class config_change extends base { return new lang_string('entityconfigchange', 'report_configlog'); } - /** - * Initialize the entity - * - * @return base - */ - public function initialise(): base { - $columns = $this->get_all_columns(); - foreach ($columns as $column) { - $this->add_column($column); - } - - $filters = $this->get_all_filters(); - foreach ($filters as $filter) { - $this->add_filter($filter); - } - - return $this; - } - /** * Returns list of all available columns * * @return column[] */ - protected function get_all_columns(): array { + protected function get_available_columns(): array { $tablealias = $this->get_table_alias('config_log'); // Time modified column. @@ -155,7 +136,7 @@ class config_change extends base { * * @return filter[] */ - protected function get_all_filters(): array { + protected function get_available_filters(): array { $tablealias = $this->get_table_alias('config_log'); // Time modified filter. diff --git a/public/report/themeusage/classes/reportbuilder/local/entities/theme.php b/public/report/themeusage/classes/reportbuilder/local/entities/theme.php index 0c7313dddc4..7cdbb69a1bd 100644 --- a/public/report/themeusage/classes/reportbuilder/local/entities/theme.php +++ b/public/report/themeusage/classes/reportbuilder/local/entities/theme.php @@ -51,26 +51,12 @@ class theme extends base { return new lang_string('theme'); } - /** - * Initialize the entity. - * - * @return base - */ - public function initialise(): base { - $columns = $this->get_all_columns(); - foreach ($columns as $column) { - $this->add_column($column); - } - - return $this; - } - /** * Returns list of all available columns. * * @return column[] */ - protected function get_all_columns(): array { + protected function get_available_columns(): array { global $DB; $themealias = $this->get_table_alias('config_plugins'); $sqlsubstring = $DB->sql_substr("{$themealias}.plugin", 7); diff --git a/public/reportbuilder/classes/local/entities/course.php b/public/reportbuilder/classes/local/entities/course.php index 5c934a855c4..9c3d520f84d 100644 --- a/public/reportbuilder/classes/local/entities/course.php +++ b/public/reportbuilder/classes/local/entities/course.php @@ -49,6 +49,9 @@ require_once($CFG->dirroot . '/course/lib.php'); */ class course extends base { + /** @var custom_fields $customfields */ + private custom_fields $customfields; + /** * Database tables that this entity uses * @@ -80,7 +83,7 @@ class course extends base { public function initialise(): base { $tablealias = $this->get_table_alias('course'); - $customfields = (new custom_fields( + $this->customfields = (new custom_fields( "{$tablealias}.id", $this->get_entity_name(), 'core_course', @@ -88,20 +91,7 @@ class course extends base { )) ->add_joins($this->get_joins()); - $columns = array_merge($this->get_all_columns(), $customfields->get_columns()); - foreach ($columns as $column) { - $this->add_column($column); - } - - // All the filters defined by the entity can also be used as conditions. - $filters = array_merge($this->get_all_filters(), $customfields->get_filters()); - foreach ($filters as $filter) { - $this - ->add_condition($filter) - ->add_filter($filter); - } - - return $this; + return parent::initialise(); } /** @@ -192,7 +182,7 @@ class course extends base { * * @return column[] */ - protected function get_all_columns(): array { + protected function get_available_columns(): array { $coursefields = $this->get_course_fields(); $tablealias = $this->get_table_alias('course'); $contexttablealias = $this->get_table_alias('context'); @@ -271,7 +261,8 @@ class course extends base { $columns[] = $column; } - return $columns; + // Merge with custom field columns. + return array_merge($columns, $this->customfields->get_columns()); } /** @@ -279,7 +270,7 @@ class course extends base { * * @return array */ - protected function get_all_filters(): array { + protected function get_available_filters(): array { $filters = []; $tablealias = $this->get_table_alias('course'); @@ -323,7 +314,8 @@ class course extends base { )) ->add_joins($this->get_joins()); - return $filters; + // Merge with custom field filters. + return array_merge($filters, $this->customfields->get_filters()); } /** diff --git a/public/reportbuilder/classes/local/entities/user.php b/public/reportbuilder/classes/local/entities/user.php index 63bbbe89d3d..7e0dcfa3d62 100644 --- a/public/reportbuilder/classes/local/entities/user.php +++ b/public/reportbuilder/classes/local/entities/user.php @@ -50,6 +50,9 @@ use core_reportbuilder\local\report\filter; */ class user extends base { + /** @var user_profile_fields $userprofilefields */ + private user_profile_fields $userprofilefields; + /** * Database tables that this entity uses * @@ -81,26 +84,13 @@ class user extends base { public function initialise(): base { $tablealias = $this->get_table_alias('user'); - $userprofilefields = (new user_profile_fields( + $this->userprofilefields = (new user_profile_fields( "{$tablealias}.id", $this->get_entity_name(), )) ->add_joins($this->get_joins()); - $columns = array_merge($this->get_all_columns(), $userprofilefields->get_columns()); - foreach ($columns as $column) { - $this->add_column($column); - } - - // All the filters defined by the entity can also be used as conditions. - $filters = array_merge($this->get_all_filters(), $userprofilefields->get_filters()); - foreach ($filters as $filter) { - $this - ->add_condition($filter) - ->add_filter($filter); - } - - return $this; + return parent::initialise(); } /** @@ -175,7 +165,7 @@ class user extends base { * * @return column[] */ - protected function get_all_columns(): array { + protected function get_available_columns(): array { $usertablealias = $this->get_table_alias('user'); $contexttablealias = $this->get_table_alias('context'); @@ -308,7 +298,8 @@ class user extends base { $columns[] = $column; } - return $columns; + // Merge with user profile field columns. + return array_merge($columns, $this->userprofilefields->get_columns()); } /** @@ -455,7 +446,7 @@ class user extends base { * * @return filter[] */ - protected function get_all_filters(): array { + protected function get_available_filters(): array { $tablealias = $this->get_table_alias('user'); // Fullname filter. @@ -532,7 +523,8 @@ class user extends base { )) ->add_joins($this->get_joins()); - return $filters; + // Merge with user profile field filters. + return array_merge($filters, $this->userprofilefields->get_filters()); } /** diff --git a/public/reportbuilder/tests/local/entities/base_test.php b/public/reportbuilder/tests/local/entities/base_test.php index 559beb68524..93a6859cd07 100644 --- a/public/reportbuilder/tests/local/entities/base_test.php +++ b/public/reportbuilder/tests/local/entities/base_test.php @@ -387,19 +387,28 @@ class base_test_entity extends base { } /** - * Initialise entity + * Entity available columns * - * @return base + * @return column[] */ - public function initialise(): base { - $column = (new column( + protected function get_available_columns(): array { + $columns[] = (new column( 'test', new lang_string('no'), $this->get_entity_name() )) ->add_field('no'); - $filter = (new filter( + return $columns; + } + + /** + * Entity available filters + * + * @return filter[] + */ + protected function get_available_filters(): array { + $filters[] = (new filter( text::class, 'test', new lang_string('no'), @@ -407,10 +416,7 @@ class base_test_entity extends base { )) ->set_field_sql('no'); - return $this - ->add_column($column) - ->add_filter($filter) - ->add_condition($filter); + return $filters; } } diff --git a/public/tag/classes/reportbuilder/local/entities/collection.php b/public/tag/classes/reportbuilder/local/entities/collection.php index 4bfb55de4a6..15c0ee8af48 100644 --- a/public/tag/classes/reportbuilder/local/entities/collection.php +++ b/public/tag/classes/reportbuilder/local/entities/collection.php @@ -55,34 +55,12 @@ class collection extends base { return new lang_string('tagcollection', 'core_tag'); } - /** - * Initialise the entity - * - * @return base - */ - public function initialise(): base { - $columns = $this->get_all_columns(); - foreach ($columns as $column) { - $this->add_column($column); - } - - // All the filters defined by the entity can also be used as conditions. - $filters = $this->get_all_filters(); - foreach ($filters as $filter) { - $this - ->add_filter($filter) - ->add_condition($filter); - } - - return $this; - } - /** * Returns list of all available columns * * @return column[] */ - protected function get_all_columns(): array { + protected function get_available_columns(): array { $collectionalias = $this->get_table_alias('tag_coll'); // Name. @@ -154,7 +132,7 @@ class collection extends base { * * @return filter[] */ - protected function get_all_filters(): array { + protected function get_available_filters(): array { $collectionalias = $this->get_table_alias('tag_coll'); // Name. diff --git a/public/tag/classes/reportbuilder/local/entities/instance.php b/public/tag/classes/reportbuilder/local/entities/instance.php index 9c91dc1e41e..89ff1b19b3c 100644 --- a/public/tag/classes/reportbuilder/local/entities/instance.php +++ b/public/tag/classes/reportbuilder/local/entities/instance.php @@ -67,34 +67,12 @@ class instance extends base { return new lang_string('taginstance', 'core_tag'); } - /** - * Initialise the entity - * - * @return base - */ - public function initialise(): base { - $columns = $this->get_all_columns(); - foreach ($columns as $column) { - $this->add_column($column); - } - - // All the filters defined by the entity can also be used as conditions. - $filters = $this->get_all_filters(); - foreach ($filters as $filter) { - $this - ->add_filter($filter) - ->add_condition($filter); - } - - return $this; - } - /** * Returns list of all available columns * * @return column[] */ - protected function get_all_columns(): array { + protected function get_available_columns(): array { $instancealias = $this->get_table_alias('tag_instance'); // Area. @@ -179,7 +157,7 @@ class instance extends base { * * @return filter[] */ - protected function get_all_filters(): array { + protected function get_available_filters(): array { global $DB; $instancealias = $this->get_table_alias('tag_instance'); diff --git a/public/tag/classes/reportbuilder/local/entities/tag.php b/public/tag/classes/reportbuilder/local/entities/tag.php index 285811ac6b6..51e77561f5e 100644 --- a/public/tag/classes/reportbuilder/local/entities/tag.php +++ b/public/tag/classes/reportbuilder/local/entities/tag.php @@ -59,34 +59,12 @@ class tag extends base { return new lang_string('tag', 'core_tag'); } - /** - * Initialise the entity - * - * @return base - */ - public function initialise(): base { - $columns = $this->get_all_columns(); - foreach ($columns as $column) { - $this->add_column($column); - } - - // All the filters defined by the entity can also be used as conditions. - $filters = $this->get_all_filters(); - foreach ($filters as $filter) { - $this - ->add_filter($filter) - ->add_condition($filter); - } - - return $this; - } - /** * Returns list of all available columns * * @return column[] */ - protected function get_all_columns(): array { + protected function get_available_columns(): array { $tagalias = $this->get_table_alias('tag'); // Name. @@ -231,7 +209,7 @@ class tag extends base { * * @return filter[] */ - protected function get_all_filters(): array { + protected function get_available_filters(): array { $tagalias = $this->get_table_alias('tag'); // Name. diff --git a/public/webservice/classes/reportbuilder/local/entities/service.php b/public/webservice/classes/reportbuilder/local/entities/service.php index 87ed6e34a19..7872e23685f 100644 --- a/public/webservice/classes/reportbuilder/local/entities/service.php +++ b/public/webservice/classes/reportbuilder/local/entities/service.php @@ -54,33 +54,12 @@ class service extends base { return new lang_string('service', 'core_webservice'); } - /** - * Initialise the entity - * - * @return base - */ - public function initialise(): base { - $columns = $this->get_all_columns(); - foreach ($columns as $column) { - $this->add_column($column); - } - // All the filters defined by the entity can also be used as conditions. - $filters = $this->get_all_filters(); - foreach ($filters as $filter) { - $this - ->add_filter($filter) - ->add_condition($filter); - } - - return $this; - } - /** * Returns list of all available columns * * @return column[] */ - protected function get_all_columns(): array { + protected function get_available_columns(): array { $tokenalias = $this->get_table_alias('external_services'); // Service name column. @@ -109,9 +88,7 @@ class service extends base { * * @return filter[] */ - protected function get_all_filters(): array { - global $DB; - + protected function get_available_filters(): array { $tablealias = $this->get_table_alias('external_services'); // Service Name filter. diff --git a/public/webservice/classes/reportbuilder/local/entities/token.php b/public/webservice/classes/reportbuilder/local/entities/token.php index d2e6aeeb8af..623a4716e7f 100644 --- a/public/webservice/classes/reportbuilder/local/entities/token.php +++ b/public/webservice/classes/reportbuilder/local/entities/token.php @@ -53,34 +53,12 @@ class token extends base { return new lang_string('token', 'core_webservice'); } - /** - * Initialise the entity - * - * @return base - */ - public function initialise(): base { - $columns = $this->get_all_columns(); - foreach ($columns as $column) { - $this->add_column($column); - } - - // All the filters defined by the entity can also be used as conditions. - $filters = $this->get_all_filters(); - foreach ($filters as $filter) { - $this - ->add_filter($filter) - ->add_condition($filter); - } - - return $this; - } - /** * Returns list of all available columns * * @return column[] */ - protected function get_all_columns(): array { + protected function get_available_columns(): array { $tokenalias = $this->get_table_alias('external_tokens'); // Token name column. @@ -138,9 +116,7 @@ class token extends base { * * @return filter[] */ - protected function get_all_filters(): array { - global $DB; - + protected function get_available_filters(): array { $tokenalias = $this->get_table_alias('external_tokens'); // Name filter.