[Operator] Perbaikan Laman Portal -> Mahasiswa
This commit is contained in:
@@ -0,0 +1,167 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers\Operator;
|
||||
|
||||
use App\Http\Controllers\Controller;
|
||||
use App\Http\Controllers\Operator\Concerns\ServesLegacyList;
|
||||
use App\Support\Legacy\AcademicOverview;
|
||||
use App\Support\Legacy\Curriculum;
|
||||
use App\Support\Legacy\PortalException;
|
||||
use App\Support\Legacy\StudentBiodata;
|
||||
use App\Support\Legacy\StudentDirectory;
|
||||
use App\Support\Legacy\StudentRecords;
|
||||
use App\Support\Prototype\Satu\Catalog;
|
||||
use Illuminate\Contracts\View\View;
|
||||
use Illuminate\Http\JsonResponse;
|
||||
use Illuminate\Http\Request;
|
||||
|
||||
/**
|
||||
* Detail mahasiswa (aksi Lihat pada Portal > Mahasiswa) untuk akun DB lama: ringkasan akademik, biodata lengkap per
|
||||
* bagian, dan data akademik, semuanya diubah per bagian lewat JSON. Satu-satunya tempat mengubah data mahasiswa;
|
||||
* daftar hanya untuk melihat. Hanya mahasiswa prodi yang dipegang akun.
|
||||
*/
|
||||
class StudentDetailController extends Controller
|
||||
{
|
||||
use ServesLegacyList;
|
||||
|
||||
private const string SLUG = 'list_mahasiswa';
|
||||
|
||||
/** Kunci bagian data akademik (ditulis StudentRecords, bukan StudentBiodata). */
|
||||
private const string ACADEMIC = 'akademik';
|
||||
|
||||
public function __construct(
|
||||
private readonly AcademicOverview $overview,
|
||||
private readonly StudentDirectory $directory,
|
||||
private readonly StudentBiodata $biodata,
|
||||
private readonly StudentRecords $records,
|
||||
private readonly Curriculum $curriculum,
|
||||
) {}
|
||||
|
||||
public function show(Request $request, int $id): View
|
||||
{
|
||||
$accountId = (int) $request->user()->getKey();
|
||||
$prodi = $this->prodiOrFail($request);
|
||||
$student = $this->directory->find($prodi, $id) ?? abort(404);
|
||||
$bio = $this->biodata->find($prodi, $id) ?? abort(404);
|
||||
$page = Catalog::page(self::SLUG);
|
||||
|
||||
// Data akademik tampil tepat sesudah data pribadi.
|
||||
$sections = array_slice($bio['sections'], 0, 1, true)
|
||||
+ [self::ACADEMIC => $this->academic($accountId, $student, $bio['extra'])]
|
||||
+ array_slice($bio['sections'], 1, null, true);
|
||||
|
||||
return view('operator.satu.mahasiswa-detail', [
|
||||
'page' => $page,
|
||||
'crumbs' => ['Beranda' => route('operator.dashboard')] + array_fill_keys(Catalog::trail(self::SLUG), null) + [$page['title'] => route('operator.halaman', self::SLUG), 'Detail' => null],
|
||||
'student' => $student,
|
||||
'sections' => $sections,
|
||||
'back' => route('operator.halaman', self::SLUG),
|
||||
'saveUrl' => route('operator.list-mahasiswa.biodata', [$id, '__SECTION__']),
|
||||
]);
|
||||
}
|
||||
|
||||
public function update(Request $request, int $id, string $section): JsonResponse
|
||||
{
|
||||
$prodi = $this->prodiOrFail($request);
|
||||
abort_unless(in_array($section, [...StudentBiodata::sectionKeys(), self::ACADEMIC], true) && $this->biodata->exists($prodi, $id), 404);
|
||||
|
||||
try {
|
||||
if ($section === self::ACADEMIC) {
|
||||
return $this->updateAcademic($request, $prodi, $id);
|
||||
}
|
||||
|
||||
$input = $this->biodata->validated($prodi, $id, $section, $request->all());
|
||||
$result = $this->biodata->update($prodi, $id, $section, $input, (string) $request->user()->username, $request->ip());
|
||||
} catch (PortalException $e) {
|
||||
return response()->json(['message' => $e->getMessage()], 422);
|
||||
}
|
||||
|
||||
return response()->json([
|
||||
'message' => $result['changed'] === 0 ? 'Tidak ada perubahan.' : 'Biodata diperbarui.',
|
||||
'values' => $result['section']['values'],
|
||||
'display' => $result['section']['display'],
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Ubah data akademik. Ringkasan di bagian atas halaman (prodi, status, semester) ikut berubah, jadi klien memuat
|
||||
* ulang halaman; pesan berhasil dititipkan lewat sesi agar tampil sebagai toast di halaman baru.
|
||||
*
|
||||
* @param list<int> $prodi
|
||||
*/
|
||||
private function updateAcademic(Request $request, array $prodi, int $id): JsonResponse
|
||||
{
|
||||
$input = $request->validate([
|
||||
'prodi' => ['required', 'integer'],
|
||||
'kurikulum' => ['required', 'integer'],
|
||||
'angkatan' => ['required', 'integer'],
|
||||
'program' => ['required', 'integer'],
|
||||
'jalur' => ['nullable', 'integer'],
|
||||
'status' => ['required', 'integer', 'in:'.implode(',', array_keys(StudentRecords::STATUS))],
|
||||
], [], ['prodi' => 'program studi', 'kurikulum' => 'kurikulum', 'angkatan' => 'angkatan', 'program' => 'program kuliah', 'jalur' => 'jalur masuk', 'status' => 'status']);
|
||||
|
||||
$this->records->update($prodi, $id, $input, (string) $request->user()->username, $request->ip());
|
||||
$request->session()->flash('status', 'Data akademik diperbarui.');
|
||||
|
||||
return response()->json(['message' => 'Data akademik diperbarui.', 'reload' => true]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Bagian data akademik dalam bentuk yang sama dengan bagian biodata: isian yang bisa diubah plus keterangan yang
|
||||
* hanya dibaca (NIM, jenjang, dosen PA, tanggal lulus).
|
||||
*
|
||||
* @param array<string, mixed> $student baris StudentDirectory::find()
|
||||
* @param array<string, mixed> $extra StudentBiodata::find()['extra']
|
||||
* @return array<string, mixed>
|
||||
*/
|
||||
private function academic(int $accountId, array $student, array $extra): array
|
||||
{
|
||||
$programs = $this->overview->programs($accountId)->all();
|
||||
$options = $this->records->options();
|
||||
$form = $student['form'];
|
||||
|
||||
$fields = [
|
||||
['name' => 'prodi', 'label' => 'Program studi', 'type' => 'select', 'options' => $programs, 'required' => true],
|
||||
['name' => 'kurikulum', 'label' => 'Kurikulum', 'type' => 'select', 'options' => $this->curriculum->curricula(array_keys($programs))->all(), 'required' => true],
|
||||
['name' => 'angkatan', 'label' => 'Angkatan', 'type' => 'select', 'options' => $options['angkatan'], 'required' => true],
|
||||
['name' => 'program', 'label' => 'Program kuliah', 'type' => 'select', 'options' => $options['program'], 'required' => true],
|
||||
['name' => 'jalur', 'label' => 'Jalur masuk', 'type' => 'select', 'options' => $options['jalur']],
|
||||
['name' => 'status', 'label' => 'Status', 'type' => 'select', 'options' => StudentRecords::STATUS, 'required' => true],
|
||||
];
|
||||
|
||||
$values = [];
|
||||
$display = ['nim' => $student['nim'], 'jenjang' => $student['jenjang'] ?? '–', 'pa' => $extra['pa'] ?? '–', 'lulus' => $extra['lulus'] ?? '–'];
|
||||
foreach ($fields as &$field) {
|
||||
$name = $field['name'];
|
||||
$value = $form[$name];
|
||||
// Kode yang tidak ada di tabel pilihan tetap tampil agar tidak hilang saat disimpan.
|
||||
if ($value !== '' && ! isset($field['options'][$value])) {
|
||||
$field['options'][$value] = 'Kode '.$value;
|
||||
}
|
||||
$values[$name] = $value;
|
||||
$display[$name] = $value === '' ? '–' : $field['options'][$value];
|
||||
}
|
||||
unset($field);
|
||||
|
||||
return [
|
||||
'key' => self::ACADEMIC,
|
||||
'title' => 'Data akademik',
|
||||
'icon' => 'identification',
|
||||
'description' => 'NIM tidak dapat diubah dan status Lulus ditetapkan lewat yudisium.',
|
||||
'fields' => $fields,
|
||||
'values' => $values,
|
||||
'display' => $display,
|
||||
'readonly' => [['name' => 'nim', 'label' => 'NIM'], ['name' => 'jenjang', 'label' => 'Jenjang'], ['name' => 'pa', 'label' => 'Dosen pembimbing akademik'], ['name' => 'lulus', 'label' => 'Tanggal lulus']],
|
||||
];
|
||||
}
|
||||
|
||||
/** @return list<int> */
|
||||
private function prodiOrFail(Request $request): array
|
||||
{
|
||||
$this->legacyOnly($request);
|
||||
$prodi = $this->overview->programs((int) $request->user()->getKey())->keys()->all();
|
||||
abort_if($prodi === [], 404);
|
||||
|
||||
return $prodi;
|
||||
}
|
||||
}
|
||||
@@ -6,10 +6,7 @@ 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\Curriculum;
|
||||
use App\Support\Legacy\PortalException;
|
||||
use App\Support\Legacy\StudentDirectory;
|
||||
use App\Support\Legacy\StudentRecords;
|
||||
use App\Support\Prototype\Satu\Catalog;
|
||||
use Illuminate\Contracts\View\View;
|
||||
use Illuminate\Http\JsonResponse;
|
||||
@@ -21,6 +18,8 @@ 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
|
||||
{
|
||||
@@ -31,8 +30,6 @@ class StudentListController extends Controller
|
||||
public function __construct(
|
||||
private readonly AcademicOverview $overview,
|
||||
private readonly StudentDirectory $directory,
|
||||
private readonly StudentRecords $records,
|
||||
private readonly Curriculum $curriculum,
|
||||
) {}
|
||||
|
||||
public function __invoke(Request $request): View
|
||||
@@ -45,9 +42,13 @@ class StudentListController extends Controller
|
||||
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. Tambah, ubah, dan hapus langsung tersimpan di basis data; mahasiswa yang sudah punya data akademik, keuangan, atau akun login tidak dapat dihapus, dan NIM tidak dapat diubah.',
|
||||
'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'] ?? []],
|
||||
@@ -68,121 +69,9 @@ class StudentListController extends Controller
|
||||
],
|
||||
'perPage' => StudentDirectory::PER_PAGE,
|
||||
'data' => $options === null ? null : $this->payload($this->search($request, $programs, $options)),
|
||||
'form' => $options === null ? null : $this->form($programs->all()),
|
||||
'destroyUrl' => $options === null ? null : route('operator.list-mahasiswa.destroy'),
|
||||
'destroy' => ['title' => 'Hapus mahasiswa?', 'message' => 'Hanya mahasiswa tanpa data akademik, keuangan, dan akun login yang dapat dihapus.'],
|
||||
]);
|
||||
}
|
||||
|
||||
public function store(Request $request): JsonResponse
|
||||
{
|
||||
$prodi = $this->prodiOrFail($request);
|
||||
$input = $this->validated($request);
|
||||
|
||||
try {
|
||||
$id = $this->records->create($prodi, $input, (string) $request->user()->username, $request->ip());
|
||||
} catch (PortalException $e) {
|
||||
return response()->json(['message' => $e->getMessage()], 422);
|
||||
}
|
||||
|
||||
return response()->json(['message' => 'Mahasiswa ditambahkan.', 'id' => $id], 201);
|
||||
}
|
||||
|
||||
public function update(Request $request, int $id): JsonResponse
|
||||
{
|
||||
$prodi = $this->prodiOrFail($request);
|
||||
$input = $this->validated($request);
|
||||
|
||||
try {
|
||||
$this->records->update($prodi, $id, $input, (string) $request->user()->username, $request->ip());
|
||||
} catch (PortalException $e) {
|
||||
return response()->json(['message' => $e->getMessage()], 422);
|
||||
}
|
||||
|
||||
return response()->json(['message' => 'Data mahasiswa diperbarui.']);
|
||||
}
|
||||
|
||||
/** Hapus satu atau beberapa mahasiswa (POST {ids}). */
|
||||
public function destroy(Request $request): JsonResponse
|
||||
{
|
||||
$prodi = $this->prodiOrFail($request);
|
||||
$ids = $request->validate(['ids' => ['required', 'array', 'min:1', 'max:100'], 'ids.*' => ['integer']], [], ['ids' => 'mahasiswa'])['ids'];
|
||||
|
||||
try {
|
||||
$deleted = $this->records->delete($prodi, $ids);
|
||||
} catch (PortalException $e) {
|
||||
return response()->json(['message' => $e->getMessage()], 422);
|
||||
}
|
||||
|
||||
return response()->json(['message' => "{$deleted} mahasiswa dihapus."]);
|
||||
}
|
||||
|
||||
/** @return list<int> */
|
||||
private function prodiOrFail(Request $request): array
|
||||
{
|
||||
$this->legacyOnly($request);
|
||||
$prodi = $this->overview->programs((int) $request->user()->getKey())->keys()->all();
|
||||
abort_if($prodi === [], 404);
|
||||
|
||||
return $prodi;
|
||||
}
|
||||
|
||||
/** @return array<string, mixed> */
|
||||
private function validated(Request $request): array
|
||||
{
|
||||
return $request->validate([
|
||||
'nim' => ['required', 'string', 'max:15'],
|
||||
'nama' => ['required', 'string', 'max:50'],
|
||||
'prodi' => ['required', 'integer'],
|
||||
'kurikulum' => ['required', 'integer'],
|
||||
'angkatan' => ['required', 'integer'],
|
||||
'program' => ['required', 'integer'],
|
||||
'jalur' => ['nullable', 'integer'],
|
||||
'kelamin' => ['required', 'integer', 'in:1,2'],
|
||||
'tmplahir' => ['nullable', 'string', 'max:30'],
|
||||
'tgllahir' => ['nullable', 'date'],
|
||||
'hp' => ['nullable', 'string', 'max:35'],
|
||||
'email' => ['nullable', 'string', 'email', 'max:50'],
|
||||
'status' => ['required', 'integer', 'in:1,2,3,4,5'],
|
||||
], [], [
|
||||
'nim' => 'NIM', 'nama' => 'nama', 'prodi' => 'program studi', 'kurikulum' => 'kurikulum', 'angkatan' => 'angkatan',
|
||||
'program' => 'program kuliah', 'jalur' => 'jalur masuk', 'kelamin' => 'jenis kelamin', 'tmplahir' => 'tempat lahir',
|
||||
'tgllahir' => 'tanggal lahir', 'hp' => 'no. HP', 'email' => 'email', 'status' => 'status',
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Formulir tambah/ubah (modal); pilihan kurikulum memuat seluruh kurikulum prodi akun.
|
||||
*
|
||||
* @param array<int, string> $programs
|
||||
* @return array<string, mixed>
|
||||
*/
|
||||
private function form(array $programs): array
|
||||
{
|
||||
$options = $this->records->options();
|
||||
|
||||
return [
|
||||
'title' => 'mahasiswa',
|
||||
'storeUrl' => route('operator.list-mahasiswa.store'),
|
||||
'updateUrl' => route('operator.list-mahasiswa.update', '__ID__'),
|
||||
'fields' => [
|
||||
['name' => 'nim', 'label' => 'NIM', 'type' => 'text', 'required' => true, 'max' => 15, 'hint' => 'Tidak dapat diubah setelah disimpan.'],
|
||||
['name' => 'nama', 'label' => 'Nama', 'type' => 'text', 'required' => true, 'max' => 50],
|
||||
['name' => 'prodi', 'label' => 'Program studi', 'type' => 'select', 'options' => $programs, 'required' => true],
|
||||
['name' => 'kurikulum', 'label' => 'Kurikulum', 'type' => 'select', 'options' => $this->curriculum->curricula(array_keys($programs))->all(), 'required' => true, 'hint' => 'Pilih kurikulum milik program studi yang sama.'],
|
||||
['name' => 'angkatan', 'label' => 'Angkatan', 'type' => 'select', 'options' => $options['angkatan'], 'required' => true],
|
||||
['name' => 'program', 'label' => 'Program kuliah', 'type' => 'select', 'options' => $options['program'], 'required' => true],
|
||||
['name' => 'jalur', 'label' => 'Jalur masuk', 'type' => 'select', 'options' => $options['jalur']],
|
||||
['name' => 'kelamin', 'label' => 'Jenis kelamin', 'type' => 'select', 'options' => StudentRecords::GENDER, 'required' => true],
|
||||
['name' => 'tmplahir', 'label' => 'Tempat lahir', 'type' => 'text', 'max' => 30],
|
||||
['name' => 'tgllahir', 'label' => 'Tanggal lahir', 'type' => 'date'],
|
||||
['name' => 'hp', 'label' => 'No. HP', 'type' => 'text', 'max' => 35],
|
||||
['name' => 'email', 'label' => 'Email', 'type' => 'text', 'max' => 50],
|
||||
['name' => 'status', 'label' => 'Status', 'type' => 'select', 'options' => StudentRecords::STATUS, 'required' => true, 'default' => 1, 'hint' => 'Status Lulus ditetapkan lewat yudisium.'],
|
||||
],
|
||||
];
|
||||
}
|
||||
|
||||
/** JSON untuk tabel (satuRemoteTable). Hanya akun DB lama yang memegang prodi. */
|
||||
public function data(Request $request): JsonResponse
|
||||
{
|
||||
@@ -225,7 +114,6 @@ class StudentListController extends Controller
|
||||
return [
|
||||
'rows' => collect($rows->items())->map(fn (array $m): array => [
|
||||
'id' => $m['id'],
|
||||
'form' => $m['form'],
|
||||
'nim' => $m['nim'],
|
||||
'nama' => $m['nama'],
|
||||
'jenjang' => $m['jenjang'] ?? '–',
|
||||
|
||||
Reference in New Issue
Block a user