ePages 6.10 - DE_EPAGES/Object/API/Object/Object.pm

Package DE_EPAGES::Object::API::Object::Object

object interface for Object. Includes methods for accessing attributes, child objects, and parents. Serialization is supported via XML import/export.

Base
DE_EPAGES::Object::API::Object::DALObject
Example
my $Object = LoadObject( $ObjectID );
print $Object->class->alias;
print $Object->path;
$Object->set( { 'LastName' => 'Watson' } );
print $Object->get( 'LastName' );
$Object->delete;

Functions

alias
child
children
childrenByClass
className
classTemplate
clearSavedPages
clone
cloneChildren
cloneFiles
dbPackage
deleteChildren
deleteFiles
deleteSelf
deleteXML
existsChild
exportXMLAttributes
exportXMLChildElements
exportXMLElements
exportableAttributes
exportableChildren
filePath
findChild
findChildren
findParent
findParentPath
findPath
findXML
folder
get
getSite
hasChildren
importXML
insertChild
isAllowedChild
isChildOf
isParentOf
load
nextAlias
nextPosition
pageCacheDuration
pageCacheMaxAge
parent
parentByClass
parentPath
path
pathString
planXMLExport
recursiveGet
relativePath
renumberChildren
reset
savePage
set
templatePath
uniqueChildAlias
updatePageCache
useFilePathPart

alias

Returns the alias of an object

Syntax
$Alias = $Object->alias;
Return
$Alias (string)
alias

child

Returns the direct child object with the given alias name. Throws an error if no such child object exists.

Syntax
$ChildObject = $Object->child( $Alias );
Input
$Alias (string)
child object alias
Return
$ChildObject (object)
child object

children

Returns all direct child objects ordered by Position.

Syntax
$aChildObjects = $Object->children;
Return
$aChildObjects (array refobject)
list of child objects

childrenByClass

Returns all direct child objects that are instances of the given class.

Syntax
$aChildObjects = $Object->childrenByClass($Class);
$aChildObjects = $Object->childrenByClass($ClassAlias);
Input
$Class (object)
class object
$ClassAlias (string)
class alias
Return
$aChildObjects (array refobject)
list of child objects

className

Returns the class name, used for DAL access.

Syntax
$ClassName = $Object->className;
Return
$ClassName (String)
class name

classTemplate

This function is used to overwrite the given template for the purpose that each content object can defined there own template (visualisation).

Syntax
$Name = $Object->classTemplate($Name, $ObjectPageType);
Input
$Name (string)
include name
$ObjectPageType (DE_EPAGES::Presentation::API::Object::ObjectPageType)
object related pagetype
Return
$Name (string)
include name

clearSavedPages

Clears the saved pages of object. See also: DE_EPAGES::Presentation::API::TLE::IncludeTemplateHandler::SavedInclude

Syntax
$Shop->clearSavedPages();

clone

Inserts a new object into the database as copy from old object.

Syntax
$Clone = $Object->clone( $hInfo );
$Clone = $Object->clone( $hInfo, $Recursive );
Input
$hInfo (hash ref)
hash with attribute values that are different in the clone object.
Note that the clone cannot have the same Parent and the same Alias.
$Recursive (boolean)
clone child object too (optional, default is false)
Return
$Clone (object)
the new object

cloneChildren

Returns all children of the object which should be cloned.

Syntax
$aChildren = $Object->cloneChildren
Example
$Description = $Object->cloneChildren;
Return
$aChildren (array ref)
children of the object

cloneFiles

Copies directories (PublicPath and PrivatePath) from original object to the clone. This function will is called by clone.

Syntax
$Object->cloneFiles( $Clone );
Input
$Clone (object)
clone object

dbPackage

Returns the database package, used for DAL access.

Syntax
$DbPackage = $Object->dbPackage;
Return
$DbPackage (String)
database package name

deleteChildren

Deletes all child objects of this object.

Syntax
$Object->deleteChildren;

deleteFiles

Deletes the directories PublicPath, PrivatePath. If Site.IsFilePathPartUsed and defined FilePathPart the directories will not deleted. Delete the directory StaticPath.

Syntax
$Object->deleteFiles;

deleteSelf

Deletes the object from database tables. Called by delete.

Syntax
$Object->deleteSelf;

deleteXML

Called by the SAX driver when a start tag for the current object class is encountered. The function identifies the object by the attributes in $hAttributes and deletes the object if it still exists and and the attribute 'delete="1"' is specified.

Syntax
$Object = DE_EPAGES::Object::API::Object::Object->deleteXML($Handler, $hElement, $hAttributes);
Input
$ObjectPackage (string)
package name of the objects's class
$Handler (object)
xml delete handler
$hElement (ref.hash)
information about the start tag, see SAX function start_element
$hAttributes (ref.hash)
attributes of the start tag
Return
$Object (object)
the found object if it still exists

existsChild

Returns true if the direct child object with the given alias name exists.

Syntax
$Exists = $Object->existsChild( $Alias );
Return
$Exists (boolean)
true if the child object exists

exportXMLAttributes

Returns plain attributes of object to XML export driver. This function removes localized attributes (deletes attribues like ParentID, Inherit if default (1), Class if equal TagName).

Syntax
$hAttributes = $Object->exportXMLAttributes( $Driver, $hAllAttributes );
Input
$Driver (object)
xml export driver with support function addObject
$hAllAttributes (ref.hash)
all attributes of object,
see $Object->allAttributes
Return
$hAttributes (ref.hash.string)
plain attributes

exportXMLChildElements

Add xml elements for children (asks each with planXMLExport to add to driver).

Syntax
$Object->exportXMLChildElements( $Driver, $hAttributes );
Input
$Driver (object)
xml export driver with support function addObject
$hAttributes (ref.hash.string)
plain attributes

exportXMLElements

Exports multilinguagal attribute value of this object to the xml SAX driver.

Syntax
$Object->exportXMLElements($Driver, $hAllAttributes);
Input
$Driver (object)
export driver
$hAllAttributes (ref.hash)
all attributes of object,
see $Object->allAttributes

exportableAttributes

Returns all attribute values that have an existing (not-null) value. Unlike $Object->_attributes this function returns localized attribute values as hash reference (language id => value).

Syntax
$hValues = $Object->exportableAttributes
Example
$Description = $Object->exportableAttributes;
Return
$hValues (hash ref)
object attributes as key => value pairs

exportableChildren

Returns all children of the object which should be exported.

Syntax
$aChildren = $Object->exportableChildren
Example
$Description = $Object->exportableChildren;
Return
$aChildren (array ref)
children of the object

filePath

Joins FilePath of site and FileAlias of this object.

Syntax
$Path = $Object->filePath;
Return
$Path (string)
relative file path

findChild

Returns the object id of a child object or undef if the child alias does not exist.

Syntax
$ChildObjectID = $Object->findChild( $Alias );
Input
$Alias (string)
child object alias
Return
$ChildObjectID (int)
child object id

findChildren

Returns a list of all child object ids of an object ordered by Position.

Syntax
$aChildObjectIDs = $Object->findChildren;
Return
$aChildObjectIDs (array ref)
list of child object ids

findParent

Returns the direct parent object identifier, Only the System object will return undef, because it does not have a parent object.

Syntax
$ParentID = $Object->findParent;
Return
$ParentID (integer)
parent object identifier

findParentPath

Returns the path of object identifier from the system root to this object. The System object is the first list item and this object is the last item in the list.

Syntax
$aParentIDs = $Object->findParentPath;
Return
$aParentIDs (ref.array.int)
list of parent objects

findPath

find the object via path started from current object. the path can be absolute "/Object1/Object2" or relative "Store/Catalog/Product" to the object.

Syntax
$ObjectID = $Object->findPath($Path);
Input
$Path (string)
path
Return
$ObjectID (integer)
object identifier

findXML

Returns object identifier if the attributes matches. if no object match the function returns undef

Syntax
$ObjectID = $Object->findXML( $hAttributes )
Example
my $ObjectID = $Object->findXML( { 'GUID' => '12345' } );
Input
$hAttributes (ref.hash.string)
keys
  • Alias
  • Path
  • GUID

Return
$ObjectID (integer)
object identifier (or undef)

folder

Returns the child object by alias name. If the child object does not exist, a new one is created with the given alias and class 'Object'.

Syntax
$Folder = $Object->folder( $Alias );
$Folder = $Object->folder( $Alias, $hInfo );
Example
$Orders = $Shop->folder( 'Orders' );
$Orders = $Shop->folder( 'Orders', { 'Position' => 50 } );
Input
$Alias (string)
child alias
$hInfo (ref.hash)
additional attribute values for creating the new object
(optional)
Return
$Folder (object)
child object

get

Returns one or more attribute values.

Syntax
$Value = $Object->get( $Name, $LanguageID );
$hValues = $Object->get( $aNames, $LanguageID );
Example
$Password = $Object->get( 'Password' );
$hCredentials = $Object->get( ['Login', 'Password'] );
printf "Login: %s\n", $hCredentials->{'Login'};
printf "Password: %s\n", $hCredentials->{'Password'};
Input
$Name (string)
attribute name
$aNames (array ref)
list of attribute names
$LanguageID (integer)
language identifier (optional)
Return
$hValues (hash ref)
name => value pairs
$Value (string (or other))
attribute value

getSite

Returns the site of an object

Syntax
$Site = $Object->getSite;
Return
$Site (object)
site object, see DE_EPAGES::Object::API::Object::Site

hasChildren

Returns true if the the object has children.

Syntax
$Has = $Object->hasChildren;
Return
$Has (boolean)
true if one child exists

importXML

Imports an object from an XML file. This function is called at the XML start tag. The end tag triggers the importXMLEnd function.

Syntax
$Object = DE_EPAGES::Object::API::Object::Object->importXML($Handler, $hElement, $Class, $hAttributes);
Input
$Handler (object)
xml import handler with support function addObject
$hElement (ref.hash)
XML element structure, see XML::SAX
$Class (object)
class object; the new object will be an instance of this class
$hAttributes (ref.hash)
attributes hash
Return
$Object (object)
the imported object

insertChild

Inserts a new object with the current object as parent.

Syntax
$NewObject = $Object->insertChild( $Class, $hInfo );
$NewObject = $Object->insertChild( $ClassAlias, $hInfo );
Example
$NewObject = $Object->insertChild( 'User', { Alias => $Login } );
Input
$Class (object)
class
$ClassAlias (string)
class alias
$hInfo (hash ref)
hash with mandatory attribute values.
  • Alias - alias - varchar(255)
  • Inherit - (optional) inherit permissions from parent object - boolean
Return
$NewObject (object)
the new object

isAllowedChild

Returns if an Object could be the parent of a PossibleChild.

Syntax
$isAllowed = $Object->isAllowedChild($PossibleChild);
Return
$isAllowed (boolean)
is a allowed child type

isChildOf

Returns whether an Object is a child (direct or indirect) of a PossibleParent.

Syntax
$isChild = $Object->isChildOf($PossibleParent);
Return
$isChild (boolean)
is a child

isParentOf

Returns if an Object is a parent (direct or indirect) of a PossibleChild.

Syntax
$isParent = $Object->isParentOf($PossibleChild);
Return
$isParent (boolean)
is a parent

load

Loads an existing object.

Syntax
$Object = DE_EPAGES::Object::API::Object->load( $ObjectID );
Note: Use <function DE_EPAGES::Object::API::Factory::LoadObject> instead.
Input
$ObjectID (int)
object id
Return
$Object (object)
existing object

nextAlias

Returns the an the next unused alias for a new object using a format pattern.

Syntax
$Alias = $Object->nextAlias;
$Alias = $Object->nextAlias( $Format );
Example
$Alias = $Object->nextAlias( "P_%s" );
Input
$Format (string)
sprintf-style format string (default "Object_%4d")
Return
$Alias (string)
next free alias string

nextPosition

Returns the next (top) position for a new child. Such as, if the last child has Position = 150 the method returns 160 (if PositionStep is 10).

Syntax
$Position = $Object->nextPosition($LastPosition);
Input
$LastPosition (integer)
last inserted position (optional)
Return
$Position (integer)
new (next) position

pageCacheDuration

How long a page can be cached.

Syntax
$PageCache = $Object->pageCacheDuration;
Return
$PageCache (integer)
maximal cache age (minutes)

pageCacheMaxAge

How long a page can be cached on client.

Syntax
$PageCache = $Object->pageCacheMaxAge;
Return
$PageCache (integer)
maximal cache age (seconds)

parent

Returns the direct parent object, Only the System object will return undef, because it does not have a parent object.

Syntax
$ParentObject = $Object->parent;
Return
$ParentObject (object)
parent object

parentByClass

Returns a parent object which is instance of class.

Syntax
$Object = $Object->parentByClass($Class);
$Object = $Object->parentByClass($ClassAlias);
Example
$Shop = $Object->parentByClass( LoadClassByAlias('Shop') );
Input
$Class (object)
class object
$ClassAlias (string)
class alias
Return
$Object (object)
parent object

parentPath

Returns the path of objects from the system root to this object. The System object is the first list item and this object is the last item in the list.

Syntax
$aParentObjects = $Object->parentPath;
Return
$aParentObjects (ref.array.object)
list of parent objects

path

find the object via path started from current object. the path can be absolute "/Object1/Object2" or relative "Store/Catalog/Product" to the object.

Syntax
$PathObject = $Object->path($Path);
Example
$User = $Order->path('../../Users/max_mustermann');
Input
$Path (string)
path
Return
$PathObject (object)
object

pathString

Returns the path of object as a string joined with '/'.

Syntax
$Path = $Object->pathString;
Return
$Path (string)
list of parent path

planXMLExport

Add this object to driver (possible for nextLevel).

Syntax
$Object->planXMLExport( $Driver );
Input
$Driver (object)
xml export driver with support function addObject

recursiveGet

Obsolete. Do not use.

relativePath

Returns the relative path of an object to another object.

Syntax
$relativePath = $Object->relativePath($Object2);
Example
$Object1 = LoadObjectByPath('/Shops/DemoShop/Products/be_40401/SubProducts/be_4040104005');
$Object2 = LoadObjectByPath('/Shops/DemoShop/Customers');
ok( $Object1->relativePath($Object2) eq '../../../../Customers' );
ok( $Object2->relativePath($Object1) eq '../Products/be_40401/SubProducts/be_4040104005' );
Input
$Object2 (object)
target object
Return
$Path (string)
relative object path

renumberChildren

Updates the Position attribute of all child objects with a distance of 10 between subsequent objects. The new position number will be 10, 20, ....

Syntax
$Object->renumberChildren;

reset

if an attribute was created or removed the class must be reset

Syntax
$Object->reset;

savePage

Save cache of actual object in File. Use static path of actual object. To save cache file the function will need a unique cachekey, this key is integrated in filename. Also a function to compute the content is needed. Content is computed if no cachefile exist.

Syntax
$Content = $Shop->savePage($CacheKey, $FallBackSub);
Example
$Content = $Shop->savePage('MBO.Menu_de',
sub{
    return join '', @{$Processor->replaceTLEs($cTemplate)};
});
Input
$CacheKey (string)
name or key must be unique for an object
$FallBackSub (sub)
function that generate and returns actual content
Return
$Content (content)
Content from cached file

set

Sets the given attribute values on the object. This function triggers hooks 'OBJ_BeforeUpdateObject' and 'OBJ_AfterUpdateObject' and any specialized OBJ_BeforeUpdate* and OBJ_AfterUpdate* hooks.

Syntax
$Object->set($hValues, $LanguageID);
Example
$Object->set({ 'LocaleID' => 'de_DE' });
$Object->set({ 'Name' => 'Fußball' }, GetPKeyLanguageByCode('de'));
$Object->set({ 'Name' => 'Soccer' }, GetPKeyLanguageByCode('en'));
Input
$hValues (ref.hash)
attribute name => value hash
$LanguageID (integer)
(optional) language id for localized attributes
Hook
OBJ_BeforeUpdateObject
hook parameter keys :
  • Object - this object - object
  • ObjectID - object id - int
  • Values - new values for object - ref.hash
  • LanguageID - values of this language will be updated - int
OBJ_AfterUpdateObject
hook parameter keys :
  • Object - this object - object
  • ObjectID - object id - int
  • Values - updated values - ref.hash
  • LanguageID - values updated of this language - int

templatePath

This function return a list of objects which can define the used templates.

Syntax
$aObjects = $Object->templatePath;
Return
$aObjects (ref.array.object)
list of objects, classes

uniqueChildAlias

Returns a safe (no special chars) alias for a given string and makes it unique by adding a counter, if an element with this alias already exists.

Syntax
$UniqueAlias = $Object->uniqueChildAlias( $String, $AllowedAlias );
Example
$UniqueAlias = $Object->uniqueChildAlias( 'my 5$-bill' );
$UniqueAlias = $Object->uniqueChildAlias( 'my 10$-bill', 'my_10_bill' );
Input
$String (string)
string
$AllowedString (string)
(optional) if the created alias matches this alias, then
use it.
Return
$UniqueAlias (string)
the unique alias

updatePageCache

Updates page cache date of the object's site if the object is an instance of one of the pre-defined classes (this classes implement invalidatePageCache method). These classes influence the content which is shown on storefront pages.

Syntax
$Object->updatePageCache;

useFilePathPart

This function return 0 as default for all objects. Mainly used for MediaGallery.

Syntax
$useFilePathPart = $Object->useFilePathPart;
Return
$useFilePathPart (boolean)
false if not use filepathpart