]> BookStack Code Mirror - bookstack/blob - app/Actions/Queries/WebhooksAllPaginatedAndSorted.php
Added force option for update-url command
[bookstack] / app / Actions / Queries / WebhooksAllPaginatedAndSorted.php
1 <?php
2
3 namespace BookStack\Actions\Queries;
4
5 use BookStack\Actions\Webhook;
6 use BookStack\Util\SimpleListOptions;
7 use Illuminate\Pagination\LengthAwarePaginator;
8
9 /**
10  * Get all the webhooks in the system in a paginated format.
11  */
12 class WebhooksAllPaginatedAndSorted
13 {
14     public function run(int $count, SimpleListOptions $listOptions): LengthAwarePaginator
15     {
16         $query = Webhook::query()->select(['*'])
17             ->withCount(['trackedEvents'])
18             ->orderBy($listOptions->getSort(), $listOptions->getOrder());
19
20         if ($listOptions->getSearch()) {
21             $term = '%' . $listOptions->getSearch() . '%';
22             $query->where(function ($query) use ($term) {
23                 $query->where('name', 'like', $term)
24                     ->orWhere('endpoint', 'like', $term);
25             });
26         }
27
28         return $query->paginate($count);
29     }
30 }