Static methods providing formatting.

package dstruct_common

 Methods

Formats html message box.

asMessage(mixed $messages, string $class) : string
Static

If a string is passed as $message, a div with the $message string is returned.
If an array is passed, and un-ordered list of the variables is returned.
Boxes have the class 'message', in addition to the default 'error' class or whatever is passed in its place.
If an empty string is passed, nothing is returned, rather than an empty box.

Parameters

$messages

mixed

$class

string

CSS class for the message box

Returns

string

Format a currency value.

currency(float $val, string $trimdecimals, \number $precision, string $symbol, string $decsep, string $thousep) : string
Static
todo Set default dec and thou separators in Prefs
todo $trimdecimals currently doesn't take account of $decsep

Parameters

$val

float

Currency value

$trimdecimals

string

Trim '.00' from end of output

$precision

\number

Decimal precision. Default is two.

$symbol

string

Symbol to prepend to output. Uses {@link Prefs::CURRENCY_SYMBOL} by default.

$decsep

string

The decimal separator. Default is UK - period.

$thousep

string

The thousands separator. Default is UK - comma.

Returns

string

Formats data to more human friendly output.

dataSize(integer $bytes) : boolean | \number | string
Static

For example, 1024 bytes --> 1kb

Parameters

$bytes

integer

Returns

boolean\numberstring

Format UTS as full date.

date(integer $uts) : string
Static
see \Prefs::FORMAT_DISPLAY_DATE

Parameters

$uts

integer

Returns

string

Format UTS short date.

formDate(integer $uts) : string
Static
see \Prefs::FORMAT_FORM_DATE

Parameters

$uts

integer

Returns

string

Format UTS short timestamp.

formTimestamp(integer $uts) : string
Static

Parameters

$uts

integer

Returns

string

Return a date in format yyyymmdd.

orderedDate(integer $uts) : string
Static

Particularly useful for where there is a need to sort by date, for example, naming folders which are to be listed by their date.

Parameters

$uts

integer

Returns

string

Format UTS as full timestamp.

timestamp(integer $uts) : string
Static
see \Prefs::FORMAT_DISPLAY_TS

Parameters

$uts

integer

Returns

string

Fast and dirty formatting of a string (typically from a database) for (X)HTML compatability.

toHTML(string $input) : string
Static

Return is HTML encoded and newlines are converted to


. Method is set to use UTF-8.

Parameters

$input

string

Returns

string

Class constructor.

__construct() 

Class should never be instanced - all methods should be static.

Exceptions

\DStructGeneralException