Penambahan menu Perkuliahan
This commit is contained in:
@@ -0,0 +1,87 @@
|
||||
<?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 > Set Grup MK Wajib Pilihan (slug set_grupmk) untuk akun DB lama: t_konsentrasi + anggota MK, hanya baca. */
|
||||
class GrupMkController extends Controller
|
||||
{
|
||||
use ServesLegacyList;
|
||||
|
||||
private const string SLUG = 'set_grupmk';
|
||||
|
||||
public function __construct(
|
||||
private readonly AcademicOverview $overview,
|
||||
private readonly Curriculum $curriculum,
|
||||
) {}
|
||||
|
||||
public function __invoke(Request $request): View
|
||||
{
|
||||
$page = Catalog::page(self::SLUG);
|
||||
$prodi = $this->overview->programs((int) $request->user()->getKey())->keys()->all();
|
||||
$curricula = $this->curriculum->curricula($prodi);
|
||||
[$labelKurikulum, $labelGrup] = $page['filters'];
|
||||
|
||||
return view('operator.satu.remote-list', [
|
||||
'page' => $page,
|
||||
'crumbs' => $this->crumbs(self::SLUG, $page),
|
||||
'note' => 'Grup mata kuliah asli (peminatan/konsentrasi kurikulum) program studi yang Anda kelola beserta mata kuliah anggotanya. Tombol tambah, ubah, dan hapus belum mengubah data.',
|
||||
'empty' => ['icon' => 'building-library', 'title' => 'Akun belum terhubung ke program studi', 'description' => 'Grup mata kuliah tampil setelah akun Anda dipetakan ke program studi oleh Pusat Komputer.'],
|
||||
'url' => route('operator.grupmk.data'),
|
||||
'filters' => [
|
||||
['name' => 'kurikulum', 'label' => $labelKurikulum, 'options' => $curricula->all()],
|
||||
['name' => 'grup', 'label' => $labelGrup, 'options' => $this->groupOptions($prodi)],
|
||||
],
|
||||
'columns' => [
|
||||
['key' => 'grup', 'label' => 'Grup MK'],
|
||||
['key' => 'mk', 'label' => 'Mata Kuliah'],
|
||||
],
|
||||
'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)));
|
||||
}
|
||||
|
||||
/**
|
||||
* Pilihan grup: semua grup prodi akun (nama grup saja; kurikulumnya ada di baris).
|
||||
*
|
||||
* @param list<int> $prodi
|
||||
* @return array<int, string>
|
||||
*/
|
||||
private function groupOptions(array $prodi): array
|
||||
{
|
||||
if ($prodi === []) {
|
||||
return [];
|
||||
}
|
||||
|
||||
return collect($this->curriculum->courseGroups($prodi, [], 500)->items())
|
||||
->mapWithKeys(fn (array $g): array => [$g['id'] => $g['grup']])->all();
|
||||
}
|
||||
|
||||
/** @param list<int> $prodi */
|
||||
private function search(Request $request, array $prodi): LengthAwarePaginator
|
||||
{
|
||||
return $this->curriculum->courseGroups($prodi, [
|
||||
'kurikulum' => $request->filled('kurikulum') ? $request->integer('kurikulum') : null,
|
||||
'grup' => $request->filled('grup') ? $request->integer('grup') : null,
|
||||
'q' => $this->query($request),
|
||||
], $this->perPage($request, Curriculum::PER_PAGE));
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user