]> BookStack Code Mirror - bookstack/blobdiff - app/Auth/Queries/RolesAllPaginatedAndSorted.php
Refactored common list handling operations to new class
[bookstack] / app / Auth / Queries / RolesAllPaginatedAndSorted.php
index 6abbfd1ad295ccec10db1df24212b19e9e8ec138..9ee4f6c249c56689849c7cb97add4ee6fbafeb25 100644 (file)
@@ -3,6 +3,7 @@
 namespace BookStack\Auth\Queries;
 
 use BookStack\Auth\Role;
+use BookStack\Util\SimpleListOptions;
 use Illuminate\Pagination\LengthAwarePaginator;
 
 /**
@@ -10,22 +11,19 @@ use Illuminate\Pagination\LengthAwarePaginator;
  */
 class RolesAllPaginatedAndSorted
 {
-    /**
-     * @param array{sort: string, order: string, search: string} $sortData
-     */
-    public function run(int $count, array $sortData): LengthAwarePaginator
+    public function run(int $count, SimpleListOptions $listOptions): LengthAwarePaginator
     {
-        $sort = $sortData['sort'];
+        $sort = $listOptions->getSort();
         if ($sort === 'created_at') {
             $sort = 'users.created_at';
         }
 
         $query = Role::query()->select(['*'])
             ->withCount(['users', 'permissions'])
-            ->orderBy($sort, $sortData['order']);
+            ->orderBy($sort, $listOptions->getOrder());
 
-        if ($sortData['search']) {
-            $term = '%' . $sortData['search'] . '%';
+        if ($listOptions->getSearch()) {
+            $term = '%' . $listOptions->getSearch() . '%';
             $query->where(function ($query) use ($term) {
                 $query->where('display_name', 'like', $term)
                     ->orWhere('description', 'like', $term);