Extra user fields

Extra user fields

by Dewet Diener -
Number of replies: 8
I saw a few postings after doing a number of searches for the topic. It seems that the User Data module is still under development, and would surely be a powerful extension once done. I have a more simple problem: all users on the site must complete a number of additional fields, so there is no variation in the fields per user.

My question really is, is it okay to extend the _user table, or must I absolutely use an extension table (ie., _user_extensions) to keep all my extra fields in? From what I can see, extending the _user table and then upgrading shouldn't be a problem, since the upgrade scripts generally extend tables, and don't recreate them, so extra, unexpected fields wouldn't be a problem. Having an extra table just means another join or something similar to get all the data, and according to SQL theory (whatever that was worth) they should be held in one table, since its a 1:1 link with a shared primary key.

Any definitive advice from the powers that be? smile
Average of ratings: -
In reply to Dewet Diener

Re: Extra user fields

by Tony Hursh -
While it might be slightly slower, it seems like the extension table would be more.... extendable. smile

I could see it being handy to have a table with records like:

(user number) (key) (value)

Where key and value are arbitrary text. Then the user profile dialog could iterate through these and generate the appropriate fields for the user to fill in.

If you wanted to add a new field to the user profile, say, AOL IM id, you could just generate a record in the extension table for every user with the key "AIM ID" (there'd need to be some method to create these automatically for new users, of course).

Or am I totally off base here?

In reply to Tony Hursh

Re: Extra user fields

by Dewet Diener -
Sure, I agree totally in terms of extensibility and flexibility. This is how I understood the User Data module (I think that was the name someone mentioned) is being developed. However, it is still a way off, and I need to implement this yesterday. The big reason I'm for extending the existing table is that all these extra fields are required for everyone, and only 1:1 for each user.

I think the real question I'm trying to pose is, is it safe to extend the table? Or is there a reason I should rather do it completely seperately, which I'm currently not seeing?
In reply to Dewet Diener

Re: Extra user fields

by Martín Langhoff -
Moodle has an extra table, called {prefix}user_preferences, much like your user_extensions table. It will allow you to store any key/value pair you want for every user.

Take a look at the functions in moodlelib.php to set/get the values, or roll up your sleeves and do the JOINs like Real Men Do ;)
In reply to Martín Langhoff

Re: Extra user fields

by Ted Sorrells -

Using get/set_user_preferences, I have added a "state" field whose values are stored in mdl_user_preferences.  It works great for manual input...but it is not getting updated via enrolment plugin/external database. Which additional files need to be edited in order for this field to be automatically populated/updated upon login?

In reply to Martín Langhoff

Re: Extra user fields

by Dan Stoll -

ok so that make no sense to me..

How do I get rid of fields...  We use moodle in house, so the need for country , location, description phone are not needed.. All I need is Name and Email.. Now if I could get AD SSO working, it would be great back I can't I've tried everything,, So POP3 auth works back to our exchange server...

I can find where to add more fields to the profile, but how can I get rid of them.. or even just make it so they aren't required...

In reply to Dan Stoll

Re: Extra user fields

by Timothy Takemoto -

In admin/auth.php? you can lock certain fields. I am not sure if that makes them disappear but I guess so.

I hacked my user/edit.html to make the profile minimalistic in the days when locking was not possible.