ePages 6.11.0 - DE_EPAGES/CSVExportImport/API/CSV/ObjectExportDriver.pm

Package DE_EPAGES::CSVExportImport::API::CSV::ObjectExportDriver

This module implements a handler to export objects via csv

Base
DE_EPAGES::Presentation::API::CSV::MonitoredExportDriver
Example
use DE_EPAGES::CSVExportImport::API::CSV::ObjectExportDriver;
my @Attributes;
push @Attributes, {
    Alias => 'Alias',
    Type => 'String',
    HeaderString => 'Alias',
};
push @Attributes, {
    Alias => 'Name',
    Type => 'String',
    HeaderString => 'Name (en)',
    LanguageID => GetPKeyLanguageByCode('en'),
};
push @Attributes, {
    Alias => 'ListPrice',
    HeaderString => 'ListPrice (EUR)',
    Type => 'Money'
};
my $Exporter = DE_EPAGES::CSVExportImport::API::CSV::ObjectExportDriver->new;
my $Shop = LoadObjectByPath( '/Shops/DemoShop' );
$Exporter->exportCSV(
    'Products.csv',
    { LocaleID => 'de_DE' },
    \@Attributes,
    $Shop,
    $Shop->get('Products')
);

Functions

drive
exportCSV
exportLine
getObjectAttributeValue
getValues
items
languages
locale
startMonitor
writeHeader

drive

starts the monitor 'CSVExportMonitor' and starts the export of data via $self->SUPER::drive()

Syntax
$self->drive();

exportCSV

exports object attributes to a CVS file.

Syntax
$Exporter->exportCSV($FileName, $hFormat, $aColumns, $ViewObject, $aObjects );
Input
$FileName (string)
export file
$hFormat (ref.hash)
export file format
  • LocaleID - locale id, e.g. 'de_DE' - string

The following parameters are optional. Their default values are
determined by the given locale id:
  • eol - row separator, e.g. "\n" - string
  • sep_char - quote character, e.g. ',' - string
  • quote_char - quote character, e.g. '"' - string
  • escape_char - escape character, e.g. '"' - string
  • DecimalSep - decimal point, e.g. '.' - string
  • ThousandSep - thousands separator, e.g. ',' - string
  • encoding - character encoding, e.g. 'iso-8859-1' - string
$ahColumns (ref.array.hash)
list of column attributes (used for header and values)
$ViewObject (object)
object to view monitor
$aObjects (ref.array.object)
list of objects

exportLine

Writes one line to the CSV file. Gets the values of the current export item from the function getValues. Increments the monitor counter if defined $self->monitor.

Syntax
$self->exportLine();

getObjectAttributeValue

Syntax
my $Value = getObjectAttributeValue($Object, $hAttribute);
Input
$Object (object)
object
$hAttribute (ref.hash)
properties of object attribute to get:
  • Alias - attribute alias, e.g. Alias, Color -string
  • LanguageID - only set if Type =~ /Localized/ - integer
  • ..
Output
$Value (scalar)
value of attribute for object

getValues

returns the values of the attributes from function columns(), uses function getObjectAttributeValue, formats the value via function DE_EPAGES::CSVExportImport::API::Tools::FormatValue()

Syntax
my $aValues = $self->getValues;
Output
$aValues (ref.array.scalar)
values of attributes ($self->columns) for object

items

Returns the objects to export, throws a Warning 'NO_ITEMS' if no items, set Monitor 'Total' if defined $self->monitor

Syntax
my $Items = $self->items();
Return
$aaData (ref.array.array.string)
parameter of exportCSV

languages

return the languages for attributes

Syntax
$ahLanguages = $self->languages;
Return
$ahLanguages (array.hash)
Languages

locale

return the current Locale

Syntax
$Locale = $self->locale;
Return
$Locale (hash)
Locale

startMonitor

starts the progress monitor. Creates an object of DE_EPAGES::Presentation::API::Object::ProgressMonitor if run inside the application server, otherwise the package DE_EPAGES::Core::API::Object::ProgressMonitor is used.

Syntax
$self->startMonitor($PageTypeName);
Input
$PageTypeName (string)
name of pagetype (only used inside application server)

writeHeader

Writes the CSV header line using the 'HeaderString' key of the column definition (see exportCSV).

Syntax
$self->writeHeader();