Username instead of full name in forums?

Username instead of full name in forums?

by Erich Nielsen -
Number of replies: 3

Hi!

I am a happy moodle-newbie, but there is one feature I can't seem to find that I guess would be greatly appreciated.

Is it possible to use usernames instead of full name in forums, as a form of alias?

All the best from a sunny Stockholm,

Erich N

Average of ratings: -
In reply to Erich Nielsen

Re: Username instead of full name in forums?

by Timothy Takemoto -

Dear Erich N

It is not possible to display usernames as opposed to full names in
the forums, without hacking the code at least.

The fact that usernames are never shown helps to improve Moodle
security, but agreed it would be nice to have the choice.  

Thinking about hacking...

Looking at mod/forum/lib it seems that "fullname" is used quite a bit throughout the code, and more than once with $USER the user data array.
So it would be necessary to change all these, I guess. And anyway there are lots of other places in moodle, other than the forums, where the users' real name is displayed (such as in the recent activities)

The easiest way would be, PERHAPS, simply change the language pack that you are using so that instead of asking for family name and given name to ask for "Alias" or (two of them!) but then you would loose track of the users' real names. 

OR perhaps, if you can find, perhaps the one(?) place in the Moodle code (Is it only one place?) where "fullname" is generated from the concatenation of family name and given name....

My guess is that somewhere in the moodle libraries (moodle/lib) there is a line, perhaps in moodlelib.php where there is something like

fullname=$USER->familyname." ".$USER->givenname

(this is probably not correct php, but the full stop is used for concatenation of strings, I believe)

Then if you changed this to

fullname=$USER->familyname (so that the given name is not concatenated into the fullname)

And then if you change your language pack entry for familyname into "Alias" and the language pack entry for *given name* to "Full name"

Then in all those places where the fullname of the user is displayed, the new Alias will be displayed.

I think that there are some places where the family name is displayed alone. These too would result in the display of the alias.

Then find all the places where the given name is displayed and make sure they are only displayed when "if isteacher"??!

This hack would take time.

Tim

In reply to Timothy Takemoto

Re: Username instead of full name in forums?

by L N -
Has anyone successfully hacked moodle code to display username only?

I attempted to by doing this:

In admin/configvars.php, I added an option in the user configuration to select display username:
$options['username'] = get_string('username');

In lib/moodlelib.php I found the fullname function and tried to add in a line as follows:
else if ($CFG->fullnamedisplay == 'username' ) {
return $user->username; }
which is in the same format as the coding for firstname only.

The pages are indeed seeing that username is the option selected, but not displaying any name whatsoever if I keep that line in. If I take it out, it defaults to firstname lastname, even though username is selected.

I am at a loss. Can anyone help?

Thanks!
In reply to L N

Re: Username instead of full name in forums?

by L N -
Ok, I finally got it, for anyone interested.

After editing those two files, I realized the query was not pulling in $user->username for forum posts, only in certain login queries, and as such, fullname was blank.

I needed to edit mod/forum/lib.php to add u.username in the select queries (I did that in all the queries where u.firstname was selected.)
I also changed "function forum_get_ratings($postid, $sort="u.firstname ASC")" to sort by username.

I think that was all that was necessary to get it to work -- I hope this helps other moodle adminstrators smile