Sort sharees

To ensure that pagination is working properly we need to make sure the
shares are always in the same order.

Sorting is first done by label (catches most instances)
If there is a user and a group with the same label we sort by shareType
If there are multiple users with the same label we sort those by
shareWith
This commit is contained in:
Roeland Jago Douma 2015-08-09 20:47:49 +02:00 committed by Joas Schilling
parent 98301210a9
commit 8a5c1e6d4d
1 changed files with 18 additions and 0 deletions

View File

@ -205,6 +205,24 @@ class Sharees {
$sharees = array_merge($sharees, $this->getRemote($search));
}
// Sort sharees
usort($sharees, function($a, $b) {
$res = strcmp($a['label'], $b['label']);
// If labels are equal sort by share type
if ($res === 0) {
$res = $a['value']['shareType'] - $b['value']['shareType'];
}
// If sharetype is equal compare shareWith
if ($res === 0) {
$res = strcmp($a['value']['shareWith'], $b['value']['shareWith']);
}
return $res;
});
//Pagination
$start = ($page - 1) * $per_page;
$end = $page * $per_page;