[Operator] Pembaruan Laman Operator
This commit is contained in:
@@ -22,6 +22,29 @@ final class Curriculum
|
||||
/** t_matakuliah.tipe: 0 kuliah; 1 KP/magang; 2 skripsi (tanpa jadwal tatap muka); 3 MK umum (agama, Pancasila); 4 seminar/kerja mandiri. */
|
||||
public const array TYPES = [0 => 'Kuliah', 1 => 'Praktik Lapangan', 2 => 'Tugas Akhir', 3 => 'Mata Kuliah Umum', 4 => 'Seminar / Kerja Mandiri'];
|
||||
|
||||
/** Kolom tabel anggota mata kuliah di modal Lihat (Set Grup MK, Kelompok MK), per kelompok semester: baris {kode, nama, sks}. */
|
||||
public const array COURSE_TABLE = [
|
||||
['key' => 'kode', 'label' => 'Kode'],
|
||||
['key' => 'nama', 'label' => 'Mata Kuliah'],
|
||||
['key' => 'sks', 'label' => 'SKS', 'num' => true],
|
||||
];
|
||||
|
||||
/**
|
||||
* Anggota mata kuliah dikelompokkan per semester untuk modal Lihat: [{judul, jumlah, baris: [{kode, nama, sks}]}].
|
||||
*
|
||||
* @param Collection<int, object> $members baris t_matakuliah (kodemk, namamk, sks, semester), sudah urut semester lalu kode
|
||||
* @return list<array{judul: string, jumlah: string, baris: list<array{kode: string, nama: string, sks: int}>}>
|
||||
*/
|
||||
public static function coursesBySemester(Collection $members): array
|
||||
{
|
||||
return $members->groupBy(fn (object $m): int => (int) $m->semester)
|
||||
->map(fn (Collection $group, int $semester): array => [
|
||||
'judul' => $semester > 0 ? 'Semester '.$semester : 'Semester belum ditentukan',
|
||||
'jumlah' => $group->count().' mata kuliah',
|
||||
'baris' => $group->map(fn (object $m): array => ['kode' => trim((string) $m->kodemk), 'nama' => trim((string) $m->namamk), 'sks' => (int) $m->sks])->values()->all(),
|
||||
])->values()->all();
|
||||
}
|
||||
|
||||
private function db(): ConnectionInterface
|
||||
{
|
||||
return DB::connection('untan');
|
||||
@@ -312,8 +335,6 @@ final class Curriculum
|
||||
->orderBy('semester')->orderBy('kodemk')
|
||||
->get(['idmatakuliah', 'idpeminatan', 'kodemk', 'namamk', 'sks', 'semester'])
|
||||
->groupBy('idpeminatan');
|
||||
// Rincian anggota untuk modal Lihat: "KODE - Nama (n SKS, semester m)"; semester 0 = belum ditentukan.
|
||||
$detail = fn (object $m): string => trim($m->kodemk).' - '.trim($m->namamk).' ('.(int) $m->sks.' SKS'.((int) $m->semester > 0 ? ', semester '.(int) $m->semester : '').')';
|
||||
|
||||
return $groups->through(fn (object $g): array => [
|
||||
'id' => (int) $g->idkonsentrasi,
|
||||
@@ -325,7 +346,8 @@ final class Curriculum
|
||||
'kurikulum' => trim(self::year($g->thakad).' – '.trim((string) $g->namakurikulum), ' –'),
|
||||
'mk' => ($members[(int) $g->idkonsentrasi] ?? collect())->map(fn (object $m): string => trim($m->kodemk).' - '.trim($m->namamk))->implode(', ') ?: '–',
|
||||
'jumlah' => ($members[(int) $g->idkonsentrasi] ?? collect())->count(),
|
||||
'anggota' => ($members[(int) $g->idkonsentrasi] ?? collect())->map($detail)->values()->all(),
|
||||
// Modal Lihat: anggota per semester, tiap semester satu tabel.
|
||||
'anggota' => self::coursesBySemester($members[(int) $g->idkonsentrasi] ?? collect()),
|
||||
]);
|
||||
}
|
||||
|
||||
|
||||
@@ -3,21 +3,25 @@
|
||||
namespace App\Support\Legacy;
|
||||
|
||||
use App\Models\Legacy\Account;
|
||||
use App\Support\Prototype\Satu\Catalog;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
|
||||
/**
|
||||
* Pohon menu SIAKAD lama (t_menu: modul → menu → submenu) untuk sidebar akun DB lama, disaring menurut menu yang dipegang
|
||||
* otoritas akun (t_otoritasuser → t_menuotoritas). Hanya menu yang sudah punya halaman di SIAKAD baru ($routes) yang
|
||||
* ditautkan; menu lain disembunyikan agar tidak ada tautan mati, dan modul/submenu yang menjadi kosong ikut hilang.
|
||||
* otoritas akun itu sendiri (t_otoritasuser → t_menuotoritas). Hanya menu yang sudah punya halaman di SIAKAD baru ($routes)
|
||||
* yang ditautkan; menu lain disembunyikan agar tidak ada tautan mati, dan modul/submenu yang menjadi kosong ikut hilang.
|
||||
* Nama menu dan urutannya persis seperti di DB (kdmenu).
|
||||
*
|
||||
* Tiap role punya pemetaan tujuannya sendiri: Superuser LegacyMenu::SUPERUSER, Operator MenuAccess::menuRoutes().
|
||||
* Bentuk tujuan per kdmenu: 'slug' (satu halaman katalog operator), ['slug', ...] (beberapa halaman: menu lama menjadi
|
||||
* subgrup berisi judul halaman katalog), atau ['route' => nama rute, 'pattern' => pola rute aktif] (halaman milik role).
|
||||
*/
|
||||
final class LegacyMenu
|
||||
{
|
||||
/**
|
||||
* Menu lama yang sudah punya halaman untuk Superuser: kdmenu => slug halaman katalog operator (dibuka lewat rute
|
||||
* operator dengan cakupan seluruh universitas, lihat EnsureLegacyMenuAccess) atau [nama rute, pola rute aktif].
|
||||
* Menu lama yang sudah punya halaman untuk Superuser.
|
||||
*
|
||||
* @var array<string, string|array{0: string, 1: string}>
|
||||
* @var array<string, string|list<string>|array{route: string, pattern: string}>
|
||||
*/
|
||||
public const array SUPERUSER = [
|
||||
// M01 Organisasi
|
||||
@@ -31,9 +35,9 @@ final class LegacyMenu
|
||||
// M03 Jadwal: pengaktifan periode per prodi (akun pusat: seluruh prodi); daftar master periode ditautkan dari halaman itu
|
||||
'M0301' => 'set_periodeaktif', // Setup Periode Kuliah Aktif
|
||||
// M04 Mahasiswa, M09 Administrasi: halaman milik Superuser sendiri
|
||||
'M0405' => ['superuser.reset-password', 'superuser.reset-password*'], // Password Mahasiswa → Atur ulang kata sandi
|
||||
'M0901' => ['superuser.hak-akses', 'superuser.hak-akses*'], // Administrasi Group User → Hak akses
|
||||
'M0902' => ['superuser.pengguna.index', 'superuser.pengguna*'], // Administrasi User → Pengguna
|
||||
'M0405' => ['route' => 'superuser.reset-password', 'pattern' => 'superuser.reset-password*'], // Password Mahasiswa
|
||||
'M0901' => ['route' => 'superuser.hak-akses', 'pattern' => 'superuser.hak-akses*'], // Administrasi Group User
|
||||
'M0902' => ['route' => 'superuser.pengguna.index', 'pattern' => 'superuser.pengguna*'], // Administrasi User
|
||||
];
|
||||
|
||||
/** Ikon modul lama M01–M09. */
|
||||
@@ -46,9 +50,9 @@ final class LegacyMenu
|
||||
private array $held = [];
|
||||
|
||||
/**
|
||||
* @param array<string, string|array{0: string, 1: string}> $routes
|
||||
* @param array<string, string|list<string>|array{route: string, pattern: string}> $routes
|
||||
* @return list<array{kode: string, nama: string, icon: string, open: bool, items: list<array<string, mixed>>}>
|
||||
* modul dengan items = tautan {kode, nama, href, active} atau submenu {kode, nama, open, items}
|
||||
* modul dengan items = tautan {kode, nama, href, active} atau subgrup {kode, nama, open, items}
|
||||
*/
|
||||
public function tree(int $iduser, array $routes): array
|
||||
{
|
||||
@@ -62,13 +66,13 @@ final class LegacyMenu
|
||||
$kids = $children->get((int) $row->idmenu, collect())->map($build)->filter()->values()->all();
|
||||
|
||||
if ($kids !== []) {
|
||||
return ['kode' => $kode, 'nama' => $nama, 'open' => collect($kids)->contains(fn (array $k): bool => $k['active'] ?? $k['open'] ?? false), 'items' => $kids];
|
||||
return self::group($kode, $nama, $kids);
|
||||
}
|
||||
if (! isset($held[(int) $row->idmenu], $routes[$kode])) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return ['kode' => $kode, 'nama' => $nama] + self::link($routes[$kode]);
|
||||
return self::target($kode, $nama, $routes[$kode]);
|
||||
};
|
||||
|
||||
return $children->get(0, collect())
|
||||
@@ -81,20 +85,60 @@ final class LegacyMenu
|
||||
/** Boleh membuka halaman katalog {slug}? Ya bila salah satu menu lama yang menunjuk slug itu dipegang otoritas akun. */
|
||||
public function allowsSlug(Account $account, string $slug, array $routes = self::SUPERUSER): bool
|
||||
{
|
||||
$codes = array_keys(array_filter($routes, fn (string|array $target): bool => $target === $slug));
|
||||
$codes = array_keys(array_filter($routes, fn (string|array $target): bool => $target === $slug || (is_array($target) && array_is_list($target) && in_array($slug, $target, true))));
|
||||
|
||||
return $codes !== [] && array_intersect_key(array_flip($codes), $this->held((int) $account->getKey())['codes']) !== [];
|
||||
}
|
||||
|
||||
/** @return array{href: string, active: bool} */
|
||||
private static function link(string|array $target): array
|
||||
/** @return array<string, mixed> */
|
||||
private static function target(string $kode, string $nama, string|array $target): array
|
||||
{
|
||||
if (is_string($target)) {
|
||||
return ['href' => route('operator.halaman', $target), 'active' => MenuAccess::slugFromPath(request()->path()) === $target];
|
||||
return self::slugLink($kode, $nama, $target);
|
||||
}
|
||||
if (! array_is_list($target)) {
|
||||
return ['kode' => $kode, 'nama' => $nama, 'href' => route($target['route']), 'active' => request()->routeIs($target['pattern'])];
|
||||
}
|
||||
if (count($target) === 1) {
|
||||
return self::slugLink($kode, $nama, $target[0]);
|
||||
}
|
||||
[$name, $pattern] = $target;
|
||||
|
||||
return ['href' => route($name), 'active' => request()->routeIs($pattern)];
|
||||
return self::group($kode, $nama, array_map(fn (string $slug): array => self::slugLink($kode, self::titles()[$slug] ?? $slug, $slug), $target));
|
||||
}
|
||||
|
||||
/** @return array{kode: string, nama: string, href: string, active: bool} */
|
||||
private static function slugLink(string $kode, string $nama, string $slug): array
|
||||
{
|
||||
return ['kode' => $kode, 'nama' => $nama, 'href' => route('operator.halaman', $slug), 'active' => MenuAccess::slugFromPath(request()->path()) === $slug];
|
||||
}
|
||||
|
||||
/**
|
||||
* @param list<array<string, mixed>> $items
|
||||
* @return array{kode: string, nama: string, open: bool, items: list<array<string, mixed>>}
|
||||
*/
|
||||
private static function group(string $kode, string $nama, array $items): array
|
||||
{
|
||||
return ['kode' => $kode, 'nama' => $nama, 'open' => collect($items)->contains(fn (array $k): bool => $k['active'] ?? $k['open'] ?? false), 'items' => $items];
|
||||
}
|
||||
|
||||
/** @return array<string, string> slug => judul halaman katalog operator (menu.txt) */
|
||||
private static function titles(): array
|
||||
{
|
||||
static $titles = null;
|
||||
if ($titles !== null) {
|
||||
return $titles;
|
||||
}
|
||||
|
||||
$titles = [];
|
||||
foreach (Catalog::menu() as $group) {
|
||||
foreach ($group['items'] as $item) {
|
||||
foreach ($item['type'] === 'link' ? [$item] : $item['items'] as $link) {
|
||||
$titles[$link['slug']] = $link['title'];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return $titles;
|
||||
}
|
||||
|
||||
/** @return array{ids: array<int, true>, codes: array<string, true>} */
|
||||
|
||||
@@ -21,7 +21,8 @@ final class MenuAccess
|
||||
/**
|
||||
* 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.
|
||||
* 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>>
|
||||
*/
|
||||
@@ -66,7 +67,6 @@ final class MenuAccess
|
||||
'data_universitas/detail' => ['M0107'],
|
||||
'list_fakultas' => ['M0104'],
|
||||
'list_prodi' => ['M0105', 'M0911'],
|
||||
'ms_bidangstudi' => ['M0202'],
|
||||
'ms_jenjang' => ['M0909'],
|
||||
'ms_sistemkuliah' => ['M0906'],
|
||||
'ms_ruang' => ['M010102'],
|
||||
@@ -76,7 +76,6 @@ final class MenuAccess
|
||||
'list_gedung' => ['M010101'],
|
||||
'ms_jenismk' => ['M0205'],
|
||||
'ms_kelompokmk' => ['M0205'],
|
||||
'ms_grupmk' => ['M0202'],
|
||||
'ms_pekerjaan' => ['M0922'],
|
||||
'ms_penghasilan' => ['M0923'],
|
||||
'ms_jenispeg' => ['M0903'],
|
||||
@@ -164,6 +163,23 @@ final class MenuAccess
|
||||
/** @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
|
||||
{
|
||||
|
||||
@@ -360,16 +360,28 @@ final class ReferenceCrud implements ReferenceWriter
|
||||
|
||||
// ---- pilihan formulir ----
|
||||
|
||||
/** @return array<int, string> unit pemilik (universitas dan fakultas) */
|
||||
private function units(): array
|
||||
/** @var array{fak: list<int>, prodi: list<int>, all: list<int>}|null batas unit akun; pilihan select sekaligus validasinya (aturan select memakai options) */
|
||||
private ?array $scope = null;
|
||||
|
||||
public function scopeTo(?array $scope): void
|
||||
{
|
||||
return $this->labels($this->db()->table('t_bagian')->whereIn('idjenisbagian', [0, 1])->orderBy('namabagian')->pluck('namabagian', 'idbagian'));
|
||||
$this->scope = $scope;
|
||||
}
|
||||
|
||||
/** @return array<int, string> */
|
||||
/** @return array<int, string> unit pemilik (universitas dan fakultas; akun berunit: fakultasnya saja) */
|
||||
private function units(): array
|
||||
{
|
||||
return $this->labels($this->db()->table('t_bagian')->whereIn('idjenisbagian', [0, 1])
|
||||
->when($this->scope !== null, fn ($q) => $q->whereIn('idbagian', $this->scope['fak']))
|
||||
->orderBy('namabagian')->pluck('namabagian', 'idbagian'));
|
||||
}
|
||||
|
||||
/** @return array<int, string> gedung (akun berunit: gedung milik unitnya saja) */
|
||||
private function buildings(): array
|
||||
{
|
||||
return $this->labels($this->db()->table('t_gedung')->orderBy('namagedung')->orderBy('idgedung')->pluck('namagedung', 'idgedung'));
|
||||
return $this->labels($this->db()->table('t_gedung')
|
||||
->when($this->scope !== null, fn ($q) => $q->whereIn('idbagian', $this->scope['all']))
|
||||
->orderBy('namagedung')->orderBy('idgedung')->pluck('namagedung', 'idgedung'));
|
||||
}
|
||||
|
||||
/** @return array<int, string> */
|
||||
|
||||
@@ -60,6 +60,35 @@ final class ReferenceData
|
||||
*
|
||||
* @return array{note: string, columns: list<array{key: string, label: string, num?: bool}>, filters: list<array{name: string, label: string, options: array<int|string, string>}>}
|
||||
*/
|
||||
/**
|
||||
* Batas unit akun (UnitScope::units) untuk halaman unit: Fakultas, Program Studi, Jurusan, Ruang, Gedung dibatasi ke
|
||||
* fakultas/prodi/jurusan akun seperti menu lama bybagian; null = seluruh universitas (akun pusat).
|
||||
*
|
||||
* @var array{fak: list<int>, prodi: list<int>, all: list<int>}|null
|
||||
*/
|
||||
private ?array $scope = null;
|
||||
|
||||
/** Kolom kunci baris pada halaman yang dibatasi unit (untuk inScope). */
|
||||
private const array SCOPED_KEYS = ['list_fakultas' => 'b.idbagian', 'list_prodi' => 'p.idbagian', 'list_jurusan' => 'b.idbagian', 'ms_ruang' => 'r.idruang', 'list_gedung' => 'g.idgedung'];
|
||||
|
||||
/** @param array{fak: list<int>, prodi: list<int>, all: list<int>}|null $scope */
|
||||
public function scopeTo(?array $scope): static
|
||||
{
|
||||
$this->scope = $scope;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/** Baris {id} halaman {slug} ada di dalam batas unit akun? Halaman tanpa batas unit selalu ya. */
|
||||
public function inScope(string $slug, int $id): bool
|
||||
{
|
||||
if ($this->scope === null || ! isset(self::SCOPED_KEYS[$slug])) {
|
||||
return true;
|
||||
}
|
||||
|
||||
return ($this->spec($slug)['query'])([])->where(self::SCOPED_KEYS[$slug], $id)->exists();
|
||||
}
|
||||
|
||||
public function definition(string $slug): array
|
||||
{
|
||||
$spec = $this->spec($slug);
|
||||
@@ -67,6 +96,7 @@ final class ReferenceData
|
||||
return [
|
||||
'note' => $spec['note'],
|
||||
'columns' => $spec['columns'],
|
||||
'detailColumns' => $spec['detailColumns'] ?? $spec['columns'],
|
||||
'filters' => array_map(fn (array $f): array => ['name' => $f['name'], 'label' => $f['label'], 'options' => ($f['options'])()], $spec['filters'] ?? []),
|
||||
];
|
||||
}
|
||||
@@ -97,7 +127,12 @@ final class ReferenceData
|
||||
}))
|
||||
->paginate($perPage, ['*'], 'page', $page);
|
||||
|
||||
return $rows->through($spec['row']);
|
||||
$rows = $rows->through($spec['row']);
|
||||
if (isset($spec['enrich'])) {
|
||||
$rows->setCollection(collect(($spec['enrich'])(array_values($rows->items()))));
|
||||
}
|
||||
|
||||
return $rows;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -144,6 +179,7 @@ final class ReferenceData
|
||||
'note' => 'Fakultas asli dari unit SIAKAD (t_fakultas). Alamat dan nomor telepon tidak tercatat di sumber data.',
|
||||
'columns' => [$col('kode', 'Kode'), $col('nama', 'Nama Fakultas'), $col('singkat', 'Nama Singkat'), $col('alamat', 'Alamat'), $col('telepon', 'No. Telepon'), $col('aktif', 'Aktif?')],
|
||||
'query' => fn (): Builder => $db->table('t_fakultas as f')->join('t_bagian as b', 'b.idbagian', '=', 'f.idbagian')
|
||||
->when($this->scope !== null, fn (Builder $query) => $query->whereIn('b.idbagian', $this->scope['fak']))
|
||||
->select('b.idbagian', 'b.kodebagian', 'b.namabagian', 'b.singkatan', 'b.stat_aktif')->orderBy('f.urutan')->orderBy('b.idbagian'),
|
||||
'search' => ['b.kodebagian', 'b.namabagian', 'b.singkatan'],
|
||||
'row' => fn (object $r): array => ['id' => (int) $r->idbagian, 'kode' => self::text($r->kodebagian), 'nama' => self::text($r->namabagian), 'singkat' => self::text($r->singkatan), 'alamat' => self::DASH, 'telepon' => self::DASH, 'aktif' => self::yesNo($r->stat_aktif)],
|
||||
@@ -157,6 +193,7 @@ final class ReferenceData
|
||||
['name' => 'status', 'label' => 'Status', 'options' => fn (): array => ['aktif' => 'Aktif', 'nonaktif' => 'Tidak aktif']],
|
||||
],
|
||||
'query' => fn (array $f): Builder => $db->table('t_progdi as p')
|
||||
->when($this->scope !== null, fn (Builder $query) => $query->whereIn('p.idbagian', $this->scope['prodi']))
|
||||
->join('t_bagian as b', 'b.idbagian', '=', 'p.idbagian')
|
||||
->leftJoin('t_bagian as i', 'i.idbagian', '=', 'b.idbagian_induk')
|
||||
->leftJoin('t_bagian as fk', 'fk.idbagian', '=', 'i.idbagian_induk')
|
||||
@@ -217,6 +254,7 @@ final class ReferenceData
|
||||
->leftJoin('t_bagian as gb', 'gb.idbagian', '=', 'g.idbagian')
|
||||
->select('r.idruang', 'r.namaruang', 'r.lantai', 'r.kapasitaskuliah', 'g.namagedung')
|
||||
->selectRaw('coalesce(rb.namabagian, gb.namabagian) as unit')
|
||||
->when($this->scope !== null, fn (Builder $query) => $query->whereIn(DB::raw('coalesce(r.idbagian, g.idbagian)'), $this->scope['all']))
|
||||
->when($f['unit'] ?? null, fn (Builder $query, int|string $id) => $query->whereRaw('coalesce(r.idbagian, g.idbagian) = ?', [(int) $id]))
|
||||
->orderByRaw('coalesce(rb.namabagian, gb.namabagian)')->orderBy('g.namagedung')->orderBy('r.namaruang')->orderBy('r.idruang'),
|
||||
'search' => ['cast(r.idruang as text)', 'r.namaruang', 'coalesce(g.namagedung, \'\')'],
|
||||
@@ -251,6 +289,7 @@ final class ReferenceData
|
||||
'query' => fn (array $f): Builder => $db->table('t_bagian as b')
|
||||
->leftJoin('t_bagian as fk', 'fk.idbagian', '=', 'b.idbagian_induk')
|
||||
->where('b.idjenisbagian', self::UNIT_JURUSAN)
|
||||
->when($this->scope !== null, fn (Builder $query) => $query->whereIn('b.idbagian_induk', $this->scope['fak']))
|
||||
->when($f['fakultas'] ?? null, fn (Builder $query, int|string $id) => $query->where('b.idbagian_induk', (int) $id))
|
||||
->select('b.idbagian', 'b.kodebagian', 'b.namabagian', 'b.singkatan', 'b.stat_aktif')
|
||||
->orderBy('fk.namabagian')->orderBy('b.namabagian')->orderBy('b.idbagian'),
|
||||
@@ -265,10 +304,17 @@ final class ReferenceData
|
||||
->leftJoin('t_bagian as b', 'b.idbagian', '=', 'g.idbagian')
|
||||
->leftJoinSub($db->table('t_ruang')->selectRaw('idgedung, count(*) as jml_ruang, max(lantai) as jml_lantai')->whereNotNull('idgedung')->groupBy('idgedung'), 'r', 'r.idgedung', '=', 'g.idgedung')
|
||||
->select('g.idgedung', 'g.namagedung', 'b.namabagian', 'r.jml_ruang', 'r.jml_lantai')
|
||||
->when($this->scope !== null, fn (Builder $query) => $query->whereIn('g.idbagian', $this->scope['all']))
|
||||
->when($f['lokasi'] ?? null, fn (Builder $query, int|string $id) => $query->where('g.idbagian', (int) $id))
|
||||
->orderBy('b.namabagian')->orderBy('g.namagedung')->orderBy('g.idgedung'),
|
||||
'search' => ['cast(g.idgedung as text)', 'g.namagedung', 'coalesce(b.namabagian, \'\')'],
|
||||
'row' => fn (object $r): array => ['id' => (int) $r->idgedung, 'kode' => (int) $r->idgedung, 'nama' => self::text($r->namagedung), 'lokasi' => self::text($r->namabagian), 'telepon' => self::DASH, 'lantai' => (int) $r->jml_lantai > 0 ? (int) $r->jml_lantai : self::DASH, 'ruang' => (int) $r->jml_ruang],
|
||||
// Modal Lihat: panel judul (kode, nama, lokasi, jumlah lantai) lalu tiap lantai satu tabel ruangan (kode, nama, kapasitas).
|
||||
'detailColumns' => [$col('kode', 'Kode'), $col('nama', 'Nama'), $col('lokasi', 'Lokasi Kampus'), $col('lantai', 'Jml. Lantai'), [
|
||||
'key' => 'ruang', 'label' => 'Ruangan', 'detail' => 'ruangan', 'grouped' => true,
|
||||
'table' => [$col('kode', 'Kode', true), $col('nama', 'Nama Ruang'), $col('kuliah', 'Kap. Kuliah', true), $col('ujian', 'Kap. Ujian', true)],
|
||||
]],
|
||||
'enrich' => fn (array $rows): array => $this->buildingRooms($rows),
|
||||
],
|
||||
'ms_jenismk' => [
|
||||
'note' => 'Jenis mata kuliah = kode tipe pada t_matakuliah (tidak ada tabel referensinya di DB lama); nama mengikuti pemetaan yang dipakai halaman Mata Kuliah.',
|
||||
@@ -378,6 +424,7 @@ final class ReferenceData
|
||||
private function faculties(): array
|
||||
{
|
||||
return $this->db()->table('t_fakultas as f')->join('t_bagian as b', 'b.idbagian', '=', 'f.idbagian')
|
||||
->when($this->scope !== null, fn (Builder $query) => $query->whereIn('b.idbagian', $this->scope['fak']))
|
||||
->orderBy('f.urutan')->orderBy('b.idbagian')->pluck('b.namabagian', 'b.idbagian')
|
||||
->mapWithKeys(fn (string $nama, int|string $id): array => [(int) $id => trim($nama)])->all();
|
||||
}
|
||||
@@ -403,15 +450,49 @@ final class ReferenceData
|
||||
{
|
||||
return $this->db()->table('t_bagian as b')
|
||||
->whereExists(fn (Builder $r) => $r->selectRaw('1')->from('t_ruang as r')->leftJoin('t_gedung as g', 'g.idgedung', '=', 'r.idgedung')->whereRaw('coalesce(r.idbagian, g.idbagian) = b.idbagian'))
|
||||
->when($this->scope !== null, fn (Builder $query) => $query->whereIn('b.idbagian', $this->scope['all']))
|
||||
->orderBy('b.namabagian')->pluck('b.namabagian', 'b.idbagian')
|
||||
->mapWithKeys(fn (string $nama, int|string $id): array => [(int) $id => trim($nama)])->all();
|
||||
}
|
||||
|
||||
/**
|
||||
* Rincian ruangan tiap gedung pada satu halaman daftar, dikelompokkan per lantai (satu teks per lantai) untuk modal Lihat.
|
||||
*
|
||||
* @param list<array<string, mixed>> $rows
|
||||
* @return list<array<string, mixed>>
|
||||
*/
|
||||
private function buildingRooms(array $rows): array
|
||||
{
|
||||
$rooms = $this->db()->table('t_ruang')->whereIn('idgedung', array_column($rows, 'id'))
|
||||
->orderByRaw('coalesce(lantai, 0)')->orderBy('namaruang')->orderBy('idruang')
|
||||
->get(['idgedung', 'idruang', 'lantai', 'namaruang', 'kapasitaskuliah', 'kapasitasujian'])
|
||||
->groupBy(fn (object $r): int => (int) $r->idgedung);
|
||||
|
||||
foreach ($rows as &$row) {
|
||||
// Modal Lihat: tiap lantai satu tabel ruangan (kode, nama, kapasitas kuliah dan ujian).
|
||||
$row['ruangan'] = ($rooms[$row['id']] ?? collect())
|
||||
->groupBy(fn (object $r): int => (int) $r->lantai)
|
||||
->map(fn (Collection $floor, int $lantai): array => [
|
||||
'judul' => $lantai > 0 ? 'Lantai '.$lantai : 'Tanpa lantai',
|
||||
'jumlah' => $floor->count().' ruang',
|
||||
'baris' => $floor->map(fn (object $r): array => [
|
||||
'kode' => (int) $r->idruang,
|
||||
'nama' => trim((string) $r->namaruang) ?: '(tanpa nama)',
|
||||
'kuliah' => (int) $r->kapasitaskuliah,
|
||||
'ujian' => (int) $r->kapasitasujian,
|
||||
])->values()->all(),
|
||||
])->values()->all();
|
||||
}
|
||||
|
||||
return $rows;
|
||||
}
|
||||
|
||||
/** @return array<int, string> unit pemilik gedung */
|
||||
private function buildingUnits(): array
|
||||
{
|
||||
return $this->db()->table('t_bagian as b')
|
||||
->whereExists(fn (Builder $g) => $g->selectRaw('1')->from('t_gedung as g')->whereColumn('g.idbagian', 'b.idbagian'))
|
||||
->when($this->scope !== null, fn (Builder $query) => $query->whereIn('b.idbagian', $this->scope['all']))
|
||||
->orderBy('b.namabagian')->pluck('b.namabagian', 'b.idbagian')
|
||||
->mapWithKeys(fn (string $nama, int|string $id): array => [(int) $id => trim($nama)])->all();
|
||||
}
|
||||
|
||||
@@ -15,6 +15,14 @@ interface ReferenceWriter
|
||||
/** @return array{create: bool, update: bool, delete: bool} */
|
||||
public function abilities(string $slug): array;
|
||||
|
||||
/**
|
||||
* Batas unit akun (UnitScope::units): pilihan unit/gedung/fakultas/jurusan di formulir dan nilai yang diterima dibatasi
|
||||
* ke unit akun seperti menu lama bybagian; null = tanpa batas.
|
||||
*
|
||||
* @param array{fak: list<int>, prodi: list<int>, all: list<int>}|null $scope
|
||||
*/
|
||||
public function scopeTo(?array $scope): void;
|
||||
|
||||
/**
|
||||
* Definisi formulir modal (format remote-list): ['title' => 'pekerjaan', 'fields' => [['name', 'label', 'type' =>
|
||||
* text|number|select, 'options' => [id => label], 'required', 'max', 'min', 'hint', 'default']]].
|
||||
|
||||
@@ -101,7 +101,8 @@ final class DosenReports implements ReportSource
|
||||
$aktif,
|
||||
$this->check('homebase', 'Tampilkan Home Base?', default: true),
|
||||
]],
|
||||
'repp_daftarpeg' => ['note' => 'Dosen dengan home base di prodi Anda dan pegawai yang memegang jabatan aktif di prodi atau fakultas Anda.', 'params' => [
|
||||
// 'search' => sumber mengenal kata cari (q) dari kotak cari daftar: NIP, NIDN, nama.
|
||||
'repp_daftarpeg' => ['note' => 'Dosen dengan home base di prodi Anda dan pegawai yang memegang jabatan aktif di prodi atau fakultas Anda.', 'search' => true, 'params' => [
|
||||
$this->select('homebase', 'Home Base', $context->prodiNames),
|
||||
$jenisPegawai,
|
||||
$this->select('kelamin', 'Jenis Kelamin', [1 => 'Laki-laki', 2 => 'Perempuan']),
|
||||
@@ -493,6 +494,8 @@ final class DosenReports implements ReportSource
|
||||
->when($params['jenis'] ?? null, fn (Builder $q, int $id) => $q->where('p.idjenispegawai', $id))
|
||||
->when($params['kelamin'] ?? null, fn (Builder $q, int $id) => $q->where('p.kelamin', $id));
|
||||
$this->filterActive($query, $params['aktif'] ?? null);
|
||||
// Kata cari dari kotak cari daftar (NIP, NIDN, nama).
|
||||
$this->searchPerson($query, isset($params['q']) ? (string) $params['q'] : null);
|
||||
|
||||
$total = (clone $query)->count();
|
||||
$found = $query
|
||||
|
||||
@@ -28,7 +28,7 @@ final class SubjectGroups
|
||||
{
|
||||
$q = mb_strtolower(trim((string) ($filter['q'] ?? '')));
|
||||
|
||||
return $this->owned($prodi)
|
||||
$rows = $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))
|
||||
@@ -49,6 +49,19 @@ final class SubjectGroups
|
||||
'nama' => trim((string) $j->keterangan) ?: '–',
|
||||
'mk' => (int) $j->jumlah_mk,
|
||||
]);
|
||||
|
||||
// Modal Lihat: anggota mata kuliah tiap kelompok sebagai baris tabel (semester, kode, nama, SKS); satu query per halaman.
|
||||
$members = $this->db()->table('t_matakuliah')->whereIn('idjenis', array_column($rows->items(), 'id'))
|
||||
->orderBy('semester')->orderBy('kodemk')->orderBy('idmatakuliah')
|
||||
->get(['idjenis', 'kodemk', 'namamk', 'sks', 'semester'])
|
||||
->groupBy(fn (object $m): int => (int) $m->idjenis);
|
||||
$rows->setCollection($rows->getCollection()->map(function (array $row) use ($members): array {
|
||||
$row['anggota'] = Curriculum::coursesBySemester($members[$row['id']] ?? collect());
|
||||
|
||||
return $row;
|
||||
}));
|
||||
|
||||
return $rows;
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -131,6 +131,7 @@ final class UnitCrud implements ReferenceWriter
|
||||
|
||||
public function create(string $slug, array $input, string $actor, ?string $ip): int|string
|
||||
{
|
||||
$this->assertInScope($slug, $input);
|
||||
$unit = $this->unit($slug);
|
||||
$v = $this->clean($slug, $input, null);
|
||||
$audit = $this->audit($actor, $ip);
|
||||
@@ -154,6 +155,7 @@ final class UnitCrud implements ReferenceWriter
|
||||
|
||||
public function update(string $slug, int|string $id, array $input, string $actor, ?string $ip): void
|
||||
{
|
||||
$this->assertInScope($slug, $input);
|
||||
$unit = $this->unit($slug);
|
||||
$id = (int) $id;
|
||||
if (! $this->found($slug, $id)) {
|
||||
@@ -382,9 +384,32 @@ final class UnitCrud implements ReferenceWriter
|
||||
}
|
||||
|
||||
/** @return array<int, string> fakultas urut tampil */
|
||||
/** @var array{fak: list<int>, prodi: list<int>, all: list<int>}|null batas unit akun untuk pilihan fakultas/jurusan dan nilainya */
|
||||
private ?array $scope = null;
|
||||
|
||||
public function scopeTo(?array $scope): void
|
||||
{
|
||||
$this->scope = $scope;
|
||||
}
|
||||
|
||||
/** Fakultas (jurusan) atau jurusan (prodi) yang dipilih harus di dalam unit akun. */
|
||||
private function assertInScope(string $slug, array $input): void
|
||||
{
|
||||
if ($this->scope === null) {
|
||||
return;
|
||||
}
|
||||
if ($slug === 'list_jurusan' && ! isset($this->facultyOptions()[(int) ($input['fakultas'] ?? 0)])) {
|
||||
throw new PortalException('Fakultas di luar unit Anda.');
|
||||
}
|
||||
if ($slug === 'list_prodi' && ! isset($this->departmentOptions()[(int) ($input['jurusan'] ?? 0)])) {
|
||||
throw new PortalException('Jurusan di luar unit Anda.');
|
||||
}
|
||||
}
|
||||
|
||||
private function facultyOptions(): array
|
||||
{
|
||||
return $this->db()->table('t_fakultas as f')->join('t_bagian as b', 'b.idbagian', '=', 'f.idbagian')
|
||||
->when($this->scope !== null, fn (Builder $q) => $q->whereIn('b.idbagian', $this->scope['fak']))
|
||||
->orderBy('f.urutan')->orderBy('b.idbagian')->get(['b.idbagian', 'b.namabagian'])
|
||||
->mapWithKeys(fn (object $r): array => [(int) $r->idbagian => trim((string) $r->namabagian)])->all();
|
||||
}
|
||||
@@ -393,7 +418,9 @@ final class UnitCrud implements ReferenceWriter
|
||||
private function departmentOptions(): array
|
||||
{
|
||||
return $this->db()->table('t_bagian as b')->leftJoin('t_bagian as f', 'f.idbagian', '=', 'b.idbagian_induk')
|
||||
->where('b.idjenisbagian', self::DEPARTMENT)->orderBy('f.namabagian')->orderBy('b.namabagian')->orderBy('b.idbagian')
|
||||
->where('b.idjenisbagian', self::DEPARTMENT)
|
||||
->when($this->scope !== null, fn (Builder $q) => $q->whereIn('b.idbagian_induk', $this->scope['fak']))
|
||||
->orderBy('f.namabagian')->orderBy('b.namabagian')->orderBy('b.idbagian')
|
||||
->get(['b.idbagian', 'b.namabagian', 'f.namabagian as fakultas'])
|
||||
->mapWithKeys(fn (object $r): array => [(int) $r->idbagian => trim((string) $r->namabagian).(filled($r->fakultas) ? ' — '.trim($r->fakultas) : '')])->all();
|
||||
}
|
||||
|
||||
@@ -39,6 +39,32 @@ final class UnitScope
|
||||
return $this->unlimited[$iduser] = $central;
|
||||
}
|
||||
|
||||
/**
|
||||
* Unit akun untuk membatasi data referensi (menu lama bybagian): fakultas dan prodi dari t_unituser beserta jurusan
|
||||
* di bawah fakultas itu. Null = tanpa batas (akun pusat tanpa unit).
|
||||
*
|
||||
* @return array{fak: list<int>, prodi: list<int>, all: list<int>}|null
|
||||
*/
|
||||
public function units(int $iduser): ?array
|
||||
{
|
||||
// Otoritas pusat: menu lamanya tanpa bybagian, jadi tidak dibatasi unit walau akun punya baris t_unituser.
|
||||
if ($this->db()->table('t_otoritasuser')->where('iduser', $iduser)->whereIn('idotoritas', MenuAccess::CENTRAL)->exists()) {
|
||||
return null;
|
||||
}
|
||||
|
||||
$rows = $this->db()->table('t_unituser')->where('iduser', $iduser)->get(['idfak', 'idprogdi']);
|
||||
$fak = $rows->pluck('idfak')->filter()->map(fn ($id): int => (int) $id)->unique()->values()->all();
|
||||
$prodi = $rows->pluck('idprogdi')->filter()->map(fn ($id): int => (int) $id)->unique()->values()->all();
|
||||
$jurusan = $fak === [] ? [] : $this->db()->table('t_bagian')->whereIn('idbagian_induk', $fak)->where('idjenisbagian', 2)
|
||||
->pluck('idbagian')->map(fn ($id): int => (int) $id)->all();
|
||||
// Prodi di bawah fakultas akun (langsung atau lewat jurusan) ikut masuk cakupan, seperti staf fakultas di aplikasi lama.
|
||||
$prodiFak = $fak === [] ? [] : $this->db()->table('t_bagian')->whereIn('idbagian_induk', [...$fak, ...$jurusan])->where('idjenisbagian', self::JENIS_PRODI)
|
||||
->pluck('idbagian')->map(fn ($id): int => (int) $id)->all();
|
||||
$prodi = array_values(array_unique([...$prodi, ...$prodiFak]));
|
||||
|
||||
return ['fak' => $fak, 'prodi' => $prodi, 'all' => array_values(array_unique([...$fak, ...$jurusan, ...$prodi]))];
|
||||
}
|
||||
|
||||
/** @return Collection<int, string> semua program studi, idbagian => nama, urut nama */
|
||||
public function allPrograms(): Collection
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user