304 lines
12 KiB
PHP
304 lines
12 KiB
PHP
<?php
|
|
|
|
namespace App\Support\Legacy;
|
|
|
|
use App\Models\Legacy\Account;
|
|
use App\Support\Legacy\Reports\ReportRegistry;
|
|
use App\Support\Prototype\Satu\Catalog;
|
|
use Illuminate\Support\Facades\DB;
|
|
|
|
/**
|
|
* Hak menu Operator menurut otoritas SIAKAD lama. Tiap halaman operator (slug katalog) dipetakan ke kode menu lama
|
|
* (t_menu.kdmenu); akun boleh membuka halaman bila salah satu otoritasnya (t_otoritasuser) memegang kode itu di
|
|
* t_menuotoritas. Halaman tanpa padanan menu lama hanya untuk otoritas pusat (Administrator Pusat dan Puskom), yang
|
|
* juga melihat semua halaman lain. Akun demo tidak disaring. Dipakai middleware EnsureLegacyMenuAccess dan menu operator.
|
|
*/
|
|
final class MenuAccess
|
|
{
|
|
/** Otoritas pusat: Administrator Pusat, Staff Puskom, KA. PUSKOM, Honor Puskom, Sisfo Puskom, Kasubbag Puskom. */
|
|
public const array CENTRAL = [1, 4, 22, 34, 40, 46];
|
|
|
|
/**
|
|
* Slug halaman operator => kode menu lama yang mewakilinya (salah satu cukup).
|
|
* Tanpa padanan (hanya pusat): Konsultasi, Kegiatan/Kalender Akademik, Monitoring Kalender, Agama, Status Mahasiswa,
|
|
* Status Keaktifan, Negara, serta Konsentrasi (ms_bidangstudi) dan Grup MK Wajib Pilihan (ms_grupmk) yang hanya
|
|
* tampilan baca dari tabel yang sama dengan Set Grup MK (M0202) sehingga tidak diulang di sidebar.
|
|
*
|
|
* @var array<string, list<string>>
|
|
*/
|
|
public const array MAP = [
|
|
// Portal
|
|
'list_mahasiswa' => ['M0402'],
|
|
'list_pegawai' => ['M0103'],
|
|
// Perkuliahan > Manajemen Kurikulum
|
|
'list_matakuliah' => ['M0206'],
|
|
'list_kurikulum' => ['M0201'],
|
|
'set_grupmk' => ['M0202'],
|
|
'ms_thnkurikulum' => ['M0201'],
|
|
// Perkuliahan > Data Kelas
|
|
'list_kelas' => ['M030301', 'M030201', 'M030203'],
|
|
'set_pemutihannilai' => ['M0804'],
|
|
'ms_tahunajaran' => ['M0301'],
|
|
'set_periodeaktif' => ['M0301'],
|
|
'data_monitorruang' => ['M030301'],
|
|
'list_rekapruang' => ['M030301'],
|
|
// Perkuliahan > Administrasi
|
|
'set_semester' => ['M0404'],
|
|
'list_mhspa' => ['M0408'],
|
|
'set_paket' => ['M0603'],
|
|
'list_evaluasimhs' => ['M0406', 'M0203'],
|
|
'set_transfermhs' => ['M0403', 'M0810'],
|
|
'set_cekal' => ['M0404'],
|
|
'set_berhentistudi' => ['M0406', 'M0404'],
|
|
'list_ekivnilai' => ['M0810'],
|
|
'list_mhskeluar' => ['M0406'],
|
|
// Perkuliahan > Tugas Akhir, Yudisium, Wisuda, Semester Pendek
|
|
'list_ta' => ['M0805'],
|
|
'list_eligibleyudisium' => ['M0809'],
|
|
'set_noyudisium' => ['M0809'],
|
|
'list_yudisium' => ['M0809'],
|
|
'ms_periodewisuda' => ['M0809'],
|
|
'list_wisuda' => ['M0809'],
|
|
'list_pesertawisuda' => ['M0809'],
|
|
'list_semesterpendek' => ['M0301'],
|
|
'list_mkpendek' => ['M030201', 'M030301'],
|
|
'list_pesertapendek' => ['M060203'],
|
|
// Data Pelengkap
|
|
'data_universitas/detail' => ['M0107'],
|
|
'list_fakultas' => ['M0104'],
|
|
'list_prodi' => ['M0105', 'M0911'],
|
|
'ms_jenjang' => ['M0909'],
|
|
'ms_sistemkuliah' => ['M0906'],
|
|
'ms_ruang' => ['M010102'],
|
|
'ms_universitas' => ['M0914'],
|
|
'ms_tingkatpendidikan' => ['M0921'],
|
|
'list_jurusan' => ['M0108'],
|
|
'list_gedung' => ['M010101'],
|
|
'ms_jenismk' => ['M0205'],
|
|
'ms_kelompokmk' => ['M0205'],
|
|
'ms_pekerjaan' => ['M0922'],
|
|
'ms_penghasilan' => ['M0923'],
|
|
'ms_jenispeg' => ['M0903'],
|
|
'ms_golpangkat' => ['M010602'],
|
|
'ms_jabfung' => ['M0904'],
|
|
'ms_jabstruktural' => ['M0904'],
|
|
'ms_propinsi' => ['M0917'],
|
|
'ms_kota' => ['M0916'],
|
|
// Laporan > Mahasiswa
|
|
'repp_absensi' => ['M0701'],
|
|
'repp_khsmahasiswa' => ['M0704'],
|
|
'repp_krsmahasiswa' => ['M0705', 'M0604'],
|
|
'repp_daftarmhs' => ['M0605', 'M0511'],
|
|
'repp_terancamdo' => ['M0406'],
|
|
'repp_transkrip' => ['M0703'],
|
|
'repp_daftarmhstransfer' => ['M0810'],
|
|
'repp_cekalmhs' => ['M0404'],
|
|
'repp_transkripsmt' => ['M0703'],
|
|
'repp_krsmhs' => ['M0705', 'M0604'],
|
|
'repp_ktm' => ['M0509'],
|
|
'repp_rekapabsenmhs' => ['M0701', 'M0504'],
|
|
'repp_khsmhskolektif' => ['M0704'],
|
|
'repp_absensimhs' => ['M0701', 'M0504'],
|
|
'repp_masastudi' => ['M0605', 'M0511'],
|
|
'repp_nilaikonversi' => ['M0810'],
|
|
'repp_kurikulummhs' => ['M0201'],
|
|
'repp_jadwalkuliah' => ['M030301'],
|
|
'repp_prosentaseabs' => ['M0701', 'M0504'],
|
|
'repp_isiabsensi' => ['M0701', 'M0504'],
|
|
// Laporan > Perkuliahan
|
|
'repp_mkmengulang' => ['M0604'],
|
|
'repp_absensiujian' => ['M0702'],
|
|
'repp_kartuujian' => ['M0702'],
|
|
'repp_kurikulumprodi' => ['M0201'],
|
|
'repp_distribusikrsmhs' => ['M0604', 'M0705'],
|
|
'repp_matakuliah' => ['M0206'],
|
|
// Laporan > Dosen
|
|
'repp_jadwalajar' => ['M0706', 'M030301'],
|
|
'repp_daftardosen' => ['M010601', 'M0103'],
|
|
'repp_rasiodosenins' => ['M010601', 'M0103'],
|
|
'repp_rekapabsendosen' => ['M0706'],
|
|
'repp_jadwalmengajar' => ['M0706', 'M030301'],
|
|
'repp_rekapmengajar' => ['M0706', 'M030301'],
|
|
'repp_distribusidosenwali' => ['M0408'],
|
|
'repp_jurnalperwalian' => ['M0408'],
|
|
'repp_dpa' => ['M0408'],
|
|
'repp_kelengkapanbiodosen' => ['M010601', 'M0103'],
|
|
'repp_distribusipengajar' => ['M0706', 'M030301'],
|
|
// Laporan > Tingkat Akhir
|
|
'repp_skripsi' => ['M0805'],
|
|
'repp_totalmhsskripsi' => ['M0805'],
|
|
'repp_bimbinganta' => ['M0805'],
|
|
'repp_mhsskripsi' => ['M0805'],
|
|
'repp_nilaiujiskripsi' => ['M0805'],
|
|
'repp_daftarwisuda' => ['M0809'],
|
|
'repp_yudisium' => ['M0809'],
|
|
'repp_rekappembimbingta' => ['M0805'],
|
|
'repp_beritaacarata' => ['M0805'],
|
|
'repp_bukuwisuda' => ['M0809'],
|
|
'repp_distgsakhir' => ['M0805'],
|
|
'repp_skpembimbingta' => ['M0805'],
|
|
'repp_skpengujita' => ['M0805'],
|
|
// Laporan > Nilai dan Rekap
|
|
'repp_ipk' => ['M0703'],
|
|
'repp_rekapipk' => ['M0703'],
|
|
'repp_distribusinilai' => ['M0807', 'M0808'],
|
|
'repp_nilaikkn' => ['M0804'],
|
|
'repp_nilaikuliah' => ['M0701', 'M0807'],
|
|
'repp_nilaimhs' => ['M0807', 'M0808'],
|
|
'repp_ipktertinggi' => ['M0703'],
|
|
'repp_nilaimk' => ['M0807', 'M0808'],
|
|
'repp_kuncinilai' => ['M0807'],
|
|
'repp_rekapkrs' => ['M0604', 'M0705'],
|
|
'repp_statussemester' => ['M0605', 'M0511'],
|
|
'repp_statusmhs5thn' => ['M0605', 'M0511'],
|
|
'repp_statusmhs' => ['M0605', 'M0511'],
|
|
'repp_kapasitaskelas' => ['M030301'],
|
|
'repp_monitoringkelas' => ['M030301'],
|
|
'repp_daftarpeg' => ['M0103'],
|
|
'repp_jadwalmingguanprodi' => ['M030301'],
|
|
'repp_rekapmhsprodi' => ['M0605', 'M0511'],
|
|
'repp_rekapbiodata' => ['M0605', 'M0511'],
|
|
];
|
|
|
|
/**
|
|
* Aksi di bawah sebuah halaman yang haknya mengikuti kode menu lama tersendiri (path "operator/{aksi}/..."), bukan kode
|
|
* halaman induknya; tidak masuk sidebar. Penetapan pengajar kelas = Input Jadwal (M030301) atau Entry Jadwal & Peminat
|
|
* (M030203) di SIAKAD lama, sedangkan Kelas Kuliah juga terbuka bagi Entry Penawaran Matakuliah (M030201).
|
|
*
|
|
* @var array<string, list<string>>
|
|
*/
|
|
public const array ACTIONS = [
|
|
'list_kelas/pengajar' => ['M030301', 'M030203'],
|
|
'list_kelas/jadwal' => ['M030301', 'M030203'],
|
|
'list_kelas/ujian' => ['M030301', 'M030203'],
|
|
];
|
|
|
|
/** @var array<int, array{central: bool, codes: list<string>}> hak per akun, dihitung sekali per permintaan */
|
|
private array $grants = [];
|
|
|
|
/**
|
|
* Tujuan menu lama untuk sidebar Operator (LegacyMenu::tree): kebalikan MAP, khusus halaman Operator dan terpisah dari
|
|
* pemetaan Superuser. Tiap halaman katalog ditempatkan pada kode pertama pemetaannya; kode yang mewakili beberapa halaman
|
|
* menjadi subgrup berjudul menu lama. Halaman tanpa padanan menu lama tidak masuk sidebar.
|
|
*
|
|
* @return array<string, list<string>> kdmenu => slug halaman operator
|
|
*/
|
|
public static function menuRoutes(): array
|
|
{
|
|
$routes = [];
|
|
foreach (self::MAP as $slug => $codes) {
|
|
$routes[$codes[0]][] = $slug;
|
|
}
|
|
|
|
return $routes;
|
|
}
|
|
|
|
/** Boleh membuka halaman {slug}? */
|
|
public function allows(Account $account, string $slug): bool
|
|
{
|
|
$grant = $this->grant((int) $account->getKey());
|
|
|
|
if ($grant['central']) {
|
|
return true;
|
|
}
|
|
|
|
$codes = self::MAP[$slug] ?? self::ACTIONS[$slug] ?? null;
|
|
|
|
return $codes !== null && array_intersect($codes, $grant['codes']) !== [];
|
|
}
|
|
|
|
/**
|
|
* Pohon menu Catalog tanpa butir yang tidak boleh dibuka akun; subgrup dan grup yang menjadi kosong ikut hilang.
|
|
*
|
|
* @param array<int, array<string, mixed>> $menu
|
|
* @return array<int, array<string, mixed>>
|
|
*/
|
|
public function filterMenu(array $menu, Account $account): array
|
|
{
|
|
$keep = [];
|
|
|
|
foreach ($menu as $group) {
|
|
$items = [];
|
|
foreach ($group['items'] as $item) {
|
|
if ($item['type'] === 'link') {
|
|
if ($this->allows($account, $item['slug'])) {
|
|
$items[] = $item;
|
|
}
|
|
|
|
continue;
|
|
}
|
|
|
|
$links = array_values(array_filter($item['items'], fn (array $link): bool => $this->allows($account, $link['slug'])));
|
|
if ($links !== []) {
|
|
$items[] = ['items' => $links] + $item;
|
|
}
|
|
}
|
|
|
|
if ($items !== []) {
|
|
$keep[] = ['items' => $items] + $group;
|
|
}
|
|
}
|
|
|
|
return $keep;
|
|
}
|
|
|
|
/**
|
|
* Slug halaman dari path permintaan ("operator/list_kelas/data" => "list_kelas", "operator/data_universitas/detail"
|
|
* => slug dua ruas itu); null bila bukan halaman katalog (dashboard, rute prototipe).
|
|
*/
|
|
public static function slugFromPath(string $path): ?string
|
|
{
|
|
$segments = explode('/', trim($path, '/'));
|
|
if (($segments[0] ?? null) !== 'operator') {
|
|
return null;
|
|
}
|
|
|
|
$known = self::knownSlugs();
|
|
$two = implode('/', array_slice($segments, 1, 2));
|
|
if (count($segments) >= 3 && isset($known[$two])) {
|
|
return $two;
|
|
}
|
|
|
|
$one = $segments[1] ?? '';
|
|
|
|
return isset($known[$one]) ? $one : null;
|
|
}
|
|
|
|
/** @return array<string, true> semua slug halaman operator: katalog menu + laporan + aksi berkode menu sendiri */
|
|
private static function knownSlugs(): array
|
|
{
|
|
$slugs = array_fill_keys(array_keys(self::ACTIONS), true);
|
|
foreach (Catalog::menu() as $group) {
|
|
foreach ($group['items'] as $item) {
|
|
foreach ($item['type'] === 'link' ? [$item] : $item['items'] as $link) {
|
|
$slugs[$link['slug']] = true;
|
|
}
|
|
}
|
|
}
|
|
foreach (ReportRegistry::slugs() as $slug) {
|
|
$slugs[$slug] = true;
|
|
}
|
|
|
|
return $slugs;
|
|
}
|
|
|
|
/** @return array{central: bool, codes: list<string>} */
|
|
private function grant(int $iduser): array
|
|
{
|
|
if (isset($this->grants[$iduser])) {
|
|
return $this->grants[$iduser];
|
|
}
|
|
|
|
$db = DB::connection('untan');
|
|
$otoritas = $db->table('t_otoritasuser')->where('iduser', $iduser)->pluck('idotoritas')->map(fn ($id): int => (int) $id)->all();
|
|
$central = array_intersect($otoritas, self::CENTRAL) !== [];
|
|
$codes = $central || $otoritas === [] ? [] : $db->table('t_menuotoritas as mo')
|
|
->join('t_menu as m', 'm.idmenu', '=', 'mo.idmenu')
|
|
->whereIn('mo.idotoritas', $otoritas)
|
|
->distinct()->pluck('m.kdmenu')
|
|
->map(fn ($code): string => trim((string) $code))->all();
|
|
|
|
return $this->grants[$iduser] = ['central' => $central, 'codes' => $codes];
|
|
}
|
|
}
|