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