glProfile

Planning and ideas for the implementation of a custom user profile plugin, perhaps to be rolled into the main codebase at some point.

The sample functions shown here are abstract ideas. The actual implementation would use object-oriented programming, with a “UserProfile” class.

Goals

  • Allow the site administrator to customize the user profile fields, and the registration screen, with a minimum of coding and file editing.
  • Plugins should be able to provide and consume data to and from the user profile.

Field Definition Table

The Field Definition table will be used by administrators to create, delete and modify custom profile fields.

Fields will normally be created and maintained by the site administrator using a form similar to that used by the glFusion configuration system. glFusion's system lacks some of the desired elements, such as checkboxes and radio buttons, as well as the ability to draw data from plugins.

FieldDescription
idRecord ID, auto_increment
orderbyOrder to appear on forms
nameField name
typeField type (integer, string, etc.). May be combined with “value” like gl_conf_values
valueField value. Use “val:prompt;val:prompt” for selections
defvalueDefault value automatically chosen
enabledBoolean, 1 indicates whether a field is in use
requiredBoolean, 1 indicates whether the field is required
user_regBoolean, 1 indicates that the field appears on the registration form. Implied by “required”
readonlyBoolean, 1 indicates that the field data is not user-modifiable
promptText string to appear with the field on forms
sizeField size. Applies to text fields only
maxlengthField Max length. Applies to text fields only
optionsField-specific options, such as date/time formats
formatFormat string, specific to date fields

User Profile Table

This table holds the actual user profile information. Any functions which access this data should be prepared for an empty result set.

FieldDescription
uidUser ID, matches gl_users
nameField name, matches definition.name
valueField value

Plugin Interaction

Since glFusion 1.1.5 has expanded the API's for plugin profiles, this sections has been removed. The Custom Profile plugin will only provide generic profile data. Plugins will be responsible for managing their own profiles in their own tables.

Profile Field Creation

The profile fields can be created similarly to the way the administrative lists are created.

function PROFILE_createFields($uid = 0)
{
  global $_PLUGINS, $LANG_PROFILE;

  // Get the current values from the user's profile record and load into a 'name'=>'value' array.
  $userResult = DB_query("SELECT * from {$_TABLES['userprofile']} WHERE uid=$uid");
  while ($row = DB_fetchArray($userResult)) {
    $userdata[] = array($row['name'] => $row['value']);
  }

  // Now get all the field definitions
  $result = DB_query("SELECT * FROM {$_TABLES['profiledef']} WHERE enabled=1");
  while ($row = DB_fetchArray($result)) {
    $field_name = $LANG_PROFILE[$row['name']];
    $field_content = $userdata['value'];

    // Ensure that the content matches the field type, and create the form elements
    switch ($row['type']) {
    case 'integer':
      $field_content = (int)$field_content;
      $html = '<input type="text" name="{$field_name}" value="{$field_content}">';
      break;
    case 'float':
      $field_content = (float)$field_content;
      $html = '<input type="text" name="{$field_name}" value="{$field_content}">';
      break;
    case 'boolean':
      $field_content = $field_content == 1 ? 1 : 0;
      $html = '<input type="checkbox" name="{$field_name}" ' .
              $field_content == 1 ? 'checked' : '' . '>';
      break;
    }
    ... add field prompt and content to the form HTML ...
  }
  ... set the template variable or return the form data ...
 }
Logged in as: Guest (anonymous)
glfusion/glprofile/dev.txt · Last modified: 2009/09/04 15:34 by lee
 
Except where otherwise noted, content on this wiki is licensed under the following license: GNU Free Documentation License 1.3