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.
Example |
my $Shop = LoadObjectByPath( 'Shops/DemoShop' ); my $Product = LoadClassByAlias('Product')->insertObject({ Parent => $Shop->child('Products'), Alias => '0815' } ); |
@EXPORT_OK |
Functions
- DeleteObject
- ExistsClassByAlias
- ExistsObject
- ExistsObjectByGUID
- ExistsObjectByPath
- GenerateSplittedGUIDPath
- 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 |
|
Return |
|
ExistsClassByAlias
Returns true if a class with the given alias exists.
Syntax |
$Exists = ExistsClassByAlias( $Alias ); |
Input |
|
Return |
|
ExistsObject
Returns true if the object id exists in the database.
Syntax |
$Exists = ExistsObject( $ObjectID ); |
Input |
|
Return |
|
ExistsObjectByGUID
Finds an object by a general unique id.
Syntax |
$Exists = ExistsObjectByGUID( $GUID ); |
Example |
if( ExistsObjectByGUID( "b09e53f4-60e9-41a6-8b30-526b69c28b5d" ) ) { ... } |
Input |
|
Return |
|
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 |
|
Return |
|
GenerateSplittedGUIDPath
Generates a directory path by the given GUID. The GUID is splitted into four-character sets, leading to a subdir per set.
Syntax |
$Path = GenerateSplittedGUIDPath( $GUID ); |
Example |
$Path = GenerateSplittedGUIDPath( "4C17-7D68-9953-E9F3-9C23-FE09-0F99-977A" ); |
Input |
|
Return |
|
GetRootObjectID
Returns the root object identifier of the system.
Syntax |
$ObjectID = GetRootObjectID(); |
Return |
|
InsertObject
obsolete
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 |
|
Return |
|
LoadClassByAlias
Loads an existing class by alias. Throws the error 'NoClassName' if the class does not exist.
Syntax |
$Class = LoadClassByAlias( $Alias ); |
Input |
|
Return |
|
LoadObject
Loads an object by object id.
Syntax |
$Object = LoadObject( $ObjectID ); $Object = LoadObject( $ObjectID, $DALPackage ); |
Input |
|
Return |
|
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 |
|
Return |
|
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 |
|
Return |
|
LoadRootObject
Returns the root object.
Syntax |
$Object = LoadRootObject(); |
Return |
|
SortObjects
Sorts the objects according to the 'OrderBy' and 'OrderDesc' parameters.
Syntax |
$aSortedObjects = SortObjects($aObjects, $OrderBy, $OrderDesc); |
Example |
$aSortedObjects = SortObjects($aObjects, "IsVisible", 1); |
Input |
|
Return |
|
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 |
|
Return |
|
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 |
|