mirror of
https://github.com/BookStackApp/BookStack.git
synced 2024-08-27 04:32:14 +00:00
![Dan Brown](/assets/img/avatar_default.png)
Also aligned query naming to start with model in use. Also added created/updated sort options to roles.
35 lines
916 B
PHP
35 lines
916 B
PHP
<?php
|
|
|
|
namespace BookStack\Actions\Queries;
|
|
|
|
use BookStack\Actions\Webhook;
|
|
use Illuminate\Pagination\LengthAwarePaginator;
|
|
|
|
/**
|
|
* Get all the webhooks in the system in a paginated format.
|
|
*/
|
|
class WebhooksAllPaginatedAndSorted
|
|
{
|
|
/**
|
|
* @param array{sort: string, order: string, search: string} $sortData
|
|
*/
|
|
public function run(int $count, array $sortData): LengthAwarePaginator
|
|
{
|
|
$sort = $sortData['sort'];
|
|
|
|
$query = Webhook::query()->select(['*'])
|
|
->withCount(['trackedEvents'])
|
|
->orderBy($sort, $sortData['order']);
|
|
|
|
if ($sortData['search']) {
|
|
$term = '%' . $sortData['search'] . '%';
|
|
$query->where(function ($query) use ($term) {
|
|
$query->where('name', 'like', $term)
|
|
->orWhere('endpoint', 'like', $term);
|
|
});
|
|
}
|
|
|
|
return $query->paginate($count);
|
|
}
|
|
}
|