MDL-76873 reportbuilder: correct checks for profile field visibility.

This commit is contained in:
Paul Holden 2023-01-12 12:02:41 +00:00
parent 8503f2cfd8
commit 65c4ae7bda
2 changed files with 12 additions and 10 deletions

View File

@ -109,28 +109,30 @@ class user extends base {
}
/**
* Returns column that corresponds to the given identity field
* 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
*
* @param string $identityfield Field from the user table, or the shortname of a custom profile field
* @param string $identityfield Field from the user table, or a custom profile field
* @return column
*/
public function get_identity_column(string $identityfield): column {
if (preg_match("/^profile_field_(?<shortname>.*)$/", $identityfield, $matches)) {
$identityfield = 'profilefield_' . $matches['shortname'];
if (preg_match(fields::PROFILE_FIELD_REGEX, $identityfield, $matches)) {
$identityfield = 'profilefield_' . $matches[1];
}
return $this->get_column($identityfield);
}
/**
* Returns filter that corresponds to the given identity field
* Returns filter that corresponds to the given identity field, profile field identifiers will be converted to those
* used by the {@see user_profile_fields} helper
*
* @param string $identityfield Field from the user table, or the shortname of a custom profile field
* @param string $identityfield Field from the user table, or a custom profile field
* @return filter
*/
public function get_identity_filter(string $identityfield): filter {
if (preg_match("/^profile_field_(?<shortname>.*)$/", $identityfield, $matches)) {
$identityfield = 'profilefield_' . $matches['shortname'];
if (preg_match(fields::PROFILE_FIELD_REGEX, $identityfield, $matches)) {
$identityfield = 'profilefield_' . $matches[1];
}
return $this->get_filter($identityfield);

View File

@ -74,8 +74,8 @@ class user_profile_fields {
* @return profile_field_base[]
*/
private function get_user_profile_fields(): array {
return array_filter(profile_get_user_fields_with_data(0), static function($profilefield): bool {
return (int)$profilefield->field->visible === (int)PROFILE_VISIBLE_ALL;
return array_filter(profile_get_user_fields_with_data(0), static function(profile_field_base $profilefield): bool {
return $profilefield->is_visible();
});
}