\Horde_Data_Tsv

Horde_Data implementation for tab-separated data (TSV).

Summary

Methods
Properties
Constants
__construct()
importData()
exportData()
importFile()
importUrl()
exportFile()
getNewline()
getFilename()
getContentType()
warnings()
nextStep()
cleanup()
$storage
No constants found
_mapDate()
$_browser
$_http
$_cleanupCallback
$_contentType
$_extension
$_vars
$_warnings
N/A
No private methods found
No private properties found
N/A

Properties

$_browser

$_browser : \Horde_Browser

Browser object.

Type

\Horde_Browser

$_http

$_http : \Horde_Http_Client

HTTP client object.

Type

\Horde_Http_Client

$_cleanupCallback

$_cleanupCallback : callback

Cleanup callback function.

Type

callback

$_contentType

$_contentType : string

MIME content type.

Type

string

$_extension

$_extension : string

File extension.

Type

string

$_vars

$_vars : \Horde_Variables

Variables object.

Type

\Horde_Variables

$_warnings

$_warnings : array

A list of warnings raised during the last operation.

Type

array

Methods

__construct()

__construct(\Horde_Data_Storage  $storage, array  $params = array()) 

Constructor.

Parameters

\Horde_Data_Storage $storage
array $params

Optional parameters:

  • browser: (Horde_Browser) A browser object.
  • http: (Horde_Http_Client) A HTTP client object.
  • cleanup: (callback) A callback to call at cleanup time.
  • vars: (Horde_Variables) Form data.

importData()

importData(string  $contents, boolean  $header = false, string  $delimiter = "\t") : array

Convert data file contents to list of data records.

Parameters

string $contents

Data file contents.

boolean $header

True if a header row is present.

string $delimiter

Field delimiter.

Returns

array —

List of data records.

exportData()

exportData(array  $data, boolean  $header = false) : string

Builds a TSV file from a given data structure and returns it as a string.

Parameters

array $data

A two-dimensional array containing the data set.

boolean $header

If true, the rows of $data are associative arrays with field names as their keys.

Returns

string —

The TSV data.

importFile()

importFile(  $filename,   $header = false) 

Imports a file.

Parameters

$filename
$header

importUrl()

importUrl(  $url,   $header = false) 

Imports a URL.

Parameters

$url
$header

exportFile()

exportFile(string  $filename, array  $data, boolean  $header = false) 

Builds a TSV file from a given data structure and triggers its download.

It DOES NOT exit the current script but only outputs the correct headers and data.

Parameters

string $filename

The name of the file to be downloaded.

array $data

A two-dimensional array containing the data set.

boolean $header

If true, the rows of $data are associative arrays with field names as their keys.

getNewline()

getNewline() : string

Tries to determine the expected newline character based on the platform information passed by the browser's agent header.

Returns

string —

The guessed expected newline characters, either \n, \r or \r\n.

getFilename()

getFilename(string  $basename) : string

Returns the full filename including the basename and extension.

Parameters

string $basename

Basename for the file.

Returns

string —

The file name.

getContentType()

getContentType() : string

Returns the content type.

Returns

string —

The content type.

warnings()

warnings() : array

Returns a list of warnings that have been raised during the last operation.

Returns

array —

A (possibly empty) list of warnings.

nextStep()

nextStep(integer  $action, array  $param = array()) : mixed

Takes all necessary actions for the given import step, parameters and form values and returns the next necessary step.

Parameters

integer $action

The current step. One of the IMPORT_* constants.

array $param

An associative array containing needed parameters for the current step.

Throws

\Horde_Data_Exception

Returns

mixed —

Either the next step as an integer constant or imported data set after the final step.

cleanup()

cleanup() : mixed

Removes any uploaded and moved files.

Returns

mixed —

If callback called, the return value of this call. This should be the value of the first import step.

_mapDate()

_mapDate(string  $date, string  $type, array  $params, integer  $key) : string

Maps a date/time string to an associative array.

Parameters

string $date

The date.

string $type

One of 'date', 'time' or 'datetime'.

array $params

Two-dimensional array with additional information about the formatting. Possible keys are:

  • delimiter: The character that seperates the different date/time parts.
  • format: If 'ampm' and $date contains a time we assume that it is in AM/PM format.
  • order: If $type is 'datetime' the order of the day and time parts: -1 (timestamp), 0 (day/time), 1 (time/day).
integer $key

The key to use for $params.

Returns

string —

The date or time in ISO format.