Category collection

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(string $select) : void

Parameters

$select

string

Select statement (see ItemCollection::select())

Exceptions

\cInvalidArgumentException If table name or primary key is not set

Adds a result field

addResultField(string $sField) 
Inherited
inherited_from \ItemCollection::addResultField()

Parameters

$sField

string

cApiCategoryCollection()

cApiCategoryCollection($select) 
deprecated [2011-03-15] Old constructor function for downwards compatibility

Parameters

$select

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

object\Itemnull

Returns the amount of returned items

count() : int
Inherited
inherited_from \ItemCollection::count()

Returns

intNumber of rows

Creates a category entry.

create(int $idclient, int $parentid, int $preid, int $postid, int $status, string $author, string $created, string $lastmodified) : \cApiCategory

Parameters

$idclient

int

$parentid

int

$preid

int

$postid

int

$status

int

$author

string

$created

string

$lastmodified

string

Returns

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

createNewItem(string | array $data) : \Item
Inherited
inherited_from \ItemCollection::createNewItem()

Parameters

$data

stringarray

optional parameter for direct input of primary key value (string) or multiple column name - value pairs

Returns

\ItemThe 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

intNumber 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

intNumber 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

stringEscaped 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

boolTrue 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

arrayResulting array

Loads a single entry by it's id.

fetchById(string | int $id) : \Item
Inherited
inherited_from \ItemCollection::fetchById()

Parameters

$id

stringint

The primary key of the item to load.

Returns

\ItemThe loaded item

Returns the last category tree entry from the category table for a specific client.

fetchLastCategoryTree(int $idclient) : \cApiCategory

Last entry has no parentid and no postid.

Parameters

$idclient

int

Returns

Fetches the resultset related to current loaded primary key as an object

fetchObject(\Item $sClassName) 
Inherited
inherited_from \ItemCollection::fetchObject()

Parameters

$sClassName

\Item

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

boolTrue on success, otherwhise false

Returns list of all child category ids and their child category ids of passed category id.

getAllCategoryIdsRecursive(int $idcat, int $idclient) : array

The list also contains the id of passed category.

The return value of this function could be used to perform bulk actions on a specific category an all of its childcategories.

NOTE: The returned array is not sorted! Return value is similar to getAllCategoryIdsRecursive2, only the sorting differs

Example:

...
this_category (*)
child_category (*)
child_category2 (*)
child_of_child_category2 (*)
child_category3 (*)
child_of_child_category3 (*)
...
(*) Returned category ids
global array $cfg

Parameters

$idcat

int

$idclient

int

Returns

array

Returns list of all child category ids and their child category ids of passed category id.

getAllCategoryIdsRecursive2(int $idcat, $idclient) : array

The list also contains the id of passed category.

The return value of this function could be used to perform bulk actions on a specific category an all of its childcategories.

NOTE: Return value is similar to getAllCategoryIdsRecursive, only the sorting differs

Example:

...
this_category (*)
child_category (*)
child_category2 (*)
child_of_child_category2 (*)
child_category3 (*)
child_of_child_category3 (*)
...
(*) Returned category ids
global array $cfg

Parameters

$idcat

int

$idclient

Returns

arraySorted by category id

Returns list of all child category ids, only them on next deeper level (not recursive!) The returned array contains already the order of the categories.

getAllChildCategoryIds(int $idcat, int | null $idlang) : array

Example:

...
this_category
child_category (*)
child_category2 (*)
child_of_child_category2
child_category3 (*)
...
(*) Returned category ids
global array $cfg

Parameters

$idcat

int

$idlang

intnull

Returns

array

Returns all ids of recordsets in the table.

getAllIds() : array
Inherited
inherited_from \ItemCollection::getAllIds()

Returns

arrayList of ids

Returns list of categories (category ids) by passed client.

getCategoryIdsByClient(int $idclient) : array

Parameters

$idclient

int

Returns

array

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

arrayList of entries with specified fields

Returns id of first child category, where parent id is the same as passed id and the previous id is 0.

getFirstChildCategoryId(int $idcat, int | null $idlang) : int

Example:

...
this_category
child_category (*)
child_category2
child_category3
...
(*) Returned category id
global array $cfg

Parameters

$idcat

int

$idlang

intnull

If defined, it checks also if there is a next deeper category in this language.

Returns

int

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

arrayList of ids

Returns the id of category which is located after passed category id.

getNextPostCategoryId(int $idcat) : int

Example:

...
parent_category
this_category
post_category (*)
...
(*) Returned category id

Parameters

$idcat

int

Returns

int

Returns the id of category which is located after passed category ids parent category.

getParentsNextPostCategoryId(int $idcat) : int

Example:

...
root_category
parent_category
previous_cateory
this_category
post_category
parents_post_category (*)
...
(*) Returned category id

Parameters

$idcat

int

Category id

Returns

int

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

\cException If item class is not set

Returns

\ItemThe newly created object

Advances to the next item in the database.

next() : \Item | bool
Inherited
inherited_from \ItemCollection::next()

Returns

\ItemboolThe next object, or false if no more objects

Builds and runs the query

query() : bool
Inherited
inherited_from \ItemCollection::query()

Exceptions

\cException if no item class has been set

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

arrayResult

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

\cInvalidArgumentException if event or class are not set or the callback is not callable

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

boolTrue 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

\cInvalidArgumentException if the event or the class are not set

Builds a where statement out of the setGroupWhere calls

_buildGroupWhereStatements() : array
Inherited
inherited_from \ItemCollection::_buildGroupWhereStatements()

Returns

arrayWith all where statements

Builds a where statement out of the setWhere calls

_buildWhereStatements() : array
Inherited
inherited_from \ItemCollection::_buildWhereStatements()

Returns

arrayWith 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

intNumber 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

\cInvalidArgumentException if the event or class is not set

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

\cException if no join partner could be found

Returns

arrayArray 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

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

\cInvalidArgumentException if the given class can not be instantiated

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

\cInvalidArgumentException if the given foreign class can not be instantiated

 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
 

$_driver : \cGenericDbDriver
Inherited
inherited_from \ItemCollection::$$_driver
 

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