Stud.IP  2.4 Revision 48548
 All Data Structures Namespaces Files Functions Variables Groups Pages
SimpleORMap Class Reference
Inheritance diagram for SimpleORMap:
Inheritance graph
Collaboration diagram for SimpleORMap:
Collaboration graph

Public Member Functions

 __construct ($id=null)
 __clone ()
 getRelationOptions ($relation)
 getTableMetadata ()
 hasAutoIncrementColumn ()
 setId ($id)
 getId ()
 getNewId ()
 toArray ($only_these_fields=null)
 toArrayRecursive ($depth=1, $only_these_fields=null)
 getValue ($field)
 getRelationValue ($relation, $field)
 setValue ($field, $value)
 __get ($field)
 __set ($field, $value)
 __isset ($field)
 offsetExists ($offset)
 offsetGet ($offset)
 offsetSet ($offset, $value)
 offsetUnset ($offset)
 getIterator ()
 count ()
 isField ($field)
 isAdditionalField ($field)
 isAliasField ($field)
 setData ($data, $reset=false)
 haveData ()
 isNew ()
 isDeleted ()
 setNew ($is_new)
 getWhereQuery ()
 restore ()
 store ()
 triggerChdate ()
 delete ()
 isDirty ()
 isFieldDirty ($field)
 revertValue ($field)
 initRelation ($relation)
 resetRelation ($relation)

Static Public Member Functions

static expireTableScheme ()
static find ($id)
static exists ($id)
static countBySql ($where=1, $params=array())
static create ($data)
static import ($data)
static findBySQL ($where, $params=array())
static findThru ($foreign_key_value, $options)
static findEachBySQL ($callable, $where, $params=array())
static findMany ($pks=array(), $order= '')
static findEachMany ($callable, $pks=array(), $order= '')
static deleteBySQL ($where, $params=array())
static toObject ($id_or_object)
static __callStatic ($name, $arguments)

Protected Member Functions

 parseRelationOptions ($type, $name, $options)
 getTableScheme ()
 storeRelations ()
 deleteRelations ()
 initializeContent ()
 applyCallbacks ($type)
 registerCallback ($types, $cb)
 unregisterCallback ($types, $cb)
 cbAutoIncrementColumn ($type)
 cbAutoKeyCreation ()

Static Protected Member Functions

static tableScheme ($db_table)

Protected Attributes

 $content = array()
 $content_db = array()
 $is_new = true
 $db_table = ''
 $db_fields = null
 $pk = null
 $default_values = array()
 $alias_fields = array()
 $additional_fields = array()
 $relations = array()
 $has_many = array()
 $has_one = array()
 $belongs_to = array()
 $has_and_belongs_to_many = array()
 $registered_callbacks
 $known_slots = array()
 $reserved_slots = array('value','newid','iterator','tablemetadata', 'relationvalue','wherequery','relationoptions','data','new','id')

Static Protected Attributes

static $schemes

Constructor & Destructor Documentation

__construct (   $id = null)

constructor, give primary key of record as param to fetch corresponding record from db if available, if not preset primary key with given value. Give null to create new record

Parameters
mixed$idprimary key of table

Reimplemented in PersonalNotifications, StudipNews, WebserviceAccessRule, Semester, Institute, LockRule, CronjobSchedule, SemesterHoliday, Banner, DatafieldEntryModel, RoomRequest, StudipComment, StudipDocument, User, StudipScmEntry, StudipAdmissionGroup, SeminarCycleDate, Kategorie, CronjobLog, UserConfigEntry, StudipStudyArea, AdmissionApplication, ConfigEntry, ArchivedCourseMember, CourseMember, InstituteMember, AuthUserMd5, UserInfo, ArchivedCourse, Course, Datafield, NewsRange, and CronjobTask.

Member Function Documentation

static __callStatic (   $name,
  $arguments 
)
static

interceptor for static findByColumn / findEachByColumn magic

Parameters
string$name
array$arguments
Exceptions
BadMethodCallException
Returns
mixed
__clone ( )

clean up references after cloning

__get (   $field)

magic method for dynamic properties

__isset (   $field)

magic method for dynamic properties

__set (   $field,
  $value 
)

magic method for dynamic properties

applyCallbacks (   $type)
protected

invoke registered callbacks for given type if one callback returns false the following will not be invoked

Parameters
string$typetype of callback
Returns
bool return value from last callback
cbAutoIncrementColumn (   $type)
protected

default callback for tables with auto_increment primary key

Parameters
string$typecallback type
Returns
boolean

Here is the call graph for this function:

cbAutoKeyCreation ( )
protected

default callback for tables without auto_increment

count ( )

Countable

Here is the caller graph for this function:

static countBySql (   $where = 1,
  $params = array() 
)
static

returns number of records

Parameters
stringsql clause to use on the right side of WHERE
arrayparams for query
Returns
number

Here is the call graph for this function:

Here is the caller graph for this function:

static create (   $data)
static

creates new record with given data in db returns the new object or null

Parameters
arrayassoc array of record
Returns
SimpleORMap
delete ( )

delete entry from database the object is cleared, but is not(!) turned to new state

Returns
int number of deleted rows

Reimplemented in RoomRequest, StudipStmInstance, StudipNews, StudipAdmissionGroup, LockRule, SeminarCycleDate, Banner, and StudipDocument.

Here is the call graph for this function:

static deleteBySQL (   $where,
  $params = array() 
)
static

deletes table rows specified by given class and sql clause

Parameters
stringsql clause to use on the right side of WHERE
arrayparameters for query
Returns
number

Here is the call graph for this function:

Here is the caller graph for this function:

deleteRelations ( )
protected

sends a delete message to all related objects if a relation has a callback for 'on_delete' configured, the callback is invoked instead

Returns
number addition of all return values, false if none was called

Here is the call graph for this function:

static exists (   $id)
static

returns true if given key exists in db

Parameters
stringprimary key
Returns
boolean

Here is the call graph for this function:

static expireTableScheme ( )
static

force reload of cached table metadata

Here is the call graph for this function:

static find (   $id)
static

returns new instance for given key when found in db, else null

Parameters
stringprimary key
Returns
SimpleORMap|NULL

Reimplemented in StudipStudyArea, Semester, and SemesterHoliday.

Here is the caller graph for this function:

static findBySQL (   $where,
  $params = array() 
)
static

returns array of instances of given class filtered by given sql

Parameters
stringsql clause to use on the right side of WHERE
arrayparameters for query
Returns
array array of "self" objects

Here is the call graph for this function:

Here is the caller graph for this function:

static findEachBySQL (   $callable,
  $where,
  $params = array() 
)
static

passes objects for given sql through given callback and returns an array of callback return values

Parameters
callable$callablecallback which gets the current record as param
stringwhere clause of sql
arraysql statement parameters
Returns
array

Here is the call graph for this function:

static findEachMany (   $callable,
  $pks = array(),
  $order = '' 
)
static

passes objects for by given pks through given callback and returns an array of callback return values

Parameters
callable$callablecallback which gets the current record as param
array$pksarray of primary keys of called class
string$orderorder by sql
Returns
array

Here is the call graph for this function:

static findMany (   $pks = array(),
  $order = '' 
)
static

returns array of instances of given class for by given pks

Parameters
arrayarray og primary keys
stringorder by clause
Returns
array

Here is the call graph for this function:

Here is the caller graph for this function:

static findThru (   $foreign_key_value,
  $options 
)
static

find related records for a n:m relation (has_many_and_belongs_to_many) using a combination table holding the keys

Parameters
stringvalue of foreign key to find related records
arrayrelation options from other side of relation
Returns
array of "self" objects

Here is the call graph for this function:

getId ( )

returns primary key, multiple keys as array

Returns
string|array current primary key, null if not set

Here is the caller graph for this function:

getIterator ( )
getNewId ( )

create new unique pk as md5 hash if pk consists of multiple columns, false is returned

Returns
boolean|string

Here is the call graph for this function:

Here is the caller graph for this function:

getRelationOptions (   $relation)

returns array with option for given relation available options: 'type': relation type, on of 'has_many', 'belongs_to', 'has_one', 'has_and_belongs_to_many' 'class_name': name of class for related records 'foreign_key': name of column with foreign key or callback to retrieve foreign key value 'assoc_foreign_key': name of foreign key column in related class 'assoc_func': name of static method to call on related class to find related records 'assoc_func_params_func': callback to retrieve params for assoc_func 'thru_table': name of relation table for n:m relation 'thru_key': name of column holding foreign key in relation table 'thru_assoc_key': name of column holding foreign key from related class in relation table 'on_delete': contains simply 'delete' to indicate that related records should be deleted or callback to invoke before record gets deleted 'on_store': contains simply 'store' to indicate that related records should be stored or callback to invoke after record gets stored

Parameters
string$relationname of relation
Returns
array assoc array containing options
getRelationValue (   $relation,
  $field 
)

gets a value from a related object only possible, if the relation has cardinality 1 e.g. 'has_one' or 'belongs_to'

Parameters
string$relationname of relation
string$fieldname of column
Exceptions
InvalidArgumentExceptionif no relation with given name is found
Returns
mixed the value from the related object
getTableMetadata ( )

returns table metadata

Returns
array assoc array with columns, primary keys and name of table
getTableScheme ( )
protected

restore table metadata from db or cache

getValue (   $field)

returns value of a column

Exceptions
InvalidArgumentExceptionif column could not be found
BadMethodCallExceptionif getter for additional field could not be found
Parameters
string$field
Returns
null|string|SimpleORMapCollection

Reimplemented in StudipStmInstance, StudipAdmissionGroup, StudipStmInstanceElement, and CronjobTask.

Here is the caller graph for this function:

getWhereQuery ( )

returns sql clause with current table and pk

Returns
boolean|string

Here is the call graph for this function:

Here is the caller graph for this function:

hasAutoIncrementColumn ( )

returns true, if table has an auto_increment column

Returns
boolean
haveData ( )

check if object is empty

Returns
bool true if at least one field is not null
static import (   $data)
static

generate SimpleORMap object structure from assoc array if given array contains data of related objects in sub-arrays they are also generated. Existing records are updated, new records are created (but changes are not yet stored)

Parameters
array$data
Returns
SimpleORMap

Here is the call graph for this function:

initializeContent ( )
protected

init internal content arrays with nulls

Exceptions
UnexpectedValueExceptionif there is an unmatched alias
initRelation (   $relation)

intitalize a relationship and get related record(s)

Parameters
string$relationname of relation
Exceptions
InvalidArgumentExceptionif the relation does not exists
Returns
void
isAdditionalField (   $field)

check if given column is additional

Parameters
string$field
Returns
boolean
isAliasField (   $field)

check if given column is an alias

Parameters
string$field
Returns
boolean
isDeleted ( )

check if object was deleted

Returns
boolean
isDirty ( )

checks if at least one field was modified since last restore

Returns
boolean

Here is the caller graph for this function:

isField (   $field)

check if given column exists in table

Parameters
string$field
Returns
boolean
isFieldDirty (   $field)

checks if given field was modified since last restore

Parameters
string$field
Returns
boolean

Here is the caller graph for this function:

isNew ( )

check if object exists in database

Returns
boolean

Here is the caller graph for this function:

offsetExists (   $offset)

ArrayAccess: Check whether the given offset exists.

offsetGet (   $offset)

ArrayAccess: Get the value at the given offset.

offsetSet (   $offset,
  $value 
)

ArrayAccess: Set the value at the given offset.

offsetUnset (   $offset)

ArrayAccess: unset the value at the given offset (not applicable)

parseRelationOptions (   $type,
  $name,
  $options 
)
protected

try to determine all needed options for a relationship from configured options

Parameters
string$type
string$name
array$options
Exceptions
Exceptionif options for thru_table could not be determined
Returns
array
registerCallback (   $types,
  $cb 
)
protected

register given callback for one or many possible callback types callback param could be a closure or method name of current class

Parameters
string | array$typestypes to register callback for
mixed$cbcallback
Exceptions
InvalidArgumentExceptionif the callback type is not known
Returns
number of registered callbacks

Here is the call graph for this function:

Here is the caller graph for this function:

resetRelation (   $relation)

clear data for a relationship

Parameters
string$relationname of relation
Exceptions
InvalidArgumentExceptionif teh relation does not exists

Here is the caller graph for this function:

restore ( )

restore entry from database

Returns
boolean

Reimplemented in RoomRequest, StudipStmInstance, StudipStmInstanceElement, and StudipAdmissionGroup.

Here is the call graph for this function:

revertValue (   $field)

reverts value of given field to last restored value

Parameters
string$field
Returns
mixed the restored value
setData (   $data,
  $reset = false 
)

set multiple column values if second param is set, existing data in object will be discarded and dirty state is cleared, else new data overrides old data

Parameters
array$dataassoc array
boolean$resetexisting data in object will be discarded
Returns
number of columns changed

Reimplemented in StudipAdmissionGroup, and LockRule.

setId (   $id)

set primary key for entry, combined keys must be passed as array

Parameters
string|arrayprimary key
Exceptions
InvalidArgumentExceptionif given key is not complete
Returns
boolean

Here is the caller graph for this function:

setNew (   $is_new)

set object to new state

Parameters
boolean$is_new
Returns
boolean

Here is the caller graph for this function:

setValue (   $field,
  $value 
)

sets value of a column

Exceptions
InvalidArgumentExceptionif column could not be found
BadMethodCallExceptionif setter for additional field could not be found
Parameters
string$field
string$value
Returns
string

Here is the caller graph for this function:

store ( )

store entry in database

Exceptions
UnexpectedValueExceptionif there are forbidden NULL values
Returns
number|boolean

Reimplemented in RoomRequest, StudipStmInstance, User, CronjobSchedule, LockRule, and StudipAdmissionGroup.

Here is the call graph for this function:

Here is the caller graph for this function:

storeRelations ( )
protected

sends a store message to all initialized related objects if a relation has a callback for 'on_store' configured, the callback is instead invoked

Returns
number addition of all return values, false if none was called

Here is the call graph for this function:

Here is the caller graph for this function:

static tableScheme (   $db_table)
staticprotected

fetch table metadata from db or from local cache

Parameters
string$db_table
Returns
bool true if metadata could be fetched

Here is the call graph for this function:

toArray (   $only_these_fields = null)

returns data of table row as assoc array pass array of fieldnames or ws separated string to limit fields

Parameters
mixed$only_these_fieldslimit returned fields
Returns
array

Here is the call graph for this function:

Here is the caller graph for this function:

toArrayRecursive (   $depth = 1,
  $only_these_fields = null 
)

returns data of table row as assoc array including all related records with a 'has*' relationship

Parameters
$depthset to > 1 if related objects schuld also call their related records
mixed$only_these_fieldslimit returned fields
Returns
array

Reimplemented in User.

static toObject (   $id_or_object)
static

returns object of given class for given id or null the param could be a string, an assoc array containing primary key field or an already matching object. In all these cases an object is returned

Parameters
mixedid as string, object or assoc array
Returns
NULL|object

Here is the caller graph for this function:

triggerChdate ( )

set chdate column to current timestamp

Returns
boolean

Reimplemented in User.

Here is the call graph for this function:

Here is the caller graph for this function:

unregisterCallback (   $types,
  $cb 
)
protected

unregister given callback for one or many possible callback types

Parameters
string | array$typestypes to unregister callback for
mixed$cb
Exceptions
InvalidArgumentExceptionif the callback type is not known
Returns
number of unregistered callbacks

Here is the call graph for this function:

Field Documentation

array $additional_fields = array()
protected

additional computed fields name => callable

array $alias_fields = array()
protected

aliases for columns alias => column

array $belongs_to = array()
protected

n:1 relations

array $content = array()
protected

table row data

array $content_db = array()
protected

table row data

array $db_fields = null
protected

table columns

string $db_table = ''
protected

name of db table

array $default_values = array()
protected

default values for columns

array $has_and_belongs_to_many = array()
protected

n:m relations

array $has_many = array()
protected

1:n relation

array $has_one = array()
protected

1:1 relation

boolean $is_new = true
protected

new state of entry

array $known_slots = array()
protected

contains an array of all used identifiers for fields (db columns + aliased columns + additional columns + relations)

array $pk = null
protected

primary key columns

array $registered_callbacks
protected
Initial value:
array('before_create' => array(),
'before_update' => array(),
'before_store' => array(),
'before_delete' => array(),
'after_create' => array(),
'after_update' => array(),
'after_store' => array(),
'after_delete' => array(),
'after_initialize' => array())

callbacks

array $relations = array()
protected

stores instantiated related objects

array $reserved_slots = array('value','newid','iterator','tablemetadata', 'relationvalue','wherequery','relationoptions','data','new','id')
protected

reserved indentifiers, fields with those names must not have an explicit getXXX() method

array $schemes
staticprotected

db table metadata


The documentation for this class was generated from the following file: