Friday, June 10, 2011

Easy extension of User Data

This week I faced the challenge of adding more data to the standard BB2.0 system user profile than is normally required.

One way it to use the list of generic xtra_fields, but this can be limiting.

In writing a system for Care Management, the user data that needs to be stored is very detailed and complex. It does not make sense to extend the 'standard user table' with all these extra fields.

So I developed a cool 'extension' function that essentially copies the required fields to the matching user record in the main user table, while allowing you the autonomy of building a bespoke module that meets your needs.

So, for example, if I wanted to create a new module to store info regarding tradespeople in a new module called bb_tradespeople, you would create the new module, and have a link-field called userISbb_usersID in the table. You would also include all the 'common' fields in your new table, for example : first_name, last_name, email, and telephone. (These need to be named exactly as they are in the bb_users table).

Now that your new class has been created, extend it using the 3 over-ride methods below:

 function pre_edit_form($conf=NULL) {   
                global $global, $class, $method;  
                $res=load_linked_user_data_in_external_module($conf,"userISbb_usersID");  
                $conf=$res;  
                return $conf;  
           }  
function post_add($conf=NULL) {   
                global $global, $class, $method;  
                $res=process_linked_user_data_in_external_module($conf,"userISbb_usersID",array("Debtors"));  
                $conf=$res;  
                return $conf;  
           }  
function post_edit($conf=NULL) {   
                global $global, $class, $method;  
                $res=process_linked_user_data_in_external_module($conf,"userISbb_usersID",array("Debtors"));  
                $conf=$res;  
                return $conf;  
}  

The 2 new functions are

load_linked_user_data_in_external_module


this takes the standard $conf input as well as a string with the field name which links to the user table

and

process_linked_user_data_in_external_module

this takes the standard $conf input as well as a string with the field name which links to the user table and also the group that you want to add the new linked-user into.

No comments:

Post a Comment