class CRM_Utils_Sort

Base class to provide generic sort functionality.

Note that some ideas have been borrowed from the drupal tablesort.inc code.

Also note that since the Pager and Sort class are similar, do match the function names if introducing additional functionality

Constants

ASCENDING

Constants to determine what direction each variable is to be sorted

DESCENDING

Constants to determine what direction each variable is to be sorted

DONTCARE

Constants to determine what direction each variable is to be sorted

SORT_ID

Constants to determine what direction each variable is to be sorted

SORT_DIRECTION

Constants to determine what direction each variable is to be sorted

SORT_ORDER

Constants to determine what direction each variable is to be sorted

Properties

protected string $_name Name of the sort function. Used to isolate session variables
array $_vars Array of variables that influence the query
$_link The newly formulated base url to be used as links for various table elements
protected string $_urlVar What's the name of the sort variable in a REQUEST
protected string $_currentSortID What variable are we currently sorting on
protected string $_currentSortDirection What direction are we sorting on
array $_response The output generated for the current form

Methods

__construct(mixed $vars, string $defaultSortOrder = NULL)

The constructor takes an assoc array key names of variable (which should be the same as the column name) value: ascending or descending

string
orderBy()

Function returns the string for the order by clause.

static string
sortIDValue(int $index, int $dir)

Create the sortID string to be used in the GET param.

initSortID(string $defaultSortOrder)

Init the sort ID values in the object.

initialize(string $defaultSortOrder)

Init the object.

int
getCurrentSortID()

Getter for currentSortID.

int
getCurrentSortDirection()

Getter for currentSortDirection.

static int
cmpFunc($a, $b)

Universal callback function for sorting by weight, id, title or name

Details

at line 118
CRM_Utils_Sort __construct(mixed $vars, string $defaultSortOrder = NULL)

The constructor takes an assoc array key names of variable (which should be the same as the column name) value: ascending or descending

Parameters

mixed $vars Assoc array as described above.
string $defaultSortOrder Order to sort.

Return Value

CRM_Utils_Sort

at line 146
string orderBy()

Function returns the string for the order by clause.

Return Value

string the order by clause

at line 174
static string sortIDValue(int $index, int $dir)

Create the sortID string to be used in the GET param.

Parameters

int $index The field index.
int $dir The direction of the sort.

Return Value

string the string to append to the url

at line 184
initSortID(string $defaultSortOrder)

Init the sort ID values in the object.

Parameters

string $defaultSortOrder The sort order to use by default.

at line 219
initialize(string $defaultSortOrder)

Init the object.

Parameters

string $defaultSortOrder The sort order to use by default.

at line 253
int getCurrentSortID()

Getter for currentSortID.

Return Value

int returns of the current sort id

at line 263
int getCurrentSortDirection()

Getter for currentSortDirection.

Return Value

int returns of the current sort direction

at line 276
static int cmpFunc($a, $b)

Universal callback function for sorting by weight, id, title or name

Parameters

$a
$b

Return Value

int (-1 or 1)