contenido\classes\class.genericdb.php

Show: PublicProtectedPrivateinherited
Table of Contents
Project: Contenido Content Management System

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

Package: Default
Class Item Class for database based items
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

>VPropertypublicarray $_arrInFilters = array('urlencode', 'conHtmlSpecialChars', 'addslashes')
Array storing the funcion names of the filters used when data is stored to the db
Default valuearray('urlencode', 'conHtmlSpecialChars', 'addslashes')Details
Type
array
Access
private  
>VPropertypublicarray $_arrOutFilters = array('stripslashes', 'htmldecode', 'urldecode')
Array storing the funcion names of the filters used when data is retrieved from the db
Default valuearray('stripslashes', 'htmldecode', 'urldecode')Details
Type
array
Access
private  
>VPropertypublic$_metaObject
Details
Type
n/a
>VPropertypublicarray $cache
Cache the result items
Details
Type
array
Access
private  
>VPropertypublicobject $db
DB_Contenido instance
Details
Type
object
Access
private  
>VPropertypublicstring $lasterror
Storage of the last error
Details
Type
string
Access
private  
>VPropertypublicint $lifetime

Lifetime in seconds

Details
Type
int
Access
private  
>VPropertypublicarray $modifiedValues
Storage of the fields which were modified
Details
Type
array
Access
private  
>VPropertypublicstring $oldPrimaryKey
stores the old primary key, just in case somebody wants to change it
Details
Type
string
Access
private  
>VPropertypublicobject $primaryKey
Primary key of the table
Details
Type
object
Access
private  
>VPropertypublicobject $properties

PropertyCollection object

Details
Type
object
Access
private  
>VPropertypublicstring $table
Storage of the source table to use for the user informations
Details
Type
string
Access
private  
>VPropertypublicarray $values
Storage of the source table to use for the user informations
Details
Type
array
Access
private  
>VPropertypublicboolean $virgin
Checks for the virginity of this object.

If true, the object is virgin and no operations on it except load-Functions are allowed.

Details
Type
boolean
Access
private  

Methods

methodpublicItem(string $table = "", string $primaryKey = "",  $lifetime = 10) : void

Constructor Function

Parameters
NameTypeDescription
$tablestring

The table to use as information source

$primaryKeystring

The primary key to use

$lifetime
methodpublic_inFilter(mixed $data) : mixed

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

Parameters
NameTypeDescription
$datamixed

Data to filter

Returns
TypeDescription
mixedFiltered data
Details
Access
private  
See
\setFilters  
methodpublic_onLoad() : \none

_onLoad ()

Function which is called whenever an item is loaded. Inherited classes should override this function if desired.

Returns
TypeDescription
\none
methodpublic_outFilter(mixed $data) : mixed

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

Parameters
NameTypeDescription
$datamixed

Data to filter

Returns
TypeDescription
mixedFiltered data
Details
Access
private  
See
\setFilters  
methodpublic_setMetaObject( $objectname) : void

Parameters
NameTypeDescription
$objectname
methodpublicdeleteProperty(string $type, string $name) : void

deleteProperty ($type, $name) Deletes a custom property

Parameters
NameTypeDescription
$typestring

Specifies the type

$namestring

Specifies the name

methodpublicget(string $field) : mixed

get($field) Wrapper for getField (less to type)

Parameters
NameTypeDescription
$fieldstring

Specifies the field to retrieve

Returns
TypeDescription
mixedValue of the field
methodpublicgetField(string $field) : mixed

getField($field) Gets the value of a specific field

Parameters
NameTypeDescription
$fieldstring

Specifies the field to retrieve

Returns
TypeDescription
mixedValue of the field
methodpublicgetMetaObject() : void

methodpublicgetProperty(string $type, string $name) : boolean

getProperty ($type, $name) Sets a custom property

Parameters
NameTypeDescription
$typestring

Specifies the type

$namestring

Specifies the name

Returns
TypeDescription
booleanValue of the given property
methodpublicloadBy(string $field, string $value, bool $bSafe = true) : bool

loadBy ($field, $value) Loads an item by colum/field from the database

Parameters
NameTypeDescription
$fieldstring

Specifies the field

$valuestring

Specifies the value

$bSafebool

use inFilter or not

Returns
TypeDescription
boolTrue if the load was successful
methodpublicloadByPrimaryKey(string $value) : bool

loadByPrimaryKey ($value) Loads an item by ID from the database

Parameters
NameTypeDescription
$valuestring

Specifies the primary key value

Returns
TypeDescription
boolTrue if the load was successful
methodpublicset(string $field, string $value,  $safe = true) : void

set($field, $value) Shortcut to setField

Parameters
NameTypeDescription
$fieldstring

Specifies the field to set

$valuestring

Specifies the value to set

$safe
methodpublicsetField(string $field, string $value, boolean $safe = true) : void

setField($field, $value) Sets the value of a specific field

Parameters
NameTypeDescription
$fieldstring

Specifies the field to set

$valuestring

Specifies the value to set

$safeboolean

Speficies if we should translate characters

methodpublicsetFilters(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'));

Parameters
NameTypeDescription
$arrInFiltersarray

inFilters array with function names

$arrOutFiltersarray

outFilters array with function names

methodpublicsetProperty(string $type, string $name, string $value) : void

setProperty ($type, $name, $value) Sets a custom property

Parameters
NameTypeDescription
$typestring

Specifies the type

$namestring

Specifies the name

$valuestring

Specifies the value

methodpublicstore() : void

store() Stores the modified user object to the database

\ItemCollection

Package: Default
Class ItemCollection Class for database based item collections
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

>VPropertypublicarray $_JoinPartners

Reverse join partners for this data object

Details
Type
array
Access
private  
>VPropertypublicstring $_encoding

Encoding

Details
Type
string
Access
private  
>VPropertypublicarray $_forwardJoinPartners

Forward join partners for this data object

Details
Type
array
Access
private  
>VPropertypublicarray $_groupConditions

Group conditions

Details
Type
array
Access
private  
>VPropertypublicarray $_innerGroupConditions = array()

Inner group conditions

Default valuearray()Details
Type
array
Access
private  
>VPropertypublicstring $_itemClass

Single item class

Details
Type
string
Access
private  
>VPropertypublicobject $_iteratorItem

Iterator object for the next() method

Details
Type
object
Access
private  
>VPropertypublicarray $_resultFields = array()

Result fields for the query

Default valuearray()Details
Type
array
Access
private  
>VPropertypublicarray $_whereRestriction

Where restrictions for the query

Details
Type
array
Access
private  
>VPropertypublicarray $cache
Cache the result items
Details
Type
array
Access
private  
>VPropertypublicobject $db
DB_Contenido instance
Details
Type
object
Access
private  
>VPropertypublicstring $lasterror
Storage of the last error
Details
Type
string
Access
private  
>VPropertypublicint $lifetime

Lifetime in seconds

Details
Type
int
Access
private  
>VPropertypublicstring $objects
Storage of all result items
Details
Type
string
Access
private  
>VPropertypublicstring $primaryKey
Storage of the primary key
Details
Type
string
Access
private  
>VPropertypublicarray $properties

Property collection

Details
Type
array
Access
private  
>VPropertypublicstring $table
Storage of the source table to use for the information
Details
Type
string
Access
private  
>VPropertypublicarray $virgin

Is entry virgin?

Details
Type
array
Access
private  

Methods

methodpublicItemCollection(string $table,  $primaryKey,  $lifetime = 10) : void

Constructor Function Note: Default lifetime is 10 seconds.

Parameters
NameTypeDescription
$tablestring

The table to use as information source

$primaryKey
$lifetime
methodpublic_buildGroupWhereStatements() : array

_buildGroupWhereStatements ()

Builds a where statement out of the setGroupWhere calls

Returns
TypeDescription
arraywith all where statements
methodpublic_buildWhereStatements() : array

_buildWhereStatements ()

Builds a where statement out of the setWhere calls

Returns
TypeDescription
arraywith all where statements
methodpublic_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

Parameters
NameTypeDescription
$ignore_root\none
Returns
TypeDescription
arraysee above
methodpublic_findReverseJoinPartner( $parentclass,  $classname) : void

Parameters
NameTypeDescription
$parentclass
$classname
methodpublic_initializeDriver( $bForceInit = false) : void

_initializeDriver: Initializes the driver to use with GenericDB.

Parameters
NameTypeDescription
$bForceInit

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

methodpublic_recursiveStructuredFetch( $objects,  $array) : void

Parameters
NameTypeDescription
$objects
$array
methodpublic_resolveLinks() : void

methodpublic_setItemClass(string $classname) : \none

_setItemClass: private method to set the accompanying item object.

Parameters
NameTypeDescription
$classnamestring

specifies the classname

Returns
TypeDescription
\none
methodpublic_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

Parameters
NameTypeDescription
$foreignCollectionClassstring

Specifies the foreign class to use

Returns
TypeDescription
\none
methodpublicaddResultField( $field) : void

Parameters
NameTypeDescription
$field
methodpubliccount() : integer

count () Returns the amount of returned items

Returns
TypeDescription
integerNumber of rows
methodpubliccreate() : void

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

methodpublicdelete( $id) : void

delete() Deletes an item in the table.

Parameters
NameTypeDescription
$id
methodpublicdeleteWhere( $field,  $restriction,  $operator = "=") : void

deleteWhere ($field, $restriction, $operator)

Restricts a query with a where clause

Parameters
NameTypeDescription
$field
$restriction
$operator
methodpublicdeleteWhereGroup( $group,  $field,  $restriction,  $operator = "=") : void

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

Restricts a query with a where clause, groupable

Parameters
NameTypeDescription
$group
$field
$restriction
$operator
methodpublicexists(integer $id) : boolean

exists ($id) Checks if a specific entry exists

Parameters
NameTypeDescription
$idinteger

The id to check for

Returns
TypeDescription
booleantrue if object exists, false if not
methodpublicfetchArray( $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.

Parameters
NameTypeDescription
$key

string Name of the field to use for the key

$fields

mixed String or array

Returns
TypeDescription
arrayResulting array
methodpublicfetchObject( $class) : void

Parameters
NameTypeDescription
$class
methodpublicfetchTable( $fields = array(),  $objects = array()) : void

Parameters
NameTypeDescription
$fields
$objects
methodpublicflexSelect(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.

Parameters
NameTypeDescription
$distinctstring

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

$fromstring

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

$wherestring

Specifies the where clause.

$group_bystring

Specifies the group by clause.

$order_bystring

Specifies the order by clause.

$limitstring

Specifies the limit by clause.

Returns
TypeDescription
arrayArray of DBObject-Objects
Details
Author
HerrB  
methodpubliclink( $foreignClass) : void

sets the query to use foreign tables in the resultset

Parameters
NameTypeDescription
$foreignClass
methodpublicloadItem( $vitem) : object

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

Needs to be overridden by the extension class.

Parameters
NameTypeDescription
$vitem
Returns
TypeDescription
objectThe newly created object
methodpublicnext() : object

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

Returns
TypeDescription
objectThe next object, or false if no more objects
methodpublicquery() : void

methodpublicqueryAndFetchStructured(\objects $objects) : array

fetchStructured Returns an array of arrays

Parameters
NameTypeDescription
$objects\objects

array with the correct order of the objects

Returns
TypeDescription
arrayresult
methodpublicremoveResultField( $field) : void

Parameters
NameTypeDescription
$field
methodpublicresetQuery() : void

methodpublicselect(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.

Parameters
NameTypeDescription
$wherestring

Specifies the where clause.

$group_bystring

Specifies the group by clause.

$order_bystring

Specifies the order by clause.

$limitstring

Specifies the limit by clause.

Returns
TypeDescription
arrayArray of DBObject-Objects
methodpublicsetEncoding( $sEncoding) : void

Parameters
NameTypeDescription
$sEncoding
methodpublicsetGroupCondition( $group1,  $group2,  $condition = "AND") : void

setGroupCondition ($group1, $group2, $condition)

Defines how groups are linked to each other

Parameters
NameTypeDescription
$group1
$group2
$condition
methodpublicsetInnerGroupCondition( $group,  $condition = "AND") : void

setInnerGroupCondition ($group, $condition)

Defines how relations in one group are linked each together

Parameters
NameTypeDescription
$group
$condition
methodpublicsetLimit( $iRowStart,  $iRowCount) : void

Parameters
NameTypeDescription
$iRowStart
$iRowCount
methodpublicsetOrder( $order) : void

Parameters
NameTypeDescription
$order
methodpublicsetWhere( $field,  $restriction,  $operator = "=") : void

setWhere ($field, $restriction, $operator)

Restricts a query with a where clause

Parameters
NameTypeDescription
$field
$restriction
$operator
methodpublicsetWhereGroup( $group,  $field,  $restriction,  $operator = "=") : void

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

Restricts a query with a where clause, groupable

Parameters
NameTypeDescription
$group
$field
$restriction
$operator
Documentation was generated by phpDocumentor 2.0.0a12.