Class Item Abstract class for database based items.

Base class with common features for database based items and item collections.

author Timo A. Hummel <Timo.Hummel@4fb.de>
author Murat Purc
version 0.3
copyright four for business 2003

 Methods

Constructor function

__construct(string $sTable, string $sPrimaryKey, int $iLifetime) 

Parameters

$sTable

string

The table to use as information source

$sPrimaryKey

string

The primary key to use

$iLifetime

int

Exceptions

\Contenido_ItemException If table name or primary key is not set

Filters the passed data using the functions defines in the _arrInFilters array.

_inFilter(mixed $mData) : mixed

see \setFilters
todo This method is used from public scope, but it should be protected

Parameters

$mData

mixed

Data to filter

Returns

mixedFiltered data

Deletes a custom property.

deleteProperty(string $sType, string $sName) : bool

Parameters

$sType

string

Specifies the type

$sName

string

Specifies the name

Returns

bool

Deletes a custom property by its id.

deletePropertyById(int $idprop) : bool

Parameters

$idprop

int

Id of property

Returns

bool

Escape string for using in SQL-Statement.

escape(string $sString) : string
Inherited

inherited_from \Contenido_ItemBaseAbstract::escape()

Parameters

$sString

string

The string to escape

Returns

stringEscaped string

Wrapper for getField (less to type).

get(string $sField) : mixed

Parameters

$sField

string

Specifies the field to retrieve

Returns

mixedValue of the field

Gets the value of a specific field.

getField(string $sField) : mixed

Parameters

$sField

string

Specifies the field to retrieve

Returns

mixedValue of the field

getMetaObject()

getMetaObject() 

Returns a custom property.

getProperty(string $sType, string $sName) : mixed

Parameters

$sType

string

Specifies the type

$sName

string

Specifies the name

Returns

mixedValue of the given property or false

Checks if a the item is already loaded.

isLoaded() : bool

Returns

bool

Loads an item by colum/field from the database.

loadBy(string $sField, mixed $mValue, bool $bSafe) : bool

Parameters

$sField

string

Specifies the field

$mValue

mixed

Specifies the value

$bSafe

bool

Use inFilter or not

Returns

boolTrue if the load was successful

Loads an item by ID from the database.

loadByPrimaryKey(string $mValue) : bool

Parameters

$mValue

string

Specifies the primary key value

Returns

boolTrue if the load was successful

Loads an item by it's recordset.

loadByRecordSet(array $aRecordSet) 

Parameters

$aRecordSet

array

The recordset of the item

Shortcut to setField.

set(string $sField, string $mValue, bool $bSafe) 

Parameters

$sField

string

Field name

$mValue

string

Value to set

$bSafe

bool

Flag to run defined inFilter on passed value

Sets the value of a specific field.

setField(string $sField, string $mValue, bool $bSafe) 

Parameters

$sField

string

Field name

$mValue

string

Value to set

$bSafe

bool

Flag to run defined inFilter on passed value

Define the filter functions used when data is being stored or retrieved from the database.

setFilters(array $aInFilters, array $aOutFilters) : void

Examples:

$obj->setFilters(array('addslashes'), array('stripslashes'));
$obj->setFilters(array('htmlencode', 'addslashes'), array('stripslashes', 'htmlencode'));

Parameters

$aInFilters

array

Array with function names

$aOutFilters

array

Array with function names

Sets a custom property.

setProperty(string $sType, string $sName, mixed $mValue) : bool

Parameters

$sType

string

Specifies the type

$sName

string

Specifies the name

$mValue

mixed

Specifies the value

Returns

bool

Stores the loaded and modified item to the database.

store() : bool

Returns

bool

Returns current item data as an assoziative array.

toArray() : array | false

Returns

arrayfalse

Returns current item data as an object.

toObject() : \stdClass | false

Returns

\stdClassfalse

Returns properties instance, instantiates it if not done before.

_getPropertiesCollectionInstance() : \PropertyCollection
Inherited

inherited_from \Contenido_ItemBaseAbstract::_getPropertiesCollectionInstance()

Returns

Returns the second database instance, usable to run additional statements without losing current query results.

_getSecondDBInstance() : \DB_Contenido
Inherited

inherited_from \Contenido_ItemBaseAbstract::_getSecondDBInstance()

Returns

Loads an item by passed where clause from the database.

_loadByWhereClause(string $sWhere) : bool

This function is expensive, since it executes allways a query to the database to retrieve the primary key, even if the record set is aleady cached. NOTE: Passed value has to be escaped before. This will not be done by this function.

Parameters

$sWhere

string

The where clause like 'idart = 123 AND idlang = 1'

Returns

boolTrue if the load was successful

Function which is called whenever an item is loaded.

_onLoad() : void

Inherited classes should override this function if desired.

Filters the passed data using the functions defines in the _arrOutFilters array.

_outFilter(mixed $mData) : mixed

see \setFilters

Parameters

$mData

mixed

Data to filter

Returns

mixedFiltered data

_setMetaObject()

_setMetaObject($sObjectName) 

Parameters

$sObjectName

 Properties

 

Storage of the primary key

$primaryKey : string
Inherited

inherited_from \Contenido_ItemBaseAbstract::$$primaryKey
 

Storage of the source table to use for the user informations

$values : array

 

Checks for the virginity of created objects. If true, the object is virgin and no operations on it except load-Functions are allowed.

$virgin : bool
Inherited

inherited_from \Contenido_ItemBaseAbstract::$$virgin
 

List of funcion names of the filters used when data is stored to the db.

$_arrInFilters : array

 

List of funcion names of the filtersused when data is retrieved from the db

$_arrOutFilters : array

 

Classname of current instance

$_className : string
Inherited

inherited_from \Contenido_ItemBaseAbstract::$$_className
 

Class name of meta object

$_metaObject : string

 

Item cache instance

$_oCache : \Contenido_ItemCache
Inherited

inherited_from \Contenido_ItemBaseAbstract::$$_oCache
 

GenericDB settings, see $cfg['sql']

$_settings : array
Inherited

inherited_from \Contenido_ItemBaseAbstract::$$_settings
 

Cache the result items FIXME seems to not used, remove it!

$cache : array
Inherited

inherited_from \Contenido_ItemBaseAbstract::$$cache
 

Database instance, contains the database object

$db : \DB_Contenido
Inherited

inherited_from \Contenido_ItemBaseAbstract::$$db
 

Storage of the last occured error

$lasterror : string
Inherited

inherited_from \Contenido_ItemBaseAbstract::$$lasterror
 

Lifetime of results/created objects? FIXME Not used at the moment!

$lifetime : int
Inherited

inherited_from \Contenido_ItemBaseAbstract::$$lifetime
 

Storage of the fields which were modified, where the keys are the fieldnames and the values just simple booleans.

$modifiedValues : array

 

Stores the old primary key, just in case somebody wants to change it

$oldPrimaryKey : string

 

Property collection instance

$properties : \PropertyCollection
Inherited

inherited_from \Contenido_ItemBaseAbstract::$$properties
 

Second DB instance, is required for some additional queries without losing an current existing query result.

$secondDb : \DB_Contenido
Inherited

inherited_from \Contenido_ItemBaseAbstract::$$secondDb
 

Storage of the source table to use for the information

$table : string
Inherited

inherited_from \Contenido_ItemBaseAbstract::$$table