[Operator] Perbaikan Halaman Pegawai dan Export Excel

This commit is contained in:
Ariyutta
2026-11-14 07:11:15 +07:00
parent 1d38086488
commit 59e941d2ce
22 changed files with 904 additions and 146 deletions
+25 -5
View File
@@ -57,16 +57,22 @@ final class ReferenceCrud implements ReferenceWriter
}
return $field;
}, $spec['fields']),
}, self::shown($spec['fields'])),
];
}
/** Isian yang tampil di formulir: tanpa isian yang nilainya sudah pasti (fixed). */
private static function shown(array $fields): array
{
return array_values(array_filter($fields, fn (array $f): bool => ! array_key_exists('fixed', $f)));
}
public function rules(string $slug): array
{
$rules = [];
$attributes = [];
foreach ($this->spec($slug)['fields'] as $f) {
foreach (self::shown($this->spec($slug)['fields']) as $f) {
$rule = [($f['required'] ?? false) ? 'required' : 'nullable'];
$rule[] = match ($f['type']) {
'number' => 'numeric',
@@ -99,7 +105,7 @@ final class ReferenceCrud implements ReferenceWriter
foreach ($this->db()->table($spec['table'])->whereIn($spec['pk'], array_map('intval', $ids))->get($columns) as $row) {
$values = [];
foreach ($spec['fields'] as $f) {
foreach (self::shown($spec['fields']) as $f) {
$value = $row->{$f['column']} ?? null;
$value = isset($f['fromDb']) && $value !== null ? ($f['fromDb'])($value) : $value;
$value = $f['type'] === 'select' && $value !== null ? (string) $value : $value;
@@ -199,6 +205,16 @@ final class ReferenceCrud implements ReferenceWriter
$byName = [];
foreach ($spec['fields'] as $f) {
// Isian tersembunyi (unit akun): diisi otomatis saat tambah; saat ubah kolomnya tidak disentuh.
if (array_key_exists('fixed', $f)) {
$byName[$f['name']] = $current === null ? $f['fixed'] : ($current->{$f['column']} ?? null);
if ($current === null) {
$values[$f['column']] = $f['fixed'];
}
continue;
}
$value = $this->clean($f, $input[$f['name']] ?? null, $current);
$byName[$f['name']] = $value;
$values[$f['column']] = (isset($f['toDb']) ? ($f['toDb'])($value) : $value) ?? ($f['nullAs'] ?? null);
@@ -469,6 +485,10 @@ final class ReferenceCrud implements ReferenceWriter
if (isset(self::EXAMPLES[$slug][$f['name']]) && ! isset($f['placeholder'])) {
$spec['fields'][$i]['placeholder'] = 'Contoh: '.self::EXAMPLES[$slug][$f['name']];
}
// Akun yang dibatasi ke satu fakultas: unit pemilik sudah pasti, jadi isiannya disembunyikan dan diisi otomatis.
if (($f['ownUnit'] ?? false) && $this->scope !== null && count($options = $this->options($f)) === 1) {
$spec['fields'][$i]['fixed'] = array_key_first($options);
}
}
return $spec;
@@ -484,7 +504,7 @@ final class ReferenceCrud implements ReferenceWriter
'table' => 't_gedung', 'pk' => 'idgedung', 'title' => 'gedung', 'audit' => self::AUDIT,
'fields' => [
self::text('nama', 'namagedung', 'Nama gedung', 50),
self::choice('unit', 'idbagian', 'Lokasi kampus (unit pemilik)', fn (): array => $this->units(), ['hint' => 'Boleh dikosongkan.']),
self::choice('unit', 'idbagian', 'Lokasi kampus (unit pemilik)', fn (): array => $this->units(), ['hint' => 'Boleh dikosongkan.', 'ownUnit' => true]),
],
'delete' => [['t_ruang', 'idgedung']],
],
@@ -496,7 +516,7 @@ final class ReferenceCrud implements ReferenceWriter
self::number('lantai', 'lantai', 'Lantai', ['required' => true, 'default' => 1, 'max' => 99]),
self::number('kapasitas', 'kapasitaskuliah', 'Kapasitas kuliah', ['required' => true, 'default' => 0]),
self::number('kapasitas_ujian', 'kapasitasujian', 'Kapasitas ujian', ['default' => 0, 'nullAs' => 0, 'hint' => 'Boleh dikosongkan.']),
self::choice('unit', 'idbagian', 'Unit pemilik ruang', fn (): array => $this->units(), ['hint' => 'Kosong = mengikuti unit gedung.']),
self::choice('unit', 'idbagian', 'Unit pemilik ruang', fn (): array => $this->units(), ['hint' => 'Kosong = mengikuti unit gedung.', 'ownUnit' => true]),
],
'delete' => [['t_jadwalruangkuliah', 'idruang'], ['t_jadwalruangujian', 'idruang']],
],