mirror of
https://github.com/Icinga/icingaweb2.git
synced 2025-07-27 07:44:04 +02:00
lib: Add SimpleQuery::splitOrder() ...
... for supporting specifying the sort direction next to the column, e.g. 'service_display_name ASC' refs #8716
This commit is contained in:
parent
e17f9d7ebe
commit
949438d753
@ -161,6 +161,26 @@ class SimpleQuery implements QueryInterface, Queryable
|
|||||||
throw new IcingaException('This function does nothing and will be removed');
|
throw new IcingaException('This function does nothing and will be removed');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Split order field into its field and sort direction
|
||||||
|
*
|
||||||
|
* @param string $field
|
||||||
|
*
|
||||||
|
* @return array
|
||||||
|
*/
|
||||||
|
public function splitOrder($field)
|
||||||
|
{
|
||||||
|
$fieldAndDirection = explode(' ', $field, 2);
|
||||||
|
if (count($fieldAndDirection) === 1) {
|
||||||
|
$direction = null;
|
||||||
|
} else {
|
||||||
|
$field = $fieldAndDirection[0];
|
||||||
|
$direction = (strtoupper(trim($fieldAndDirection[1])) === 'DESC') ?
|
||||||
|
Sortable::SORT_DESC : Sortable::SORT_ASC;
|
||||||
|
}
|
||||||
|
return array($field, $direction);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Sort result set by the given field (and direction)
|
* Sort result set by the given field (and direction)
|
||||||
*
|
*
|
||||||
@ -177,13 +197,9 @@ class SimpleQuery implements QueryInterface, Queryable
|
|||||||
public function order($field, $direction = null)
|
public function order($field, $direction = null)
|
||||||
{
|
{
|
||||||
if ($direction === null) {
|
if ($direction === null) {
|
||||||
$fieldAndDirection = explode(' ', $field, 2);
|
list($field, $direction) = $this->splitOrder($field);
|
||||||
if (count($fieldAndDirection) === 1) {
|
if ($direction === null) {
|
||||||
$direction = self::SORT_ASC;
|
$direction = Sortable::SORT_ASC;
|
||||||
} else {
|
|
||||||
$field = $fieldAndDirection[0];
|
|
||||||
$direction = (strtoupper(trim($fieldAndDirection[1])) === 'DESC') ?
|
|
||||||
Sortable::SORT_DESC : Sortable::SORT_ASC;
|
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
switch (($direction = strtoupper($direction))) {
|
switch (($direction = strtoupper($direction))) {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user