Extend the User Parameters

Have a programming question regarding your component, plug-in, extension or core hacks? Have an interesting tidbit, FAQ or programming tip you’d like to share? This is the place for you.

Moderators: tjay, seadap, Rogue4ngel, matthewhayashida

Post Reply
User avatar
AmyStephen
Joomla! Guru
Joomla! Guru
Posts: 579
Joined: Wed Nov 22, 2006 3:35 pm
Location: Nebraska
Contact:

Extend the User Parameters

Post by AmyStephen » Tue Sep 18, 2007 5:07 am

On Sunday, I noticed this comment in the SVN Updates:
SVN 8930 09/16/2007 Jinx - Added a $path parameter to JUser::getParameters. This change allows to easily extend the user parameters and allow the use of a custom parameters xml file for each usertype.


Intrigued, I started looking at custom parameters for Users. It appears like we can add our own custom parameters for User and have those stored in #__users table within the params column.

1. It appears we could update the administrator/components/com_users/models/user.xml file to add new param lines.

For example: name="test" type="test" default="" label="Test" description="Test for this User" />

  • name - Name of parameter; must be unique
  • type - valid choices for "type" are identified by the listing of files in the libraries/joomla/html/parameter/element. Created "Gender" and "UserCategory" example for creating new "type."
  • default - default value when not initialized for user
  • label - Value displayed in interface for user
  • description - when mouse is hovered over label, this values is provided

With this ability, we could add User Parameters, like:

Example 1: Display Profile

Code: Select all

<param name="displayprofile" type="radio" default="1" label="Display Profile" description="Dsplay private profile information.">
   <option value="0">No</option>
   <option value="1">Yes</option>
</param>


Example 2: Gender

Code: Select all

<param name="gender" type="gender" default="" label="Gender" description="Gender for this User" />


See attached file that to be placed in libraries/joomla/html/parameter/element/gender.php

Example 3: User Category

Code: Select all

<param name="usercategory" type="usercategory" default="" label="User Category" description="Category for this User" />


See attached file that to be placed in libraries/joomla/html/parameter/element/usercategory.php

These parameters are automatically loaded into the Backend User Manager and the Front End Your Details forms, and updated within the database for changes.

It appears that joomla/user/user and joomla.html.parameter load $params with the User Parameters.

*****

Questions:

If we create an extension and desire additional user parameters (fields) is it intended that we add to administrator/components/com_users/models/user.xml, or are we to create another user.xml file, at a new location, to append in custom user parameters?

If we are to change the administrator/components/com_users/models/user.xml as part of an extension installation, how can we "tell" the installation to automatically add custom parameters and remove these parameters upon de-install of the extension?

If we are to create new "data access" programs for the type parameter, how do we "tell" the installation process to place the new "type" file within the libraries/joomla/html/parameter/element/ (assuming the new file has been created)?

Again, very cool design and hats off to the developers. If someone has ideas on these questions - and can tell me if my thinking on User Parameters is correct or not, I would appreciate the guidance.

Amy :)
Attachments
usercategory.txt
(1.92 KiB) Downloaded 5 times
gender.txt
(1.38 KiB) Downloaded 8 times
Last edited by AmyStephen on Tue Sep 18, 2007 5:10 am, edited 1 time in total.
~*~ Joomla!'s Queen of the Blues - Jennifer Marriott ~*~
http://OpenSourceCommunity.org/node/1719/

User avatar
Jinx
Joomla! Engineer
Joomla! Engineer
Posts: 269
Joined: Fri Aug 12, 2005 12:47 am
Contact:

Re: Extend the User Parameters

Post by Jinx » Tue Sep 18, 2007 5:42 am

Hi Amy,

Not sure if you already read :

- http://forum.joomla.org/index.php/topic ... #msg995599
- http://forum.joomla.org/index.php/topic ... #msg995739

Most of your questions are already answered there.

In short :

1. Yes, it's intended that you store them in another location

2. By using different xml files this becomes as easy as removing them. The problem will be that you will also need to reset the data in the user parameters field. This is a problem the developer need to think about.

3. It does not need to, the params have an addpath attribute that allows you to specify a custom path. The parameter file we be loaded by the framework from that location.

Hope this helps.

Johan
Last edited by Jinx on Tue Sep 18, 2007 8:55 pm, edited 1 time in total.
Core Team member - Lead developer
'Making good things happen'

http://www.joomlatools.org - training, consulting and extension development

User avatar
AmyStephen
Joomla! Guru
Joomla! Guru
Posts: 579
Joined: Wed Nov 22, 2006 3:35 pm
Location: Nebraska
Contact:

Re: Extend the User Parameters

Post by AmyStephen » Tue Sep 18, 2007 1:38 pm

Excellent - thanks so much, Johan. I had *not* noticed those threads and they are, indeed, very helpful.

I was certain you intended additional XML files as that is consistent with the way you handle CSS and Javascript for extensions, as well. The way you have designed this, installing and removing extensions is not "dangerous" to the core.

The user params column is brilliant. The database can be extended without change. AND, providing ability to extend by usertype is very nice. From the threads referred to, it sounds like there is also ability to add tables through the JUser::getTable function. That should take care of any possible need for User data elements required by extensions.

The framework is so well considered and, for that reason, fun to explore.

I'll look at this, again, knowing, now, how it is intended. Thanks for taking time to respond,
Amy :)
~*~ Joomla!'s Queen of the Blues - Jennifer Marriott ~*~
http://OpenSourceCommunity.org/node/1719/


Post Reply