adds possibility to sort ascending or descending by timestamp
This commit is contained in:
parent
fbd9e9bd30
commit
4ff3b79b99
2 changed files with 14 additions and 6 deletions
|
@ -80,7 +80,8 @@ switch ($method) {
|
|||
case 'list':
|
||||
$limit = getOptionalPostParameter('limit', $config['list_default_limit']);
|
||||
$offset = getOptionalPostParameter('offset', 0);
|
||||
$files = listFiles($userJid, $limit, $offset);
|
||||
$descending = getOptionalPostParameter('descending', 'false') === 'true';
|
||||
$files = listFiles($userJid, $limit, $offset, $descending);
|
||||
$result = ['list' => $files];
|
||||
break;
|
||||
case 'upload':
|
||||
|
|
|
@ -24,14 +24,21 @@ function loadSlotParameters($slotUUID, $config) {
|
|||
return $slotParameters;
|
||||
}
|
||||
|
||||
function listFiles($jid, $limit = -1, $offset = 0) {
|
||||
function listFiles($jid, $limit = -1, $offset = 0, $descending = false) {
|
||||
// Read complete set of existing slots per jid (unsorted)
|
||||
$slots = readSlots($jid, $limit, $offset);
|
||||
|
||||
// Sort ascending by timestamp
|
||||
usort($slots, function($a, $b) {
|
||||
return $a['sent_time'] - $b['sent_time'];
|
||||
});
|
||||
if ($descending) {
|
||||
// Sort descending by timestamp
|
||||
usort($slots, function($a, $b) {
|
||||
return $b['sent_time'] - $a['sent_time'];
|
||||
});
|
||||
} else {
|
||||
// Sort ascending by timestamp
|
||||
usort($slots, function($a, $b) {
|
||||
return $a['sent_time'] - $b['sent_time'];
|
||||
});
|
||||
}
|
||||
|
||||
// Select requested slot subset
|
||||
$offsetCounter = 0;
|
||||
|
|
Loading…
Reference in a new issue