Provides methods to create sorted tables

copyright CONTREXX CMS - COMVATION AG
author Reto Kohli
version 3.0.0
package contrexx
subpackage core

 Methods

Constructor

__construct($baseUri, array $arrField, boolean $flagDefaultAsc, $orderUriParameter) : \Sorting

Note that the base page URI is handed over by reference and that the order parameter name is removed from that, if present.

author Reto Kohli

Parameters

$baseUri

$arrField

array

The field names and corresponding header texts

$flagDefaultAsc

boolean

The flag indicating the default order direction. Defaults to true (ascending).

$orderUriParameter

Returns

Returns the field array as provided to the constructor

getFieldArray() : array
author Reto Kohli
see \__construct()
see \$arrField

Returns

arrayThe field array

Extracts table plus field name, and the direction from an order definition in SQL syntax and returns them in an array

getFieldDirection(string $order_sql) : array
Static

The array looks like array( 0 => [table.]field, 1 => direction, ) Note that if the table name is not found, it is omitted in the respective array element. No dot is included in this case. The direction may be missing, in which case element #1 is set to the empty string.

Parameters

$order_sql

string

The order in SQL syntax

Returns

arrayThe array with table plus field name and direction on success, null otherwise

Extracts table name, field name, and direction from an order definition in SQL syntax and returns them in a string

getFieldindex(string $order_sql) : string
Static

The string is solely intended for use as an index of the object's field array. It has the form "[table.]field[ direction] Note that if the table name is not found, it is omitted in the respective array element. No dot is included in this case. Similarly, if the direction cannot be extracted from the string, no space is added either.

Parameters

$order_sql

string

The order in SQL syntax

Returns

stringThe field array index on success, null otherwise

Returns an array of strings to display the table headers.

getHeaderArray() : array

Uses the order currently stored in the object, as set by setOrder(). The array is, of course, in the same order as the arrays of field and header names used.

author Reto Kohli

Returns

arrayThe array of clickable table headers.

Returns a string to display the table header for the given field name.

getHeaderForField($field) : string

Uses the order currently stored in the object, as set by setOrder().

author Reto Kohli

Parameters

$field

Returns

stringThe string for a clickable table header field.

Returns the current order string (SQL-ish syntax)

getOrder() : string

Note that this adds backticks around the order table (if present) and field name. The string looks like "table.field dir" or "field dir"

author Reto Kohli

Returns

string

Returns the sorting direction string

getOrderDirection() : string

This is either 'ASC' or 'DESC'.

author Reto Kohli

Returns

stringorder direction string

Returns an HTML img tag with the icon representing the current order direction

getOrderDirectionImage() : string

Note that the decision where to include the icon or not must be made by the code calling.

Returns

stringThe HTML img tag for the sorting direction icon

Returns the reverse sorting direction string

getOrderDirectionReverse(string $direction) : string

This is either 'ASC' or 'DESC'. If empty, the $direction parameter defaults to this objects' $orderDirection variable.

author Reto Kohli

Parameters

$direction

string

The optional order direction

Returns

stringThe reverse order direction

Returns the current order field name

getOrderField() : string
author Reto Kohli

Returns

stringThe field name

Returns the order parameter name used for this Sorting

getOrderParameterName() : string
author Reto Kohli

Returns

stringThe parameter name

Returns the sorting order string in URI encoded format

getOrderReverseUriEncoded($field) : string

The returned string contains both the parameter name, 'order', and the current order string value. It is ready to be used in an URI in a link.

author Reto Kohli

Parameters

$field

Returns

stringURI encoded order string

Returns the sorting order string in URI encoded format

getOrderUriEncoded(string $field) : string

The returned string contains both the parameter name, and the current order string value.

author Reto Kohli

Parameters

$field

string

The optional order field

Returns

stringURI encoded order string

Returns the base URI with HTML entities encoded

getUri_entities(string $field) : string

If the optional $field parameter contains any valid field name, the sorting and direction for that field is appended.

Parameters

$field

string

The optional field name

Returns

stringThe URI

Sets the order string (SQL-ish syntax)

setOrder(string $order) 
author Reto Kohli

Parameters

$order

string

The order string

Set the sorting direction string

setOrderDirection(string $direction) 

$direction defaults to 'ASC' and may be left empty, or set to 'ASC' or 'DESC'. Any other value is ignored and the default used instead.

author Reto Kohli

Parameters

$direction

string

The optional order direction string

Set the order parameter name to be used for this Sorting

setOrderParameterName(string $parameter_name) 
author Reto Kohli

Parameters

$parameter_name

string

The parameter name

Sets the base URI

setUri(string $uri) 

Parameters

$uri

string

The URI

 Properties

 

$arrField : array

Note that the first element will be the default sorting field.

 

$baseUri : string

The sorting parameters will be appended to this string and used to build the header array. Note that, as this is only used in links, the URI is stored with any "&"s replaced by "&" already! See {@see setUri()}.

 

$flagDefaultAsc : boolean

if true, the default order is ascending, or descending otherwise.

 

$orderDirection : string
 

$orderField : string

See setOrder().

Note that this may include the table name, and even the order direction!

 

$orderUriParameter 

 Constants

 

Default URL parameter name for the sorting order

DEFAULT_PARAMETER_NAME 

You MUST specify this yourself using {@see setOrderParameterName()} when using more than one Sorting at a time!

 

Regular expression used to match the field name and order direction used in an ORDER BY statement

REGEX_ORDER_FIELD 

Matches the table name ($1), field name ($2), and direction ($3). Ignores leading and trailing "stuff".

© Copyright 2014 by Comvation AG
Generated on 2014-07-11T08:39:22+02:00.