Additional name fields

Jump to: navigation, search

Moodle 2.6

Background

Previous to Moodle 2.6 we only had two user name fields: First name and Surname (last name). This can be very restrictive depending on the country or culture that is using Moodle. The Moodle Association of Japan (http://moodlejapan.org) was specifically vocal about the need to include more information for users and created MDL-31776.

What has changed?

Full name format

The setting for fullnamedisplay (Full name format) has been moved from [Administration ► Site administration ► Security ► Site policies] to [Administration ► Site administration ► Users ► Permissions ► User policies]. It was decided that this setting made more sense being located with other user display information such as hiddenuserfields (Hide user fields) and showuseridentity (Show user identity).

The setting has changed from a select menu to a text box. An upgrade from a previous version will keep the old settings intact.

The fullnamedisplay setting now uses place holders. These are:

  • language
  • firstname
  • lastname
  • firstnamephonetic
  • lastnamephonetic
  • middlename
  • alternatename

These place holders can be arranged in any order required and punctuation can now also be included. e.g. "firstname (middlename) lastname" to output "Robert (Bruce) Bannner".

The fullname function

The fullname function now requires a USER object that includes the new additional name fields (firstnamephonetic, lastnamephonetic, middlename, alternatename). If your code does not provide these extra fields then the following debugging message will be displayed: "You need to update your sql query to include additional name fields in the user object."

The recommended way to retrieve all of the information for displaying user detail is to use the user_picture::fields() function, especially if you plan on displaying a user picture. e.g.

$extrauserfields = get_extra_user_fields_sql($context);
$mainuserfields = user_picture::fields();
$sql = "SELECT $mainuserfields, $extrauserfields";
...

get_all_user_name_fields()

This is a new function which can be used for retrieving the user name fields in either a string or an array. This is useful for specific sql queries that do not require the user picture information and require some additional complexity.

order_in_string()

This function was created to assist with displaying table headings correctly. It returns an array of values in order of occurrence in a provided string. The array key is the character position in the string that was provided.

Related Issues

This issue is not fully complete, there are still some areas that need changing and improving.

  • MDL-40683 - Allow alternate names to be uploaded via CSV in the bulk user upload area.
  • MDL-38606 - Include caching to speed things up further.
  • MDL-40667 - Include translations for place holders in the admin setting.