Posted by Dave Redfern (Writer), Base on 02 Dec 2008 @ 20:24
Provides a consistent interface to any param table so long as it conforms to the schema: id, $this->_DbPropertyField, $this->_DbPropertyValueField where the primary key is made of id & $this->_DbPropertyField.
The value field should be of "text" type or equivalent as all params stored are serialised before being stored. This allows arrays and/or objects to be stored without having to first check the values.
This class should be used inside other objects and be lazy loaded when required.
// straight initialisation
$oParams = new baseTableParamSet('myDatabase','myTable','tableIndex', 4);
// within an object
class myObject {
function getParams() {
if ( !$this->_ParamSet instanceof baseTableParamSet ) {
$this->_ParamSet = new baseTableParamSet(
'myDatabase', 'myTable', 'tableIndex', 'tableParamNameColumn',
'tableParamValueColumn', $this->_IndexID
);
}
return $this->_ParamSet;
}
}
$oObject = new myObject;
$oObject->getParams()->setParam('paramName', 'value');
// object parent save method should cascade to param set...
$oObject->save();
public __construct($inDbName, $inDbTable, $inDbTableIndex, $inDbPropertyField, $inDbPropertyValueField, $inIndexID, [$inAutoSerialise = true])
Returns a new paramCollection
public __toString()
Returns a textual representation of this object
public toArray()
Returns object properties as an array
public load()
Loads param collection into object
public save()
Saves back params to the database if updated / changed, returns number of rows affected
public delete()
Deletes the queued params from the database
public deleteAll()
Deletes all params for the current index; returns rows affected
public findByRegex($inRegex)
Find a parameter(s) using a regular expression, always returns an array
public reset()
Clears all values
public getIndexID()
Returns the index for the param set
public setIndexID($inIndexID)
Allows you to reset the indexID
public setParam($inParamName, $inParamValue)
Sets a new param -> value pair
public getParam([$inParamName = null], [$inDefault = null])
Returns the value of $inParamName, if $inParamName is null returns all params, if $inDefault is specifed returns $inDefault if no param match
public unsetParam($inParamName)
Unsets a param from the set
public getParamCount()
Returns the number of params in the set
public mergeParams($inParams)
Merges $inParams into this param set
public getDbName()
Returns $_DbName
public setDbName($inDbName)
Set DbName to $inDbName
public getDbTable()
Returns $_DbTable
public setDbTable($inDbTable)
Set $_DbTable to $inDbTable
public getDbTableIndex()
Return $_DbTableIndex
public setTableIndex($inTableIndex)
Set $_DbTableIndex to $inTableIndex
public getDbPropertyField()
Returns $_DbPropertyField
public setDbPropertyField($inDbPropertyField)
Set DbPropertyField property
public getDbPropertyValueField()
Returns $_DbPropertyValueField
public setDbPropertyValueField($inDbPropertyValueField)
Set DbPropertyValueField property
public getAutoSerialise()
Returns $_AutoSerialise
public setAutoSerialise($inAutoSerialise)
Set $_AutoSerialise to $inAutoSerialise