eZPersistentObject Class Reference
[Kernel system]

Allows for object persistence in a database. More...

Inheritance diagram for eZPersistentObject:

eZBasket eZBinaryFile eZCollaborationGroup eZCollaborationItem eZCollaborationItemGroupLink eZCollaborationItemMessageLink eZCollaborationItemParticipantLink eZCollaborationItemStatus eZCollaborationProfile eZCollaborationSimpleMessage eZContentClassAttribute eZContentObject eZContentObjectAttribute eZContentObjectTreeNode eZContentObjectVersion eZContentTranslation eZDiscountRule eZDiscountSubRule eZDiscountSubRuleValue eZEnumObjectValue eZEnumValue eZForgotPassword eZForgotPassword eZImage eZImageVariation eZInformationCollection eZInformationCollectionAttribute eZMedia eZModuleRun eZNodeAssignment eZOperationMemento eZOrder eZOrderItem eZPolicy eZPolicyLimitation eZPolicyLimitationValue eZProductCollection eZProductCollectionItem eZProductCollectionItemOption eZPublishOnTimeValue eZRole eZSection eZTrigger eZURL eZUser eZUserAccountKey eZUserDiscountRule eZVatType eZWaitUntilDateValue eZWishList eZWorkflowGroup List of all members.

Public Methods

 eZPersistentObject ($row)
 fill (&$row)
fetchObject (&$def,$field_filters,$conds,$asObject=true,$grouping=null,$custom_fields=null)
 remove ($conditions=null,$extraConditions=null)
 removeObject (&$def,$conditions=null,$extraConditions=null)
 store ($fieldFilters=null)
 sync ($fieldFilters=null)
conditionText (&$conditions)
conditionTextByRow (&$conditions,&$row)
fetchObjectList (&$def,$field_filters=null,$conds=null,$sorts=null,$limit=null,$asObject=true,$grouping=false,$custom_fields=null)
 swapRow ($table,&$keys,&$order_id,&$rows,$id1,$id2)
 newObjectOrder (&$def,$orderField,$conditions)
 reorderObject (&$def,$orderField,$conditions,$down=true)
definition ()
attributes ()
 hasAttribute ($attr)
attribute ($attr)
 setAttribute ($attr,$val)
 hasDirtyData ()
 setHasDirtyData ($hasDirtyData)

Private Methods

 storeObject (&$obj,$fieldFilters=null)

Private Attributes

 PersistentDataDirty

Detailed Description

Allows for object persistence in a database.

Classes which stores simple types in databases should inherit from this and implement the definition() function. The class will then get initialization, fetching, listing, moving, storing and deleting for free as well as attribute access. The new class must have a constructor which takes one parameter called $row and pass that this constructor.

class MyClass extends eZPersistentObject
{
    function MyClass( $row )
    {
        $this->eZPersistentObject( $row );
    }
}

Definition at line ezpersistentobject.php.


Constructor & Destructor Documentation

eZPersistentObject::eZPersistentObject   row
 

Initializes the object with the row $row. It will try to set each field taken from the database row. Calls fill to do the job. If the parameter $row is an integer it will try to fetch it from the database using it as the unique ID.

Definition at line ezpersistentobject.php.

References PersistentDataDirty.

Referenced by eZWaitUntilDateValue::eZWaitUntilDateValue().


Member Function Documentation

& eZPersistentObject::attribute   attr
 

Returns:
the attribute data for $attr, this is either returned from the member variables or a member function depending on whether the definition field or function attributes matched.

Reimplemented in eZWaitUntilDateValue.

Definition at line ezpersistentobject.php.

References eZDebug::writeError().

Referenced by remove().

& eZPersistentObject::attributes  
 

Returns:
the attributes for this object, taken from the definition fields and function attributes.

Reimplemented in eZWorkflowGroup.

Definition at line ezpersistentobject.php.

Referenced by eZContentObject::setContentObjectAttributes().

& eZPersistentObject::conditionText &$    conditions
 

Calls conditionTextByRow with an empty row and $conditions.

Definition at line ezpersistentobject.php.

References conditionTextByRow().

Referenced by storeObject().

& eZPersistentObject::conditionTextByRow &$    conditions,
&$    row
 

Generates an SQL sentence from the conditions $conditions and row data $row. If $row is empty (null) it uses the condition data instead of row data.

Definition at line ezpersistentobject.php.

References eZDB::instance().

Referenced by reorderObject().

& eZPersistentObject::definition  
 

Returns:
the definition for the object, the default implementation is to return an empty array. It's upto each inheriting class to return a proper definition array.
The definition array is an associative array consists of these keys:
  • fields - an associative array of fields which defines which database field (the key) is to fetched and how they map to object member variables (the value).
  • keys - an array of fields which is used for uniquely identifying the object in the table.
  • function_attributes - an associative array of attributes which maps to member functions, used for fetching data with functions.
  • set_functions - an associative array of attributes which maps to member functions, used for setting data with functions.
  • increment_key - the field which is incremented on table inserts.
  • class_name - the classname which is used for instantiating new objecs when fetching from the database.
  • sort - an associative array which defines the default sorting of lists, the key is the table field while the value is the sorting method which is either asc or desc.
  • name - the name of the database table
Example:
function definition()
{
    return array( "fields" => array( "id" => "ID",
                                     "version" => "Version",
                                     "name" => "Name" ),
                  "keys" => array( "id", "version" ),
                  "function_attributes" => array( "current" => "currentVersion",
                                                  "class_name" => "className" ),
                  "increment_key" => "id",
                  "class_name" => "eZContentClass",
                  "sort" => array( "id" => "asc" ),
                  "name" => "ezcontentclass" );
}

Reimplemented in eZWaitUntilDateValue.

Definition at line ezpersistentobject.php.

Referenced by remove().

& eZPersistentObject::fetchObject &$    def,
  field_filters,
  conds,
  asObject = true,
  grouping = null,
  custom_fields = null
 

Creates an SQL query out of the different parameters and returns an object with the result. If $asObject is true the returned item is an object otherwise a db row. Uses fetchObjectList for the actual SQL handling and just returns the first row item.

Parameters:
def  The definition structure
field_filters  If defined determines the fields which are extracted, if not all fields are fetched
conds  An array of conditions which determines which rows are fetched
grouping  An array of elements to group by
custom_fields  An array of extra fields to fetch, each field may be a SQL operation

Definition at line ezpersistentobject.php.

References fetchObjectList().

Referenced by eZSection::fetch().

& eZPersistentObject::fetchObjectList &$    def,
  field_filters = null,
  conds = null,
  sorts = null,
  limit = null,
  asObject = true,
  grouping = false,
  custom_fields = null
 

Creates an SQL query out of the different parameters and returns an array with the result. If $asObject is true the array contains objects otherwise a db row.

Parameters:
def  The definition structure
field_filters  If defined determines the fields which are extracted, if not all fields are fetched
conds  An array of conditions which determines which rows are fetched
sorts  An array of sorting conditions
limit  Offset and limit
grouping  An array of elements to group by
custom_fields  An array of extra fields to fetch, each field may be a SQL operation

Definition at line ezpersistentobject.php.

References eZDB::instance().

Referenced by eZContentObject::versions().

eZPersistentObject::fill &$    row
 

Tries to fill in the data in the object by using the object definition which is returned by the function definition() and the database row data $row. Each field will be fetch from the definition and then use that fieldname to fetch from the row and set the data.

Definition at line ezpersistentobject.php.

References definition().

Referenced by eZPersistentObject().

eZPersistentObject::hasAttribute   attr
 

Returns:
true if the attribute $attr is part of the definition fields or function attributes.

Reimplemented in eZWaitUntilDateValue.

Definition at line ezpersistentobject.php.

Referenced by eZBasket::hasAttribute().

eZPersistentObject::hasDirtyData  
 

Returns:
true if the data is considered dirty and needs to be stored.
See also:
sync

Definition at line ezpersistentobject.php.

Referenced by sync().

eZPersistentObject::newObjectOrder &$    def,
  orderField,
  conditions
 

Returns an order value which can be used for new items in table, for instance placement. Uses $def, $orderField and $conditions to figure out the currently maximum order value and returns one that is larger.

Definition at line ezpersistentobject.php.

References eZDB::instance().

eZPersistentObject::remove   conditions = null,
  extraConditions = null
 

Removes the object from the database, it will use the keys in the object definition to figure out which table row should be removed unless $conditions is defined as an array with fieldnames. It uses removeObject to do the real job and passes the object defintion, conditions and extra conditions $extraConditions to this function.

Reimplemented in eZWaitUntilDateValue.

Definition at line ezpersistentobject.php.

References removeObject().

Referenced by eZContentObject::remove().

eZPersistentObject::removeObject &$    def,
  conditions = null,
  extraConditions = null
 

Deletes the object from the table defined in $def with conditions $conditions and extra conditions $extraConditions. The extra conditions will either be appended to the existing conditions or overwrite existing fields. Uses conditionText() to create the condition SQL.

Definition at line ezpersistentobject.php.

References eZDB::instance().

Referenced by eZBinaryFile::remove().

eZPersistentObject::reorderObject &$    def,
  orderField,
  conditions,
  down = true
 

Moves a row in a database table. $def is the object definition. Uses $orderField to determine the order of objects in a table, usually this is a placement of some kind. It uses this order field to figure out how move the row, the row is either swapped with another row which is either above or below according to whether $down is true or false, or it is swapped with the first item or the last item depending on whether this row is first or last. Uses $conditions to figure out unique rows.

See also:
swapRow
Parameters:
orderField  Associative array with one element, the key is the order id and values is order value.

Definition at line ezpersistentobject.php.

References swapRow().

Referenced by eZContentClassAttribute::move().

eZPersistentObject::setAttribute   attr,
  val
 

Sets the attribute $attr to the value $val. The attribute must be present in the objects definition fields or set functions.

Definition at line ezpersistentobject.php.

References eZDebug::writeError().

Referenced by eZUser::setInformation().

eZPersistentObject::setHasDirtyData   hasDirtyData
 

Sets whether the object has dirty data or not.

See also:
hasDirtyData, sync

Definition at line ezpersistentobject.php.

eZPersistentObject::store   fieldFilters = null
 

Stores the object in the database, uses storeObject() to do the actual job and passes $fieldFilters to it.

Definition at line ezpersistentobject.php.

References storeObject().

Referenced by sync().

eZPersistentObject::storeObject &$    obj,
  fieldFilters = null
[private]
 

Stores the data in $obj to database.

Parameters:
fieldFilters  If specified only certain fields will be stored.

Definition at line ezpersistentobject.php.

References eZDB::instance().

Referenced by store().

eZPersistentObject::swapRow   table,
&$    keys,
&$    order_id,
&$    rows,
  id1,
  id2
 

Sets row id $id2 to have the placement of row id $id1.

Definition at line ezpersistentobject.php.

References eZDB::instance().

Referenced by reorderObject().

eZPersistentObject::sync   fieldFilters = null
 

Makes sure data is stored if the data is considered dirty.

See also:
hasDirtyData

Definition at line ezpersistentobject.php.

References store().


Member Data Documentation

eZPersistentObject::PersistentDataDirty [private]
 

Whether the data is dirty, ie needs to be stored, or not.

Definition at line ezpersistentobject.php.

Referenced by eZPersistentObject().


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

Exponential