contenido\classes\class.genericdb.php
Description: Generic database abstraction functions
Requirements:
- Author
- Timo A. Hummel
- Con_php_req
- 5.0
- Copyright
- four for business AG
- License
- http://www.contenido.org/license/LIZENZ.txt
- Link
- http://www.4fb.de
- Link
- http://www.contenido.org
- Package
- Contenido Backend classes
- Since
- file available since contenido release <= 4.6 {@internal created 3003-07-18 modified 2008-07-02, Frederic Schneider, add security fix modified 2010-05-20, Murat Purc, Removed check of $_REQUEST['cfg'] during processing ticket [#CON-307] $Id: class.genericdb.php 1157 2010-05-20 14:10:43Z xmurrix $: }}
- Version
- 1.0.2
\Item
- Children
- \Article
- \ArtSpecItem
- \CategoryItem
- \CategoryLanguageItem
- \CommunicationItem
- \DBFSItem
- \FrontendGroup
- \FrontendGroupMember
- \FrontendPermission
- \FrontendUser
- \InUseItem
- \Language
- \RecipientGroup
- \RecipientGroupMember
- \cNewsletterJob
- \cNewsletterLog
- \Newsletter
- \Recipient
- \PropertyItem
- \UploadItem
- \cApiAction
- \cApiArea
- \cApiArticle
- \cApiArticleLanguage
- \cApiCategory
- \cApiCategoryArticle
- \cApiCategoryLanguage
- \cApiTree
- \cApiClient
- \cApiClientLanguage
- \cApiContainer
- \cApiContainerConfiguration
- \cApiFile
- \cApiFrameFile
- \cApiLanguage
- \cApiLayout
- \cApiModule
- \cApiModuleTranslation
- \cApiTemplate
- \cApiTemplateConfiguration
- \cApiUser
- \Workflow
- \WorkflowAction
- \WorkflowAllocation
- \WorkflowArtAllocation
- \WorkflowItem
- \WorkflowTask
- \WorkflowUserSequence
- Author
- Timo A. Hummel
- Copyright
- four for business 2003
- Version
- 0.1
Properties


array $_arrInFilters = array('urlencode', 'conHtmlSpecialChars', 'addslashes')
array('urlencode', 'conHtmlSpecialChars', 'addslashes')
Details- Type
- array
- Access
- private


array $_arrOutFilters = array('stripslashes', 'htmldecode', 'urldecode')
array('stripslashes', 'htmldecode', 'urldecode')
Details- Type
- array
- Access
- private


string $oldPrimaryKey
- Type
- string
- Access
- private


string $table
- Type
- string
- Access
- private


array $values
- Type
- array
- Access
- private
Methods


Item(string $table = "", string $primaryKey = "", $lifetime = 10) : void
Constructor Function
Name | Type | Description |
---|---|---|
$table | string | The table to use as information source |
$primaryKey | string | The primary key to use |
$lifetime |


_inFilter(mixed $data) : mixed
Filters the passed data using the functions defines in the _arrInFilters array.
Name | Type | Description |
---|---|---|
$data | mixed | Data to filter |
Type | Description |
---|---|
mixed | Filtered data |
- Access
- private
- See
- \setFilters


_onLoad() : \none
_onLoad ()
Function which is called whenever an item is loaded. Inherited classes should override this function if desired.
Type | Description |
---|---|
\none |


_outFilter(mixed $data) : mixed
Filters the passed data using the functions defines in the _arrOutFilters array.
Name | Type | Description |
---|---|---|
$data | mixed | Data to filter |
Type | Description |
---|---|
mixed | Filtered data |
- Access
- private
- See
- \setFilters


deleteProperty(string $type, string $name) : void
deleteProperty ($type, $name) Deletes a custom property
Name | Type | Description |
---|---|---|
$type | string | Specifies the type |
$name | string | Specifies the name |


get(string $field) : mixed
get($field) Wrapper for getField (less to type)
Name | Type | Description |
---|---|---|
$field | string | Specifies the field to retrieve |
Type | Description |
---|---|
mixed | Value of the field |


getField(string $field) : mixed
getField($field) Gets the value of a specific field
Name | Type | Description |
---|---|---|
$field | string | Specifies the field to retrieve |
Type | Description |
---|---|
mixed | Value of the field |


getProperty(string $type, string $name) : boolean
getProperty ($type, $name) Sets a custom property
Name | Type | Description |
---|---|---|
$type | string | Specifies the type |
$name | string | Specifies the name |
Type | Description |
---|---|
boolean | Value of the given property |


loadBy(string $field, string $value, bool $bSafe = true) : bool
loadBy ($field, $value) Loads an item by colum/field from the database
Name | Type | Description |
---|---|---|
$field | string | Specifies the field |
$value | string | Specifies the value |
$bSafe | bool | use inFilter or not |
Type | Description |
---|---|
bool | True if the load was successful |


loadByPrimaryKey(string $value) : bool
loadByPrimaryKey ($value) Loads an item by ID from the database
Name | Type | Description |
---|---|---|
$value | string | Specifies the primary key value |
Type | Description |
---|---|
bool | True if the load was successful |


set(string $field, string $value, $safe = true) : void
set($field, $value) Shortcut to setField
Name | Type | Description |
---|---|---|
$field | string | Specifies the field to set |
$value | string | Specifies the value to set |
$safe |


setField(string $field, string $value, boolean $safe = true) : void
setField($field, $value) Sets the value of a specific field
Name | Type | Description |
---|---|---|
$field | string | Specifies the field to set |
$value | string | Specifies the value to set |
$safe | boolean | Speficies if we should translate characters |


setFilters(array $arrInFilters = array(), array $arrOutFilters = array()) : void
Define the filter functions used when data is being stored or retrieved from the database.
Examples:
$obj->setFilters(array('addslashes'), array('stripslashes')); $obj->setFilters(array('htmlencode', 'addslashes'), array('stripslashes', 'htmlencode'));
Name | Type | Description |
---|---|---|
$arrInFilters | array | inFilters array with function names |
$arrOutFilters | array | outFilters array with function names |


setProperty(string $type, string $name, string $value) : void
setProperty ($type, $name, $value) Sets a custom property
Name | Type | Description |
---|---|---|
$type | string | Specifies the type |
$name | string | Specifies the name |
$value | string | Specifies the value |
\ItemCollection
- Children
- \ArtSpecCollection
- \CategoryCollection
- \CategoryLanguageCollection
- \CommunicationCollection
- \DBFSCollection
- \FrontendGroupCollection
- \FrontendGroupMemberCollection
- \FrontendPermissionCollection
- \FrontendUserCollection
- \InUseCollection
- \Languages
- \RecipientGroupCollection
- \RecipientGroupMemberCollection
- \cNewsletterJobCollection
- \cNewsletterLogCollection
- \NewsletterCollection
- \RecipientCollection
- \PropertyCollection
- \UploadCollection
- \cApiActionCollection
- \cApiAreaCollection
- \cApiArticleCollection
- \cApiArticleLanguageCollection
- \cApiCategoryCollection
- \cApiCategoryArticleCollection
- \cApiCategoryLanguageCollection
- \cApiCategoryTreeCollection
- \cApiClientCollection
- \cApiClientLanguageCollection
- \cApiContainerCollection
- \cApiContainerConfigurationCollection
- \cApiFileCollection
- \cApiFrameFileCollection
- \cApiLanguageCollection
- \cApiLayoutCollection
- \cApiModuleCollection
- \cApiModuleTranslationCollection
- \cApiTemplateCollection
- \cApiTemplateConfigurationCollection
- \cApiUserCollection
- \Workflows
- \WorkflowActions
- \WorkflowAllocations
- \WorkflowArtAllocations
- \WorkflowItems
- \WorkflowTasks
- \WorkflowUserSequences
- Author
- Timo A. Hummel
- Copyright
- four for business 2003
- Version
- 0.1
Properties


array $_innerGroupConditions = array()
Inner group conditions
array()
Details- Type
- array
- Access
- private


array $_resultFields = array()
Result fields for the query
array()
Details- Type
- array
- Access
- private
Methods


ItemCollection(string $table, $primaryKey, $lifetime = 10) : void
Constructor Function Note: Default lifetime is 10 seconds.
Name | Type | Description |
---|---|---|
$table | string | The table to use as information source |
$primaryKey | ||
$lifetime |


_buildGroupWhereStatements() : array
_buildGroupWhereStatements ()
Builds a where statement out of the setGroupWhere calls
Type | Description |
---|---|
array | with all where statements |


_buildWhereStatements() : array
_buildWhereStatements ()
Builds a where statement out of the setWhere calls
Type | Description |
---|---|
array | with all where statements |


_fetchJoinTables(\none $ignore_root) : array
_fetchJoinTables ()
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
Name | Type | Description |
---|---|---|
$ignore_root | \none |
Type | Description |
---|---|
array | see above |


_findReverseJoinPartner( $parentclass, $classname) : void
Name | Type | Description |
---|---|---|
$parentclass | ||
$classname |


_initializeDriver( $bForceInit = false) : void
_initializeDriver: Initializes the driver to use with GenericDB.
Name | Type | Description |
---|---|---|
$bForceInit | boolean If true, forces the driver to initialize, even if it already exists. |


_setItemClass(string $classname) : \none
_setItemClass: private method to set the accompanying item object.
Name | Type | Description |
---|---|---|
$classname | string | specifies the classname |
Type | Description |
---|---|
\none |


_setJoinPartner(string $foreignCollectionClass) : \none
_setJoinPartner: Defines the reverse links for this table.
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
Name | Type | Description |
---|---|---|
$foreignCollectionClass | string | Specifies the foreign class to use |
Type | Description |
---|---|
\none |


count() : integer
count () Returns the amount of returned items
Type | Description |
---|---|
integer | Number of rows |


deleteWhere( $field, $restriction, $operator = "=") : void
deleteWhere ($field, $restriction, $operator)
Restricts a query with a where clause
Name | Type | Description |
---|---|---|
$field | ||
$restriction | ||
$operator |


deleteWhereGroup( $group, $field, $restriction, $operator = "=") : void
deleteWhereGroup ($group, $field, $restriction, $operator)
Restricts a query with a where clause, groupable
Name | Type | Description |
---|---|---|
$group | ||
$field | ||
$restriction | ||
$operator |


exists(integer $id) : boolean
exists ($id) Checks if a specific entry exists
Name | Type | Description |
---|---|---|
$id | integer | The id to check for |
Type | Description |
---|---|
boolean | true if object exists, false if not |


fetchArray( $key, $fields) : array
fetchArray() Fetches an array of fields from the database.
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.
Name | Type | Description |
---|---|---|
$key | string Name of the field to use for the key | |
$fields | mixed String or array |
Type | Description |
---|---|
array | Resulting array |


fetchTable( $fields = array(), $objects = array()) : void
Name | Type | Description |
---|---|---|
$fields | ||
$objects |


flexSelect(string $distinct = "", string $from = "", string $where = "", string $group_by = "", string $order_by = "", string $limit = "") : array
flexSelect ($distinct = "", $from = "", $where = "", $group_by = "", $order_by = "", $limit = "") Selects all entries from the database and returns them as DBObject-objects to the user.
Objects are loaded using their primary key.
Name | Type | Description |
---|---|---|
$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. |
Type | Description |
---|---|
array | Array of DBObject-Objects |
- Author
- HerrB


link( $foreignClass) : void
sets the query to use foreign tables in the resultset
Name | Type | Description |
---|---|---|
$foreignClass |


loadItem( $vitem) : object
loadItem ($item) Loads a single object from the database.
Needs to be overridden by the extension class.
Name | Type | Description |
---|---|---|
$vitem |
Type | Description |
---|---|
object | The newly created object |


next() : object
next () Advances to the next item in the database.
Type | Description |
---|---|
object | The next object, or false if no more objects |


queryAndFetchStructured(\objects $objects) : array
fetchStructured Returns an array of arrays
Name | Type | Description |
---|---|---|
$objects | \objects | array with the correct order of the objects |
Type | Description |
---|---|
array | result |


select(string $where = "", string $group_by = "", string $order_by = "", string $limit = "") : array
select ($where = "", $group_by = "", $order_by = "", $limit = "") Selects all entries from the database and returns them as DBObject-objects to the user.
Objects are loaded using their primary key.
Name | Type | Description |
---|---|---|
$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. |
Type | Description |
---|---|
array | Array of DBObject-Objects |


setGroupCondition( $group1, $group2, $condition = "AND") : void
setGroupCondition ($group1, $group2, $condition)
Defines how groups are linked to each other
Name | Type | Description |
---|---|---|
$group1 | ||
$group2 | ||
$condition |


setInnerGroupCondition( $group, $condition = "AND") : void
setInnerGroupCondition ($group, $condition)
Defines how relations in one group are linked each together
Name | Type | Description |
---|---|---|
$group | ||
$condition |


setWhere( $field, $restriction, $operator = "=") : void
setWhere ($field, $restriction, $operator)
Restricts a query with a where clause
Name | Type | Description |
---|---|---|
$field | ||
$restriction | ||
$operator |