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

Package DE_EPAGES::Object::API::BaseAttribute

Base class for implementing custom attributes. Normally you override at least the function getAttributes. If your atrributes are writeable, also override setAttributes.

Functions

canDeleteObject
cloneAttributes
defaultAttributes
deleteAttribute
deleteObject
exportXMLAttributes
exportXMLElements
getAllAttributes
getAttribute
getAttributes
importXML
setAttribute
setAttributes

canDeleteObject

Tests if the object can be deleted. If there is any reason why the object should not be deleted, these reasons are appended to the @$aWarnings list.

Syntax
$Package->canDeleteObject( $Object, $aWarnings );
Example
sub canDeleteObject {
    my $self = shift;
    my ($Object, $aWarnings) = @_;

    my $Warning = DE_EPAGES::Core::API::Warning->new(
        Code => $Code,
        Vars => $hVars
    );
    push @$aWarnings, $Warning;
    return;
}
Input
$Object (object)
object
$aWarnings (array.ref)
array of Warning Objects

cloneAttributes

copy object attributes to clone.

Syntax
$Package->cloneAttributes( $Object, $Clone );
Input
$Object (object)
source object
$Clone (object)
clone

defaultAttributes

Returns default values for a new object. It is possible to get extra information from the parent object.

Syntax
$Package->defaultAttributes( $Parent, $aNames );
Example
sub defaultAttributes {
    my $self = shift;
    my ($Parent, $aNames) = @_;

    return {
        LocaleID => $Parent->getSite()->get('LocaleID'),
        IsVisible => 0,
    };
}
Input
$Parent (object)
parent of new or existing object
$aNames (ref.array.string)
attribute names
$hInfo (ref.hash)
attribute name => value hash (passed to insert())

deleteAttribute

Called when the attribute is deleted from the class. Used to clean up all data that is related to this attribute.

Syntax
$Package->deleteAttribute( $Attribute );
Example
sub deleteAttribute {
    my $self = shift;
    my ($Attribute) = @_;

    if( $Attribute->alias eq 'GroupMembers' ) {
        GetCurrentDBHandle()->do( 'TRUNCATE TABLE groupmembers' );
    }
}
Input
$Attribute (object)
attribute object

deleteObject

Called before the object is deleted. Used to clean up any data that is related to the object.

Syntax
$Package->deleteObject( $Object );
Example
sub deleteObject {
    my $self = shift;
    my ($Object) = @_;

    GetCurrentDBHandle()->do( 'DELETE FROM groupmember WHERE groupid = ?',
        [ $Object->id ] );
    GetCurrentDBHandle()->do( 'DELETE FROM group WHERE groupid = ?',
        [ $Object->id ] );
    return;
}
Input
$Object (object)
object

exportXMLAttributes

Adds attributes to the XML start tag when the object is exported.

Syntax
$Package->exportXMLAttributes($Driver, $Object, $aNames, $hAttributes);
Example
sub exportXMLAttributes {
    my $self = shift;
    my ($Driver, $Object, $aNames, $hAttributes) = @_;

    foreach my $Name (@$aNames) {
        if( $Name eq 'ActionClass' ) {
            $hAttributes->{'Class'} = $Object->get('ActionClass')->alias;
        }
    }
}
Input
$Driver (object)
xml export driver
$Object (object)
object to export
$aNames (ref.array.string)
attribute names
$hAttributes (ref.hash)
imported attributes

exportXMLElements

Adds sub elements to the XML file when the object is exported.

Syntax
$Package->exportXMLElements($Driver, $Object, $aNames, $hAttributes);
Example
sub exportXMLElements {
    my $self = shift;
    my ($Driver, $Object, $aNames, $hAttributes) = @_;

    foreach my $Name (@$aNames) {
        if( $Name eq 'Members' ) {
            $Driver->addObject('Member', $_) foreach @{$Object->get('Members')};
        }
    }
}
Input
$Driver (object)
xml export driver
$Object (object)
object to export
$aNames (ref.array.string)
attribute names
$hAttributes (ref.hash)
imported attributes

getAllAttributes

Returns multiple attribute values. Don't call this function directly. Use $Object->get() instead. The default implementation calls getAttributes.

Syntax
$hValues = $Package->getAllAttributes( $Object, $aNames );
Input
$Object (object)
object
$aNames (array ref)
list of attribute names (optional)
Return
$hValues (hash ref)
attribute name => value hash

getAttribute

Returns a single attribute value. Don't call this function directly. Use $Object->get() instead. The default implementation calls getAttributes

Syntax
$Value = $Package->getAttribute( $Object, $Name, $LanguageID );
Input
$Object (object)
object
$Name (string)
attribute name
$LanguageID (int)
language id
Return
$Value (string)
attribute value

getAttributes

Returns multiple attribute values. Don't call this function directly. Use $Object->get() instead.

Syntax
$hValues = $Package->getAttributes( $Object, $aNames, $LanguageID );
Example
sub getAttributes {
    my $self = shift;
    my ($Object, $aNames, $LanguageID) = @_;

    my %Values;
    foreach my $Name ( @$aNames ) {
        if( $Name eq 'Name' ) {
            my $aRows = GetCurrentDBHandle()->execute(
                'SELECT name FROM group WHERE groupid = ?',
                [ $Object->id ] );
            $Values{$Name} = $aRows->[0]->[0];
        }
    }
    return \%Values;
}
Input
$Object (object)
object
$aNames (array ref)
list of attribute names
$LanguageID (int)
language id
Return
$hValues (hash ref)
attribute name => value hash

importXML

Converts attributes from the XML start tag to object attribute values.

Syntax
$Package->importXML($Handler, $Class, $aNames, $hAttributes);
Example
sub importXML {
    my $self = shift;
    my ($Handler, $Class, $aNames, $hAttributes) = @_;

    if( exists $hAttributes->{'Class'} ) {
        $hAttributes->{'ActionClass'} = LoadClassByAlias($hAttributes->{'Class'});
        delete $hAttributes->{'Class'};
    }
}
Input
$Handler (object)
xml import handler with support function addObject
$Class (object)
class of imported object
$aNames (ref.array.string)
attribute names
$hAttributes (ref.hash)
imported attributes (attribute name => value).
On input, the values are taken from the XML start tag.
This function can modify the values, for example to load the
object value by name.

setAttribute

Sets a single attribute value. Don't call this function directly. Use $Object->set() instead. The default implementation calls setAttribute.

Syntax
$Package->setAttribute( $Object, $Name, $Value, $LanguageID );
Input
$Object (object)
object
$Name (string)
attribute name
$Value (string)
attribute value
$LanguageID (int)
language id

setAttributes

Sets multiple attribute values. Don't call this function directly. Use $Object->set() instead.

Syntax
$Package->setAttributes( $Object, $hValues, $LanguageID );
Example
sub setAttributes {
    my $self = shift;
    my ($Object, $hValues, $LanguageID) = @_;

    foreach my $Name (keys %$hValues) {
        if( $Name eq 'Name' ) {
            GetCurrentDBHandle()->do( 'UPDATE group SET name = ? WHERE groupid = ?',
                [ $hValues->{'Name'}, $Object->id ] );
        }
    }
    return;
}
Input
$Object (object)
object
$hValues (hash ref)
attribute name => value hash
$LanguageID (integer)
language id (optional)