Change "username" to "staffid" in upload users csv

Change "username" to "staffid" in upload users csv

by Chris Khoo -
Number of replies: 8

For Moodle 3.3, how do I change from "username" to "staffid" in upload users csv?

From "username,firstname,lastname,email" to "staffid,firstname,lastname,email"

Thanks!


Average of ratings: -
In reply to Chris Khoo

Re: Change "username" to "staffid" in upload users csv

by Jamie Kramer -

I believe that is not possible to match the rows in the csv file by anything other than username with the upload users tool. It would be possible if one were to customize the tool, but out of the box the upload file requires username to match/key between the CSV rows and user records in the database.


Question: what does staffid in the csv contain? Another way to put this: what field in the user profile does staffid map to? Is it the idnumber field? Or a custom user profile field? Or does it actually contain Moodle usernames?

In reply to Jamie Kramer

Re: Change "username" to "staffid" in upload users csv

by Chris Khoo -

The staffid represent the company staff id. We plan to use the staff id to login to Moodle.

We just want to change the username to staffid label in the csv file.


The closest solution I have is using ID number (idnumber) in Moodle as staffid. Next creating username column that is equal value to idnumber column. Please see attachment.


Is there a way to customize the tool?

Attachment UploadUsers   Google Sheets.png
In reply to Chris Khoo

Re: Change "username" to "staffid" in upload users csv

by Jamie Kramer -

The staffid represent the company staff id. We plan to use the staff id to login to Moodle.

So your intention is to have your users enter "staffid" as the username during the Moodle login/authentication?

We just want to change the username to staffid label in the csv file.

I am curious as to why you couldn't just use username in the CSV. Perhaps because the system you are exporting from doesn't accommodate that with automaticity?

The closest solution I have is using ID number (idnumber) in Moodle as staffid. Next creating username column that is equal value to idnumber column. Please see attachment.

It is a clever solution and I've done the same type of thing.

Is there a way to customize the tool?

Yes it is possible to customize the import tool in Moodle, but with all the caveats of customizing Moodle (long term maintenance of customization, return on investment evaluation, upgrades, consideration of whether hosting provider would allow it, etc).   It probably wouldn't take too much effort, but I say that without having done specific analysis on it.

In reply to Jamie Kramer

Re: Change "username" to "staffid" in upload users csv

by Chris Khoo -

Yeap, I just want the users to enter their staffid as the username during the Moodle login/authentication.

It could be 11111. 12345, 54321 and so on.


I am not sure, it's a request. My guess is it's just to keep things consistent and simple to the user.


Thanks, hoping to improve on this solution though.


I just thought about create an intermediate webpage where you upload the csv file.

Then the page will change the staffid string to username string in the csv file.

After that upload the new csv file to Moodle.

I am trying to avoid the using excel macros because I want to hide that operation from the user.


Saying that is there a tutorial or something to customize the import tool?

In reply to Chris Khoo

Re: Change "username" to "staffid" in upload users csv

by Jamie Kramer -

Customization of Moodle typically starts with this resource: https://docs.moodle.org/dev/Main_Page

Specifically for the user import tool, the code is here for 3.3: https://github.com/moodle/moodle/tree/MOODLE_33_STABLE/admin/tool/uploaduser

A quick review of the code (admin/tool/uploaduser/index.php) shows that STD_FIELDS is an array set to the values of allowed column names in the csv:.

std_fields required for user import csv file, highlighting username in the array


One could presumably add staffid to this array. Then, when the uu_validate_user_upload_columns function is called later in index.php, then the staffid column would be recognized as a valid column.

Further down in index.php I see this code:

        if (!isset($user->username)) {
            // prevent warnings below
            $user->username = '';
        }

What I was thinking is that maybe at that point in the code, one could just set the $user->username equal to staffid.

So maybe this code could be used, so the above code has an extra bit before it:

        if (isset($user->staffid)) {
	    $user->username = $user->staffid;
        }
        if (!isset($user->username)) {
            // prevent warnings below
            $user->username = '';
        }

I am not sure if that will work, or if it is the best solution since I haven't tested it, but perhaps this information can serve as a mini-tutorial to get you started.

Good luck!






Average of ratings: Useful (1)
In reply to Jamie Kramer

Re: Change "username" to "staffid" in upload users csv

by Chris Khoo -
Sorry for the late reply. I had a long weekend smile


I have backup and restore Bitnami Moodle before upgrading the Moodle version.


If I need to upgrade the Moodle version, would I need to redo the edit in index.php?

In reply to Chris Khoo

Re: Change "username" to "staffid" in upload users csv

by Jamie Kramer -

Yes it is true that you would need to maintain customizations when upgrading Moodle. This is part of the bigger picture to consider when deciding whether to introduce customizations. 

In reply to Jamie Kramer

Re: Change "username" to "staffid" in upload users csv

by Chris Khoo -

Thanks for clarifying Jamie!

This means I have to record all core codes changes.