Hiding surname (lastname) from students only

Hiding surname (lastname) from students only

by Blair F. -
Number of replies: 17
Picture of Particularly helpful Moodlers

We've had more than one student express concerns about having their family name available to other students, so I'm investigating ways of dealing with that.

First, I checked out the hiddenuserfields. I believe that would work, but the lastname field is not an option. Would there be a way to add it, somehow?

Second, I checked out the viewuseridentity capability and changed the Student role to prevent. That didn't see to change anything (I was looking, specifically, at the participation list of a class).

Any ideas are appreciated, thanks!

Average of ratings: Useful (1)
In reply to Blair F.

Re: Hiding surname (lastname) from students only

by Blair F. -
Picture of Particularly helpful Moodlers

I found this in the Moodle readme.txt file, which leads me to believe that we could add the lastname field to the list of hiddenuserfields. Now I'm just trying to figure out how to make it work. I tried it in a local installation I have on my desktop and it made no difference. I think it might have to be there during the installation process and can't be added later. 

Customised site defaults
------------------------
Different default site settings can be stored in file /local/defaults.php.
These new defaults are used during installation, upgrade and later are
displayed as default values in admin settings. This means that the content
of the defaults files is usually updated BEFORE installation or upgrade.

These customised defaults are useful especially when using CLI tools
for installation and upgrade.

Sample /local/defaults.php file content:
<?php
$defaults['moodle']['forcelogin'] = 1;  // new default for $CFG->forcelogin
$defaults['scorm']['maxgrade'] = 20;    // default for get_config('scorm', 'maxgrade')
$defaults['moodlecourse']['numsections'] = 11;
$defaults['moodle']['hiddenuserfields'] = array('city', 'country');

First bracket contains string from column plugin of config_plugins table.
Second bracket is the name of setting. In the admin settings UI the plugin and
name of setting is separated by "|".

The values usually correspond to the raw string in config table, with the exception
of comma separated lists that are usually entered as real arrays.

Please note that not all settings are converted to admin_tree,
they are mostly intended to be set directly in config.php.
In reply to Blair F.

Re: Hiding surname (lastname) from students only

by Blair F. -
Picture of Particularly helpful Moodlers

Following up on my post of Tuesday, 7 May 2019, 9:55 AM , I have tried making this work with a local, Windows installation, to no avail.  I added a simple default.php file, as shown below, into the server/moodle/local folder BEFORE the installation. Maybe someone can tell me what I'm doing wrong.

Attachment defaults.PNG
In reply to Blair F.

Re: Hiding surname (lastname) from students only

by Jon Bolton -
Picture of Particularly helpful Moodlers Picture of Testers

Moodle has had this functionality for a long time, and it’s documented in the config-dist.php file.

In short, you don't need to alter anything or add any files like you have mentioned. You just need to make a small addition to your config.php file.

In config.php, BEFORE the line require_once(__DIR__ . '/lib/setup.php'); // Do not edit

add this...

// Force displayed usernames
// All non-teachers will always
// see this for every person.
$CFG->forcelastname  = 'Student';

and I've just tested it, and this works too:

$CFG->forcelastname  = ' ';
In reply to Jon Bolton

Re: Hiding surname (lastname) from students only

by Blair F. -
Picture of Particularly helpful Moodlers

Thank you for that suggestion, Jon!  I tried it on my local installation and it worked, as you've stated.

I have found another way. By changing the fullnamedisplay setting to use alternatename, it will only show either what the student has put in the alternatename field, or their firstname if the alternatename field is empty. This solution works better, in my case, since I don't have access to the config.php file on our live site. An additional bonus to this method is that non-editing teachers (term instructors) will still see the full name for marking purposes.

This is probably what we'll have to go ahead with, although I wish there were a way for the student to decide what shows up to other students. That would be ideal. My sense is the number of students wanting to hide their surnames is very small, and we have classes with multiple students with the same first name. This is actually very common among some of our international classes.

For now, this works. 

Thanks, again!


Attachment fullnamedisplay.PNG
In reply to Blair F.

Re: Re: Hiding surname (lastname) from students only

by Blair F. -
Picture of Particularly helpful Moodlers
Now that we're using the settings

FULL NAME FORMAT - fullnamedisplay = alternatename
ALTERNATIVE FULL NAME FORMAT - alternativefullnameformat = firstname lastname (alternatename)

I've found one little problem: The messaging interface doesn't show the alternative full name format , so instructors see only first or alternate names. Bummer.
In reply to Blair F.

Re: Re: Re: Hiding surname (lastname) from students only

by Jon Bolton -
Picture of Particularly helpful Moodlers Picture of Testers

The suggestion I made above does not affect the messaging interface. And I was slightly confused by your reply to that when you said that "An additional bonus to this method is that non-editing teachers (term instructors) will still see the full name for marking purposes." - they would also see the full name if you used the addition to the config.php file too as it only affects the student view.

In reply to Jon Bolton

Re: Re: Re: Re: Hiding surname (lastname) from students only

by Blair F. -
Picture of Particularly helpful Moodlers
Thanks for your reply Jon.

I went back into my test environment (Moodle 3.6.3), removed my settings and implemented only your solution. As you can see, in the attached image, only the first names (and "Student") appear in the messaging interface for admin and teachers. Is it possible that this is something new with 3.6? I know that the messaging system was overhauled.

BTW, you're right about the marking names. I don't know why I thought otherwise.
Attachment configfix.PNG
In reply to Blair F.

Re: Re: Re: Re: Re: Hiding surname (lastname) from students only

by Jon Bolton -
Picture of Particularly helpful Moodlers Picture of Testers
Ohh, that's not helpful. Might be worth filing a bug report - it shouldn't affect teacher view anywhere sad
In reply to Jon Bolton

Re: Re: Re: Re: Re: Re: Hiding surname (lastname) from students only

by Blair F. -
Picture of Particularly helpful Moodlers
I just managed to test it in our 3.4.8 environment, and it's the same thing. Instructors see only first names (or "Student") in the following locations:
  • messaging interface
  • online users plugin
  • latest announcements block
In reply to Blair F.

Re: Re: Re: Re: Re: Re: Re: Hiding surname (lastname) from students only

by Blair F. -
Picture of Particularly helpful Moodlers

Here it is in a local installation of 3.4.9. Same thing. sad

Attachment Moodle349.png
In reply to Blair F.

Re: Re: Re: Re: Re: Re: Re: Hiding surname (lastname) from students only

by Blair F. -
Picture of Particularly helpful Moodlers
Just discovered that the logs displays are also affected.
In reply to Blair F.

Re: Re: Re: Re: Re: Re: Re: Re: Hiding surname (lastname) from students only

by Blair F. -
Picture of Particularly helpful Moodlers
And, today, I discovered the same in the Profile Based Cohort plugin

It looks like I'm going to have to abandon this, there are too many negative side effects and we're having instructors complain. sad  Darn it all!
In reply to Blair F.

Re: Hiding surname (lastname) from students only

by Blair F. -
Picture of Particularly helpful Moodlers
Even though Jon has made another suggestion (Thank you, Jon), I haven't completely let go of the solution suggested in the Customized Site Defaults section of the Moodle readme.txt file.

Today, I tried it, once again. I installed Moodle 3.6.6 on my desktop computer. I added a default.php file (see contents, below) to the folder, \server\moodle\local and then ran the installation. Still, the change did not show up and when I look into the config_plugins table, there's no sign of it.

Does anyone have any idea what I might be doing wrong, here?

This is my default.php file:
<?php
$defaults['moodle']['hiddenuserfields'] = array('lastname');
?>
Thanks, in advance.
In reply to Blair F.

Re: Hiding surname (lastname) from students only

by Blair F. -
Picture of Particularly helpful Moodlers

I should add that I realize I could change the fullnamedisplay setting to exclude lastname, but that would affect the Teacher view, as well, which I really don't want to do. I only want to hide lastname from students.

In reply to Blair F.

Re: Hiding surname (lastname) from students only

by REMI PICARD (substitute) -
hi,
i have a similar need (or issue) :
https://moodle.org/mod/forum/discuss.php?d=387559#p1562386

to solve your case, you could add a new field to the profil (ex : real last name), because new field have the feature to be hiden from other users:
Who is this field visible to?

Then, let user add whatever they want into the "core" surname field.

Best regards.
In reply to REMI PICARD (substitute)

Re: Hiding surname (lastname) from students only

by Blair F. -
Picture of Particularly helpful Moodlers
Thank you for your suggestion, Pierre. I don't see that solution working for our particular situation, since the lastname field is populated by our main student registration system.