Additional name fields: Difference between revisions
David Mudrak (talk | contribs) m (Text replacement - "<code php>" to "<syntaxhighlight lang="php">") |
(This page will not be migrated to new devdocs) |
||
Line 1: | Line 1: | ||
{{Template:WillNotMigrate}} | |||
{{Moodle 2.6}} | {{Moodle 2.6}} | ||
=Background= | =Background= |
Latest revision as of 13:41, 3 May 2024
Warning: This page is no longer in use. The information contained on the page should NOT be seen as relevant or reliable. |
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.