]> BookStack Code Mirror - bookstack/blobdiff - app/Repos/UserRepo.php
replace GPL diff lib with MIT lib
[bookstack] / app / Repos / UserRepo.php
index b4931bdffbd859222238bcefbfa56c0fd3cbb2cb..0926f630471c24e1583b937e91ce74f2414d5da9 100644 (file)
@@ -51,6 +51,27 @@ class UserRepo
         return $this->user->with('roles', 'avatar')->orderBy('name', 'asc')->get();
     }
 
+    /**
+     * Get all the users with their permissions in a paginated format.
+     * @param int $count
+     * @param $sortData
+     * @return \Illuminate\Database\Eloquent\Builder|static
+     */
+    public function getAllUsersPaginatedAndSorted($count = 20, $sortData)
+    {
+        $query = $this->user->with('roles', 'avatar')->orderBy($sortData['sort'], $sortData['order']);
+
+        if ($sortData['search']) {
+            $term = '%' . $sortData['search'] . '%';
+            $query->where(function($query) use ($term) {
+                $query->where('name', 'like', $term)
+                    ->orWhere('email', 'like', $term);
+            });
+        }
+
+        return $query->paginate($count);
+    }
+
     /**
      * Creates a new user and attaches a role to them.
      * @param array $data