1. Defining possible profile options
The first step to account profiles is defining the attributes for which
the user can set default values. You will also have to define the type
(text, checkbox, ...) of the profile options.
The profile editor then will display a fieldset for each module
containing its profile options.
The profile options are specified with
get_profileOptions()
or
meta['profile_options'].
Example:
The
inetOrgPerson
module has only two attributes which may be set to a default value: job
title and employee type.
The other attributes are account specific and not useful as profile
options.
/**
* Returns meta data that is interpreted by parent
class
*
* @return array array with meta data
*/
function
get_metaData() {
$return = array();
// profile elements
$return['profile_options'] = array(
array(
0 => array('kind' => 'text', 'text' =>
_('Job title') . ":"),
1 => array('kind' => 'input', 'name' =>
'inetOrgPerson_title', 'type' => 'text', 'size' => '30',
'maxlength' => '255'),
2 => array('kind' => 'help', 'value' =>
'title')),
array(
0 => array('kind' => 'text', 'text' =>
_('Employee type') . ":"),
1 => array('kind' => 'input', 'name' =>
'inetOrgPerson_employeeType', 'type' => 'text', 'size' => '30',
'maxlength' => '255'),
2 => array('kind' => 'help', 'value' =>
'employeeType'))
);
[...]
|
This defines two text boxes in the profile editor, one for the job
title and one for the employee type.
Your profile options should also provide a help link if the description
of the input element might be not enough.
2. Checking user input
Probably you also want to check if the input data is syntactically
correct.
The
baseModule already
provides different checks which can be activated with
meta data. However you can also do
the checking in the module.
Implementing the function
check_profileOptions()
in your module will allow you to do the checks yourself. Basic checks
can be defined with
meta['profile_checks'].
Example:
The
inetOrgPerson module only
needs some regular expression checks on the input. This can be done by
the
baseModule.
/**
* Returns meta data that is interpreted by parent
class
*
* @return array array with meta data
*/
function
get_metaData() {
$return = array();
// profile checks
$return['profile_checks']['inetOrgPerson_title'] = array(
'type' =>
'ext_preg',
'regex' =>
'title',
'error_message' => $this->messages['title'][0]);
$return['profile_checks']['inetOrgPerson_employeeType'] =
array(
'type' =>
'ext_preg',
'regex' =>
'employeeType',
'error_message' => $this->messages['employeeType'][0]);
[...]
|
The type
"ext_preg" means that
the
baseModule will use the
get_preg() function in
lib/account.inc for the syntax
check. This function already contains regular expressions for the most
common cases.
3. Loading an account profile
TODO