Skip to content

Commit

Permalink
MDL-45242 Lib: Allow custom profile fields in showuseridentity
Browse files Browse the repository at this point in the history
  • Loading branch information
sammarshallou committed Mar 8, 2021
1 parent 9ddb51b commit 677e1c6
Show file tree
Hide file tree
Showing 9 changed files with 1,353 additions and 92 deletions.
43 changes: 30 additions & 13 deletions admin/settings/users.php
Original file line number Diff line number Diff line change
Expand Up @@ -214,21 +214,38 @@
// with moodle/site:viewuseridentity).
// Options include fields from the user table that might be helpful to
// distinguish when adding or listing users ('I want to add the John
// Smith from Science faculty').
// Custom user profile fields are not currently supported.
// Smith from Science faculty') and any custom profile fields.
$temp->add(new admin_setting_configmulticheckbox('showuseridentity',
new lang_string('showuseridentity', 'admin'),
new lang_string('showuseridentity_desc', 'admin'), array('email' => 1), array(
'username' => new lang_string('username'),
'idnumber' => new lang_string('idnumber'),
'email' => new lang_string('email'),
'phone1' => new lang_string('phone1'),
'phone2' => new lang_string('phone2'),
'department' => new lang_string('department'),
'institution' => new lang_string('institution'),
'city' => new lang_string('city'),
'country' => new lang_string('country'),
)));
new lang_string('showuseridentity_desc', 'admin'), ['email' => 1],
function() {
global $DB;

// Basic fields available in user table.
$fields = [
'username' => new lang_string('username'),
'idnumber' => new lang_string('idnumber'),
'email' => new lang_string('email'),
'phone1' => new lang_string('phone1'),
'phone2' => new lang_string('phone2'),
'department' => new lang_string('department'),
'institution' => new lang_string('institution'),
'city' => new lang_string('city'),
'country' => new lang_string('country'),
];

// Custom profile fields.
$profilefields = $DB->get_records('user_info_field', ['datatype' => 'text'], 'sortorder ASC');
foreach ($profilefields as $key => $field) {
// Only reasonable-length fields can be used as identity fields.
if ($field->param2 > 255) {
continue;
}
$fields['profile_field_' . $field->shortname] = $field->name . ' *';
}

return $fields;
}));
$setting = new admin_setting_configtext('fullnamedisplay', new lang_string('fullnamedisplay', 'admin'),
new lang_string('configfullnamedisplay', 'admin'), 'language', PARAM_TEXT, 50);
$setting->set_force_ltr(true);
Expand Down
4 changes: 3 additions & 1 deletion lang/en/admin.php
Original file line number Diff line number Diff line change
Expand Up @@ -1205,7 +1205,9 @@
$string['showcommentscount'] = 'Show comments count';
$string['showdetails'] = 'Show details';
$string['showuseridentity'] = 'Show user identity';
$string['showuseridentity_desc'] = 'When selecting or searching for users, and when displaying lists of users, these fields may be shown in addition to their full name. The fields are only shown to users who have the moodle/site:viewuseridentity capability; by default, teachers and managers. (This option makes most sense if you choose one or two fields that are mandatory at your institution.)';
$string['showuseridentity_desc'] = 'When selecting or searching for users, and when displaying lists of users, these fields may be shown in addition to their full name. The fields are only shown to users who have the moodle/site:viewuseridentity capability; by default, teachers and managers. (This option makes most sense if you choose one or two fields that are mandatory at your institution.)
Fields marked * are custom user profile fields. You can select these fields, but there are currently some screens on which they will not appear.';
$string['simplexmlrequired'] = 'The SimpleXML PHP extension is now required by Moodle.';
$string['sitemenubar'] = 'Site navigation';
$string['sitemailcharset'] = 'Character set';
Expand Down
Loading

0 comments on commit 677e1c6

Please sign in to comment.