1
0
mirror of https://github.com/BookStackApp/BookStack.git synced 2025-07-30 04:23:11 +03:00

Added pagination, sorting & searching to users list

As requested on #113
This commit is contained in:
Dan Brown
2016-05-22 10:44:31 +01:00
parent 23ab1f0c81
commit be517de7dc
7 changed files with 123 additions and 17 deletions

View File

@ -59,3 +59,35 @@ function setting($key, $default = false)
$settingService = app('BookStack\Services\SettingService');
return $settingService->get($key, $default);
}
/**
* Generate a url with multiple parameters for sorting purposes.
* Works out the logic to set the correct sorting direction
* Discards empty parameters and allows overriding.
* @param $path
* @param array $data
* @param array $overrideData
* @return string
*/
function sortUrl($path, $data, $overrideData = [])
{
$queryStringSections = [];
$queryData = array_merge($data, $overrideData);
// Change sorting direction is already sorted on current attribute
if (isset($overrideData['sort']) && $overrideData['sort'] === $data['sort']) {
$queryData['order'] = ($data['order'] === 'asc') ? 'desc' : 'asc';
} else {
$queryData['order'] = 'asc';
}
foreach ($queryData as $name => $value) {
$trimmedVal = trim($value);
if ($trimmedVal === '') continue;
$queryStringSections[] = urlencode($name) . '=' . urlencode($trimmedVal);
}
if (count($queryStringSections) === 0) return $path;
return $path . '?' . implode('&', $queryStringSections);
}