MDL-77705 reportbuilder: avoid re-using field alias between entities.

Ensure that when the user entity is added multiple times to a report,
when there are custom profile fields, each of those gets a unique table
alias per-entity.
This commit is contained in:
Paul Holden 2023-03-21 16:02:54 +00:00
parent 231c25e498
commit ee3924702f
No known key found for this signature in database
GPG Key ID: A81A96D6045F6164

View File

@ -115,11 +115,21 @@ class user_profile_fields {
/**
* Generate table alias for given profile field
*
* The entity name is used to ensure the alias differs when the entity is used multiple times within the same report, each
* having their own table alias/join
*
* @param profile_field_base $profilefield
* @return string
*/
private function get_table_alias(profile_field_base $profilefield): string {
return "upfs{$profilefield->fieldid}";
static $aliases = [];
$aliaskey = "{$this->entityname}_{$profilefield->fieldid}";
if (!array_key_exists($aliaskey, $aliases)) {
$aliases[$aliaskey] = database::generate_alias();
}
return $aliases[$aliaskey];
}
/**