Quote from: sottwell at Jul 18, 2006, 01:22 AM
Quote from: PaulGregory at Jul 17, 2006, 10:47 PM
The other route to consider would be adding fields to the user table and giving everyone a web account. Then you’d just need someone to write a Web User List snippet.
You don’t need to add anything to the user table, you can use the user_settings table for any extra data.
Or web_user_settings, as appropriate.
Quote from: sottwell at Jul 18, 2006, 03:50 AM
That table has three columns, user (user ID), setting_name (first_name) and setting_value (’Susan’).
You want the first name of user 48? SELECT setting_value FROM modx_user_settings WHERE user = 48 AND setting_name = ’first_name’.
You want to list everybody by their last name? SELECT user, setting_value FROM modx_user_settings WHERE setting_name = ’last_name’ ORDER BY setting_name
I rather think that the question was how you *add* the data, rather than how you get it out.
But yes, it is true that user_settings can be used to store user information, and the table is worth considering for a number of purposes. (Although that needs to be ORDER BY setting_value).
However, I do not think using user_settings is the best way for an Employee Directory.
1) It is counterintuitive.
The user’s phone number is already stored in the "phone" field of user_attributes / web_user_attributes. As is "fullname", "email, "mobilephone" etc. It appears to me that _settings are more "optional" settings, like "which days of the week can they access", etc. Every (human) user has a first name and a last name. Unless Madonna is on the payroll. Even so, it’s more likely than having a mobile phone. So adding 2 fields (firstname & lastname) to _attributes makes sense.
2) There is little benefit to the Manager in this instance.
Given that one would have to hack "mutate_user.dynamic.action.php" to add the fields/quasi-fields to either tab, there’s no benefit there. (If there was an User Setting Editor allowing you to add settings as if they were template variables, this reason would be void).
3) There is little benefit to Any Other Script in this instance.
It is obviously easier to add/update "fullname", "first_name", "last_name" and "phone" data at the same time. (If there was an API feature for checking for the existence of a user_setting entry and either adding one or amending the existing one, this reason would be void).
4) It is harder to sort properly by last_name, first_name if both are in the same table.
Compare
SELECT * FROM modx_user_attributes ORDER BY last_name, first_name
with
SELECT * FROM modx_user_settings US1, modx_user_settings US2 WHERE US1.user = US2.user AND US1.setting_name = 'first_name' AND US2.setting_name = 'last_name' ORDER BY US1.setting_value, US2.setting_value
Now try adding the phone number, or worse another _settings value.
5) Before anyone says it, any "future db versions do it more like _settings than _attributes" argument doesn’t wash.
Any major change of data model would need to convert the _attributes anyway.
So whilst I welcome being reminded of the _settings table, my opinion is that it is better to add fields to _attributes.
Field for sorting
One thing worth considering in place of "firstname" / "lastname" is "SortBy".
That way "Bruce Forsyth" would be "Forsyth Bruce", "Scott McQueen" would be "MacQueen Scott" etc. That may well be better if you have lots of names where the traditional human sorting is different from what would be achieved by Lastname, Firstname sort (eg cultural differences). It is also a field used in Outlook, which may well be the source of the employee data.