Class ItemCollection Class for database based item collections

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

 Methods

Constructor Function Note: Default lifetime is 10 seconds.

ItemCollection(string $table, $primaryKey, $lifetime) 

Parameters

$table

string

The table to use as information source

$primaryKey

$lifetime

_buildGroupWhereStatements ()

_buildGroupWhereStatements() : array

Builds a where statement out of the setGroupWhere calls

Returns

arraywith all where statements

_buildWhereStatements ()

_buildWhereStatements() : array

Builds a where statement out of the setWhere calls

Returns

arraywith all where statements

_fetchJoinTables ()

_fetchJoinTables(\none $ignore_root) : array

Fetches all tables which will be joined later on.

The returned array has the following format:

array( array(fields), array(tables), array(joins), array(wheres) );

Notes: The table is the table name which needs to be added to the FROM clause The join statement which is inserted after the master table The where statement is combined with all other where statements The fields to select from

Parameters

$ignore_root

\none

Returns

arraysee above

_findReverseJoinPartner()

_findReverseJoinPartner($parentclass, $classname) 

Parameters

$parentclass

$classname

_initializeDriver: Initializes the driver to use with GenericDB.

_initializeDriver($bForceInit) 

Parameters

$bForceInit

boolean If true, forces the driver to initialize, even if it already exists.

_recursiveStructuredFetch()

_recursiveStructuredFetch($objects, $array) 

Parameters

$objects

$array

_setItemClass: private method to set the accompanying item object.

_setItemClass(string $classname) : \none

Parameters

$classname

string

specifies the classname

Returns

\none

_setJoinPartner: Defines the reverse links for this table.

_setJoinPartner(string $foreignCollectionClass) : \none

Important: The class specified by $foreignCollectionClass needs to be a collection class and has to exist Define all links in the constructor of your object

Parameters

$foreignCollectionClass

string

Specifies the foreign class to use

Returns

\none

addResultField()

addResultField($field) 

Parameters

$field

count () Returns the amount of returned items

count() : integer

Returns

integerNumber of rows

create() Creates a new item in the table and loads it afterwards.

create() 

delete() Deletes an item in the table.

delete($id) 

Parameters

$id

deleteWhere ($field, $restriction, $operator)

deleteWhere($field, $restriction, $operator) 

Restricts a query with a where clause

Parameters

$field

$restriction

$operator

deleteWhereGroup ($group, $field, $restriction, $operator)

deleteWhereGroup($group, $field, $restriction, $operator) 

Restricts a query with a where clause, groupable

Parameters

$group

$field

$restriction

$operator

exists ($id) Checks if a specific entry exists

exists(integer $id) : boolean

Parameters

$id

integer

The id to check for

Returns

booleantrue if object exists, false if not

fetchArray() Fetches an array of fields from the database.

fetchArray($key, $fields) : array

Example: $i = $object->fetchArray("idartlang", array("idlang", "name"));

could result in: $i[5] = array("idlang" => 5, "name" => "My Article");

Important: If you don't pass an array for fields, the function doesn't create an array.

Parameters

$key

string Name of the field to use for the key

$fields

mixed String or array

Returns

arrayResulting array

fetchObject()

fetchObject($class) 

Parameters

$class

fetchTable()

fetchTable($fields, $objects) 

Parameters

$fields

$objects

flexSelect ($distinct = "", $from = "", $where = "", $group_by = "", $order_by = "", $limit = "") Selects all entries from the database and returns them as DBObject-objects to the user.

flexSelect(string $distinct, string $from, string $where, string $group_by, string $order_by, string $limit) : array

Objects are loaded using their primary key.

author HerrB

Parameters

$distinct

string

Specifies if distinct will be added to the SQL statement ($distinct !== "" -> DISTINCT)

$from

string

Specifies the additional from clause (e.g. "con_news_groups AS groups, con_news_groupmembers AS groupmembers").

$where

string

Specifies the where clause.

$group_by

string

Specifies the group by clause.

$order_by

string

Specifies the order by clause.

$limit

string

Specifies the limit by clause.

Returns

arrayArray of DBObject-Objects

loadItem ($item) Loads a single object from the database.

loadItem($vitem) : object

Needs to be overridden by the extension class.

Parameters

$vitem

Returns

objectThe newly created object

next () Advances to the next item in the database.

next() : object

Returns

objectThe next object, or false if no more objects

query()

query() 

fetchStructured Returns an array of arrays

queryAndFetchStructured(\objects $objects) : array

Parameters

$objects

\objects

array with the correct order of the objects

Returns

arrayresult

removeResultField()

removeResultField($field) 

Parameters

$field

resetQuery()

resetQuery() 

select ($where = "", $group_by = "", $order_by = "", $limit = "") Selects all entries from the database and returns them as DBObject-objects to the user.

select(string $where, string $group_by, string $order_by, string $limit) : array

Objects are loaded using their primary key.

Parameters

$where

string

Specifies the where clause.

$group_by

string

Specifies the group by clause.

$order_by

string

Specifies the order by clause.

$limit

string

Specifies the limit by clause.

Returns

arrayArray of DBObject-Objects

setEncoding()

setEncoding($sEncoding) 

Parameters

$sEncoding

setGroupCondition ($group1, $group2, $condition)

setGroupCondition($group1, $group2, $condition) 

Defines how groups are linked to each other

Parameters

$group1

$group2

$condition

setInnerGroupCondition ($group, $condition)

setInnerGroupCondition($group, $condition) 

Defines how relations in one group are linked each together

Parameters

$group

$condition

setLimit()

setLimit($iRowStart, $iRowCount) 

Parameters

$iRowStart

$iRowCount

setOrder()

setOrder($order) 

Parameters

$order

setWhere ($field, $restriction, $operator)

setWhere($field, $restriction, $operator) 

Restricts a query with a where clause

Parameters

$field

$restriction

$operator

setWhereGroup ($group, $field, $restriction, $operator)

setWhereGroup($group, $field, $restriction, $operator) 

Restricts a query with a where clause, groupable

Parameters

$group

$field

$restriction

$operator

 Properties

 

Reverse join partners for this data object

$_JoinPartners : array
access private
 

Encoding

$_encoding : string
access private
 

Forward join partners for this data object

$_forwardJoinPartners : array
access private
 

Group conditions

$_groupConditions : array
access private
 

Inner group conditions

$_innerGroupConditions : array
access private
 

Single item class

$_itemClass : string
access private
 

Iterator object for the next() method

$_iteratorItem : object
access private
 

Result fields for the query

$_resultFields : array
access private
 

Where restrictions for the query

$_whereRestriction : array
access private
 

$cache : array
access private
 

$db : object
access private
 

$lasterror : string
access private
 

Lifetime in seconds

$lifetime : int
access private
 

$objects : string
access private
 

$primaryKey : string
access private
 

Property collection

$properties : array
access private
 

$table : string
access private
 

Is entry virgin?

$virgin : array
access private