Reference Manuals

PreferencesMixIn

PreferencesMixIn — A user preferences mixin for the User module

PreferencesMixIn is part of the User package.

Synopsis

class PreferencesMixIn extends UserMixIn {
        public         string              $db_preferences
        public         string              $db_user_preferences
        public         array               $preference

        public         void                destroy                   ( void );
        public         void                init                      ( User &$user );
        private        void                load_defaults             ( void );
        public         void                save_preferences          ( void );
        public         void                start                     ( void );
}

Object Hierarchy

UserMixIn
 +----PreferencesMixIn

Description

A user preferences mixin for the User module

This extension implements a simple user preferences system for the User module. Preferences can be accessed through the $preferences attribute. This extension requires two database tables. The table names are defined in $db_preferences and $db_user_preferences.

 CREATE TABLE preferences (
   preference_name VARCHAR(64),
   preference_default TEXT
 )

 CREATE TABLE user_preferences (
   user_id,
   preference_name VARCHAR(64),
   preference_value TEXT
 )

Attribute Details

$db_preferences

public         string         $db_preferences

The name of the preferences table

Default value: empty string


$db_user_preferences

public         string         $db_user_preferences

The name of the user_preferences table

Default value: empty string


$preference

public         array          $preference

An associative array containing all preferences and their values

Default value: empty string

Method Details

destroy()

public         void           destroy                   ( void );

Set the options back to default when stopping a session


init()

public         void           init                      ( User &$user );

Initialize the extension and load $preference with the default values

&$user
A reference to the User object

load_defaults()

private        void           load_defaults             ( void );

Load the default options


save_preferences()

public         void           save_preferences          ( void );

Save the preferences to the database

This will only save the preferences which exist in the preferences table and which differ from the defaults.


start()

public         void           start                     ( void );

Load a user's specific preferences