135 lines
6.8 KiB
PHP
135 lines
6.8 KiB
PHP
<?php
|
||
|
||
namespace App\Http\Controllers\Operator;
|
||
|
||
use App\Http\Controllers\Controller;
|
||
use App\Http\Controllers\Operator\Concerns\ServesLegacyList;
|
||
use App\Models\Legacy\Account;
|
||
use App\Support\Legacy\AcademicOverview;
|
||
use App\Support\Legacy\StudentDirectory;
|
||
use App\Support\Prototype\Satu\Catalog;
|
||
use Illuminate\Contracts\View\View;
|
||
use Illuminate\Http\JsonResponse;
|
||
use Illuminate\Http\Request;
|
||
use Illuminate\Pagination\LengthAwarePaginator;
|
||
use Illuminate\Support\Collection;
|
||
|
||
/**
|
||
* Portal > Mahasiswa (slug list_mahasiswa) untuk akun DB lama: daftar mahasiswa asli prodi yang dipegang akun,
|
||
* dengan format tabel SATU yang sama. Halaman dipanggil oleh SatuPageController (rute dan menu tetap `operator.halaman`);
|
||
* filter, pencarian, dan halaman berikutnya diambil lewat data() (JSON) sehingga alamat halaman tidak berubah.
|
||
* Daftar hanya untuk melihat: tidak ada tambah, hapus, cetak, atau ubah di sini. Biodata dan data akademik diubah
|
||
* di halaman detail (StudentDetailController).
|
||
*/
|
||
class StudentListController extends Controller
|
||
{
|
||
use ServesLegacyList;
|
||
|
||
private const string SLUG = 'list_mahasiswa';
|
||
|
||
public function __construct(
|
||
private readonly AcademicOverview $overview,
|
||
private readonly StudentDirectory $directory,
|
||
) {}
|
||
|
||
public function __invoke(Request $request): View
|
||
{
|
||
$page = Catalog::page(self::SLUG);
|
||
$programs = $this->overview->programs((int) $request->user()->getKey());
|
||
$options = $programs->isEmpty() ? null : $this->directory->options($programs->keys()->all());
|
||
[$labelProdi, $labelAngkatan, $labelStatus, $labelProgram, $labelJalur] = $page['filters'];
|
||
|
||
return view('operator.satu.remote-list', [
|
||
'page' => $page,
|
||
'crumbs' => ['Beranda' => route('operator.dashboard')] + array_fill_keys(Catalog::trail(self::SLUG), null) + [$page['title'] => null],
|
||
'note' => 'Data mahasiswa asli dari SIAKAD untuk program studi yang Anda kelola. Pilih Lihat untuk membuka biodata lengkap; perubahan data dilakukan di dalam halaman detail.',
|
||
'empty' => ['icon' => 'building-library', 'title' => 'Akun belum terhubung ke program studi', 'description' => 'Daftar mahasiswa tampil setelah akun Anda dipetakan ke program studi oleh Pusat Komputer.'],
|
||
'url' => route('operator.mahasiswa.data'),
|
||
'viewUrl' => route('operator.list-mahasiswa.show', '__ID__'),
|
||
// Tanpa Tambah, Hapus, Cetak, dan kotak centang (tidak ada aksi massal).
|
||
'tools' => [],
|
||
'selectable' => false,
|
||
'filters' => [
|
||
['name' => 'prodi', 'label' => $labelProdi, 'options' => $programs->all()],
|
||
['name' => 'angkatan', 'label' => $labelAngkatan, 'options' => $options['angkatan'] ?? []],
|
||
['name' => 'status', 'label' => $labelStatus, 'options' => $this->directory->statusOptions()->all()],
|
||
['name' => 'program', 'label' => $labelProgram, 'options' => $options['program'] ?? []],
|
||
['name' => 'jalur', 'label' => $labelJalur, 'options' => $options['jalur'] ?? []],
|
||
],
|
||
'columns' => [
|
||
['key' => 'nim', 'label' => 'NIM'],
|
||
['key' => 'nama', 'label' => 'Nama'],
|
||
['key' => 'jenjang', 'label' => 'Jenjang'],
|
||
['key' => 'prodi', 'label' => 'Program Studi'],
|
||
['key' => 'masuk', 'label' => 'Masuk'],
|
||
['key' => 'status', 'label' => 'Status', 'badge' => true],
|
||
['key' => 'smt', 'label' => 'Smt', 'num' => true],
|
||
['key' => 'sks', 'label' => 'SKS', 'num' => true],
|
||
['key' => 'ipk', 'label' => 'IPK', 'num' => true],
|
||
],
|
||
'perPage' => StudentDirectory::PER_PAGE,
|
||
'data' => $options === null ? null : $this->payload($this->search($request, $programs, $options)),
|
||
]);
|
||
}
|
||
|
||
/** JSON untuk tabel (satuRemoteTable). Hanya akun DB lama yang memegang prodi. */
|
||
public function data(Request $request): JsonResponse
|
||
{
|
||
abort_unless($request->user() instanceof Account, 404);
|
||
|
||
$programs = $this->overview->programs((int) $request->user()->getKey());
|
||
abort_if($programs->isEmpty(), 404);
|
||
|
||
return response()->json($this->payload($this->search($request, $programs, $this->directory->options($programs->keys()->all()))));
|
||
}
|
||
|
||
/**
|
||
* Nilai filter di luar pilihan (termasuk prodi milik akun lain) diabaikan.
|
||
*
|
||
* @param Collection<int, string> $programs
|
||
* @param array{angkatan: array<int, string>, program: array<int, string>, jalur: array<int, string>} $options
|
||
*/
|
||
private function search(Request $request, Collection $programs, array $options): LengthAwarePaginator
|
||
{
|
||
$prodi = $programs->has($request->integer('prodi')) ? $request->integer('prodi') : null;
|
||
$status = (string) $request->string('status');
|
||
$perPage = in_array($request->integer('per'), StudentDirectory::PER_PAGE, true) ? $request->integer('per') : StudentDirectory::PER_PAGE[0];
|
||
|
||
return $this->directory->search($prodi ? [$prodi] : $programs->keys()->all(), [
|
||
'q' => mb_substr(trim((string) $request->string('q')), 0, 100),
|
||
'angkatan' => isset($options['angkatan'][$request->integer('angkatan')]) ? $request->integer('angkatan') : null,
|
||
'status' => $this->directory->statusOptions()->has($status) ? $status : null,
|
||
'program' => isset($options['program'][$request->integer('program')]) ? $request->integer('program') : null,
|
||
'jalur' => isset($options['jalur'][$request->integer('jalur')]) ? $request->integer('jalur') : null,
|
||
], $perPage);
|
||
}
|
||
|
||
/**
|
||
* Baris siap tampil (angka sudah diformat) dan keterangan halaman.
|
||
*
|
||
* @return array{rows: list<array<string, mixed>>, page: int, last_page: int, total: int, per_page: int}
|
||
*/
|
||
private function payload(LengthAwarePaginator $rows): array
|
||
{
|
||
return [
|
||
'rows' => collect($rows->items())->map(fn (array $m): array => [
|
||
'id' => $m['id'],
|
||
'nim' => $m['nim'],
|
||
'nama' => $m['nama'],
|
||
'jenjang' => $m['jenjang'] ?? '–',
|
||
'prodi' => $m['prodi'],
|
||
'masuk' => $m['angkatan'] === null ? '–' : (string) $m['angkatan'],
|
||
'status' => $m['status']['label'],
|
||
'tone' => $m['status']['tone'] === 'neutral' ? null : $m['status']['tone'],
|
||
'smt' => $m['semester'] === null ? '–' : (string) $m['semester'],
|
||
'sks' => number_format($m['sks_lulus'], 0, ',', '.'),
|
||
'ipk' => $m['ipk'] === null ? '–' : number_format($m['ipk'], 2, ',', ''),
|
||
])->all(),
|
||
'page' => $rows->currentPage(),
|
||
'last_page' => $rows->lastPage(),
|
||
'total' => $rows->total(),
|
||
'per_page' => $rows->perPage(),
|
||
];
|
||
}
|
||
}
|