b2evolution

Multilingual multiuser multiblog engine

b2evolution Technical Documentation (CVS HEAD) [ class tree: evocore ] [ index: evocore ] [ all elements ]

Class: AbstractSettings

Source Location: /blogs/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 /blogs/inc/settings/model/_abstractsettings.class.php [line 55]



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

Properties

Methods

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

[ 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.
NULL|mixed   param_Request()   Get a param from Request and save it to Settings, or default to previously saved user setting.
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 107]

Do we have loaded everything?


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

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 88]

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 71]

Array with DB column key names.

API Tags:
Access:  protected


[ Top ]
string   $col_value_name [line 79]

DB column name for the value.

API Tags:
Access:  protected


[ Top ]
string   $db_table_name [line 63]

The DB table which stores the settings.

API Tags:
Access:  protected


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

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 128]

  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 576]

  boolean dbupdate( )

Commit changed settings to DB.


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


Redefined in descendants as:

[ Top ]
delete  [line 511]

  boolean delete( array $args  )

Remove a setting.

Parameters:
array   $args:  List of $col_key_names


Redefined in descendants as:

[ Top ]
delete_array  [line 546]

  void delete_array( array $array  )

Delete an array of values.

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


[ Top ]
get  [line 274]

  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 415]

  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 395]

  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 154]

  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 ]
param_Request  [line 736]

  NULL|mixed param_Request( string $param_name, string $set_name, [string $type = ''], [mixed $default = ''], [boolean $memorize = false], [boolean $override = false]  )

Get a param from Request and save it to Settings, or default to previously saved user setting.

If the setting was not set before (and there's no default given that gets returned), $default gets used.

Parameters:
string   $param_name:  Request param name
string   $set_name:  setting name. Make sure this is unique!
string   $type:  Force value type to one of:
  • integer
  • float
  • string (strips (HTML-)Tags, trims whitespace)
  • array
  • object
  • null
  • html (does nothing)
  • '' (does nothing)
  • '/^...$/' check regexp pattern match (string)
  • boolean (will force type to boolean, but you can't use 'true' as a default since it has special meaning. There is no real reason to pass booleans on a URL though. Passing 0 and 1 as integers seems to be best practice).
Value type will be forced only if resulting value (probably from default then) is !== NULL
mixed   $default:  Default value or TRUE
boolean   $memorize:  Do we need to memorize this to regenerate the URL for this page?
boolean   $override:  Override if variable already set

API Tags:
Return:  NULL, if neither a param was given nor knows about it.


Redefined in descendants as:

[ Top ]
reset  [line 705]

  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 563]

  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 441]

  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 496]

  void set_array( array $array  )

Set an array of values.

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


[ Top ]
_load  [line 170]

  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 ]

Documentation generated on Sat, 06 Mar 2010 03:59:37 +0100 by phpDocumentor 1.4.2. This site is hosted and maintained by Daniel HAHLER (Contact).