mirror of
https://github.com/BookStackApp/BookStack.git
synced 2024-10-01 01:36:00 -04:00
36 lines
999 B
PHP
36 lines
999 B
PHP
<?php
|
|
|
|
namespace BookStack\Users\Queries;
|
|
|
|
use BookStack\Users\Models\Role;
|
|
use BookStack\Util\SimpleListOptions;
|
|
use Illuminate\Pagination\LengthAwarePaginator;
|
|
|
|
/**
|
|
* Get all the roles in the system in a paginated format.
|
|
*/
|
|
class RolesAllPaginatedAndSorted
|
|
{
|
|
public function run(int $count, SimpleListOptions $listOptions): LengthAwarePaginator
|
|
{
|
|
$sort = $listOptions->getSort();
|
|
if ($sort === 'created_at') {
|
|
$sort = 'users.created_at';
|
|
}
|
|
|
|
$query = Role::query()->select(['*'])
|
|
->withCount(['users', 'permissions'])
|
|
->orderBy($sort, $listOptions->getOrder());
|
|
|
|
if ($listOptions->getSearch()) {
|
|
$term = '%' . $listOptions->getSearch() . '%';
|
|
$query->where(function ($query) use ($term) {
|
|
$query->where('display_name', 'like', $term)
|
|
->orWhere('description', 'like', $term);
|
|
});
|
|
}
|
|
|
|
return $query->paginate($count);
|
|
}
|
|
}
|