Base class with common features for database based items and item collections.
package |
CONTENIDO API |
subpackage |
Model |
copyright |
four for business AG |
Methods
Constructor function for downwards compatibility
ItemCollection($sTable, $sPrimaryKey, $iLifetime)
Inherited
inherited_from |
\ItemCollection::ItemCollection() |
Parameters
$sTable
$sPrimaryKey
$iLifetime
Magic method to invoke inaccessible methods.
__call(string $name, array $arguments) : mixed
Inherited
Currently it works as a fallback for the not supported method create() which
creates a PHP Strict warning.
inherited_from |
\ItemCollection::__call() |
Parameters
$name
string
$arguments
array
Returns
mixed
Constructor Function
__construct($select) : void
Parameters
$select
Exceptions
Adds a result field
addResultField(string $sField)
Inherited
inherited_from |
\ItemCollection::addResultField() |
Parameters
$sField
string
assignModul()
assignModul($idtpl, $number, $idmod)
Parameters
$idtpl
$number
$idmod
cApiContainerCollection()
cApiContainerCollection($select)
deprecated |
[2011-03-15] Old constructor function for downwards
compatibility |
Parameters
$select
clearAssignments()
clearAssignments($idtpl)
Inserts a new item entry by using a existing item entry.
copyItem(object $srcItem, array $fieldsToOverwrite) : object | \Item | null
Inherited
inherited_from |
\ItemCollection::copyItem() |
Parameters
$srcItem
object
Source Item instance to copy
$fieldsToOverwrite
array
Assoziative list of fields to overwrite.
Exceptions
\cInvalidArgumentException |
If Item class doesn't match the defined _itemClass property
or passed Item instance has no loaded recordset |
Returns
Returns the amount of returned items
count() : int
Inherited
inherited_from |
\ItemCollection::count() |
Returns
int
Number of rows
create()
create($idtpl, $number, $idmod)
Parameters
$idtpl
$number
$idmod
Creates a new item in the table and loads it afterwards.
createNewItem(string | array $data) : \Item
Inherited
inherited_from |
\ItemCollection::createNewItem() |
Parameters
$data
string
array
optional parameter for direct input of
primary key value (string) or multiple column name - value pairs
Returns
\Item
The newly created object
Deletes an item in the table.
delete(mixed $mId) : bool
Inherited
Deletes also cached e entry and any existing properties.
inherited_from |
\ItemCollection::delete() |
Parameters
$mId
mixed
Id of entry to delete
Returns
bool
Deletes all found items in the table matching the passed field and it's value.
deleteBy(string $sField, mixed $mValue) : int
Inherited
Deletes also cached e entries and any existing properties.
inherited_from |
\ItemCollection::deleteBy() |
Parameters
$sField
string
The field name
$mValue
mixed
The value of the field
Returns
int
Number of deleted entries
Deletes all found items in the table matching the passed field and it's value.
deleteByMany($values) : bool
Inherited
Deletes also cached e entries and any existing properties.
inherited_from |
\ItemCollection::deleteByMany() |
Parameters
$values
Returns
bool
Deletes all found items in the table matching the rules in the passed where clause.
deleteByWhereClause(string $sWhere) : int
Inherited
Deletes also cached e entries and any existing properties.
inherited_from |
\ItemCollection::deleteByWhereClause() |
Parameters
$sWhere
string
The where clause of the SQL statement
Returns
int
Number of deleted entries
Removes a previous set where clause (@see ItemCollection::setWhere).
deleteWhere(string $sField, mixed $mRestriction, string $sOperator)
Inherited
inherited_from |
\ItemCollection::deleteWhere() |
Parameters
$sField
string
$mRestriction
mixed
$sOperator
string
Removes a previous set groupable where clause (@see ItemCollection::setWhereGroup).
deleteWhereGroup(string $sGroup, string $sField, mixed $mRestriction, string $sOperator)
Inherited
inherited_from |
\ItemCollection::deleteWhereGroup() |
Parameters
$sGroup
string
$sField
string
$mRestriction
mixed
$sOperator
string
Escape string for using in SQL-Statement.
escape(string $sString) : string
Inherited
inherited_from |
\cItemBaseAbstract::escape() |
inherited_from |
\ItemCollection::escape() |
Parameters
$sString
string
The string to escape
Returns
string
Escaped string
Checks if a specific entry exists.
exists(mixed $mId) : bool
Inherited
inherited_from |
\ItemCollection::exists() |
Parameters
$mId
mixed
The id to check for (could be numeric or string)
Returns
bool
True if object exists, false if not
Fetches an array of fields from the database.
fetchArray(string $sKey, mixed $mFields) : array
Inherited
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.
inherited_from |
\ItemCollection::fetchArray() |
Parameters
$sKey
string
Name of the field to use for the key
$mFields
mixed
String or array
Returns
array
Resulting array
Loads a single entry by it's id.
fetchById(string | int $id) : \Item
Inherited
inherited_from |
\ItemCollection::fetchById() |
Parameters
$id
string
int
The primary key of the item to load.
Returns
Fetches the resultset related to current loaded primary key as an object
fetchObject(\Item $sClassName)
Inherited
inherited_from |
\ItemCollection::fetchObject() |
Parameters
fetchTable()
fetchTable(array $aFields, array $aObjects)
Inherited
inherited_from |
\ItemCollection::fetchTable() |
Parameters
$aFields
$aObjects
Selects all entries from the database.
flexSelect(string $sDistinct, string $sFrom, string $sWhere, string $sGroupBy, string $sOrderBy, string $sLimit) : bool
Inherited
Objects are loaded using their primary key.
author |
HerrB |
inherited_from |
\ItemCollection::flexSelect() |
Parameters
$sDistinct
string
Specifies if distinct will be added to the SQL
statement ($sDistinct !== '' -> DISTINCT)
$sFrom
string
Specifies the additional from clause (e.g.
'con_news_groups AS groups, con_news_groupmembers AS groupmembers').
$sWhere
string
Specifies the where clause.
$sGroupBy
string
Specifies the group by clause.
$sOrderBy
string
Specifies the order by clause.
$sLimit
string
Specifies the limit by clause.
Returns
bool
True on success, otherwhise false
Returns all ids of recordsets in the table.
getAllIds() : array
Inherited
inherited_from |
\ItemCollection::getAllIds() |
Returns
array
List of ids
Returns all specified fields of recordsets in the table matching the rules in the passed where clause.
getFieldsByWhereClause(array $aFields, string $sWhere) : array
Inherited
inherited_from |
\ItemCollection::getFieldsByWhereClause() |
Parameters
$aFields
array
List of fields to get
$sWhere
string
The where clause of the SQL statement
Returns
array
List of entries with specified fields
Returns all ids of recordsets in the table matching the rules in the passed where clause.
getIdsByWhereClause(string $sWhere) : array
Inherited
inherited_from |
\ItemCollection::getIdsByWhereClause() |
Parameters
$sWhere
string
The where clause of the SQL statement
Returns
array
List of ids
Sets the query to use foreign tables in the resultset
link(string $sForeignClass) : void
Inherited
inherited_from |
\ItemCollection::link() |
Parameters
$sForeignClass
string
The class of foreign table to use
Exceptions
Loads a single object from the database.
loadItem(mixed $mItem) : \Item
Inherited
inherited_from |
\ItemCollection::loadItem() |
Parameters
$mItem
mixed
The primary key of the item to load or a recordset
with itemdata (array) to inject to the item object.
Exceptions
Returns
\Item
The newly created object
Advances to the next item in the database.
next() : \Item | bool
Inherited
inherited_from |
\ItemCollection::next() |
Returns
\Item
bool
The next object, or false if no more objects
Builds and runs the query
query() : bool
Inherited
inherited_from |
\ItemCollection::query() |
Exceptions
Returns
bool
Returns an array of arrays
queryAndFetchStructured(array $aObjects) : array
Inherited
inherited_from |
\ItemCollection::queryAndFetchStructured() |
Parameters
$aObjects
array
With the correct order of the objects
Returns
array
Result
Registers a new callback.
register(string $event, mixed $callback, mixed $class) : void
InheritedStatic
Example:
cGenericDb::register(cGenericDb::CREATE_SUCCESS, 'itemCreateHandler', 'cApiArticle');
cGenericDb::register(cGenericDb::CREATE_SUCCESS, array('cCallbackHandler', 'executeCreateHandle'), 'cApiArticle');
inherited_from |
\cGenericDb::register() |
inherited_from |
\cItemBaseAbstract::register() |
inherited_from |
\ItemCollection::register() |
Parameters
$event
string
Callback event, must be a valid value of a cGenericDb event constant
$callback
mixed
Callback to register
$class
mixed
Class name for registering callback (can be string of array with names of the concrete Item classes)
Exceptions
Removes existing result field
removeResultField(string $sField)
Inherited
inherited_from |
\ItemCollection::removeResultField() |
Parameters
$sField
string
Resets the properties
resetQuery()
Inherited
inherited_from |
\ItemCollection::resetQuery() |
Selects all entries from the database.
select(string $sWhere, string $sGroupBy, string $sOrderBy, string $sLimit) : bool
Inherited
Objects are loaded using their primary key.
inherited_from |
\ItemCollection::select() |
Parameters
$sWhere
string
Specifies the where clause.
$sGroupBy
string
Specifies the group by clause.
$sOrderBy
string
Specifies the order by clause.
$sLimit
string
Specifies the limit by clause.
Returns
bool
True on success, otherwhise false
Sets the encoding.
setEncoding(string $sEncoding)
Inherited
inherited_from |
\ItemCollection::setEncoding() |
Parameters
$sEncoding
string
Defines how groups are linked to each other
setGroupCondition(string $sGroup1, string $sGroup2, string $sCondition)
Inherited
inherited_from |
\ItemCollection::setGroupCondition() |
Parameters
$sGroup1
string
$sGroup2
string
$sCondition
string
Defines how relations in one group are linked each together
setInnerGroupCondition(string $sGroup, string $sCondition)
Inherited
inherited_from |
\ItemCollection::setInnerGroupCondition() |
Parameters
$sGroup
string
$sCondition
string
Sets the limit for results
setLimit(int $iRowStart, int $iRowCount)
Inherited
inherited_from |
\ItemCollection::setLimit() |
Parameters
$iRowStart
int
$iRowCount
int
Sets the result order part of the query
(e.
setOrder(string $order)
Inherited
g. "fieldname", "fieldname DESC", "fieldname DESC, field2name ASC")
inherited_from |
\ItemCollection::setOrder() |
Parameters
$order
string
Restricts a query with a where clause
setWhere(string $sField, mixed $mRestriction, string $sOperator)
Inherited
inherited_from |
\ItemCollection::setWhere() |
Parameters
$sField
string
$mRestriction
mixed
$sOperator
string
Restricts a query with a where clause, groupable
setWhereGroup(string $sGroup, string $sField, mixed $mRestriction, string $sOperator)
Inherited
inherited_from |
\ItemCollection::setWhereGroup() |
Parameters
$sGroup
string
$sField
string
$mRestriction
mixed
$sOperator
string
Unregisters all callbacks for a specific event in a class.
unregister(string $event, mixed $class) : void
InheritedStatic
Example:
cGenericDb::unregister(cGenericDb::CREATE_SUCCESS, 'cApiArticle');
inherited_from |
\cGenericDb::unregister() |
inherited_from |
\cItemBaseAbstract::unregister() |
inherited_from |
\ItemCollection::unregister() |
Parameters
$event
string
Callback event, must be a valid value of a cGenericDb event constant
$class
mixed
Class name for unregistering callback (can be string of array with names of the concrete Item classes)
Exceptions
Builds a where statement out of the setGroupWhere calls
_buildGroupWhereStatements() : array
Inherited
inherited_from |
\ItemCollection::_buildGroupWhereStatements() |
Returns
array
With all where statements
Builds a where statement out of the setWhere calls
_buildWhereStatements() : array
Inherited
inherited_from |
\ItemCollection::_buildWhereStatements() |
Returns
array
With all where statements
Deletes an item in the table, deletes also existing cache entries and
properties of the item.
_delete(mixed $mId) : bool
Inherited
inherited_from |
\ItemCollection::_delete() |
Parameters
$mId
mixed
Id of entry to delete
Returns
bool
Deletes all items in the table, deletes also existing cache entries and
properties of the item.
_deleteMultiple(array $aIds) : int
Inherited
inherited_from |
\ItemCollection::_deleteMultiple() |
Parameters
$aIds
array
Id of entries to delete
Returns
int
Number of affected records
Executes all callbacks for a specific event in a class.
_executeCallbacks(string $event, string $class, array $arguments) : void
Inherited
inherited_from |
\cGenericDb::_executeCallbacks() |
inherited_from |
\cItemBaseAbstract::_executeCallbacks() |
inherited_from |
\ItemCollection::_executeCallbacks() |
Parameters
$event
string
Callback event, must be a valid value of a cGenericDb event constant
$class
string
Class name for executing callback
$arguments
array
Arguments to pass to the callback function
Exceptions
Fetches all tables which will be joined later on.
_fetchJoinTables(\??? $ignoreRoot) : array
Inherited
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
inherited_from |
\ItemCollection::_fetchJoinTables() |
Parameters
$ignoreRoot
\???
Exceptions
Returns
array
Array structure, see above
Returns reverse join partner.
_findReverseJoinPartner(string $sParentClass, string $sClassName)
Inherited
inherited_from |
\ItemCollection::_findReverseJoinPartner() |
Parameters
$sParentClass
string
$sClassName
string
Returns properties instance, instantiates it if not done before.
_getPropertiesCollectionInstance() : \cApiPropertyCollection
Inherited
inherited_from |
\cItemBaseAbstract::_getPropertiesCollectionInstance() |
inherited_from |
\ItemCollection::_getPropertiesCollectionInstance() |
Returns
Returns the second database instance, usable to run additional statements
without losing current query results.
_getSecondDBInstance() : \cDb
Inherited
inherited_from |
\cItemBaseAbstract::_getSecondDBInstance() |
inherited_from |
\ItemCollection::_getSecondDBInstance() |
Returns
Initializes the driver to use with GenericDB.
_initializeDriver($bForceInit)
Inherited
inherited_from |
\ItemCollection::_initializeDriver() |
Parameters
$bForceInit
boolean If true, forces the driver to initialize, even if it already exists.
_recursiveStructuredFetch()
_recursiveStructuredFetch(array $aObjects, array $aResult)
Inherited
inherited_from |
\ItemCollection::_recursiveStructuredFetch() |
Parameters
$aObjects
$aResult
Resolves links (class names of joined partners)
_resolveLinks() : array
Inherited
inherited_from |
\ItemCollection::_resolveLinks() |
Returns
array
Method to set the accompanying item object.
_setItemClass(string $sClassName) : void
Inherited
inherited_from |
\ItemCollection::_setItemClass() |
Parameters
$sClassName
string
Specifies the classname of item
Exceptions
Defines the reverse links for this table.
_setJoinPartner(string $sForeignCollectionClass) : void
Inherited
Important: The class specified by $sForeignCollectionClass needs to be a
collection class and has to exist.
Define all links in the constructor of your object.
inherited_from |
\ItemCollection::_setJoinPartner() |
Parameters
$sForeignCollectionClass
string
Specifies the foreign class to use
Exceptions
Properties
$primaryKey : string
Inherited
inherited_from |
\cItemBaseAbstract::$$primaryKey |
inherited_from |
\ItemCollection::$$primaryKey |
$virgin : bool
Inherited
If true, the object
is virgin and no operations on it except load-Functions are allowed.
inherited_from |
\cItemBaseAbstract::$$virgin |
inherited_from |
\ItemCollection::$$virgin |
Reverse join partners for this data object
$_JoinPartners : array
Inherited
inherited_from |
\ItemCollection::$$_JoinPartners |
$_aOperators : array
Inherited
inherited_from |
\ItemCollection::$$_aOperators |
$_bAllMode : bool
Inherited
Reduces the number of queries send
to the database.
inherited_from |
\ItemCollection::$$_bAllMode |
$_className : string
Inherited
inherited_from |
\cItemBaseAbstract::$$_className |
inherited_from |
\ItemCollection::$$_className |
$_collectionCache : array
Inherited
inherited_from |
\ItemCollection::$$_collectionCache |
Encoding
$_encoding : string
Inherited
inherited_from |
\ItemCollection::$$_encoding |
Forward join partners for this data object
$_forwardJoinPartners : array
Inherited
inherited_from |
\ItemCollection::$$_forwardJoinPartners |
Group conditions
$_groupConditions : array
Inherited
inherited_from |
\ItemCollection::$$_groupConditions |
Inner group conditions
$_innerGroupConditions : array
Inherited
inherited_from |
\ItemCollection::$$_innerGroupConditions |
Single item class
$_itemClass : string
Inherited
inherited_from |
\ItemCollection::$$_itemClass |
Iterator object for the next() method
$_iteratorItem : object
Inherited
inherited_from |
\ItemCollection::$$_iteratorItem |
$_oCache : \cItemCache
Inherited
inherited_from |
\cItemBaseAbstract::$$_oCache |
inherited_from |
\ItemCollection::$$_oCache |
Result fields for the query
$_resultFields : array
Inherited
inherited_from |
\ItemCollection::$$_resultFields |
$_settings : array
Inherited
inherited_from |
\cItemBaseAbstract::$$_settings |
inherited_from |
\ItemCollection::$$_settings |
Where restrictions for the query
$_whereRestriction : array
Inherited
inherited_from |
\ItemCollection::$$_whereRestriction |
$cache : array
Inherited
inherited_from |
\cItemBaseAbstract::$$cache |
inherited_from |
\ItemCollection::$$cache |
$db : \cDb
Inherited
inherited_from |
\cItemBaseAbstract::$$db |
inherited_from |
\ItemCollection::$$db |
$lasterror : string
Inherited
inherited_from |
\cItemBaseAbstract::$$lasterror |
inherited_from |
\ItemCollection::$$lasterror |
$lifetime : int
Inherited
inherited_from |
\cItemBaseAbstract::$$lifetime |
inherited_from |
\ItemCollection::$$lifetime |
$objects : string
Inherited
inherited_from |
\ItemCollection::$$objects |
$properties : \cApiPropertyCollection
Inherited
inherited_from |
\cItemBaseAbstract::$$properties |
inherited_from |
\ItemCollection::$$properties |
$secondDb : \cDb
Inherited
inherited_from |
\cItemBaseAbstract::$$secondDb |
inherited_from |
\ItemCollection::$$secondDb |
$table : string
Inherited
inherited_from |
\cItemBaseAbstract::$$table |
inherited_from |
\ItemCollection::$$table |
$_callbacks : array
Inherited
inherited_from |
\cGenericDb::$$_callbacks |
inherited_from |
\cItemBaseAbstract::$$_callbacks |
inherited_from |
\ItemCollection::$$_callbacks |
Constants
Callbacks are executed before a item is created.
CREATE_BEFORE
Inherited
Expected parameters for callback: none
inherited_from |
\cGenericDb::CREATE_BEFORE |
inherited_from |
\cItemBaseAbstract::CREATE_BEFORE |
inherited_from |
\ItemCollection::CREATE_BEFORE |
Callbacks are executed if item could not be created.
CREATE_FAILURE
Inherited
Expected parameters for callback: none
inherited_from |
\cGenericDb::CREATE_FAILURE |
inherited_from |
\cItemBaseAbstract::CREATE_FAILURE |
inherited_from |
\ItemCollection::CREATE_FAILURE |
Callbacks are executed if item could be created successfully.
CREATE_SUCCESS
Inherited
Expected parameters for callback: ID of created item
inherited_from |
\cGenericDb::CREATE_SUCCESS |
inherited_from |
\cItemBaseAbstract::CREATE_SUCCESS |
inherited_from |
\ItemCollection::CREATE_SUCCESS |
Callbacks are executed before deleting an item.
DELETE_BEFORE
Inherited
Expected parameters for callback: ID of them item to delete
inherited_from |
\cGenericDb::DELETE_BEFORE |
inherited_from |
\cItemBaseAbstract::DELETE_BEFORE |
inherited_from |
\ItemCollection::DELETE_BEFORE |
Callbacks are executed if deletion of an item fails.
DELETE_FAILURE
Inherited
Expected parameters for callback: ID of them item to delete
inherited_from |
\cGenericDb::DELETE_FAILURE |
inherited_from |
\cItemBaseAbstract::DELETE_FAILURE |
inherited_from |
\ItemCollection::DELETE_FAILURE |
Callbacks are executed if item was deleted successfully.
DELETE_SUCCESS
Inherited
Expected parameters for callback: ID of them item to delete
inherited_from |
\cGenericDb::DELETE_SUCCESS |
inherited_from |
\cItemBaseAbstract::DELETE_SUCCESS |
inherited_from |
\ItemCollection::DELETE_SUCCESS |
Callbacks are executed before store process is executed.
STORE_BEFORE
Inherited
Expected parameters for callback: Item instance
inherited_from |
\cGenericDb::STORE_BEFORE |
inherited_from |
\cItemBaseAbstract::STORE_BEFORE |
inherited_from |
\ItemCollection::STORE_BEFORE |
Callbacks are executed if store process failed.
STORE_FAILURE
Inherited
This is also likely to happen if query would not change anything in database!
Expected parameters for callback: Item instance
inherited_from |
\cGenericDb::STORE_FAILURE |
inherited_from |
\cItemBaseAbstract::STORE_FAILURE |
inherited_from |
\ItemCollection::STORE_FAILURE |
Callbacks are executed if store process saved the values in the database.
STORE_SUCCESS
Inherited
Expected parameters for callback: Item instance
inherited_from |
\cGenericDb::STORE_SUCCESS |
inherited_from |
\cItemBaseAbstract::STORE_SUCCESS |
inherited_from |
\ItemCollection::STORE_SUCCESS |