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 |
|
cloneAttributes
copy object attributes to clone.
Syntax |
$Package->cloneAttributes( $Object, $Clone ); |
Input |
|
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 |
|
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 |
|
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 |
|
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 |
|
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 |
|
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 |
|
Return |
|
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 |
|
Return |
|
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 |
|
Return |
|
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 |
|
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 |
|
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 |
|