phpDocumentor pond
[ class tree: pond ] [ index: pond ] [ all elements ]

Class: AbstractSettings

Source Location: /qp_inc/settings/model/_abstractsettings.class.php

Class AbstractSettings

Class Overview

Class to handle settings in an abstract manner (to get used with either 1, 2 or 3 DB column keys).

Arrays and Objects automatically get serialized and unserialized (in AbstractSettings::get() and AbstractSettings::dbupdate()).

Note: I've evaluated splitting this into single classes for performance reasons, but only get() is relevant performance-wise and we could now only get rid of the switch() therein, which is not sufficient to split it into *_base + _X classes. (blueyed, 2006-08)

Located in /qp_inc/settings/model/_abstractsettings.class.php [line 50]



		
				Author(s):
		
API Tags:
See:  UserSettings, GeneralSettings, PluginSettings, CollectionSettings
Abstract:  

Properties

Methods

[ Top ]
Descendants
Child Class Description
CollectionSettings Class to handle the settings for collections/blogs
PluginSettings Class to handle settings for plugins
PluginUserSettings Class to handle settings for plugins
GeneralSettings Class to handle the global settings.
UserSettings Class to handle the settings for users

[ Top ]
Property Summary
boolean   $all_loaded   Do we have loaded everything?
array   $cache   The internal cache.
integer   $cache_by_col_keys   The number of column keys to cache by. This are the first x keys of $col_key_names. 0 means 'load all'.
array   $col_key_names   Array with DB column key names.
string   $col_value_name   DB column name for the value.
string   $db_table_name   The DB table which stores the settings.
array   $_defaults   Default settings.

[ Top ]
Method Summary
AbstractSettings   AbstractSettings()   Constructor.
boolean   dbupdate()   Commit changed settings to DB.
boolean   delete()   Remove a setting.
void   delete_array()   Delete an array of values.
string|false|NULL   get()   Get a setting from the DB settings table.
boolean   get_cond()   Only set the first variable (passed by reference) if we could retrieve a setting.
NULL|mixed   get_default()   Get the default for the last key of $col_key_names
void   load_all()   Load all settings, disregarding the derived classes setting of $cache_by_col_keys
  • useful if you know that you want to get
all user settings for example.
void   reset()   Reset cache (includes settings to be written to DB).
boolean   restore_defaults()   Delete values for $_defaults in DB.
boolean   set()   Temporarily sets a setting (dbupdate() writes it to DB).
void   set_array()   Set an array of values.
boolean   _load()   Loads the settings. Not meant to be called directly, but gets called when needed.

[ Top ]
Properties
boolean   $all_loaded = false [line 102]

Do we have loaded everything?


[ Top ]
array   $cache = NULL [line 94]

The internal cache.

false, if settings could not be loaded or NULL if not initialized.

API Tags:
Access:  protected


[ Top ]
integer   $cache_by_col_keys [line 83]

The number of column keys to cache by. This are the first x keys of $col_key_names. 0 means 'load all'.


[ Top ]
array   $col_key_names = array() [line 66]

Array with DB column key names.

API Tags:
Access:  protected


[ Top ]
string   $col_value_name [line 74]

DB column name for the value.

API Tags:
Access:  protected


[ Top ]
string   $db_table_name [line 58]

The DB table which stores the settings.

API Tags:
Access:  protected


[ Top ]
array   $_defaults = array() [line 113]

Default settings.

Maps last colkeyname to some default setting that will be used by get() if no value was defined (and it is set as a default).


Redefined in descendants as:

[ Top ]
Methods
Constructor AbstractSettings  [line 123]

  AbstractSettings AbstractSettings( string $db_table_name, array $col_key_names, string $col_value_name, [integer $cache_by_col_keys = 0]  )

Constructor.

Parameters:
string   $db_table_name:  The name of the DB table with the settings stored.
array   $col_key_names:  List of names for the DB columns keys that reference a value.
string   $col_value_name:  The name of the DB column that holds the value.
integer   $cache_by_col_keys:  The number of column keys to cache by. This are the first x keys of $col_key_names. 0 means 'load all'.


[ Top ]
dbupdate  [line 571]

  boolean dbupdate( )

Commit changed settings to DB.


API Tags:
Return:  true, if settings have been updated; false otherwise


[ Top ]
delete  [line 506]

  boolean delete( array $args  )

Remove a setting.

Parameters:
array   $args:  List of $col_key_names


Redefined in descendants as:

[ Top ]
delete_array  [line 541]

  void delete_array( array $array  )

Delete an array of values.

Parameters:
array   $array:  Array of parameters for delete()


[ Top ]
get  [line 269]

  string|false|NULL get( string $col_key1, [string $col_key2 = NULL], [string $col_key3 = NULL]  )

Get a setting from the DB settings table.

Parameters:
string   $col_key1:  First column key
string   $col_key2:  Second column key
string   $col_key3:  Third column key

API Tags:
Return:  value as string on success; NULL if not found; false in case of error
Uses:  AbstractSettings::get_default()


Redefined in descendants as:

[ Top ]
get_cond  [line 410]

  boolean get_cond( mixed &$toset, string 1  )

Only set the first variable (passed by reference) if we could retrieve a setting.

Parameters:
string   1:  the values for the column keys (depends on $this->col_key_names and must match its count and order)
mixed   &$toset:  variable to set maybe (by reference)

API Tags:
Return:  true on success (variable was set), false if not


[ Top ]
get_default  [line 390]

  NULL|mixed get_default( string $last_key  )

Get the default for the last key of $col_key_names

Parameters:
string   $last_key:  The last column key

API Tags:
Return:  NULL if no default is set, otherwise the value (should be string).
Usedby:  AbstractSettings::get()


[ Top ]
load_all  [line 149]

  void load_all( )

Load all settings, disregarding the derived classes setting of $cache_by_col_keys

  • useful if you know that you want to get
all user settings for example.



[ Top ]
reset  [line 700]

  void reset( )

Reset cache (includes settings to be written to DB).

This is useful, to rollback settings that have been made, e.g. when a Plugin decides that his settings should not get updated.



[ Top ]
restore_defaults  [line 558]

  boolean restore_defaults( )

Delete values for $_defaults in DB.

This will use the default settings on the next get() again.


API Tags:
Return:  true, if settings have been updated; false otherwise


[ Top ]
set  [line 436]

  boolean set( string $args,...  )

Temporarily sets a setting (dbupdate() writes it to DB).

Parameters:
string   $args,...:  the values for the column keys and column value. Must match order and count!

API Tags:
Return:  true, if the value has been set, false if it has not changed.


Redefined in descendants as:

[ Top ]
set_array  [line 491]

  void set_array( array $array  )

Set an array of values.

Parameters:
array   $array:  Array of parameters for set()


[ Top ]
_load  [line 165]

  boolean _load( [string $arg1 = NULL], [string $arg2 = NULL], [string $arg3 = NULL]  )

Loads the settings. Not meant to be called directly, but gets called when needed.

Parameters:
string   $arg1:  First column key
string   $arg2:  Second column key
string   $arg3:  Third column key

API Tags:
Return:  always true
Access:  protected


Redefined in descendants as:

[ Top ]