184 lines
9.1 KiB
PHP
184 lines
9.1 KiB
PHP
<?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\Administration;
|
|
use App\Support\Legacy\Graduation;
|
|
use App\Support\Legacy\GraduationWriter;
|
|
use App\Support\Legacy\PortalException;
|
|
use App\Support\Prototype\Satu\Catalog;
|
|
use Illuminate\Contracts\View\View;
|
|
use Illuminate\Http\JsonResponse;
|
|
use Illuminate\Http\Request;
|
|
use Illuminate\Pagination\LengthAwarePaginator;
|
|
|
|
/** Perkuliahan > Data Tugas Akhir > Daftar Tugas Akhir (slug list_ta) untuk akun DB lama: t_skripsi prodi akun; tambah, ubah, hapus. */
|
|
class TugasAkhirController extends Controller
|
|
{
|
|
use ServesLegacyList;
|
|
|
|
private const string SLUG = 'list_ta';
|
|
|
|
public function __construct(
|
|
private readonly AcademicOverview $overview,
|
|
private readonly Graduation $graduation,
|
|
private readonly Administration $admin,
|
|
private readonly GraduationWriter $writer,
|
|
) {}
|
|
|
|
public function __invoke(Request $request): View
|
|
{
|
|
$page = Catalog::page(self::SLUG);
|
|
$programs = $this->overview->programs((int) $request->user()->getKey());
|
|
$prodi = $programs->keys()->all();
|
|
[$labelUnit, $labelMasuk, $labelStatus, $labelTahap, $labelPembimbing, $labelPenguji] = $page['filters'];
|
|
|
|
return view('operator.satu.remote-list', [
|
|
'page' => $page,
|
|
'crumbs' => $this->crumbs(self::SLUG, $page),
|
|
'note' => 'Tugas akhir asli (t_skripsi) mahasiswa program studi yang Anda kelola: judul, pembimbing, penguji, tahap (lulus ujian bila tanggal lulus terisi), nilai dari mata kuliah tugas akhir. Tambah, ubah, dan hapus langsung tersimpan di basis data (tugas akhir yang sudah lulus ujian tidak bisa dihapus).',
|
|
'empty' => ['icon' => 'building-library', 'title' => 'Akun belum terhubung ke program studi', 'description' => 'Daftar tugas akhir tampil setelah akun Anda dipetakan ke program studi oleh Pusat Komputer.'],
|
|
'url' => route('operator.tugas-akhir.data'),
|
|
'filters' => [
|
|
['name' => 'prodi', 'label' => $labelUnit, 'options' => $programs->all()],
|
|
['name' => 'angkatan', 'label' => $labelMasuk, 'options' => $this->admin->cohorts($prodi)->all()],
|
|
['name' => 'status', 'label' => $labelStatus, 'options' => Graduation::THESIS_STATUS],
|
|
['name' => 'tahap', 'label' => $labelTahap, 'options' => Graduation::THESIS_STAGE],
|
|
['name' => 'pembimbing', 'label' => $labelPembimbing, 'options' => $this->graduation->examiners($prodi)->all()],
|
|
['name' => 'penguji', 'label' => $labelPenguji, 'options' => $this->graduation->examiners($prodi, false)->all()],
|
|
],
|
|
'columns' => [
|
|
['key' => 'mahasiswa', 'label' => 'Nama Mahasiswa'],
|
|
['key' => 'prodi_masuk', 'label' => 'Prodi dan Periode Masuk'],
|
|
['key' => 'judul', 'label' => 'Judul Tugas Akhir'],
|
|
['key' => 'dosen', 'label' => 'Dosen Pembimbing dan Penguji'],
|
|
['key' => 'tahap', 'label' => 'Tahap Tugas Akhir'],
|
|
['key' => 'nilai', 'label' => 'Nilai'],
|
|
['key' => 'status', 'label' => 'Status', 'badge' => true],
|
|
],
|
|
'perPage' => Graduation::PER_PAGE,
|
|
'data' => $prodi === [] ? null : $this->payload($this->search($request, $prodi)),
|
|
'form' => $prodi === [] ? null : $this->form($prodi),
|
|
'destroyUrl' => route('operator.tugas-akhir.destroy'),
|
|
'destroy' => ['title' => 'Hapus tugas akhir terpilih?', 'message' => 'Tugas akhir yang sudah lulus ujian akan ditolak.'],
|
|
]);
|
|
}
|
|
|
|
/** @param list<int> $prodi */
|
|
private function form(array $prodi): array
|
|
{
|
|
$lecturers = $this->graduation->lecturerOptions($prodi);
|
|
|
|
return [
|
|
'title' => 'tugas akhir',
|
|
'storeUrl' => route('operator.tugas-akhir.store'),
|
|
'updateUrl' => route('operator.tugas-akhir.update', '__ID__'),
|
|
'fields' => [
|
|
['name' => 'nim', 'label' => 'NIM mahasiswa', 'type' => 'text', 'required' => true, 'max' => 30, 'hint' => 'Mahasiswa program studi Anda; tidak berubah saat Ubah.'],
|
|
['name' => 'judul', 'label' => 'Judul tugas akhir', 'type' => 'text', 'required' => true, 'max' => 1000],
|
|
['name' => 'pembimbing1', 'label' => 'Pembimbing 1', 'type' => 'select', 'options' => $lecturers],
|
|
['name' => 'pembimbing2', 'label' => 'Pembimbing 2', 'type' => 'select', 'options' => $lecturers],
|
|
['name' => 'penguji1', 'label' => 'Penguji 1', 'type' => 'select', 'options' => $lecturers],
|
|
['name' => 'penguji2', 'label' => 'Penguji 2', 'type' => 'select', 'options' => $lecturers],
|
|
['name' => 'mulai', 'label' => 'Tanggal mulai', 'type' => 'date'],
|
|
['name' => 'lulus', 'label' => 'Tanggal lulus ujian', 'type' => 'date', 'hint' => 'Diisi bila ujian sudah lulus.'],
|
|
],
|
|
];
|
|
}
|
|
|
|
public function store(Request $request): JsonResponse
|
|
{
|
|
$prodi = $this->prodiOrFail($request);
|
|
$input = $this->validated($request, true);
|
|
|
|
try {
|
|
$id = $this->writer->createThesis($prodi, $input, (string) $request->user()->username, $request->ip());
|
|
} catch (PortalException $e) {
|
|
return response()->json(['message' => $e->getMessage()], 422);
|
|
}
|
|
|
|
return response()->json(['message' => 'Tugas akhir ditambahkan.', 'id' => $id], 201);
|
|
}
|
|
|
|
public function update(Request $request, int $id): JsonResponse
|
|
{
|
|
$prodi = $this->prodiOrFail($request);
|
|
$input = $this->validated($request, false);
|
|
|
|
try {
|
|
$this->writer->updateThesis($prodi, $id, $input, (string) $request->user()->username, $request->ip());
|
|
} catch (PortalException $e) {
|
|
return response()->json(['message' => $e->getMessage()], 422);
|
|
}
|
|
|
|
return response()->json(['message' => 'Tugas akhir diperbarui.']);
|
|
}
|
|
|
|
/** Hapus satu atau beberapa tugas akhir (POST {ids}). */
|
|
public function destroy(Request $request): JsonResponse
|
|
{
|
|
$prodi = $this->prodiOrFail($request);
|
|
$ids = $request->validate(['ids' => ['required', 'array', 'min:1'], 'ids.*' => ['integer']], [], ['ids' => 'tugas akhir'])['ids'];
|
|
|
|
try {
|
|
$deleted = $this->writer->deleteTheses($prodi, $ids);
|
|
} catch (PortalException $e) {
|
|
return response()->json(['message' => $e->getMessage()], 422);
|
|
}
|
|
|
|
return response()->json(['message' => "{$deleted} tugas akhir dihapus."]);
|
|
}
|
|
|
|
/** @return array<string, mixed> */
|
|
private function validated(Request $request, bool $creating): array
|
|
{
|
|
return $request->validate([
|
|
'nim' => [$creating ? 'required' : 'nullable', 'string', 'max:30'],
|
|
'judul' => ['required', 'string', 'max:1000'],
|
|
'pembimbing1' => ['nullable', 'integer'], 'pembimbing2' => ['nullable', 'integer'],
|
|
'penguji1' => ['nullable', 'integer'], 'penguji2' => ['nullable', 'integer'],
|
|
'mulai' => ['nullable', 'date_format:Y-m-d'],
|
|
'lulus' => ['nullable', 'date_format:Y-m-d'],
|
|
], [], [
|
|
'nim' => 'NIM', 'judul' => 'judul tugas akhir', 'pembimbing1' => 'pembimbing 1', 'pembimbing2' => 'pembimbing 2',
|
|
'penguji1' => 'penguji 1', 'penguji2' => 'penguji 2', 'mulai' => 'tanggal mulai', 'lulus' => 'tanggal lulus ujian',
|
|
]);
|
|
}
|
|
|
|
/** @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;
|
|
}
|
|
|
|
public function data(Request $request): JsonResponse
|
|
{
|
|
$this->legacyOnly($request);
|
|
$prodi = $this->overview->programs((int) $request->user()->getKey())->keys()->all();
|
|
abort_if($prodi === [], 404);
|
|
|
|
return response()->json($this->payload($this->search($request, $prodi)));
|
|
}
|
|
|
|
/** @param list<int> $prodi */
|
|
private function search(Request $request, array $prodi): LengthAwarePaginator
|
|
{
|
|
return $this->graduation->theses($prodi, [
|
|
'prodi' => $request->filled('prodi') && in_array($request->integer('prodi'), $prodi, true) ? $request->integer('prodi') : null,
|
|
'angkatan' => $request->filled('angkatan') ? $request->integer('angkatan') : null,
|
|
'status' => isset(Graduation::THESIS_STATUS[(string) $request->string('status')]) ? (string) $request->string('status') : null,
|
|
'tahap' => isset(Graduation::THESIS_STAGE[(string) $request->string('tahap')]) ? (string) $request->string('tahap') : null,
|
|
'pembimbing' => $request->filled('pembimbing') ? $request->integer('pembimbing') : null,
|
|
'penguji' => $request->filled('penguji') ? $request->integer('penguji') : null,
|
|
'q' => $this->query($request),
|
|
], $this->perPage($request, Graduation::PER_PAGE));
|
|
}
|
|
}
|