mirror of
https://github.com/moodle/moodle.git
synced 2025-04-12 03:52:16 +02:00
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:
parent
fc29adddf9
commit
b1e9990de1
@ -129,8 +129,9 @@ class user_profile_fields {
|
||||
END";
|
||||
}
|
||||
|
||||
$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
|
||||
))
|
||||
@ -155,7 +156,7 @@ class user_profile_fields {
|
||||
}, $profilefield);
|
||||
}
|
||||
|
||||
return $columns;
|
||||
return array_values($columns);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -213,9 +214,10 @@ class user_profile_fields {
|
||||
$userinfoparams[$paramdefault] = $fielddefault;
|
||||
}
|
||||
|
||||
$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,
|
||||
$userinfosql,
|
||||
@ -229,10 +231,10 @@ class user_profile_fields {
|
||||
$filter->set_options($profilefield->options);
|
||||
}
|
||||
|
||||
$filters[] = $filter;
|
||||
$filters[$filtername] = $filter;
|
||||
}
|
||||
|
||||
return $filters;
|
||||
return array_values($filters);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -91,6 +91,13 @@ final 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();
|
||||
@ -175,6 +182,13 @@ final 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();
|
||||
|
Loading…
x
Reference in New Issue
Block a user