Documentation

Export
in package
implements ActionInterface Uses BackwardCompatibility

This class contains functions to export a member's profile data to a downloadable file.

Tags
todo

Add CSV, JSON as other possible export formats besides XML and HTML?

Table of Contents

Interfaces

ActionInterface
Interface for all action classes.

Properties

$id  : int
$datatypes  : array<string|int, mixed>
$formats  : array<string|int, mixed>
$obj  : object
$backcompat  : array<string|int, mixed>

Methods

call()  : void
Convenience method to load() and execute() an instance of this class.
createDir()  : string|bool
Returns the path to a secure directory for storing exported profile data.
execute()  : void
Does the job.
exportStatic()  : void
Provides a way to export a class's public static properties and methods to global namespace.
getFormats()  : array<string|int, mixed>
Helper function that defines data export formats in a single location.
load()  : object
Static wrapper for constructor.
__construct()  : mixed
Constructor. Protected to force instantiation via self::load().

Properties

$id

public int $id

ID of the member whose profile is being viewed.

$datatypes

protected array<string|int, mixed> $datatypes

Types of exportable data, and instructions on how to get it. This is populated by the constructor.

$formats

protected static array<string|int, mixed> $formats = ['XML_XSLT' => ['extension' => 'styled.xml', 'mime' => 'text/xml', 'description' => 'export_format_xml_xslt', 'per_page' => 500], 'HTML' => ['extension' => 'html', 'mime' => 'text/html', 'description' => 'export_format_html', 'per_page' => 500], 'XML' => ['extension' => 'xml', 'mime' => 'text/xml', 'description' => 'export_format_xml', 'per_page' => 2000]]

Supported formats for the export files. Protected to force access via Export::getFormats()

$obj

protected static object $obj

An instance of this class. This is used by the load() method to prevent mulitple instantiations.

$backcompat

private static array<string|int, mixed> $backcompat = ['func_names' => ['call' => 'export_profile_data', 'createDir' => 'create_export_dir', 'getFormats' => 'get_export_formats']]

BackwardCompatibility settings for this class.

Methods

call()

Convenience method to load() and execute() an instance of this class.

public static call() : void

createDir()

Returns the path to a secure directory for storing exported profile data.

public static createDir([mixed $fallback = '' ]) : string|bool

The directory is created if it does not yet exist, and is secured using the same method that we use to secure attachment directories. Files in this directory can only be downloaded via the download_export_file() function.

Parameters
$fallback : mixed = ''
Return values
string|bool

The path to the directory, or false on error.

execute()

Does the job.

public execute() : void

exportStatic()

Provides a way to export a class's public static properties and methods to global namespace.

public static exportStatic() : void

To do so:

  1. Use this trait in the class.
  2. At the END of the class's file, call its exportStatic() method.

Although it might not seem that way at first glance, this approach conforms to section 2.3 of PSR 1, since executing this method is simply a dynamic means of declaring functions when the file is included; it has no other side effects.

Regarding the $backcompat items:

A class's static properties are not exported to global variables unless explicitly included in $backcompat['prop_names']. Likewise, a class's static methods are not exported as global functions unless explicitly included in $backcompat['func_names'].

$backcompat['prop_names'] is a simple array where the keys are the names of one or more of a class's static properties, and the values are the names of global variables. In each case, the global variable will be set to a reference to the static property. Static properties that are not named in this array will not be exported.

$backcompat['func_names'] is a simple array where the keys are the names of one or more of a class's static methods, and the values are the names that should be used for global functions that will encapsulate those methods. Methods that are not named in this array will not be exported.

Adding non-static properties or methods to the $backcompat arrays will produce runtime errors. It is the responsibility of the developer to make sure not to do this.

getFormats()

Helper function that defines data export formats in a single location.

public static getFormats() : array<string|int, mixed>
Return values
array<string|int, mixed>

Information about supported data formats for profile exports.

load()

Static wrapper for constructor.

public static load() : object
Return values
object

An instance of this class.

__construct()

Constructor. Protected to force instantiation via self::load().

protected __construct() : mixed

        
On this page

Search results