Package DE_EPAGES::Object::API::Factory
This package provides helper functions for working with objects that
are stored in the 'object' table. You can create, retrieve and delete
such objects.
Use the functions of this package if you don't have a reference to object
yet. Once you have an object reference, use the methods of the
DE_EPAGES::Object::API::Object::Object or derived package.
Functions
- DeleteObject
- ExistsClassByAlias
- ExistsObject
- ExistsObjectByGUID
- ExistsObjectByPath
- GetRootObjectID
- InsertObject
- JoinObjectPath
- LoadClassByAlias
- LoadObject
- LoadObjectByGUID
- LoadObjectByPath
- LoadRootObject
- SortObjects
- SplitObjectPath
- Transaction
DeleteObject
Deletes an object by object id, if object exists.
Syntax |
$Object = DeleteObject( $ObjectID );
|
Input |
- $ObjectID (int)
- object id
|
Return |
- $Object (object)
- object
|
ExistsClassByAlias
Returns true if a class with the given alias exists.
Syntax |
$Exists = ExistsClassByAlias( $Alias );
|
Input |
- $Alias (string)
- class alias
|
Return |
- $Exists (boolean)
- true if the class exists
|
ExistsObject
Returns true if the object id exists in the database.
Syntax |
$Exists = ExistsObject( $ObjectID );
|
Input |
- $ObjectID (int)
- object id
|
Return |
- $Exists (boolean)
- true if the object exists
|
ExistsObjectByGUID
Finds an object by a general unique id.
Syntax |
$Exists = ExistsObjectByGUID( $GUID );
|
Example |
if( ExistsObjectByGUID( "b09e53f4-60e9-41a6-8b30-526b69c28b5d" ) ) { ... }
|
Input |
- $GUID (string)
- general unique id of object
|
Return |
- $Exists (boolean)
- true if the specified object exists
|
ExistsObjectByPath
Finds an object by a path of alias names from a given root object.
The alias names are separated by slash (/) characters.
Syntax |
$Exists = ExistsObjectByPath( $Path );
$Exists = ExistsObjectByPath( $Path, $RootObjectID );
|
Example |
if( ExistsObjectByPath( "Shops/MyShop/HotDeals" ) ) { ... }
|
Input |
- $Path
- path of alias names from the root object
|
Return |
- $Exists (boolean)
- true if the specified object exists
|
GetRootObjectID
Returns the root object identifier of the system.
Syntax |
$ObjectID = GetRootObjectID();
|
Return |
- $ObjectID (int)
- object id
|
InsertObject
Syntax |
(OLD) $Object = InsertObject( $Class, $hObject );
(NEW) $Object = $Class->insertObject( $hObject );
(OLD) $Object = InsertObject( $ClassAlias, $hObject );
(NEW) $Object = LoadClassByAlias($Class)->insertObject( $hObject );
|
JoinObjectPath
Joins alias names with '/'.
Quotes alias alias names that contain a slash or doublequote character.
Syntax |
$Path = JoinObjectPath( $aPath );
|
Example |
$Path = JoinObjectPath( [ 'Shops', 'DemoShop', 'Products', '08/15' ] );
|
Input |
- $aPath (ref.array.string)
- list of object alias names
|
Return |
- $Path (string)
- path of alias names from the root object
|
LoadClassByAlias
Loads an existing class by alias.
Throws the error 'NoClassName' if the class does not exist.
Syntax |
$Class = LoadClassByAlias( $Alias );
|
Input |
- $Alias (string)
- class alias
|
Return |
- $Class (object)
- class object
|
LoadObject
Loads an object by object id.
Syntax |
$Object = LoadObject( $ObjectID );
|
Input |
- $ObjectID (int)
- object id
|
Return |
- $Object (object)
- object
|
LoadObjectByGUID
Returns the object by GUID.
Throws an error if no such objects exists.
Syntax |
$Object = LoadObjectByGUID( $GUID );
|
Example |
$Object = LoadObjectByGUID( "b09e53f4-60e9-41a6-8b30-526b69c28b5d" );
|
Input |
- $GUID (string)
- general unique id of the object
|
Return |
- $Object (object)
- object
|
LoadObjectByPath
Finds an object by a path of alias names from a given root object.
The alias names are separated by slash (/) characters.
Syntax |
$Object = LoadObjectByPath( $Path );
$Object = LoadObjectByPath( $Path, $RootObjectID );
|
Example |
$Object = LoadObjectByPath( "Shops/MyShop/HotDeals" );
|
Input |
- $Path (string)
- path of alias names from the root object
- $RootObjectID (int)
- (optional) object id of a parent or grand parent
|
Return |
- $Object (object)
- object
|
LoadRootObject
Returns the root object.
Syntax |
$Object = LoadRootObject();
|
Return |
- $Object (object)
- root object
|
SortObjects
Sorts the objects according to the 'OrderBy' and 'OrderDesc' parameters.
Syntax |
$aSortedObjects = SortObjects($aObjects, $OrderBy, $OrderDesc);
|
Example |
$aSortedObjects = SortObjects($aObjects, "IsVisible", 1);
|
Input |
- $aObjects (ref.array.object)
- list of objects
- $OrderBy (string)
- attribute (path) to order by
- $OrderDesc (boolean)
- order descending
|
Return |
- $aSortedObjects (ref.array.object)
- sorted list of objects
|
SplitObjectPath
Splits path on '/'.
Unquotes any parts that are delimited with doublequotes.
Syntax |
$aPath = SplitObjectPath( $Path );
|
Example |
$aPath = SplitObjectPath( '/Shops/DemoShop/Products/"08/15"' );
|
Input |
- $Path (string)
- path of alias names from the root object
|
Return |
- $aPath (ref.array.string)
- list of object alias names
|
Transaction
Runs a code block in a transaction using the current database handle.
If an error occurs, the local data cache is reset and the code block
$cRollback is executed.
Syntax |
Transaction( $cCode );
Transaction( $cCode, $cRollback );
|
Example |
Transaction( sub {
DeleteObject( ... );
DeleteObject( ... );
} );
Transaction( sub {
DeleteObject( ... );
DeleteObject( ... );
}, sub {
print STDERR "Our transaction was rolled back";
} } );
|
Input |
- $cCode (code reference)
- code block
- $cRollback (code reference)
- roll back code block (optional)
|