[Superuser] Integrasi Pertama ke Database
This commit is contained in:
@@ -2,13 +2,37 @@
|
||||
|
||||
namespace App\Http\Controllers;
|
||||
|
||||
use App\Models\Legacy\Account;
|
||||
use App\Support\Legacy\AcademicCalendar;
|
||||
use App\Support\Prototype\Sample;
|
||||
use Illuminate\Contracts\View\View;
|
||||
use Illuminate\Http\Request;
|
||||
|
||||
/** Kalender akademik bersama. Akun DB lama: kegiatan asli t_kalender_kegiatan per periode; akun demo: contoh. */
|
||||
class KalenderController extends Controller
|
||||
{
|
||||
public function __invoke(): View
|
||||
public function __invoke(Request $request, AcademicCalendar $calendar): View
|
||||
{
|
||||
return view('kalender.index', ['tahun' => Sample::TAHUN_AKTIF, 'events' => Sample::kalender()]);
|
||||
if (! $request->user() instanceof Account) {
|
||||
return view('kalender.index', ['tahun' => Sample::TAHUN_AKTIF, 'events' => Sample::kalender()]);
|
||||
}
|
||||
|
||||
$periods = $calendar->periods();
|
||||
$periode = $periods->has($request->integer('periode')) ? $request->integer('periode') : $calendar->currentPeriod($periods);
|
||||
|
||||
$events = $periode === null ? collect() : $calendar->schedule($periode)->map(fn (array $e): array => [
|
||||
'judul' => $e['keterangan'] !== '' ? $e['keterangan'] : $e['jenis'],
|
||||
'kategori' => $e['jenis'],
|
||||
'tone' => str_contains(mb_strtolower($e['jenis']), 'libur') ? 'gold' : 'neutral',
|
||||
'mulai' => $e['mulai'],
|
||||
'selesai' => $e['selesai'] === $e['mulai'] ? null : $e['selesai'],
|
||||
]);
|
||||
|
||||
return view('kalender.index', [
|
||||
'tahun' => $periode === null ? '' : $periods[$periode],
|
||||
'events' => $events,
|
||||
'periods' => $periods,
|
||||
'periode' => $periode,
|
||||
]);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -78,7 +78,9 @@ class KelasController extends Controller
|
||||
'storeUrl' => route('operator.kelas-kuliah.store'),
|
||||
'updateUrl' => route('operator.kelas-kuliah.update', '__ID__'),
|
||||
'fields' => [
|
||||
['name' => 'mk', 'label' => 'Mata kuliah', 'type' => 'select', 'options' => $this->curriculum->courseOptions($prodi)->all(), 'required' => true, 'hint' => 'Mata kuliah dan periode tidak dapat diubah setelah kelas dibuat.'],
|
||||
// Pilihan bertingkat: program studi -> mata kuliah kurikulum prodi itu (dependsOn/optionsBy).
|
||||
['name' => 'prodi', 'label' => 'Program studi', 'type' => 'select', 'options' => $programs->all(), 'required' => true, 'placeholder' => 'Pilih Program Studi', 'search' => true, 'default' => $programs->count() === 1 ? $programs->keys()->first() : ''],
|
||||
['name' => 'mk', 'label' => 'Mata kuliah', 'type' => 'select', 'dependsOn' => 'prodi', 'optionsBy' => $this->curriculum->courseOptionsByProdi($prodi), 'emptyHint' => 'Belum ada mata kuliah untuk program studi ini. Tambahkan lewat Perkuliahan > Mata Kuliah.', 'required' => true, 'placeholder' => 'Pilih Mata Kuliah', 'search' => true, 'hint' => 'Program studi, mata kuliah, dan periode tidak dapat diubah setelah kelas dibuat.'],
|
||||
['name' => 'periode', 'label' => 'Periode akademik', 'type' => 'select', 'options' => $periods->all(), 'required' => true, 'default' => $default],
|
||||
['name' => 'kelas', 'label' => 'Nama kelas', 'type' => 'text', 'required' => true, 'max' => 5],
|
||||
['name' => 'kapasitas', 'label' => 'Kapasitas', 'type' => 'number', 'required' => true, 'min' => 0, 'max' => 999, 'default' => 0],
|
||||
@@ -209,11 +211,12 @@ class KelasController extends Controller
|
||||
private function validated(Request $request): array
|
||||
{
|
||||
return $request->validate([
|
||||
'prodi' => ['required', 'integer'],
|
||||
'mk' => ['required', 'integer'],
|
||||
'periode' => ['required', 'integer'],
|
||||
'kelas' => ['required', 'string', 'max:5'],
|
||||
'kapasitas' => ['required', 'integer', 'min:0', 'max:999'],
|
||||
], [], ['mk' => 'mata kuliah', 'periode' => 'periode akademik', 'kelas' => 'nama kelas', 'kapasitas' => 'kapasitas']);
|
||||
], [], ['prodi' => 'program studi', 'mk' => 'mata kuliah', 'periode' => 'periode akademik', 'kelas' => 'nama kelas', 'kapasitas' => 'kapasitas']);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -0,0 +1,154 @@
|
||||
<?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\SubjectGroups;
|
||||
use App\Support\Prototype\Satu\Catalog;
|
||||
use Illuminate\Contracts\View\View;
|
||||
use Illuminate\Http\JsonResponse;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Pagination\LengthAwarePaginator;
|
||||
|
||||
/**
|
||||
* Data Pelengkap > Perkuliahan > Kelompok Matakuliah (slug ms_kelompokmk) untuk akun DB lama: t_jenismatakuliah per
|
||||
* kurikulum prodi akun. Kelompok inilah yang dipilih di formulir Mata Kuliah; tambah/ubah lewat modal, hapus per baris.
|
||||
*/
|
||||
class KelompokMkController extends Controller
|
||||
{
|
||||
use ServesLegacyList;
|
||||
|
||||
private const string SLUG = 'ms_kelompokmk';
|
||||
|
||||
public function __construct(
|
||||
private readonly AcademicOverview $overview,
|
||||
private readonly Curriculum $curriculum,
|
||||
private readonly SubjectGroups $groups,
|
||||
) {}
|
||||
|
||||
public function __invoke(Request $request): View
|
||||
{
|
||||
$page = Catalog::page(self::SLUG);
|
||||
$programs = $this->overview->programs((int) $request->user()->getKey());
|
||||
$prodi = $programs->keys()->all();
|
||||
|
||||
return view('operator.satu.remote-list', [
|
||||
'page' => $page,
|
||||
'crumbs' => $this->crumbs(self::SLUG, $page),
|
||||
'note' => 'Kelompok mata kuliah asli (t_jenismatakuliah) per kurikulum program studi yang Anda kelola; kelompok inilah yang dipilih saat menambah mata kuliah. Kelompok baru wajib dibuat dulu untuk kurikulum yang baru. Tambah, ubah, dan hapus langsung tersimpan; kelompok yang sudah dipakai mata kuliah tidak bisa dihapus atau dipindah kurikulum.',
|
||||
'empty' => ['icon' => 'building-library', 'title' => 'Akun belum terhubung ke program studi', 'description' => 'Daftar kelompok mata kuliah tampil setelah akun Anda dipetakan ke program studi oleh Pusat Komputer.'],
|
||||
'url' => route('operator.kelompokmk.data'),
|
||||
'filters' => [
|
||||
['name' => 'prodi', 'label' => 'Program Studi', 'options' => $programs->all()],
|
||||
['name' => 'kurikulum', 'label' => 'Kurikulum', 'options' => $this->curriculum->curricula($prodi)->all()],
|
||||
],
|
||||
'columns' => [
|
||||
['key' => 'kurikulum', 'label' => 'Kurikulum'],
|
||||
['key' => 'prodi', 'label' => 'Program Studi'],
|
||||
['key' => 'kode', 'label' => 'Kode'],
|
||||
['key' => 'nama', 'label' => 'Nama Kelompok Mata Kuliah'],
|
||||
['key' => 'mk', 'label' => 'Mata Kuliah', 'num' => true],
|
||||
],
|
||||
'perPage' => Curriculum::PER_PAGE,
|
||||
'data' => $prodi === [] ? null : $this->payload($this->search($request, $prodi)),
|
||||
'form' => $prodi === [] ? null : [
|
||||
'title' => 'kelompok mata kuliah',
|
||||
'storeUrl' => route('operator.kelompokmk.store'),
|
||||
'updateUrl' => route('operator.kelompokmk.update', '__ID__'),
|
||||
'fields' => [
|
||||
['name' => 'prodi', 'label' => 'Program studi', 'type' => 'select', 'options' => $programs->all(), 'required' => true, 'placeholder' => 'Pilih Program Studi', 'search' => true, 'default' => $programs->count() === 1 ? $programs->keys()->first() : ''],
|
||||
['name' => 'kurikulum', 'label' => 'Kurikulum', 'type' => 'select', 'dependsOn' => 'prodi', 'optionsBy' => $this->curriculum->curriculaByProdi($prodi), 'required' => true, 'placeholder' => 'Pilih Kurikulum', 'search' => true],
|
||||
['name' => 'kode', 'label' => 'Kode kelompok', 'type' => 'text', 'required' => true, 'max' => 50, 'hint' => 'Contoh: MKWU, MKK, MKP. Kode "MKP" atau keterangan berisi "pilihan" dihitung sebagai SKS pilihan.'],
|
||||
['name' => 'nama', 'label' => 'Nama kelompok', 'type' => 'text', 'required' => true, 'max' => 50],
|
||||
],
|
||||
],
|
||||
'destroyUrl' => $prodi === [] ? null : route('operator.kelompokmk.destroy'),
|
||||
'destroy' => ['title' => 'Hapus kelompok mata kuliah?', 'message' => 'Kelompok dihapus bila belum dipakai mata kuliah mana pun.'],
|
||||
]);
|
||||
}
|
||||
|
||||
public function data(Request $request): JsonResponse
|
||||
{
|
||||
$prodi = $this->prodiOrFail($request);
|
||||
|
||||
return response()->json($this->payload($this->search($request, $prodi)));
|
||||
}
|
||||
|
||||
public function store(Request $request): JsonResponse
|
||||
{
|
||||
$prodi = $this->prodiOrFail($request);
|
||||
$input = $this->validated($request);
|
||||
|
||||
try {
|
||||
$id = $this->groups->create($prodi, $input, (string) $request->user()->username, $request->ip());
|
||||
} catch (PortalException $e) {
|
||||
return response()->json(['message' => $e->getMessage()], 422);
|
||||
}
|
||||
|
||||
return response()->json(['message' => 'Kelompok mata kuliah ditambahkan.', 'id' => $id], 201);
|
||||
}
|
||||
|
||||
public function update(Request $request, int $id): JsonResponse
|
||||
{
|
||||
$prodi = $this->prodiOrFail($request);
|
||||
$input = $this->validated($request);
|
||||
|
||||
try {
|
||||
$this->groups->update($prodi, $id, $input, (string) $request->user()->username, $request->ip());
|
||||
} catch (PortalException $e) {
|
||||
return response()->json(['message' => $e->getMessage()], 422);
|
||||
}
|
||||
|
||||
return response()->json(['message' => 'Kelompok mata kuliah diperbarui.']);
|
||||
}
|
||||
|
||||
/** Hapus satu atau beberapa kelompok (POST {ids}). */
|
||||
public function destroy(Request $request): JsonResponse
|
||||
{
|
||||
$prodi = $this->prodiOrFail($request);
|
||||
$ids = $request->validate(['ids' => ['required', 'array', 'min:1'], 'ids.*' => ['integer']], [], ['ids' => 'kelompok mata kuliah'])['ids'];
|
||||
|
||||
try {
|
||||
$deleted = $this->groups->delete($prodi, $ids);
|
||||
} catch (PortalException $e) {
|
||||
return response()->json(['message' => $e->getMessage()], 422);
|
||||
}
|
||||
|
||||
return response()->json(['message' => "{$deleted} kelompok mata kuliah 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([
|
||||
'prodi' => ['required', 'integer'],
|
||||
'kurikulum' => ['required', 'integer'],
|
||||
'kode' => ['required', 'string', 'max:50'],
|
||||
'nama' => ['required', 'string', 'max:50'],
|
||||
], [], ['prodi' => 'program studi', 'kurikulum' => 'kurikulum', 'kode' => 'kode kelompok', 'nama' => 'nama kelompok']);
|
||||
}
|
||||
|
||||
/** @param list<int> $prodi */
|
||||
private function search(Request $request, array $prodi): LengthAwarePaginator
|
||||
{
|
||||
return $this->groups->list($prodi, [
|
||||
'prodi' => $request->filled('prodi') && in_array($request->integer('prodi'), $prodi, true) ? $request->integer('prodi') : null,
|
||||
'kurikulum' => $request->filled('kurikulum') ? $request->integer('kurikulum') : null,
|
||||
'q' => $this->query($request),
|
||||
], $this->perPage($request, Curriculum::PER_PAGE));
|
||||
}
|
||||
}
|
||||
@@ -67,8 +67,7 @@ class KurikulumController extends Controller
|
||||
'updateUrl' => route('operator.kurikulum.update', '__ID__'),
|
||||
'fields' => [
|
||||
['name' => 'prodi', 'label' => 'Program studi', 'type' => 'select', 'options' => $programs->all(), 'required' => true],
|
||||
['name' => 'program', 'label' => 'Sistem kuliah', 'type' => 'select', 'options' => $this->writer->programOptions()->all(), 'required' => true],
|
||||
['name' => 'periode', 'label' => 'Periode berlaku', 'type' => 'select', 'options' => $this->schedule->periods()->all(), 'required' => true, 'hint' => 'Program studi, sistem kuliah, dan periode tidak dapat diubah setelah kurikulum dipakai.'],
|
||||
['name' => 'program', 'label' => 'Sistem kuliah', 'type' => 'select', 'options' => $this->writer->programOptions()->all(), 'required' => true, 'hint' => 'Periode berlaku otomatis periode aktif. Program studi dan sistem kuliah tidak dapat diubah setelah kurikulum dipakai.'],
|
||||
['name' => 'nama', 'label' => 'Nama kurikulum', 'type' => 'text', 'required' => true, 'max' => 30],
|
||||
['name' => 'deskripsi', 'label' => 'Deskripsi', 'type' => 'text', 'max' => 255],
|
||||
['name' => 'aktif', 'label' => 'Status', 'type' => 'select', 'options' => [1 => 'Aktif', 0 => 'Tidak aktif'], 'required' => true, 'default' => 1],
|
||||
@@ -83,6 +82,11 @@ class KurikulumController extends Controller
|
||||
{
|
||||
$prodi = $this->prodiOrFail($request);
|
||||
$input = $this->validated($request);
|
||||
// Periode berlaku tidak diisi operator: selalu periode aktif prodi yang dipilih.
|
||||
$input['periode'] = $this->schedule->defaultPeriod([(int) $input['prodi']], $this->schedule->periods());
|
||||
if ($input['periode'] === null) {
|
||||
return response()->json(['message' => 'Periode aktif belum tersedia.'], 422);
|
||||
}
|
||||
|
||||
try {
|
||||
$id = $this->writer->create($prodi, $input, (string) $request->user()->username, $request->ip());
|
||||
@@ -138,11 +142,10 @@ class KurikulumController extends Controller
|
||||
return $request->validate([
|
||||
'prodi' => ['required', 'integer'],
|
||||
'program' => ['required', 'integer'],
|
||||
'periode' => ['required', 'integer'],
|
||||
'nama' => ['required', 'string', 'max:30'],
|
||||
'deskripsi' => ['nullable', 'string', 'max:255'],
|
||||
'aktif' => ['required', 'boolean'],
|
||||
], [], ['prodi' => 'program studi', 'program' => 'sistem kuliah', 'periode' => 'periode berlaku', 'nama' => 'nama kurikulum', 'deskripsi' => 'deskripsi', 'aktif' => 'status']);
|
||||
], [], ['prodi' => 'program studi', 'program' => 'sistem kuliah', 'nama' => 'nama kurikulum', 'deskripsi' => 'deskripsi', 'aktif' => 'status']);
|
||||
}
|
||||
|
||||
public function data(Request $request): JsonResponse
|
||||
|
||||
@@ -62,9 +62,11 @@ class MataKuliahController extends Controller
|
||||
'title' => 'mata kuliah',
|
||||
'storeUrl' => route('operator.matakuliah.store'),
|
||||
'updateUrl' => route('operator.matakuliah.update', '__ID__'),
|
||||
// Pilihan bertingkat: program studi -> kurikulum prodi itu -> kelompok MK kurikulum itu (dependsOn/optionsBy).
|
||||
'fields' => [
|
||||
['name' => 'kurikulum', 'label' => 'Kurikulum', 'type' => 'select', 'options' => $this->curriculum->curricula($prodi)->all(), 'required' => true],
|
||||
['name' => 'jenis', 'label' => 'Kelompok mata kuliah', 'type' => 'select', 'options' => $this->curriculum->groupOptions($prodi)->all(), 'required' => true, 'hint' => 'Pilih kelompok dari kurikulum yang sama.'],
|
||||
['name' => 'prodi', 'label' => 'Program studi', 'type' => 'select', 'options' => $programs->all(), 'required' => true, 'placeholder' => 'Pilih Program Studi', 'search' => true, 'default' => $programs->count() === 1 ? $programs->keys()->first() : ''],
|
||||
['name' => 'kurikulum', 'label' => 'Kurikulum', 'type' => 'select', 'dependsOn' => 'prodi', 'optionsBy' => $this->curriculum->curriculaByProdi($prodi), 'required' => true, 'placeholder' => 'Pilih Kurikulum', 'search' => true],
|
||||
['name' => 'jenis', 'label' => 'Kelompok mata kuliah', 'type' => 'select', 'dependsOn' => 'kurikulum', 'optionsBy' => $this->curriculum->groupsByCurriculum($prodi), 'emptyHint' => 'Belum ada kelompok untuk kurikulum ini. Tambahkan lewat Data Pelengkap > Perkuliahan > Kelompok Matakuliah.', 'required' => true, 'placeholder' => 'Pilih Kelompok MK', 'search' => true],
|
||||
['name' => 'kode', 'label' => 'Kode MK', 'type' => 'text', 'required' => true, 'max' => 15],
|
||||
['name' => 'nama', 'label' => 'Nama mata kuliah', 'type' => 'text', 'required' => true, 'max' => 50],
|
||||
['name' => 'sks', 'label' => 'SKS', 'type' => 'number', 'required' => true, 'min' => 0, 'max' => 24, 'default' => 2],
|
||||
@@ -142,6 +144,7 @@ class MataKuliahController extends Controller
|
||||
private function validated(Request $request): array
|
||||
{
|
||||
return $request->validate([
|
||||
'prodi' => ['required', 'integer'],
|
||||
'kurikulum' => ['required', 'integer'],
|
||||
'jenis' => ['required', 'integer'],
|
||||
'kode' => ['required', 'string', 'max:15'],
|
||||
@@ -151,7 +154,7 @@ class MataKuliahController extends Controller
|
||||
'tipe' => ['required', 'integer', 'in:'.implode(',', array_keys(Curriculum::TYPES))],
|
||||
'nilailulus' => ['nullable', 'integer', 'in:'.implode(',', array_keys(Curriculum::PASS_GRADES))],
|
||||
], [], [
|
||||
'kurikulum' => 'kurikulum', 'jenis' => 'kelompok mata kuliah', 'kode' => 'kode MK', 'nama' => 'nama mata kuliah',
|
||||
'prodi' => 'program studi', 'kurikulum' => 'kurikulum', 'jenis' => 'kelompok mata kuliah', 'kode' => 'kode MK', 'nama' => 'nama mata kuliah',
|
||||
'sks' => 'SKS', 'semester' => 'semester', 'tipe' => 'jenis MK', 'nilailulus' => 'nilai lulus minimal',
|
||||
]);
|
||||
}
|
||||
|
||||
@@ -27,6 +27,7 @@ class SatuPageController extends Controller
|
||||
'list_kurikulum' => KurikulumController::class,
|
||||
'set_grupmk' => GrupMkController::class,
|
||||
'ms_thnkurikulum' => TahunKurikulumController::class,
|
||||
'ms_kelompokmk' => KelompokMkController::class,
|
||||
'list_kelas' => KelasController::class,
|
||||
'set_pemutihannilai' => [KelasController::class, 'pemutihan'],
|
||||
'ms_tahunajaran' => TahunAjaranController::class,
|
||||
@@ -56,7 +57,7 @@ class SatuPageController extends Controller
|
||||
'list_fakultas' => DataPelengkapController::class, 'list_prodi' => DataPelengkapController::class, 'ms_bidangstudi' => DataPelengkapController::class,
|
||||
'ms_jenjang' => DataPelengkapController::class, 'ms_sistemkuliah' => DataPelengkapController::class, 'ms_ruang' => DataPelengkapController::class,
|
||||
'ms_universitas' => DataPelengkapController::class, 'ms_tingkatpendidikan' => DataPelengkapController::class, 'list_jurusan' => DataPelengkapController::class,
|
||||
'list_gedung' => DataPelengkapController::class, 'ms_jenismk' => DataPelengkapController::class, 'ms_kelompokmk' => DataPelengkapController::class,
|
||||
'list_gedung' => DataPelengkapController::class, 'ms_jenismk' => DataPelengkapController::class,
|
||||
'ms_grupmk' => DataPelengkapController::class, 'ms_agama' => DataPelengkapController::class, 'ms_pekerjaan' => DataPelengkapController::class,
|
||||
'ms_penghasilan' => DataPelengkapController::class, 'ms_statusmhs' => DataPelengkapController::class, 'ms_jenispeg' => DataPelengkapController::class,
|
||||
'ms_golpangkat' => DataPelengkapController::class, 'ms_jabfung' => DataPelengkapController::class, 'ms_jabstruktural' => DataPelengkapController::class,
|
||||
|
||||
@@ -2,6 +2,8 @@
|
||||
|
||||
namespace App\Http\Controllers;
|
||||
|
||||
use App\Enums\Role;
|
||||
use App\Models\Legacy\Account;
|
||||
use App\Support\Prototype\Sample;
|
||||
use Illuminate\Contracts\View\View;
|
||||
use Illuminate\Support\Collection;
|
||||
@@ -10,17 +12,28 @@ class PengumumanController extends Controller
|
||||
{
|
||||
public function index(): View
|
||||
{
|
||||
$this->closedForLegacySuperuser();
|
||||
|
||||
return view('pengumuman.index', ['items' => $this->visible()]);
|
||||
}
|
||||
|
||||
public function show(int $id): View
|
||||
{
|
||||
$this->closedForLegacySuperuser();
|
||||
|
||||
$item = $this->visible()->firstWhere('id', $id);
|
||||
abort_if($item === null, 404);
|
||||
|
||||
return view('pengumuman.show', ['item' => $item]);
|
||||
}
|
||||
|
||||
/** Pengumuman belum punya sumber data di DB lama: Superuser akun DB lama tidak melihat contoh (menunya juga disembunyikan). */
|
||||
private function closedForLegacySuperuser(): void
|
||||
{
|
||||
$user = auth()->user();
|
||||
abort_if($user instanceof Account && $user->role === Role::Superuser, 404);
|
||||
}
|
||||
|
||||
/** Pengumuman terbit yang ditujukan ke semua pengguna atau ke role pengguna ini. @return Collection<int, array<string, mixed>> */
|
||||
private function visible(): Collection
|
||||
{
|
||||
|
||||
@@ -4,6 +4,9 @@ namespace App\Http\Controllers\Superuser;
|
||||
|
||||
use App\Enums\Role;
|
||||
use App\Http\Controllers\Controller;
|
||||
use App\Models\Legacy\Account;
|
||||
use App\Support\Legacy\LoginHistory;
|
||||
use App\Support\Legacy\SystemOverview;
|
||||
use App\Support\Prototype\Sample;
|
||||
use App\Support\Prototype\SuperuserData;
|
||||
use Illuminate\Contracts\View\View;
|
||||
@@ -12,7 +15,7 @@ use Illuminate\Support\Carbon;
|
||||
|
||||
class DashboardController extends Controller
|
||||
{
|
||||
public function __invoke(Request $request): View
|
||||
public function __invoke(Request $request, SystemOverview $overview, LoginHistory $history): View
|
||||
{
|
||||
$role = Role::Superuser;
|
||||
$user = $request->user()->loadMissing($role->profileRelation());
|
||||
@@ -26,6 +29,24 @@ class DashboardController extends Controller
|
||||
'Unit kerja' => $profile?->unit_kerja,
|
||||
], fn (mixed $value): bool => $value !== null));
|
||||
|
||||
// Akun DB lama: ringkasan asli akun, otoritas, dan riwayat masuk dari t_account, t_otoritasuser, dan t_historilogin.
|
||||
if ($user instanceof Account) {
|
||||
$authorities = $overview->authorities();
|
||||
$logins = $overview->logins();
|
||||
|
||||
return view('superuser.dashboard-legacy', [
|
||||
'user' => $user,
|
||||
'details' => $details,
|
||||
'accounts' => $overview->accounts(),
|
||||
'authorityLabels' => array_keys($authorities),
|
||||
'authorityData' => array_values($authorities),
|
||||
'loginLabels' => array_map(strval(...), array_keys($logins['tahun'])),
|
||||
'loginData' => array_values($logins['tahun']),
|
||||
'lastLogin' => $logins['terakhir'],
|
||||
'latest' => $history->latest(),
|
||||
]);
|
||||
}
|
||||
|
||||
$pengguna = SuperuserData::pengguna();
|
||||
$aktivitas = SuperuserData::aktivitas();
|
||||
$cadangan = SuperuserData::cadangan();
|
||||
|
||||
@@ -3,17 +3,36 @@
|
||||
namespace App\Http\Controllers\Superuser;
|
||||
|
||||
use App\Http\Controllers\Controller;
|
||||
use App\Models\Legacy\Account;
|
||||
use App\Support\Legacy\AuthorityDirectory;
|
||||
use App\Support\Prototype\SuperuserData;
|
||||
use Illuminate\Contracts\View\View;
|
||||
use Illuminate\Http\Request;
|
||||
|
||||
/** Hak akses. Akun DB lama: otoritas asli beserta menunya; akun demo: matriks prototipe. */
|
||||
class HakAksesController extends Controller
|
||||
{
|
||||
public function __invoke(): View
|
||||
public function __construct(private readonly AuthorityDirectory $authorities) {}
|
||||
|
||||
public function __invoke(Request $request): View
|
||||
{
|
||||
if ($request->user() instanceof Account) {
|
||||
return view('superuser.hak-akses.legacy', ['authorities' => $this->authorities->all()]);
|
||||
}
|
||||
|
||||
return view('superuser.hak-akses.index', [
|
||||
'roles' => SuperuserData::ROLES,
|
||||
'groups' => SuperuserData::hakAkses(),
|
||||
'kode' => SuperuserData::kodeAkses(),
|
||||
]);
|
||||
}
|
||||
|
||||
public function show(Request $request, int $id): View
|
||||
{
|
||||
abort_unless($request->user() instanceof Account, 404);
|
||||
$authority = $this->authorities->find($id);
|
||||
abort_if($authority === null, 404);
|
||||
|
||||
return view('superuser.hak-akses.show', ['authority' => $authority]);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -3,12 +3,15 @@
|
||||
namespace App\Http\Controllers\Superuser;
|
||||
|
||||
use App\Http\Controllers\Controller;
|
||||
use App\Models\Legacy\Account;
|
||||
use App\Support\Legacy\SystemOverview;
|
||||
use Illuminate\Contracts\View\View;
|
||||
use Illuminate\Http\Request;
|
||||
|
||||
/** Ringkasan kondisi sistem dari konfigurasi dan pemeriksaan sederhana pada server ini. */
|
||||
class KesehatanSistemController extends Controller
|
||||
{
|
||||
public function __invoke(): View
|
||||
public function __invoke(Request $request, SystemOverview $overview): View
|
||||
{
|
||||
$total = @disk_total_space(storage_path());
|
||||
$bebas = @disk_free_space(storage_path());
|
||||
@@ -31,7 +34,15 @@ class KesehatanSistemController extends Controller
|
||||
['nama' => 'Lingkungan produksi', 'ok' => app()->isProduction(), 'catatan' => 'Lingkungan saat ini: '.app()->environment().'.'],
|
||||
];
|
||||
|
||||
// Akun DB lama: koneksi ke basis data SIAKAD diperiksa langsung dan masuk hitungan kesiapan.
|
||||
$database = null;
|
||||
if ($request->user() instanceof Account) {
|
||||
$database = $overview->database();
|
||||
array_unshift($periksa, ['nama' => 'Koneksi basis data SIAKAD', 'ok' => $database['ok'], 'catatan' => $database['catatan']]);
|
||||
}
|
||||
|
||||
return view('superuser.kesehatan-sistem.index', [
|
||||
'database' => $database,
|
||||
'versi' => [
|
||||
'Laravel' => app()->version(),
|
||||
'PHP' => PHP_VERSION,
|
||||
|
||||
@@ -3,12 +3,50 @@
|
||||
namespace App\Http\Controllers\Superuser;
|
||||
|
||||
use App\Http\Controllers\Prototype\ResourceController;
|
||||
use App\Models\Legacy\Account;
|
||||
use App\Support\Legacy\LoginHistory;
|
||||
use App\Support\Prototype\SuperuserData;
|
||||
use Illuminate\Contracts\View\View;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Support\Collection;
|
||||
|
||||
/** Log aktivitas: hanya baca. */
|
||||
/**
|
||||
* Log aktivitas: hanya baca. Akun DB lama: riwayat masuk asli (t_historilogin), dicari dan disaring di server;
|
||||
* akun demo: contoh dari SuperuserData.
|
||||
*/
|
||||
class LogAktivitasController extends ResourceController
|
||||
{
|
||||
public function __construct(private readonly LoginHistory $history) {}
|
||||
|
||||
public function index(Request $request): View
|
||||
{
|
||||
if (! $this->legacy()) {
|
||||
return parent::index($request);
|
||||
}
|
||||
|
||||
$per = in_array($request->integer('per'), LoginHistory::PER_PAGE, true) ? $request->integer('per') : LoginHistory::PER_PAGE[0];
|
||||
$filter = $request->only(['q', 'dari', 'sampai']) + ['pengguna' => $request->filled('pengguna') ? $request->integer('pengguna') : null];
|
||||
|
||||
return view('crud.index', $this->share([
|
||||
'rows' => $this->history->search($filter, $per)->withQueryString(),
|
||||
'columns' => $this->columns(),
|
||||
'filters' => [
|
||||
['name' => 'dari', 'label' => 'Dari tanggal', 'type' => 'date'],
|
||||
['name' => 'sampai', 'label' => 'Sampai tanggal', 'type' => 'date'],
|
||||
// Saringan satu akun (dari detail Pengguna) tetap terbawa saat filter lain diubah.
|
||||
...($filter['pengguna'] === null ? [] : [['name' => 'pengguna', 'type' => 'hidden']]),
|
||||
],
|
||||
'searchable' => true,
|
||||
'searchPlaceholder' => 'Cari nama, NIP, atau NIM pemilik akun',
|
||||
'rowActions' => fn (array $row): array => [],
|
||||
]));
|
||||
}
|
||||
|
||||
private function legacy(): bool
|
||||
{
|
||||
return request()->user() instanceof Account;
|
||||
}
|
||||
|
||||
protected function rows(): Collection
|
||||
{
|
||||
return SuperuserData::aktivitas();
|
||||
@@ -24,7 +62,9 @@ class LogAktivitasController extends ResourceController
|
||||
return [
|
||||
'singular' => 'Aktivitas',
|
||||
'plural' => 'Log aktivitas',
|
||||
'description' => 'Jejak audit tindakan penting pengguna pada sistem, dari yang terbaru.',
|
||||
'description' => $this->legacy()
|
||||
? 'Riwayat masuk asli ke SIAKAD (waktu, komputer, alamat IP), dari yang terbaru. Sumber data hanya mencatat aktivitas masuk.'
|
||||
: 'Jejak audit tindakan penting pengguna pada sistem, dari yang terbaru.',
|
||||
];
|
||||
}
|
||||
|
||||
@@ -55,6 +95,17 @@ class LogAktivitasController extends ResourceController
|
||||
|
||||
protected function columns(): array
|
||||
{
|
||||
if ($this->legacy()) {
|
||||
return [
|
||||
['label' => 'Waktu', 'key' => 'waktu'],
|
||||
['label' => 'Pengguna', 'key' => 'pengguna'],
|
||||
['label' => 'NIP/NIM', 'key' => 'username'],
|
||||
['label' => 'Aksi', 'key' => 'aksi', 'badge' => fn (array $r): string => 'success'],
|
||||
['label' => 'Komputer', 'key' => 'komputer'],
|
||||
['label' => 'Alamat IP', 'key' => 'ip'],
|
||||
];
|
||||
}
|
||||
|
||||
return [
|
||||
['label' => 'Waktu', 'key' => 'waktu'],
|
||||
['label' => 'Pengguna', 'key' => 'pengguna'],
|
||||
|
||||
@@ -3,11 +3,117 @@
|
||||
namespace App\Http\Controllers\Superuser;
|
||||
|
||||
use App\Http\Controllers\Prototype\ResourceController;
|
||||
use App\Models\Legacy\Account;
|
||||
use App\Support\Legacy\AccountDirectory;
|
||||
use App\Support\Legacy\PortalException;
|
||||
use App\Support\Prototype\SuperuserData;
|
||||
use Illuminate\Contracts\View\View;
|
||||
use Illuminate\Http\RedirectResponse;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Support\Collection;
|
||||
|
||||
/**
|
||||
* Pengguna. Akun DB lama: daftar dan detail asli t_account (dicari, disaring, dipaginasi di server); yang bisa diubah hanya
|
||||
* status akun dan otoritas pegawai, tanpa menyentuh akun sendiri. Akun demo: CRUD prototipe dari SuperuserData.
|
||||
*/
|
||||
class PenggunaController extends ResourceController
|
||||
{
|
||||
public function __construct(private readonly AccountDirectory $accounts) {}
|
||||
|
||||
public function index(Request $request): View
|
||||
{
|
||||
if (! $this->legacy()) {
|
||||
return parent::index($request);
|
||||
}
|
||||
|
||||
$filter = $request->only(['q', 'jenis', 'status', 'otoritas']);
|
||||
$per = in_array($request->integer('per'), AccountDirectory::PER_PAGE, true) ? $request->integer('per') : AccountDirectory::PER_PAGE[0];
|
||||
$rows = $this->accounts->search($filter, $per)->withQueryString();
|
||||
|
||||
return view('crud.index', $this->share([
|
||||
'rows' => $rows,
|
||||
'columns' => $this->columns(),
|
||||
'filters' => [
|
||||
['name' => 'jenis', 'label' => 'Jenis akun', 'options' => AccountDirectory::JENIS],
|
||||
['name' => 'status', 'label' => 'Status', 'options' => ['aktif' => 'Aktif', 'beku' => 'Dibekukan']],
|
||||
['name' => 'otoritas', 'label' => 'Otoritas', 'options' => $this->accounts->authorities()->all()],
|
||||
],
|
||||
'searchable' => true,
|
||||
'searchPlaceholder' => 'Cari nama, NIP, atau NIM',
|
||||
'rowActions' => fn (array $row): array => $this->rowActions($row),
|
||||
]));
|
||||
}
|
||||
|
||||
public function show(string $record): View
|
||||
{
|
||||
abort_unless($this->legacy(), 404);
|
||||
$account = $this->accounts->find((int) $record);
|
||||
abort_if($account === null, 404);
|
||||
|
||||
$own = (int) request()->user()->getKey() === $account['id'];
|
||||
|
||||
return view('superuser.pengguna.show', [
|
||||
'account' => $account,
|
||||
'own' => $own,
|
||||
'authorities' => $this->accounts->authorities()->except(array_keys($account['granted']))->all(),
|
||||
]);
|
||||
}
|
||||
|
||||
/** Bekukan atau aktifkan akun. */
|
||||
public function status(Request $request, string $record): RedirectResponse
|
||||
{
|
||||
abort_unless($this->legacy(), 404);
|
||||
$active = $request->validate(['aktif' => ['required', 'boolean']], [], ['aktif' => 'status'])['aktif'];
|
||||
|
||||
return $this->change($request, (int) $record, fn (int $id) => $this->accounts->setActive($id, (bool) $active, (string) $request->user()->username, $request->ip()), $active ? 'Akun diaktifkan kembali.' : 'Akun dibekukan.');
|
||||
}
|
||||
|
||||
public function grant(Request $request, string $record): RedirectResponse
|
||||
{
|
||||
abort_unless($this->legacy(), 404);
|
||||
$authority = $request->validate(['otoritas' => ['required', 'integer']], [], ['otoritas' => 'otoritas'])['otoritas'];
|
||||
|
||||
return $this->change($request, (int) $record, fn (int $id) => $this->accounts->grant($id, (int) $authority, (string) $request->user()->username, $request->ip()), 'Otoritas ditambahkan.');
|
||||
}
|
||||
|
||||
public function revoke(Request $request, string $record, string $otoritas): RedirectResponse
|
||||
{
|
||||
abort_unless($this->legacy(), 404);
|
||||
|
||||
return $this->change($request, (int) $record, fn (int $id) => $this->accounts->revoke($id, (int) $otoritas), 'Otoritas dicabut.');
|
||||
}
|
||||
|
||||
/** Akun sendiri tidak boleh dibekukan atau diubah otoritasnya agar Superuser tidak mengunci diri. */
|
||||
private function change(Request $request, int $id, \Closure $action, string $done): RedirectResponse
|
||||
{
|
||||
$back = redirect()->route('superuser.pengguna.show', $id);
|
||||
|
||||
if ((int) $request->user()->getKey() === $id) {
|
||||
return $back->with('error', 'Akun Anda sendiri tidak dapat diubah dari sini.');
|
||||
}
|
||||
|
||||
try {
|
||||
$action($id);
|
||||
} catch (PortalException $e) {
|
||||
return $back->with('error', $e->getMessage());
|
||||
}
|
||||
|
||||
return $back->with('status', $done);
|
||||
}
|
||||
|
||||
private function legacy(): bool
|
||||
{
|
||||
return request()->user() instanceof Account;
|
||||
}
|
||||
|
||||
/** Akun DB lama hanya bisa dilihat; pengelolaan lewat halaman detail. */
|
||||
protected function abilities(): array
|
||||
{
|
||||
return $this->legacy()
|
||||
? ['create' => false, 'show' => true, 'edit' => false, 'delete' => false]
|
||||
: parent::abilities();
|
||||
}
|
||||
|
||||
protected function rows(): Collection
|
||||
{
|
||||
return SuperuserData::pengguna();
|
||||
@@ -20,7 +126,7 @@ class PenggunaController extends ResourceController
|
||||
|
||||
protected function keyName(): string
|
||||
{
|
||||
return 'username';
|
||||
return $this->legacy() ? 'id' : 'username';
|
||||
}
|
||||
|
||||
protected function names(): array
|
||||
@@ -28,7 +134,9 @@ class PenggunaController extends ResourceController
|
||||
return [
|
||||
'singular' => 'Pengguna',
|
||||
'plural' => 'Pengguna',
|
||||
'description' => 'Kelola akun semua peran: tambah, ubah data, aktifkan atau nonaktifkan, dan atur ulang kata sandi.',
|
||||
'description' => $this->legacy()
|
||||
? 'Akun asli SIAKAD: pegawai dan mahasiswa beserta otoritasnya. Buka sebuah akun untuk membekukan atau mengaktifkannya dan mengatur otoritas pegawai; kata sandi diatur ulang lewat Atur ulang kata sandi.'
|
||||
: 'Kelola akun semua peran: tambah, ubah data, aktifkan atau nonaktifkan, dan atur ulang kata sandi.',
|
||||
];
|
||||
}
|
||||
|
||||
@@ -47,6 +155,18 @@ class PenggunaController extends ResourceController
|
||||
|
||||
protected function columns(): array
|
||||
{
|
||||
if ($this->legacy()) {
|
||||
return [
|
||||
['label' => 'Nama', 'key' => 'nama'],
|
||||
['label' => 'NIP/NIM', 'key' => 'username'],
|
||||
['label' => 'Jenis', 'key' => 'jenis'],
|
||||
['label' => 'Otoritas', 'key' => 'otoritas'],
|
||||
['label' => 'Peran', 'key' => 'peran', 'badge' => fn (array $r): string => SuperuserData::ROLE_TONE[$r['peran']] ?? 'neutral'],
|
||||
['label' => 'Status', 'key' => 'status', 'badge' => fn (array $r): string => $r['aktif'] ? 'success' : 'danger'],
|
||||
['label' => 'Masuk terakhir', 'key' => 'terakhir'],
|
||||
];
|
||||
}
|
||||
|
||||
return [
|
||||
['label' => 'Nama', 'key' => 'nama'],
|
||||
['label' => 'Username', 'key' => 'username'],
|
||||
@@ -73,6 +193,10 @@ class PenggunaController extends ResourceController
|
||||
|
||||
protected function rowActions(array $row): array
|
||||
{
|
||||
return [['label' => 'Kata sandi', 'href' => route('superuser.pengguna.password', $row['username']), 'icon' => 'key']];
|
||||
$href = $this->legacy()
|
||||
? route('superuser.reset-password', ['username' => $row['username']])
|
||||
: route('superuser.pengguna.password', $row['username']);
|
||||
|
||||
return [['label' => 'Kata sandi', 'href' => $href, 'icon' => 'key']];
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,22 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Middleware;
|
||||
|
||||
use App\Models\Legacy\Account;
|
||||
use Closure;
|
||||
use Illuminate\Http\Request;
|
||||
use Symfony\Component\HttpFoundation\Response;
|
||||
|
||||
/**
|
||||
* Menutup halaman prototipe yang tidak punya sumber data di DB lama (sesi aktif, cadangan, pengaturan, pengumuman):
|
||||
* akun DB lama mendapat 404 dan menunya disembunyikan. Akun demo tetap melihatnya.
|
||||
*/
|
||||
class HideForLegacyAccount
|
||||
{
|
||||
public function handle(Request $request, Closure $next): Response
|
||||
{
|
||||
abort_if($request->user() instanceof Account, 404);
|
||||
|
||||
return $next($request);
|
||||
}
|
||||
}
|
||||
@@ -94,6 +94,38 @@ orm (nilai isian ubah), lainnya tidak dapat diubah.
|
||||
->through(fn (object $row): array => $this->present($row, $types, $filter['units'] ?? null));
|
||||
}
|
||||
|
||||
/**
|
||||
* Periode yang aktif di setidaknya satu program studi (terbaru) bila ada di daftar, kalau tidak periode terbaru.
|
||||
*
|
||||
* @param Collection<int, string> $periods
|
||||
*/
|
||||
public function currentPeriod(Collection $periods): ?int
|
||||
{
|
||||
$active = $this->db()->table('t_periodekuliahaktif')->max('idperiode');
|
||||
|
||||
return $active !== null && $periods->has((int) $active) ? (int) $active : $periods->keys()->first();
|
||||
}
|
||||
|
||||
/**
|
||||
* Semua kegiatan satu periode dengan tanggal mentah (Y-m-d), berurutan TMT; dipakai kalender bersama semua role.
|
||||
*
|
||||
* @return Collection<int, array{id: int, jenis: string, keterangan: string, mulai: string, selesai: string}>
|
||||
*/
|
||||
public function schedule(int $periode): Collection
|
||||
{
|
||||
return $this->base()
|
||||
->where('k.idperiodekuliah', $periode)
|
||||
->orderBy('k.mulai')->orderBy('k.idkegiatan')
|
||||
->get()
|
||||
->map(fn (object $row): array => [
|
||||
'id' => (int) $row->idkegiatan,
|
||||
'jenis' => trim($row->jeniskegiatan),
|
||||
'keterangan' => trim((string) $row->deskripsi),
|
||||
'mulai' => substr((string) $row->mulai, 0, 10),
|
||||
'selesai' => substr((string) $row->selesai, 0, 10),
|
||||
]);
|
||||
}
|
||||
|
||||
/** Jumlah baris jalur minimum per minggu agar tinggi minggu tetap lega walau kegiatannya sedikit. */
|
||||
private const int MIN_LANES = 3;
|
||||
|
||||
|
||||
@@ -0,0 +1,225 @@
|
||||
<?php
|
||||
|
||||
namespace App\Support\Legacy;
|
||||
|
||||
use Illuminate\Database\ConnectionInterface;
|
||||
use Illuminate\Database\Query\Builder;
|
||||
use Illuminate\Database\Query\JoinClause;
|
||||
use Illuminate\Pagination\LengthAwarePaginator;
|
||||
use Illuminate\Support\Carbon;
|
||||
use Illuminate\Support\Collection;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
use Illuminate\Support\Str;
|
||||
|
||||
/**
|
||||
* Pengguna (Superuser): akun asli t_account beserta identitas pegawai/mahasiswa dan otoritasnya. Daftar dan detail hanya
|
||||
* membaca; yang ditulis hanya status akun (t_account.status: 0 aktif, 1 dibekukan, seperti f_login_er_new) dan otoritas
|
||||
* pegawai (t_otoritasuser), keduanya dengan kolom audit cname/cip/uname/tanggal seperti aplikasi lama. Sandi tidak pernah dibaca.
|
||||
*/
|
||||
final class AccountDirectory
|
||||
{
|
||||
public const array PER_PAGE = [25, 50, 100];
|
||||
|
||||
public const array JENIS = [LegacyRole::JENIS_PEGAWAI => 'Pegawai', LegacyRole::JENIS_MAHASISWA => 'Mahasiswa'];
|
||||
|
||||
private function db(): ConnectionInterface
|
||||
{
|
||||
return DB::connection('untan');
|
||||
}
|
||||
|
||||
/** @return Collection<int, string> idotoritas => nama */
|
||||
public function authorities(): Collection
|
||||
{
|
||||
return $this->db()->table('t_otoritas')->orderBy('otoritas')->pluck('otoritas', 'idotoritas')
|
||||
->map(fn (?string $name): string => trim((string) $name));
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array{q?: ?string, jenis?: ?string, status?: ?string, otoritas?: ?string} $filter
|
||||
* @return LengthAwarePaginator<int, array<string, mixed>>
|
||||
*/
|
||||
public function search(array $filter, int $perPage = self::PER_PAGE[0]): LengthAwarePaginator
|
||||
{
|
||||
$q = mb_strtolower(trim((string) ($filter['q'] ?? '')));
|
||||
$jenis = $filter['jenis'] ?? null;
|
||||
$status = $filter['status'] ?? null;
|
||||
$otoritas = $filter['otoritas'] ?? null;
|
||||
|
||||
$page = $this->base()
|
||||
->when($q !== '', fn (Builder $query) => $query->where(fn (Builder $w) => $w
|
||||
->whereRaw('lower(p.nama) like ?', ['%'.$q.'%'])
|
||||
->orWhereRaw('lower(m.nama) like ?', ['%'.$q.'%'])
|
||||
->orWhereRaw('lower(p.nip) like ?', [$q.'%'])
|
||||
->orWhereRaw('lower(m.nim) like ?', [$q.'%'])))
|
||||
->when(isset(self::JENIS[(int) $jenis]) && $jenis !== null && $jenis !== '', fn (Builder $query) => $query->where('a.jenis', (int) $jenis))
|
||||
->when(in_array($status, ['aktif', 'beku'], true), fn (Builder $query) => $status === 'aktif' ? $query->where('a.status', 0) : $query->where('a.status', '>', 0))
|
||||
->when(filled($otoritas), fn (Builder $query) => $query->whereExists(fn (Builder $sub) => $sub
|
||||
->selectRaw('1')->from('t_otoritasuser as o')
|
||||
->whereColumn('o.iduser', 'a.iduser')->where('o.idotoritas', (int) $otoritas)))
|
||||
->orderBy('a.iduser')
|
||||
->paginate($perPage);
|
||||
|
||||
$ids = collect($page->items())->pluck('iduser')->all();
|
||||
$granted = $ids === [] ? collect() : $this->granted($ids);
|
||||
|
||||
return $page->through(fn (object $row): array => $this->present($row, $granted->get((int) $row->iduser, collect())));
|
||||
}
|
||||
|
||||
/**
|
||||
* Satu akun lengkap: identitas, otoritas, unit, dan 10 login terakhir. Null bila tidak ada.
|
||||
*
|
||||
* @return array<string, mixed>|null
|
||||
*/
|
||||
public function find(int $id): ?array
|
||||
{
|
||||
$row = $this->base()->where('a.iduser', $id)->addSelect('a.cname', 'a.uname', 'a.tanggal')->first();
|
||||
if ($row === null) {
|
||||
return null;
|
||||
}
|
||||
|
||||
$granted = $this->granted([$id])->get($id, collect());
|
||||
$account = $this->present($row, $granted);
|
||||
|
||||
$units = (int) $row->jenis === LegacyRole::JENIS_PEGAWAI
|
||||
? $this->db()->table('t_unituser as u')
|
||||
->join('t_bagian as b', fn (JoinClause $join) => $join->on('b.idbagian', '=', $this->db()->raw('coalesce(u.idprogdi, u.idfak)')))
|
||||
->where('u.iduser', $id)->orderBy('u.idunituser')->pluck('b.namabagian')
|
||||
->map(fn (?string $name): string => trim((string) $name))->unique()->values()->all()
|
||||
: [];
|
||||
|
||||
$program = (int) $row->jenis === LegacyRole::JENIS_MAHASISWA && $row->idprogdi !== null
|
||||
? $this->db()->table('t_bagian')->where('idbagian', $row->idprogdi)->value('namabagian')
|
||||
: null;
|
||||
|
||||
$history = $this->db()->table('t_historilogin')->where('iduser', $id)->orderByDesc('idhistori')->limit(10)
|
||||
->get(['logintimestamp', 'logincname', 'logincip'])
|
||||
->map(fn (object $h): array => [
|
||||
'waktu' => LoginHistory::time($h->logintimestamp),
|
||||
'komputer' => LoginHistory::clean($h->logincname),
|
||||
'ip' => LoginHistory::clean($h->logincip),
|
||||
])->all();
|
||||
|
||||
return $account + [
|
||||
'email' => filled($row->email_akun) ? trim($row->email_akun) : null,
|
||||
'unit' => $units,
|
||||
'program_studi' => filled($program) ? trim($program) : null,
|
||||
'granted' => $granted->all(),
|
||||
'diubah_oleh' => filled($row->uname) ? trim($row->uname) : null,
|
||||
'diubah_pada' => $row->tanggal === null ? null : Carbon::parse($row->tanggal)->locale('id')->isoFormat('D MMM YYYY, HH.mm'),
|
||||
'riwayat' => $history,
|
||||
];
|
||||
}
|
||||
|
||||
/** Bekukan (false) atau aktifkan (true) akun: t_account.status 1 atau 0. */
|
||||
public function setActive(int $id, bool $active, string $actor, ?string $ip = null): void
|
||||
{
|
||||
$this->requireAccount($id);
|
||||
|
||||
$this->db()->table('t_account')->where('iduser', $id)->update([
|
||||
'status' => $active ? 0 : 1,
|
||||
'cname' => Str::substr((string) config('app.name'), 0, 20),
|
||||
'uname' => Str::substr($actor, 0, 15),
|
||||
'tanggal' => now(),
|
||||
] + $this->ipColumn($ip));
|
||||
}
|
||||
|
||||
/** Beri otoritas pada akun pegawai (mahasiswa otomatis berotoritas Mahasiswa dan tidak punya baris di t_otoritasuser). */
|
||||
public function grant(int $id, int $authority, string $actor, ?string $ip = null): void
|
||||
{
|
||||
$account = $this->requireAccount($id);
|
||||
|
||||
if ((int) $account->jenis !== LegacyRole::JENIS_PEGAWAI) {
|
||||
throw new PortalException('Otoritas hanya dapat diatur untuk akun pegawai.');
|
||||
}
|
||||
if (! $this->db()->table('t_otoritas')->where('idotoritas', $authority)->exists()) {
|
||||
throw new PortalException('Otoritas tidak ditemukan.');
|
||||
}
|
||||
if ($this->db()->table('t_otoritasuser')->where('iduser', $id)->where('idotoritas', $authority)->exists()) {
|
||||
throw new PortalException('Akun ini sudah memiliki otoritas tersebut.');
|
||||
}
|
||||
|
||||
$this->db()->table('t_otoritasuser')->insert([
|
||||
'iduser' => $id,
|
||||
'idotoritas' => $authority,
|
||||
'cname' => Str::substr((string) config('app.name'), 0, 20),
|
||||
'uname' => Str::substr($actor, 0, 15),
|
||||
'tanggal' => now(),
|
||||
] + $this->ipColumn($ip));
|
||||
}
|
||||
|
||||
public function revoke(int $id, int $authority): void
|
||||
{
|
||||
$this->requireAccount($id);
|
||||
|
||||
$deleted = $this->db()->table('t_otoritasuser')->where('iduser', $id)->where('idotoritas', $authority)->delete();
|
||||
|
||||
if ($deleted === 0) {
|
||||
throw new PortalException('Akun ini tidak memiliki otoritas tersebut.');
|
||||
}
|
||||
}
|
||||
|
||||
private function requireAccount(int $id): object
|
||||
{
|
||||
return $this->db()->table('t_account')->where('iduser', $id)->first(['iduser', 'jenis', 'status'])
|
||||
?? throw new PortalException('Akun tidak ditemukan.');
|
||||
}
|
||||
|
||||
/** cip NOT NULL di DB lama: tanpa IP, nilai bawaan/lama dipertahankan. @return array<string, string> */
|
||||
private function ipColumn(?string $ip): array
|
||||
{
|
||||
return $ip === null ? [] : ['cip' => Str::substr($ip, 0, 20)];
|
||||
}
|
||||
|
||||
/** Kolom akun beserta identitasnya dalam satu query (tanpa kolom sandi). */
|
||||
private function base(): Builder
|
||||
{
|
||||
return $this->db()->table('t_account as a')
|
||||
->leftJoin('t_pegawai as p', fn (JoinClause $join) => $join
|
||||
->on('p.idpegawai', '=', 'a.identitas')->where('a.jenis', LegacyRole::JENIS_PEGAWAI))
|
||||
->leftJoin('t_mahasiswa as m', fn (JoinClause $join) => $join
|
||||
->on('m.idmahasiswa', '=', 'a.identitas')->where('a.jenis', LegacyRole::JENIS_MAHASISWA))
|
||||
->select(['a.iduser', 'a.jenis', 'a.status', 'a.lastlogin', 'p.nip', 'p.nama as pegawai_nama', 'p.gelardepan', 'p.gelarbelakang', 'p.email as pegawai_email', 'm.nim', 'm.nama as mahasiswa_nama', 'm.email_mhs', 'm.idprogdi'])
|
||||
->selectRaw('coalesce(p.email, m.email_mhs) as email_akun')
|
||||
->selectRaw('case when a.jenis = ? and exists (select 1 from t_dosen d where d.idpegawai = a.identitas) then 1 else 0 end as is_dosen', [LegacyRole::JENIS_PEGAWAI]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Otoritas tiap akun, urut idotoritas.
|
||||
*
|
||||
* @param list<int> $ids
|
||||
* @return Collection<int, Collection<int, string>> iduser => (idotoritas => nama)
|
||||
*/
|
||||
private function granted(array $ids): Collection
|
||||
{
|
||||
return $this->db()->table('t_otoritasuser as o')
|
||||
->join('t_otoritas as t', 't.idotoritas', '=', 'o.idotoritas')
|
||||
->whereIn('o.iduser', $ids)
|
||||
->orderBy('o.idotoritas')
|
||||
->get(['o.iduser', 'o.idotoritas', 't.otoritas'])
|
||||
->groupBy(fn (object $r): int => (int) $r->iduser)
|
||||
->map(fn (Collection $rows): Collection => $rows->mapWithKeys(fn (object $r): array => [(int) $r->idotoritas => trim((string) $r->otoritas)]));
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Collection<int, string> $granted idotoritas => nama
|
||||
* @return array<string, mixed>
|
||||
*/
|
||||
private function present(object $row, Collection $granted): array
|
||||
{
|
||||
$jenis = (int) $row->jenis;
|
||||
$pegawai = $jenis === LegacyRole::JENIS_PEGAWAI;
|
||||
$role = LegacyRole::resolve($jenis, $granted->keys()->map(fn ($key): int => (int) $key)->all(), (bool) $row->is_dosen);
|
||||
|
||||
return [
|
||||
'id' => (int) $row->iduser,
|
||||
'nama' => $pegawai ? LegacyFormat::pegawaiName($row->gelardepan, $row->pegawai_nama, $row->gelarbelakang) : trim((string) $row->mahasiswa_nama),
|
||||
'username' => $pegawai ? trim((string) $row->nip) : trim((string) $row->nim),
|
||||
'jenis' => self::JENIS[$jenis] ?? '-',
|
||||
'otoritas' => $pegawai ? ($granted->isEmpty() ? '-' : $granted->implode(', ')) : 'Mahasiswa',
|
||||
'peran' => $role?->label() ?? 'Tanpa peran',
|
||||
'aktif' => (int) $row->status === 0,
|
||||
'status' => (int) $row->status === 0 ? 'Aktif' : 'Dibekukan',
|
||||
'terakhir' => $row->lastlogin === null ? null : Carbon::parse($row->lastlogin)->locale('id')->isoFormat('D MMM YYYY, HH.mm'),
|
||||
];
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,77 @@
|
||||
<?php
|
||||
|
||||
namespace App\Support\Legacy;
|
||||
|
||||
use Illuminate\Database\ConnectionInterface;
|
||||
use Illuminate\Support\Collection;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
|
||||
/**
|
||||
* Hak akses (Superuser): otoritas asli t_otoritas beserta jumlah pemegangnya (t_otoritasuser), menu yang boleh dibuka
|
||||
* (t_menuotoritas atas t_menu), dan role SIAKAD tempat otoritas itu dipetakan (LegacyRole). Hanya baca.
|
||||
*/
|
||||
final class AuthorityDirectory
|
||||
{
|
||||
private function db(): ConnectionInterface
|
||||
{
|
||||
return DB::connection('untan');
|
||||
}
|
||||
|
||||
/** @return Collection<int, array<string, mixed>> */
|
||||
public function all(): Collection
|
||||
{
|
||||
return $this->db()->table('t_otoritas as t')
|
||||
->selectRaw('t.idotoritas, t.otoritas, (select count(*) from t_otoritasuser o where o.idotoritas = t.idotoritas) as pengguna, (select count(*) from t_menuotoritas m where m.idotoritas = t.idotoritas) as menu')
|
||||
->orderBy('t.idotoritas')
|
||||
->get()
|
||||
->map(fn (object $row): array => $this->present($row));
|
||||
}
|
||||
|
||||
/**
|
||||
* Satu otoritas dengan menunya dikelompokkan menurut induk (modul), berurutan kode menu.
|
||||
*
|
||||
* @return array<string, mixed>|null
|
||||
*/
|
||||
public function find(int $id): ?array
|
||||
{
|
||||
$row = $this->db()->table('t_otoritas as t')
|
||||
->selectRaw('t.idotoritas, t.otoritas, (select count(*) from t_otoritasuser o where o.idotoritas = t.idotoritas) as pengguna, (select count(*) from t_menuotoritas m where m.idotoritas = t.idotoritas) as menu')
|
||||
->where('t.idotoritas', $id)->first();
|
||||
|
||||
if ($row === null) {
|
||||
return null;
|
||||
}
|
||||
|
||||
$menus = $this->db()->table('t_menuotoritas as mo')
|
||||
->join('t_menu as m', 'm.idmenu', '=', 'mo.idmenu')
|
||||
->leftJoin('t_menu as p', 'p.idmenu', '=', 'm.idmenuinduk')
|
||||
->where('mo.idotoritas', $id)
|
||||
->orderBy('m.kdmenu')->orderBy('m.idmenu')
|
||||
->get(['m.idmenu', 'm.kdmenu', 'm.menu', 'm.islink', 'mo.bybagian', 'p.menu as induk']);
|
||||
|
||||
$groups = $menus
|
||||
->groupBy(fn (object $menu): string => filled($menu->induk) ? trim($menu->induk) : 'Menu utama')
|
||||
->map(fn (Collection $items): array => $items->map(fn (object $menu): array => [
|
||||
'kode' => trim((string) $menu->kdmenu),
|
||||
'nama' => trim((string) $menu->menu),
|
||||
'unit' => (bool) $menu->bybagian,
|
||||
])->all())
|
||||
->all();
|
||||
|
||||
return $this->present($row) + ['groups' => $groups];
|
||||
}
|
||||
|
||||
/** @return array<string, mixed> */
|
||||
private function present(object $row): array
|
||||
{
|
||||
$role = LegacyRole::all(LegacyRole::JENIS_PEGAWAI, [(int) $row->idotoritas], false)[0] ?? null;
|
||||
|
||||
return [
|
||||
'id' => (int) $row->idotoritas,
|
||||
'nama' => trim((string) $row->otoritas),
|
||||
'peran' => $role?->label() ?? 'Tanpa peran',
|
||||
'pengguna' => (int) $row->pengguna,
|
||||
'menu' => (int) $row->menu,
|
||||
];
|
||||
}
|
||||
}
|
||||
@@ -86,7 +86,7 @@ final class ClassSchedule
|
||||
[$lecturers, $meetings, $participants] = [$this->lecturers($ids), $this->meetings($ids), $this->participants($ids)];
|
||||
|
||||
return $rows->through(fn (object $s): array => $this->present($s) + [
|
||||
'form' => ['mk' => (int) $s->idmatakuliah, 'periode' => (int) $s->idperiode, 'kelas' => trim((string) $s->kelas), 'kapasitas' => (int) $s->kapasitas],
|
||||
'form' => ['prodi' => (int) $s->idprogdi, 'mk' => (int) $s->idmatakuliah, 'periode' => (int) $s->idperiode, 'kelas' => trim((string) $s->kelas), 'kapasitas' => (int) $s->kapasitas],
|
||||
'pengajar' => ($lecturers[(int) $s->idjadwal] ?? collect())->pluck('nama')->implode('; ') ?: '–',
|
||||
'jadwal' => ($meetings[(int) $s->idjadwal] ?? collect())->map(fn (array $t): string => $t['teks'])->implode('; ') ?: '–',
|
||||
'pst' => (int) ($participants[(int) $s->idjadwal] ?? 0),
|
||||
@@ -281,7 +281,7 @@ final class ClassSchedule
|
||||
->leftJoin('t_periodekuliah as kp', 'kp.idperiode', '=', 'k.idperiode')
|
||||
->leftJoin('t_periodekuliah as p', 'p.idperiode', '=', 's.idperiode')
|
||||
->leftJoin('t_jenisprogram as jp', 'jp.idprogram', '=', 'k.idprogram')
|
||||
->select('s.idjadwal', 's.idmatakuliah', 's.idperiode', 's.kelas', 's.kapasitas', 's.flag_cetak', 'm.kodemk', 'm.namamk', 'm.sks', 'kp.thakad', 'k.namakurikulum', 'b.namabagian', 'jp.program')
|
||||
->select('s.idjadwal', 's.idmatakuliah', 's.idprogdi', 's.idperiode', 's.kelas', 's.kapasitas', 's.flag_cetak', 'm.kodemk', 'm.namamk', 'm.sks', 'kp.thakad', 'k.namakurikulum', 'b.namabagian', 'jp.program')
|
||||
->addSelect(DB::raw('('.$this->db()->table('pdpt_tmst_program_studi as pp')->join('t_jenjangprogdi as jpg', 'jpg.kode', '=', 'pp.kode_jenjang_pendidikan')->whereColumn('pp.idbagianuntan', 's.idprogdi')->selectRaw('min(jpg.kdjenjang)')->toSql().') as jenjang'));
|
||||
}
|
||||
|
||||
|
||||
@@ -30,6 +30,10 @@ final class ClassWriter
|
||||
public function create(array $prodi, array $input, string $actor, ?string $ip): int
|
||||
{
|
||||
$course = $this->ownedCourse($prodi, $input['mk'] ?? 0);
|
||||
// Program studi di formulir hanya penyaring pilihan mata kuliah; harus sama dengan prodi kurikulum mata kuliah itu.
|
||||
if (isset($input['prodi']) && (int) $input['prodi'] !== (int) $course->idprogdi) {
|
||||
throw new PortalException('Mata kuliah harus dipilih dari program studi yang dipilih.');
|
||||
}
|
||||
$periode = (int) ($input['periode'] ?? 0);
|
||||
if (! $this->db()->table('t_periodekuliah')->where('idperiode', $periode)->whereIn('perkuliahan', [1, 2])->exists()) {
|
||||
throw new PortalException('Periode akademik harus dipilih dari daftar.');
|
||||
|
||||
@@ -57,6 +57,43 @@ final class Curriculum
|
||||
->mapWithKeys(fn (object $k): array => [(int) $k->idkurikulum => trim(self::year($k->thakad).' – '.trim((string) $k->namakurikulum).' ('.trim($k->namabagian).')', ' –')]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Kurikulum prodi akun dikelompokkan menurut program studinya, untuk pilihan bertingkat di formulir (pilih prodi dulu).
|
||||
* Daftar pasangan [id, label] (bukan peta) agar urutan terbaru-dulu tidak diacak oleh kunci angka JSON.
|
||||
*
|
||||
* @param list<int> $prodi
|
||||
* @return array<int, list<array{0: int, 1: string}>> idprogdi => [[idkurikulum, "2023 – Kurikulum 2023/2024"], ...]
|
||||
*/
|
||||
public function curriculaByProdi(array $prodi): array
|
||||
{
|
||||
$byProdi = [];
|
||||
foreach ($this->db()->table('t_kurikulum as k')->leftJoin('t_periodekuliah as p', 'p.idperiode', '=', 'k.idperiode')
|
||||
->whereIn('k.idprogdi', $prodi)->orderByDesc('p.thakad')->orderByDesc('k.idkurikulum')
|
||||
->get(['k.idkurikulum', 'k.idprogdi', 'k.namakurikulum', 'p.thakad']) as $k) {
|
||||
$byProdi[(int) $k->idprogdi][] = [(int) $k->idkurikulum, trim(self::year($k->thakad).' – '.trim((string) $k->namakurikulum), ' –') ?: 'Kurikulum '.$k->idkurikulum];
|
||||
}
|
||||
|
||||
return $byProdi;
|
||||
}
|
||||
|
||||
/**
|
||||
* Kelompok mata kuliah (t_jenismatakuliah) dikelompokkan menurut kurikulumnya, untuk pilihan bertingkat di formulir.
|
||||
*
|
||||
* @param list<int> $prodi
|
||||
* @return array<int, list<array{0: int, 1: string}>> idkurikulum => [[idjenis, "MKWU – Mata Kuliah Wajib Umum"], ...]
|
||||
*/
|
||||
public function groupsByCurriculum(array $prodi): array
|
||||
{
|
||||
$byCurriculum = [];
|
||||
foreach ($this->db()->table('t_jenismatakuliah as j')->join('t_kurikulum as k', 'k.idkurikulum', '=', 'j.idkurikulum')
|
||||
->whereIn('k.idprogdi', $prodi)->orderBy('j.idkurikulum')->orderBy('j.urutan')->orderBy('j.idjenis')
|
||||
->get(['j.idjenis', 'j.idkurikulum', 'j.jenis', 'j.keterangan']) as $j) {
|
||||
$byCurriculum[(int) $j->idkurikulum][] = [(int) $j->idjenis, trim(trim((string) $j->jenis).' – '.trim((string) $j->keterangan), ' –')];
|
||||
}
|
||||
|
||||
return $byCurriculum;
|
||||
}
|
||||
|
||||
/**
|
||||
* Kelompok mata kuliah (kode jenis t_jenismatakuliah) kurikulum prodi akun.
|
||||
*
|
||||
@@ -111,13 +148,13 @@ final class Curriculum
|
||||
->when($q !== '', fn (Builder $query) => $query->where(fn (Builder $w) => $w
|
||||
->whereRaw('lower(m.kodemk) like ?', ["%{$q}%"])->orWhereRaw('lower(m.namamk) like ?', ["%{$q}%"])))
|
||||
->orderByDesc('p.thakad')->orderByDesc('k.idkurikulum')->orderBy('m.semester')->orderBy('m.kodemk')->orderBy('m.idmatakuliah')
|
||||
->select('m.idmatakuliah', 'm.kodemk', 'm.namamk', 'm.sks', 'm.tipe', 'm.semester', 'm.idkurikulum', 'm.idjenis', 'm.nilailulus', 'p.thakad', 'k.namakurikulum', 'b.namabagian', 'j.jenis')
|
||||
->select('m.idmatakuliah', 'm.kodemk', 'm.namamk', 'm.sks', 'm.tipe', 'm.semester', 'm.idkurikulum', 'm.idjenis', 'm.nilailulus', 'p.thakad', 'k.idprogdi', 'k.namakurikulum', 'b.namabagian', 'j.jenis')
|
||||
->addSelect($this->levelSub('k.idprogdi'))
|
||||
->paginate($perPage)
|
||||
->through(fn (object $m): array => [
|
||||
'id' => (int) $m->idmatakuliah,
|
||||
'form' => [
|
||||
'kurikulum' => (int) $m->idkurikulum, 'kode' => trim($m->kodemk), 'nama' => trim($m->namamk), 'sks' => (int) $m->sks,
|
||||
'prodi' => (int) $m->idprogdi, 'kurikulum' => (int) $m->idkurikulum, 'kode' => trim($m->kodemk), 'nama' => trim($m->namamk), 'sks' => (int) $m->sks,
|
||||
'semester' => $m->semester === null ? '' : (int) $m->semester, 'tipe' => (int) $m->tipe, 'jenis' => $m->idjenis === null ? '' : (int) $m->idjenis,
|
||||
'nilailulus' => isset(self::PASS_GRADES[(int) $m->nilailulus]) ? (int) $m->nilailulus : 2,
|
||||
],
|
||||
@@ -168,7 +205,7 @@ final class Curriculum
|
||||
}
|
||||
|
||||
return $query->paginate($perPage)->through(fn (object $k): array => $this->presentCurriculum($k) + ['form' => [
|
||||
'prodi' => (int) $k->idprogdi, 'program' => (int) $k->idprogram, 'periode' => (int) $k->idperiode,
|
||||
'prodi' => (int) $k->idprogdi, 'program' => (int) $k->idprogram,
|
||||
'nama' => trim((string) $k->namakurikulum), 'deskripsi' => trim((string) $k->deskripsi), 'aktif' => (int) (bool) $k->aktif,
|
||||
]]);
|
||||
}
|
||||
@@ -344,8 +381,29 @@ final class Curriculum
|
||||
}
|
||||
|
||||
/**
|
||||
* Mata kuliah prodi akun dikelompokkan menurut program studi kurikulumnya, untuk pilihan bertingkat (pilih prodi dulu).
|
||||
* Daftar pasangan [id, label] agar urutan terbaru-dulu tidak diacak oleh kunci angka JSON.
|
||||
*
|
||||
* @param list<int> $prodi
|
||||
* @param array{kurikulum: int, kode: string, nama: string, sks: int, semester?: ?int, tipe: int, jenis: int, nilailulus?: ?int} $input
|
||||
* @return array<int, list<array{0: int, 1: string}>> idprogdi => [[idmatakuliah, "2020 – IF311 Sistem Basis Data"], ...]
|
||||
*/
|
||||
public function courseOptionsByProdi(array $prodi): array
|
||||
{
|
||||
$byProdi = [];
|
||||
foreach ($this->db()->table('t_matakuliah as m')->join('t_kurikulum as k', 'k.idkurikulum', '=', 'm.idkurikulum')
|
||||
->leftJoin('t_periodekuliah as p', 'p.idperiode', '=', 'k.idperiode')
|
||||
->whereIn('k.idprogdi', $prodi)
|
||||
->orderByDesc('p.thakad')->orderByDesc('m.idkurikulum')->orderBy('m.semester')->orderBy('m.kodemk')
|
||||
->get(['m.idmatakuliah', 'm.kodemk', 'm.namamk', 'k.idprogdi', 'p.thakad']) as $m) {
|
||||
$byProdi[(int) $m->idprogdi][] = [(int) $m->idmatakuliah, trim(self::year($m->thakad).' – '.trim($m->kodemk).' '.trim($m->namamk), ' –')];
|
||||
}
|
||||
|
||||
return $byProdi;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param list<int> $prodi
|
||||
* @param array{prodi: int, kurikulum: int, kode: string, nama: string, sks: int, semester?: ?int, tipe: int, jenis: int, nilailulus?: ?int} $input
|
||||
* @return int id baru
|
||||
*/
|
||||
public function createCourse(array $prodi, array $input, string $actor, ?string $ip): int
|
||||
@@ -357,7 +415,7 @@ final class Curriculum
|
||||
|
||||
/**
|
||||
* @param list<int> $prodi
|
||||
* @param array{kurikulum: int, kode: string, nama: string, sks: int, semester?: ?int, tipe: int, jenis: int, nilailulus?: ?int} $input
|
||||
* @param array{prodi: int, kurikulum: int, kode: string, nama: string, sks: int, semester?: ?int, tipe: int, jenis: int, nilailulus?: ?int} $input
|
||||
*/
|
||||
public function updateCourse(array $prodi, int $id, array $input, string $actor, ?string $ip): void
|
||||
{
|
||||
@@ -477,7 +535,14 @@ final class Curriculum
|
||||
*/
|
||||
private function courseValues(array $prodi, array $input, ?int $ignore): array
|
||||
{
|
||||
$prodiId = (int) ($input['prodi'] ?? 0);
|
||||
if (! in_array($prodiId, $prodi, true)) {
|
||||
throw new PortalException('Program studi harus dipilih dari program studi Anda.');
|
||||
}
|
||||
$kurikulum = $this->ownedCurriculum($prodi, $input['kurikulum'] ?? 0);
|
||||
if (! $this->db()->table('t_kurikulum')->where('idkurikulum', $kurikulum)->where('idprogdi', $prodiId)->exists()) {
|
||||
throw new PortalException('Kurikulum harus dipilih dari program studi yang dipilih.');
|
||||
}
|
||||
$kode = mb_substr(trim((string) ($input['kode'] ?? '')), 0, 15);
|
||||
$nama = mb_substr(trim((string) ($input['nama'] ?? '')), 0, 50);
|
||||
$sks = (int) ($input['sks'] ?? -1);
|
||||
|
||||
@@ -64,11 +64,12 @@ final class CurriculumWriter
|
||||
if ($current === null) {
|
||||
throw new PortalException('Kurikulum tidak ditemukan.');
|
||||
}
|
||||
$v = $this->values($prodi, $input, $id);
|
||||
// Periode berlaku ditetapkan saat dibuat dan tidak diubah lewat formulir.
|
||||
$v = $this->values($prodi, ['periode' => $current->idperiode] + $input, $id);
|
||||
|
||||
if ((int) $current->idprogdi !== $v['idprogdi'] || (int) $current->idprogram !== $v['idprogram'] || (int) $current->idperiode !== $v['idperiode']) {
|
||||
if ((int) $current->idprogdi !== $v['idprogdi'] || (int) $current->idprogram !== $v['idprogram']) {
|
||||
if (($used = $this->usedBy([$id])) !== null) {
|
||||
throw new PortalException("Program studi, sistem kuliah, dan periode berlaku tidak dapat diubah karena kurikulum sudah punya {$used}.");
|
||||
throw new PortalException("Program studi dan sistem kuliah tidak dapat diubah karena kurikulum sudah punya {$used}.");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,153 @@
|
||||
<?php
|
||||
|
||||
namespace App\Support\Legacy;
|
||||
|
||||
use Illuminate\Database\ConnectionInterface;
|
||||
use Illuminate\Database\Query\Builder;
|
||||
use Illuminate\Pagination\LengthAwarePaginator;
|
||||
use Illuminate\Support\Carbon;
|
||||
use Illuminate\Support\Collection;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
|
||||
/**
|
||||
* Log aktivitas (Superuser): riwayat masuk asli t_historilogin (waktu, komputer, alamat IP) beserta nama pemilik akunnya.
|
||||
* Satu-satunya jenis aktivitas yang dicatat sumber data ini adalah "Masuk". Hanya baca.
|
||||
*/
|
||||
final class LoginHistory
|
||||
{
|
||||
public const array PER_PAGE = AccountDirectory::PER_PAGE;
|
||||
|
||||
/** Batas akun yang dicocokkan oleh pencarian nama atau NIP/NIM agar daftar idnya tetap kecil. */
|
||||
private const int MAX_MATCHES = 500;
|
||||
|
||||
private function db(): ConnectionInterface
|
||||
{
|
||||
return DB::connection('untan');
|
||||
}
|
||||
|
||||
/** Waktu catatan, mis. "10 Apr 2018, 04.39". */
|
||||
public static function time(?string $value): string
|
||||
{
|
||||
return $value === null ? '-' : Carbon::parse($value)->locale('id')->isoFormat('D MMM YYYY, HH.mm');
|
||||
}
|
||||
|
||||
/** Teks kolom dipangkas; alamat IP tanpa awalan jaringan "/32" bawaan tipe inet. */
|
||||
public static function clean(?string $value): ?string
|
||||
{
|
||||
$text = trim(preg_replace('#/(32|128)$#', '', trim((string) $value)));
|
||||
|
||||
return $text === '' ? null : $text;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array{q?: ?string, dari?: ?string, sampai?: ?string, pengguna?: ?int} $filter
|
||||
* @return LengthAwarePaginator<int, array<string, mixed>>
|
||||
*/
|
||||
public function search(array $filter, int $perPage = self::PER_PAGE[0]): LengthAwarePaginator
|
||||
{
|
||||
$q = trim((string) ($filter['q'] ?? ''));
|
||||
$dari = $this->date($filter['dari'] ?? null);
|
||||
$sampai = $this->date($filter['sampai'] ?? null);
|
||||
$user = $filter['pengguna'] ?? null;
|
||||
|
||||
$page = $this->db()->table('t_historilogin as h')
|
||||
->select(['h.idhistori', 'h.iduser', 'h.logintimestamp', 'h.logincname', 'h.logincip'])
|
||||
->when($user !== null, fn (Builder $query) => $query->where('h.iduser', $user))
|
||||
->when($q !== '', fn (Builder $query) => $query->whereIn('h.iduser', $this->accountIds($q)))
|
||||
->when($dari !== null, fn (Builder $query) => $query->where('h.logintimestamp', '>=', $dari->startOfDay()))
|
||||
->when($sampai !== null, fn (Builder $query) => $query->where('h.logintimestamp', '<=', $sampai->endOfDay()))
|
||||
->orderByDesc('h.idhistori')
|
||||
->paginate($perPage);
|
||||
|
||||
$owners = $this->owners(collect($page->items())->pluck('iduser')->unique()->all());
|
||||
|
||||
return $page->through(fn (object $row): array => $this->present($row, $owners[(int) $row->iduser] ?? null));
|
||||
}
|
||||
|
||||
/**
|
||||
* Masuk terbaru (untuk dashboard).
|
||||
*
|
||||
* @return list<array<string, mixed>>
|
||||
*/
|
||||
public function latest(int $limit = 5): array
|
||||
{
|
||||
$rows = $this->db()->table('t_historilogin')->orderByDesc('idhistori')->limit($limit)
|
||||
->get(['idhistori', 'iduser', 'logintimestamp', 'logincname', 'logincip']);
|
||||
$owners = $this->owners($rows->pluck('iduser')->unique()->all());
|
||||
|
||||
return $rows->map(fn (object $row): array => $this->present($row, $owners[(int) $row->iduser] ?? null))->all();
|
||||
}
|
||||
|
||||
/** @return list<int> iduser yang nama, NIP, atau NIM-nya cocok dengan kata kunci */
|
||||
private function accountIds(string $q): array
|
||||
{
|
||||
$like = '%'.mb_strtolower($q).'%';
|
||||
$prefix = mb_strtolower($q).'%';
|
||||
|
||||
$pegawai = $this->db()->table('t_account as a')
|
||||
->join('t_pegawai as p', fn ($join) => $join->on('p.idpegawai', '=', 'a.identitas')->where('a.jenis', LegacyRole::JENIS_PEGAWAI))
|
||||
->where(fn (Builder $w) => $w->whereRaw('lower(p.nama) like ?', [$like])->orWhereRaw('lower(p.nip) like ?', [$prefix]))
|
||||
->limit(self::MAX_MATCHES)->pluck('a.iduser');
|
||||
|
||||
$mahasiswa = $this->db()->table('t_account as a')
|
||||
->join('t_mahasiswa as m', fn ($join) => $join->on('m.idmahasiswa', '=', 'a.identitas')->where('a.jenis', LegacyRole::JENIS_MAHASISWA))
|
||||
->where(fn (Builder $w) => $w->whereRaw('lower(m.nama) like ?', [$like])->orWhereRaw('lower(m.nim) like ?', [$prefix]))
|
||||
->limit(self::MAX_MATCHES)->pluck('a.iduser');
|
||||
|
||||
return $pegawai->merge($mahasiswa)->map(fn ($id): int => (int) $id)->all();
|
||||
}
|
||||
|
||||
/**
|
||||
* Nama dan username pemilik akun.
|
||||
*
|
||||
* @param list<int> $ids
|
||||
* @return array<int, array{nama: string, username: string}>
|
||||
*/
|
||||
private function owners(array $ids): array
|
||||
{
|
||||
if ($ids === []) {
|
||||
return [];
|
||||
}
|
||||
|
||||
/** @var Collection<int, object> $rows */
|
||||
$rows = $this->db()->table('t_account as a')
|
||||
->leftJoin('t_pegawai as p', fn ($join) => $join->on('p.idpegawai', '=', 'a.identitas')->where('a.jenis', LegacyRole::JENIS_PEGAWAI))
|
||||
->leftJoin('t_mahasiswa as m', fn ($join) => $join->on('m.idmahasiswa', '=', 'a.identitas')->where('a.jenis', LegacyRole::JENIS_MAHASISWA))
|
||||
->whereIn('a.iduser', $ids)
|
||||
->get(['a.iduser', 'a.jenis', 'p.nip', 'p.nama as pegawai_nama', 'p.gelardepan', 'p.gelarbelakang', 'm.nim', 'm.nama as mahasiswa_nama']);
|
||||
|
||||
$owners = [];
|
||||
foreach ($rows as $row) {
|
||||
$pegawai = (int) $row->jenis === LegacyRole::JENIS_PEGAWAI;
|
||||
$owners[(int) $row->iduser] = [
|
||||
'nama' => $pegawai ? LegacyFormat::pegawaiName($row->gelardepan, $row->pegawai_nama, $row->gelarbelakang) : trim((string) $row->mahasiswa_nama),
|
||||
'username' => trim((string) ($pegawai ? $row->nip : $row->nim)),
|
||||
];
|
||||
}
|
||||
|
||||
return $owners;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array{nama: string, username: string}|null $owner
|
||||
* @return array<string, mixed>
|
||||
*/
|
||||
private function present(object $row, ?array $owner): array
|
||||
{
|
||||
return [
|
||||
'id' => (int) $row->idhistori,
|
||||
'iduser' => (int) $row->iduser,
|
||||
'waktu' => self::time($row->logintimestamp),
|
||||
'pengguna' => $owner['nama'] ?? 'Akun tidak ditemukan',
|
||||
'username' => $owner['username'] ?? null,
|
||||
'aksi' => 'Masuk',
|
||||
'komputer' => self::clean($row->logincname),
|
||||
'ip' => self::clean($row->logincip),
|
||||
];
|
||||
}
|
||||
|
||||
private function date(?string $value): ?Carbon
|
||||
{
|
||||
return filled($value) && preg_match('/^\d{4}-\d{2}-\d{2}$/', $value) === 1 ? Carbon::createFromFormat('Y-m-d', $value)?->startOfDay() : null;
|
||||
}
|
||||
}
|
||||
@@ -23,7 +23,7 @@ final class ReferenceData
|
||||
public const array LISTS = [
|
||||
'list_fakultas', 'list_prodi', 'ms_bidangstudi', 'ms_jenjang', 'ms_sistemkuliah', 'ms_ruang', 'ms_universitas',
|
||||
'ms_tingkatpendidikan', 'list_jurusan', 'list_gedung',
|
||||
'ms_jenismk', 'ms_kelompokmk', 'ms_grupmk',
|
||||
'ms_jenismk', 'ms_grupmk',
|
||||
'ms_agama', 'ms_pekerjaan', 'ms_penghasilan',
|
||||
'ms_statusmhs',
|
||||
'ms_jenispeg', 'ms_golpangkat', 'ms_jabfung', 'ms_jabstruktural', 'ms_statusaktif',
|
||||
@@ -275,17 +275,6 @@ final class ReferenceData
|
||||
'columns' => [$col('kode', 'Kode'), $col('nama', 'Nama Jenis Mata Kuliah')],
|
||||
'query' => fn (): Collection => collect(Curriculum::TYPES)->map(fn (string $nama, int $kode): array => ['id' => $kode, 'kode' => $kode, 'nama' => $nama])->values(),
|
||||
],
|
||||
'ms_kelompokmk' => [
|
||||
'note' => 'Kelompok mata kuliah asli dari t_jenismatakuliah: pasangan kode dan nama unik dari seluruh kurikulum (satu kode bisa muncul dengan beberapa ejaan nama).',
|
||||
'columns' => [$col('kode', 'Kode'), $col('nama', 'Nama Kelompok Mata Kuliah')],
|
||||
'query' => fn (): Builder => $db->table('t_jenismatakuliah')
|
||||
->selectRaw('upper(trim(jenis)) as kode, trim(coalesce(keterangan, \'\')) as nama, count(*) as n')
|
||||
->whereRaw('trim(jenis) not in (\'\', \'0\')')
|
||||
->groupByRaw('upper(trim(jenis)), trim(coalesce(keterangan, \'\'))')
|
||||
->orderBy('kode')->orderBy('nama'),
|
||||
'search' => ['jenis', 'coalesce(keterangan, \'\')'],
|
||||
'row' => fn (object $r): array => ['id' => $r->kode.'|'.$r->nama, 'kode' => self::text($r->kode), 'nama' => self::text($r->nama)],
|
||||
],
|
||||
'ms_grupmk' => [
|
||||
'note' => 'Grup mata kuliah wajib pilihan = nama konsentrasi/peminatan unik dari t_konsentrasi (sumber yang sama dengan Set Grup Mata Kuliah).',
|
||||
'columns' => [$col('nama', 'Nama Grup MK')],
|
||||
|
||||
@@ -0,0 +1,160 @@
|
||||
<?php
|
||||
|
||||
namespace App\Support\Legacy;
|
||||
|
||||
use Illuminate\Database\ConnectionInterface;
|
||||
use Illuminate\Database\Query\Builder;
|
||||
use Illuminate\Pagination\LengthAwarePaginator;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
|
||||
/**
|
||||
* Kelompok mata kuliah per kurikulum (t_jenismatakuliah: kode `jenis` + nama `keterangan`) milik prodi akun: lihat,
|
||||
* tambah, ubah, hapus. Kelompok dipilih di formulir Mata Kuliah (t_matakuliah.idjenis), jadi yang sudah dipakai
|
||||
* mata kuliah tidak boleh dihapus dan tidak boleh dipindah ke kurikulum lain.
|
||||
*/
|
||||
final class SubjectGroups
|
||||
{
|
||||
private function db(): ConnectionInterface
|
||||
{
|
||||
return DB::connection('untan');
|
||||
}
|
||||
|
||||
/**
|
||||
* @param list<int> $prodi
|
||||
* @param array{prodi?: ?int, kurikulum?: ?int, q?: ?string} $filter
|
||||
* @return LengthAwarePaginator<int, array<string, mixed>>
|
||||
*/
|
||||
public function list(array $prodi, array $filter, int $perPage): LengthAwarePaginator
|
||||
{
|
||||
$q = mb_strtolower(trim((string) ($filter['q'] ?? '')));
|
||||
|
||||
return $this->owned($prodi)
|
||||
->join('t_bagian as b', 'b.idbagian', '=', 'k.idprogdi')
|
||||
->leftJoin('t_periodekuliah as p', 'p.idperiode', '=', 'k.idperiode')
|
||||
->when($filter['prodi'] ?? null, fn (Builder $query, int $id) => $query->where('k.idprogdi', $id))
|
||||
->when($filter['kurikulum'] ?? null, fn (Builder $query, int $id) => $query->where('j.idkurikulum', $id))
|
||||
->when($q !== '', fn (Builder $query) => $query->where(fn (Builder $w) => $w
|
||||
->whereRaw('lower(coalesce(j.jenis, \'\')) like ?', ["%{$q}%"])->orWhereRaw('lower(coalesce(j.keterangan, \'\')) like ?', ["%{$q}%"])
|
||||
->orWhereRaw('lower(coalesce(k.namakurikulum, \'\')) like ?', ["%{$q}%"])))
|
||||
->orderByDesc('p.thakad')->orderByDesc('j.idkurikulum')->orderBy('j.urutan')->orderBy('j.idjenis')
|
||||
->select('j.idjenis', 'j.idkurikulum', 'j.jenis', 'j.keterangan', 'k.idprogdi', 'k.namakurikulum', 'p.thakad', 'b.namabagian')
|
||||
->selectSub($this->db()->table('t_matakuliah as m')->selectRaw('count(*)')->whereColumn('m.idjenis', 'j.idjenis'), 'jumlah_mk')
|
||||
->paginate($perPage)
|
||||
->through(fn (object $j): array => [
|
||||
'id' => (int) $j->idjenis,
|
||||
'form' => ['prodi' => (int) $j->idprogdi, 'kurikulum' => (int) $j->idkurikulum, 'kode' => trim((string) $j->jenis), 'nama' => trim((string) $j->keterangan)],
|
||||
'kurikulum' => trim(substr(trim((string) $j->thakad), 0, 4).' – '.trim((string) $j->namakurikulum), ' –'),
|
||||
'prodi' => trim((string) $j->namabagian),
|
||||
'kode' => trim((string) $j->jenis) ?: '–',
|
||||
'nama' => trim((string) $j->keterangan) ?: '–',
|
||||
'mk' => (int) $j->jumlah_mk,
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param list<int> $prodi
|
||||
* @param array{prodi: int, kurikulum: int, kode: string, nama: string} $input
|
||||
* @return int id kelompok baru
|
||||
*/
|
||||
public function create(array $prodi, array $input, string $actor, ?string $ip): int
|
||||
{
|
||||
$v = $this->values($prodi, $input, null);
|
||||
$urutan = (int) $this->db()->table('t_jenismatakuliah')->where('idkurikulum', $v['idkurikulum'])->max('urutan') + 1;
|
||||
|
||||
return (int) $this->db()->table('t_jenismatakuliah')->insertGetId($v + ['urutan' => $urutan] + $this->audit($actor, $ip), 'idjenis');
|
||||
}
|
||||
|
||||
/**
|
||||
* @param list<int> $prodi
|
||||
* @param array{prodi: int, kurikulum: int, kode: string, nama: string} $input
|
||||
*/
|
||||
public function update(array $prodi, int $id, array $input, string $actor, ?string $ip): void
|
||||
{
|
||||
$current = $this->owned($prodi)->where('j.idjenis', $id)->first(['j.idjenis', 'j.idkurikulum']);
|
||||
if ($current === null) {
|
||||
throw new PortalException('Kelompok mata kuliah tidak ditemukan.');
|
||||
}
|
||||
$v = $this->values($prodi, $input, $id);
|
||||
|
||||
if ((int) $current->idkurikulum !== $v['idkurikulum'] && ($used = $this->courseCount($id)) > 0) {
|
||||
throw new PortalException("Kurikulum tidak dapat diubah karena kelompok ini sudah dipakai {$used} mata kuliah.");
|
||||
}
|
||||
|
||||
$this->db()->table('t_jenismatakuliah')->where('idjenis', $id)->update($v + $this->audit($actor, $ip));
|
||||
}
|
||||
|
||||
/**
|
||||
* Hapus kelompok prodi akun yang belum dipakai mata kuliah mana pun; mengembalikan jumlah yang terhapus.
|
||||
*
|
||||
* @param list<int> $prodi
|
||||
* @param list<int> $ids
|
||||
*/
|
||||
public function delete(array $prodi, array $ids): int
|
||||
{
|
||||
$owned = $this->owned($prodi)->whereIn('j.idjenis', array_map('intval', $ids))->get(['j.idjenis', 'j.jenis']);
|
||||
if ($owned->isEmpty()) {
|
||||
throw new PortalException('Kelompok mata kuliah tidak ditemukan.');
|
||||
}
|
||||
foreach ($owned as $g) {
|
||||
if (($used = $this->courseCount((int) $g->idjenis)) > 0) {
|
||||
throw new PortalException('Kelompok '.(trim((string) $g->jenis) ?: "#{$g->idjenis}")." sudah dipakai {$used} mata kuliah, sehingga tidak boleh dihapus.");
|
||||
}
|
||||
}
|
||||
|
||||
return $this->db()->table('t_jenismatakuliah')->whereIn('idjenis', $owned->pluck('idjenis')->all())->delete();
|
||||
}
|
||||
|
||||
/** Mata kuliah yang merujuk kelompok ini (termasuk arsip mata kuliah terhapus bila tabelnya ada). */
|
||||
private function courseCount(int $id): int
|
||||
{
|
||||
$count = $this->db()->table('t_matakuliah')->where('idjenis', $id)->count();
|
||||
if ($this->db()->getSchemaBuilder()->hasTable('t_matakuliahdel')) {
|
||||
$count += $this->db()->table('t_matakuliahdel')->where('idjenis', $id)->count();
|
||||
}
|
||||
|
||||
return $count;
|
||||
}
|
||||
|
||||
/** @param list<int> $prodi */
|
||||
private function owned(array $prodi): Builder
|
||||
{
|
||||
return $this->db()->table('t_jenismatakuliah as j')->join('t_kurikulum as k', 'k.idkurikulum', '=', 'j.idkurikulum')->whereIn('k.idprogdi', $prodi);
|
||||
}
|
||||
|
||||
/**
|
||||
* Rapikan dan periksa isian; kode unik per kurikulum (huruf besar/kecil dianggap sama).
|
||||
*
|
||||
* @param list<int> $prodi
|
||||
* @return array{idkurikulum: int, jenis: string, keterangan: string}
|
||||
*/
|
||||
private function values(array $prodi, array $input, ?int $ignore): array
|
||||
{
|
||||
$progdi = (int) ($input['prodi'] ?? 0);
|
||||
$kurikulum = (int) ($input['kurikulum'] ?? 0);
|
||||
$kode = mb_substr(trim((string) ($input['kode'] ?? '')), 0, 50);
|
||||
$nama = mb_substr(trim((string) ($input['nama'] ?? '')), 0, 50);
|
||||
|
||||
if (! in_array($progdi, $prodi, true)) {
|
||||
throw new PortalException('Program studi harus dipilih dari program studi Anda.');
|
||||
}
|
||||
if (! $this->db()->table('t_kurikulum')->where('idkurikulum', $kurikulum)->where('idprogdi', $progdi)->exists()) {
|
||||
throw new PortalException('Kurikulum harus dipilih dari program studi yang dipilih.');
|
||||
}
|
||||
if ($kode === '' || $nama === '') {
|
||||
throw new PortalException('Kode dan nama kelompok mata kuliah wajib diisi.');
|
||||
}
|
||||
$duplicate = $this->db()->table('t_jenismatakuliah')->where('idkurikulum', $kurikulum)->whereRaw('upper(trim(jenis)) = ?', [mb_strtoupper($kode)])
|
||||
->when($ignore !== null, fn (Builder $q) => $q->where('idjenis', '<>', $ignore))->exists();
|
||||
if ($duplicate) {
|
||||
throw new PortalException("Kelompok dengan kode {$kode} sudah ada di kurikulum itu.");
|
||||
}
|
||||
|
||||
return ['idkurikulum' => $kurikulum, 'jenis' => $kode, 'keterangan' => $nama];
|
||||
}
|
||||
|
||||
/** Kolom audit seperti aplikasi lama: cname nama aplikasi, cip alamat IP (maks. 20), uname username (maks. 15). */
|
||||
private function audit(string $actor, ?string $ip): array
|
||||
{
|
||||
return ['cname' => ActivityTypes::APP_NAME, 'cip' => mb_substr($ip ?? '', 0, 20), 'uname' => mb_substr($actor, 0, 15), 'tanggal' => now()];
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,146 @@
|
||||
<?php
|
||||
|
||||
namespace App\Support\Legacy;
|
||||
|
||||
use Illuminate\Database\ConnectionInterface;
|
||||
use Illuminate\Support\Carbon;
|
||||
use Illuminate\Support\Facades\Cache;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
use Throwable;
|
||||
|
||||
/**
|
||||
* Ringkasan Superuser dari DB lama: jumlah akun (t_account), pegawai per otoritas, riwayat masuk per tahun
|
||||
* (t_historilogin), serta kondisi koneksi basis data untuk halaman Kesehatan sistem. Hanya baca.
|
||||
*/
|
||||
final class SystemOverview
|
||||
{
|
||||
/** Riwayat masuk puluhan tahun dan berhenti bertambah; agregatnya cukup dihitung sekali per jam. */
|
||||
private const int LOGIN_CACHE_SECONDS = 3600;
|
||||
|
||||
private const int TOP_AUTHORITIES = 8;
|
||||
|
||||
private const int YEARS = 8;
|
||||
|
||||
private function db(): ConnectionInterface
|
||||
{
|
||||
return DB::connection('untan');
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array{total: int, aktif: int, beku: int, pegawai: int, mahasiswa: int, tanpaPeran: int, superuser: int}
|
||||
*/
|
||||
public function accounts(): array
|
||||
{
|
||||
$count = [];
|
||||
foreach ($this->db()->table('t_account')->selectRaw('jenis, case when status = 0 then 0 else 1 end as beku, count(*) as jumlah')->groupBy('jenis')->groupByRaw('case when status = 0 then 0 else 1 end')->get() as $row) {
|
||||
$count[(int) $row->jenis][(int) $row->beku] = (int) $row->jumlah;
|
||||
}
|
||||
|
||||
$of = fn (int $jenis): int => array_sum($count[$jenis] ?? []);
|
||||
$beku = array_sum(array_column($count, 1));
|
||||
|
||||
// Pegawai tanpa otoritas dan bukan dosen ditolak saat masuk (LegacyRole).
|
||||
$tanpaPeran = $this->db()->table('t_account as a')
|
||||
->where('a.jenis', LegacyRole::JENIS_PEGAWAI)
|
||||
->whereNotExists(fn ($sub) => $sub->selectRaw('1')->from('t_otoritasuser as o')->whereColumn('o.iduser', 'a.iduser'))
|
||||
->whereNotExists(fn ($sub) => $sub->selectRaw('1')->from('t_dosen as d')->whereColumn('d.idpegawai', 'a.identitas'))
|
||||
->count();
|
||||
|
||||
return [
|
||||
'total' => $of(LegacyRole::JENIS_PEGAWAI) + $of(LegacyRole::JENIS_MAHASISWA),
|
||||
'aktif' => $of(LegacyRole::JENIS_PEGAWAI) + $of(LegacyRole::JENIS_MAHASISWA) - $beku,
|
||||
'beku' => $beku,
|
||||
'pegawai' => $of(LegacyRole::JENIS_PEGAWAI),
|
||||
'mahasiswa' => $of(LegacyRole::JENIS_MAHASISWA),
|
||||
'tanpaPeran' => $tanpaPeran,
|
||||
'superuser' => $this->db()->table('t_otoritasuser')->where('idotoritas', 1)->distinct()->count('iduser'),
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Pemegang otoritas terbanyak (gabungan sisanya dalam "Lainnya").
|
||||
*
|
||||
* @return array<string, int> nama otoritas => jumlah pemegang
|
||||
*/
|
||||
public function authorities(): array
|
||||
{
|
||||
$rows = $this->db()->table('t_otoritasuser as o')
|
||||
->join('t_otoritas as t', 't.idotoritas', '=', 'o.idotoritas')
|
||||
->selectRaw('t.otoritas, count(*) as jumlah')
|
||||
->groupBy('t.otoritas')
|
||||
->orderByDesc('jumlah')->orderBy('t.otoritas')
|
||||
->get();
|
||||
|
||||
$out = [];
|
||||
foreach ($rows->take(self::TOP_AUTHORITIES) as $row) {
|
||||
$out[trim((string) $row->otoritas)] = (int) $row->jumlah;
|
||||
}
|
||||
if ($rows->count() > self::TOP_AUTHORITIES) {
|
||||
$out['Lainnya'] = (int) $rows->slice(self::TOP_AUTHORITIES)->sum('jumlah');
|
||||
}
|
||||
|
||||
return $out;
|
||||
}
|
||||
|
||||
/**
|
||||
* Jumlah masuk per tahun pada tahun-tahun terakhir yang tercatat, dan waktu masuk terakhir.
|
||||
*
|
||||
* @return array{tahun: array<int, int>, terakhir: ?string}
|
||||
*/
|
||||
public function logins(): array
|
||||
{
|
||||
return Cache::remember('superuser.logins.'.md5((string) config('database.connections.untan.database')), self::LOGIN_CACHE_SECONDS, function (): array {
|
||||
$latest = $this->db()->table('t_historilogin')->max('logintimestamp');
|
||||
if ($latest === null) {
|
||||
return ['tahun' => [], 'terakhir' => null];
|
||||
}
|
||||
|
||||
$last = Carbon::parse($latest)->year;
|
||||
$year = $this->db()->getDriverName() === 'sqlite' ? "cast(strftime('%Y', logintimestamp) as integer)" : 'extract(year from logintimestamp)::int';
|
||||
$rows = $this->db()->table('t_historilogin')
|
||||
->where('logintimestamp', '>=', Carbon::create($last - self::YEARS + 1)->startOfYear())
|
||||
->selectRaw("$year as tahun, count(*) as jumlah")
|
||||
->groupByRaw($year)->orderByRaw($year)
|
||||
->pluck('jumlah', 'tahun');
|
||||
|
||||
$perYear = [];
|
||||
for ($y = $last - self::YEARS + 1; $y <= $last; $y++) {
|
||||
$perYear[$y] = (int) ($rows[$y] ?? 0);
|
||||
}
|
||||
|
||||
return ['tahun' => $perYear, 'terakhir' => LoginHistory::time($latest)];
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Kondisi koneksi ke DB lama untuk Kesehatan sistem: label => nilai. Galat apa pun dilaporkan, tidak dilempar.
|
||||
*
|
||||
* @return array{ok: bool, info: array<string, string>, catatan: string}
|
||||
*/
|
||||
public function database(): array
|
||||
{
|
||||
$start = hrtime(true);
|
||||
|
||||
try {
|
||||
$this->db()->selectOne('select 1');
|
||||
$ms = round((hrtime(true) - $start) / 1e6);
|
||||
$sqlite = $this->db()->getDriverName() === 'sqlite';
|
||||
|
||||
$info = [
|
||||
'Server' => $sqlite ? 'SQLite '.$this->db()->selectOne('select sqlite_version() as v')->v : (string) preg_replace('/\s+on\s.*$/', '', $this->db()->selectOne('select version() as v')->v),
|
||||
'Basis data' => (string) ($sqlite ? 'tiruan' : $this->db()->selectOne('select current_database() as d')->d),
|
||||
'Waktu respons' => $ms.' ms',
|
||||
];
|
||||
|
||||
if (! $sqlite) {
|
||||
$info['Ukuran basis data'] = (string) $this->db()->selectOne('select pg_size_pretty(pg_database_size(current_database())) as s')->s;
|
||||
$info['Jumlah tabel'] = number_format((int) $this->db()->selectOne("select count(*) as c from information_schema.tables where table_schema = 'public' and table_type = 'BASE TABLE'")->c, 0, ',', '.');
|
||||
}
|
||||
|
||||
return ['ok' => true, 'info' => $info, 'catatan' => 'Terhubung ke basis data SIAKAD.'];
|
||||
} catch (Throwable) {
|
||||
// Pesan asli bisa memuat alamat server dan kredensial; cukup dilaporkan tidak terjangkau.
|
||||
return ['ok' => false, 'info' => [], 'catatan' => 'Basis data SIAKAD tidak terjangkau dari server ini.'];
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -45,7 +45,7 @@ ms_tingkatpendidikan|Tk. Pendidikan||Jenjang;Nama Jenjang Pendidikan;Nama Jenjan
|
||||
list_jurusan|Jurusan|Daftar Jurusan|Fakultas|Kode;Nama Jurusan;Nama Singkat;Alamat;No. Telepon;Aktif?;Aksi|
|
||||
list_gedung|Gedung|Daftar Gedung Kampus|Lokasi Kampus|#;Kode;Nama;Lokasi Kampus;Telepon;Jml. Lantai;Jml. Ruang;Aksi|TH
|
||||
ms_jenismk|Jenis Mata Kuliah||Kode;Nama Jenis Mata Kuliah|
|
||||
ms_kelompokmk|Kelompok MK||Kode;Nama Kelompok Mata Kuliah|
|
||||
ms_kelompokmk|Kelompok MK|||Kurikulum;Program Studi;Kode;Nama Kelompok Mata Kuliah;Mata Kuliah;Aksi|T
|
||||
ms_grupmk|Grup MK Wajib Pilihan||Nama Grup MK|
|
||||
ms_agama|Agama||Kode;Nama Agama|
|
||||
ms_pekerjaan|Pekerjaan||Kode;Nama Pekerjaan|
|
||||
|
||||
Reference in New Issue
Block a user