2022-10-30 03:52:17 +08:00
|
|
|
<?php
|
|
|
|
|
2022-10-30 20:02:06 +08:00
|
|
|
namespace BookStack\Actions\Queries;
|
2022-10-30 03:52:17 +08:00
|
|
|
|
2022-10-30 20:02:06 +08:00
|
|
|
use BookStack\Actions\Webhook;
|
2022-10-30 23:16:06 +08:00
|
|
|
use BookStack\Util\SimpleListOptions;
|
2022-10-30 03:52:17 +08:00
|
|
|
use Illuminate\Pagination\LengthAwarePaginator;
|
|
|
|
|
|
|
|
/**
|
2022-10-30 20:02:06 +08:00
|
|
|
* Get all the webhooks in the system in a paginated format.
|
2022-10-30 03:52:17 +08:00
|
|
|
*/
|
2022-10-30 20:02:06 +08:00
|
|
|
class WebhooksAllPaginatedAndSorted
|
2022-10-30 03:52:17 +08:00
|
|
|
{
|
2022-10-30 23:16:06 +08:00
|
|
|
public function run(int $count, SimpleListOptions $listOptions): LengthAwarePaginator
|
2022-10-30 03:52:17 +08:00
|
|
|
{
|
2022-10-30 20:02:06 +08:00
|
|
|
$query = Webhook::query()->select(['*'])
|
|
|
|
->withCount(['trackedEvents'])
|
2022-10-30 23:16:06 +08:00
|
|
|
->orderBy($listOptions->getSort(), $listOptions->getOrder());
|
2022-10-30 03:52:17 +08:00
|
|
|
|
2022-10-30 23:16:06 +08:00
|
|
|
if ($listOptions->getSearch()) {
|
|
|
|
$term = '%' . $listOptions->getSearch() . '%';
|
2022-10-30 03:52:17 +08:00
|
|
|
$query->where(function ($query) use ($term) {
|
2022-10-30 20:02:06 +08:00
|
|
|
$query->where('name', 'like', $term)
|
|
|
|
->orWhere('endpoint', 'like', $term);
|
2022-10-30 03:52:17 +08:00
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
return $query->paginate($count);
|
|
|
|
}
|
|
|
|
}
|