From 586ead512c5983f6c25502805629fd87f3e3dd86 Mon Sep 17 00:00:00 2001 From: Paul Holden Date: Tue, 15 Apr 2025 17:55:33 +0100 Subject: [PATCH] MDL-85223 reportbuilder: initialize user entity filters just once. --- reportbuilder/classes/local/entities/user.php | 31 +++++++------------ 1 file changed, 12 insertions(+), 19 deletions(-) diff --git a/reportbuilder/classes/local/entities/user.php b/reportbuilder/classes/local/entities/user.php index bcf319268a5..ac6397864c2 100644 --- a/reportbuilder/classes/local/entities/user.php +++ b/reportbuilder/classes/local/entities/user.php @@ -76,42 +76,35 @@ class user extends base { } /** - * Initialise the entity, add all user fields and all 'visible' user profile fields + * Initialise the entity * * @return base */ public function initialise(): base { - $userprofilefields = $this->get_user_profile_fields(); + $tablealias = $this->get_table_alias('user'); + + $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_filter($filter); - } - - $conditions = array_merge($this->get_all_filters(), $userprofilefields->get_filters()); - foreach ($conditions as $condition) { - $this->add_condition($condition); + $this + ->add_condition($filter) + ->add_filter($filter); } return $this; } - /** - * Get user profile fields helper instance - * - * @return user_profile_fields - */ - protected function get_user_profile_fields(): user_profile_fields { - $userprofilefields = new user_profile_fields($this->get_table_alias('user') . '.id', $this->get_entity_name()); - $userprofilefields->add_joins($this->get_joins()); - return $userprofilefields; - } - /** * Returns column that corresponds to the given identity field, profile field identifiers will be converted to those * used by the {@see user_profile_fields} helper