MDL-82475 reportbuilder: account for duplicate profile field names.
Long-term, it would be better to not allow this scenario to happen at all but until then we'll have to work around it (see MDL-73461).
This commit is contained in:
@@ -166,8 +166,9 @@ class user_profile_fields {
|
||||
$columnfieldsql = $DB->sql_order_by_text($columnfieldsql, 1024);
|
||||
}
|
||||
|
||||
$columns[] = (new column(
|
||||
'profilefield_' . core_text::strtolower($profilefield->field->shortname),
|
||||
$columnname = 'profilefield_' . core_text::strtolower($profilefield->field->shortname);
|
||||
$columns[$columnname] = (new column(
|
||||
$columnname,
|
||||
new lang_string('customfieldcolumn', 'core_reportbuilder', $profilefield->display_name(false)),
|
||||
$this->entityname
|
||||
))
|
||||
@@ -186,7 +187,7 @@ class user_profile_fields {
|
||||
}, $profilefield);
|
||||
}
|
||||
|
||||
return $columns;
|
||||
return array_values($columns);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -231,9 +232,10 @@ class user_profile_fields {
|
||||
break;
|
||||
}
|
||||
|
||||
$filtername = 'profilefield_' . core_text::strtolower($profilefield->field->shortname);
|
||||
$filter = (new filter(
|
||||
$classname,
|
||||
'profilefield_' . core_text::strtolower($profilefield->field->shortname),
|
||||
$filtername,
|
||||
new lang_string('customfieldcolumn', 'core_reportbuilder', $profilefield->display_name(false)),
|
||||
$this->entityname,
|
||||
$fieldsql,
|
||||
@@ -247,10 +249,10 @@ class user_profile_fields {
|
||||
$filter->set_options($profilefield->options);
|
||||
}
|
||||
|
||||
$filters[] = $filter;
|
||||
$filters[$filtername] = $filter;
|
||||
}
|
||||
|
||||
return $filters;
|
||||
return array_values($filters);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -94,6 +94,13 @@ class user_profile_fields_test extends core_reportbuilder_testcase {
|
||||
return $column->get_type();
|
||||
}, $initialcolumns);
|
||||
|
||||
// Create a field which will duplicate one of the subsequently generated fields (case-insensitive shortname).
|
||||
$this->getDataGenerator()->create_custom_profile_field([
|
||||
'shortname' => 'CHECKBOX',
|
||||
'name' => 'Duplicate checkbox field',
|
||||
'datatype' => 'checkbox',
|
||||
]);
|
||||
|
||||
// Add new custom profile fields.
|
||||
$userprofilefields = $this->generate_userprofilefields();
|
||||
$columns = $userprofilefields->get_columns();
|
||||
@@ -177,6 +184,13 @@ class user_profile_fields_test extends core_reportbuilder_testcase {
|
||||
return $filter->get_header();
|
||||
}, $initialfilters);
|
||||
|
||||
// Create a field which will duplicate one of the subsequently generated fields (case-insensitive shortname).
|
||||
$this->getDataGenerator()->create_custom_profile_field([
|
||||
'shortname' => 'CHECKBOX',
|
||||
'name' => 'Duplicate checkbox field',
|
||||
'datatype' => 'checkbox',
|
||||
]);
|
||||
|
||||
// Add new custom profile fields.
|
||||
$userprofilefields = $this->generate_userprofilefields();
|
||||
$filters = $userprofilefields->get_filters();
|
||||
|
||||
Reference in New Issue
Block a user