95 lines
4.4 KiB
PHP
95 lines
4.4 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\Curriculum;
|
|
use App\Support\Prototype\Satu\Catalog;
|
|
use Illuminate\Contracts\View\View;
|
|
use Illuminate\Http\JsonResponse;
|
|
use Illuminate\Http\Request;
|
|
use Illuminate\Pagination\LengthAwarePaginator;
|
|
|
|
/** Perkuliahan > Manajemen Kurikulum > Kurikulum Prodi (slug list_kurikulum) untuk akun DB lama: t_kurikulum + distribusi SKS, dan rinciannya. */
|
|
class KurikulumController extends Controller
|
|
{
|
|
use ServesLegacyList;
|
|
|
|
private const string SLUG = 'list_kurikulum';
|
|
|
|
public function __construct(
|
|
private readonly AcademicOverview $overview,
|
|
private readonly Curriculum $curriculum,
|
|
) {}
|
|
|
|
public function __invoke(Request $request): View
|
|
{
|
|
$page = Catalog::page(self::SLUG);
|
|
$programs = $this->overview->programs((int) $request->user()->getKey());
|
|
$prodi = $programs->keys()->all();
|
|
[$labelTahun, $labelJenjang, $labelProdi] = $page['filters'];
|
|
|
|
return view('operator.satu.remote-list', [
|
|
'page' => $page,
|
|
'crumbs' => $this->crumbs(self::SLUG, $page),
|
|
'note' => 'Kurikulum asli program studi yang Anda kelola. SKS pilihan dihitung dari kelompok mata kuliah berketerangan "pilihan" (MKP); sisanya wajib.',
|
|
'empty' => ['icon' => 'building-library', 'title' => 'Akun belum terhubung ke program studi', 'description' => 'Daftar kurikulum tampil setelah akun Anda dipetakan ke program studi oleh Pusat Komputer.'],
|
|
'url' => route('operator.kurikulum.data'),
|
|
'viewUrl' => route('operator.kurikulum.show', '__ID__'),
|
|
'filters' => [
|
|
['name' => 'tahun', 'label' => $labelTahun, 'options' => $this->curriculum->years($prodi)->all()],
|
|
['name' => 'jenjang', 'label' => $labelJenjang, 'options' => $this->curriculum->levels($prodi)->all()],
|
|
['name' => 'prodi', 'label' => $labelProdi, 'options' => $programs->all()],
|
|
],
|
|
'columns' => [
|
|
['key' => 'kurikulum', 'label' => 'Kurikulum'],
|
|
['key' => 'kode', 'label' => 'Kode Prodi'],
|
|
['key' => 'prodi', 'label' => 'Program Studi'],
|
|
['key' => 'wajib', 'label' => 'Wajib', 'num' => true],
|
|
['key' => 'pilihan', 'label' => 'Pilihan', 'num' => true],
|
|
['key' => 'total', 'label' => 'Total', 'num' => true],
|
|
],
|
|
'perPage' => Curriculum::PER_PAGE,
|
|
'data' => $prodi === [] ? null : $this->payload($this->search($request, $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)));
|
|
}
|
|
|
|
public function show(Request $request, int $id): View
|
|
{
|
|
$this->legacyOnly($request);
|
|
$prodi = $this->overview->programs((int) $request->user()->getKey())->keys()->all();
|
|
$detail = $this->curriculum->detail($prodi, $id) ?? abort(404);
|
|
$page = Catalog::page(self::SLUG);
|
|
|
|
return view('operator.satu.kurikulum-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],
|
|
'kurikulum' => $detail['kurikulum'],
|
|
'semesters' => $detail['semesters'],
|
|
'back' => route('operator.halaman', self::SLUG),
|
|
]);
|
|
}
|
|
|
|
/** @param list<int> $prodi */
|
|
private function search(Request $request, array $prodi): LengthAwarePaginator
|
|
{
|
|
return $this->curriculum->list($prodi, [
|
|
'tahun' => preg_match('/^\d{4}$/', (string) $request->string('tahun')) ? (string) $request->string('tahun') : null,
|
|
'jenjang' => preg_match('/^[A-Za-z0-9]{1,6}$/', (string) $request->string('jenjang')) ? (string) $request->string('jenjang') : null,
|
|
'prodi' => $request->filled('prodi') && in_array($request->integer('prodi'), $prodi, true) ? $request->integer('prodi') : null,
|
|
'q' => $this->query($request),
|
|
], $this->perPage($request, Curriculum::PER_PAGE));
|
|
}
|
|
}
|