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

Refactored common list handling operations to new class

This commit is contained in:
Dan Brown
2022-10-30 15:16:06 +00:00
parent f75091a1c5
commit ec4cbbd004
17 changed files with 212 additions and 143 deletions

View File

@@ -3,6 +3,7 @@
namespace BookStack\Actions\Queries;
use BookStack\Actions\Webhook;
use BookStack\Util\SimpleListOptions;
use Illuminate\Pagination\LengthAwarePaginator;
/**
@@ -10,19 +11,14 @@ use Illuminate\Pagination\LengthAwarePaginator;
*/
class WebhooksAllPaginatedAndSorted
{
/**
* @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'];
$query = Webhook::query()->select(['*'])
->withCount(['trackedEvents'])
->orderBy($sort, $sortData['order']);
->orderBy($listOptions->getSort(), $listOptions->getOrder());
if ($sortData['search']) {
$term = '%' . $sortData['search'] . '%';
if ($listOptions->getSearch()) {
$term = '%' . $listOptions->getSearch() . '%';
$query->where(function ($query) use ($term) {
$query->where('name', 'like', $term)
->orWhere('endpoint', 'like', $term);