50 lines
1.7 KiB
PHP
50 lines
1.7 KiB
PHP
<?php
|
|
|
|
namespace App\Http\Controllers\Operator\Concerns;
|
|
|
|
use App\Models\Legacy\Account;
|
|
use App\Support\Prototype\Satu\Catalog;
|
|
use Illuminate\Http\Request;
|
|
use Illuminate\Pagination\LengthAwarePaginator;
|
|
|
|
/** Bagian bersama pengendali halaman SATU berdata asli: jejak, muatan JSON tabel, penjagaan akun DB lama, per halaman. */
|
|
trait ServesLegacyList
|
|
{
|
|
/** @return array<string, ?string> */
|
|
protected function crumbs(string $slug, array $page): array
|
|
{
|
|
return ['Beranda' => route(auth()->user()->role->dashboardRoute())] + array_fill_keys(Catalog::trail($slug), null) + [$page['title'] => null];
|
|
}
|
|
|
|
/** @return array{rows: list<array<string, mixed>>, page: int, last_page: int, total: int, per_page: int} */
|
|
protected function payload(LengthAwarePaginator $rows): array
|
|
{
|
|
return [
|
|
'rows' => array_values($rows->items()),
|
|
'page' => $rows->currentPage(),
|
|
'last_page' => $rows->lastPage(),
|
|
'total' => $rows->total(),
|
|
'per_page' => $rows->perPage(),
|
|
];
|
|
}
|
|
|
|
/** Hanya akun DB lama yang memegang data asli; akun demo mendapat 404 (halamannya prototipe). */
|
|
protected function legacyOnly(Request $request): void
|
|
{
|
|
abort_unless($request->user() instanceof Account, 404);
|
|
}
|
|
|
|
/** @param list<int> $allowed */
|
|
protected function perPage(Request $request, array $allowed): int
|
|
{
|
|
return in_array($request->integer('per'), $allowed, true) ? $request->integer('per') : $allowed[0];
|
|
}
|
|
|
|
protected function query(Request $request): string
|
|
{
|
|
$q = $request->input('q');
|
|
|
|
return is_string($q) ? mb_substr(trim($q), 0, 100) : '';
|
|
}
|
|
}
|