Penambahan Akses Laman Dosen dab perbaikan fix
This commit is contained in:
@@ -0,0 +1,264 @@
|
||||
<?php
|
||||
|
||||
namespace App\Support\Legacy;
|
||||
|
||||
use Illuminate\Database\ConnectionInterface;
|
||||
use Illuminate\Support\Carbon;
|
||||
use Illuminate\Support\Collection;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
|
||||
/**
|
||||
* Dosen PA di DB lama: mahasiswa bimbingan (t_mahasiswa.idpa), persetujuan KRS semester berjalan prodi mahasiswa
|
||||
* (t_kst.stat 0 menunggu, 1/3 disetujui), dan bimbingan skripsi (t_skripsi.pembimbing1/2).
|
||||
* Setujui = stat 0 menjadi 1. Tolak = f_hapuslirs act 1 (hapus oleh staf) untuk mata kuliah yang masih menunggu;
|
||||
* DB lama tidak punya kolom catatan penolakan.
|
||||
*/
|
||||
class AcademicAdvising
|
||||
{
|
||||
private const int KRS_PENDING = 0;
|
||||
|
||||
private const int KRS_CANCELLED = 2;
|
||||
|
||||
/** t_mahasiswa.stataktif (lihat StudentDirectory). */
|
||||
private const array STATUS = [1 => 'Aktif', 2 => 'Lulus', 3 => 'Mengundurkan diri', 4 => 'Keluar', 5 => 'Pindah'];
|
||||
|
||||
/** Nada badge per status; tidak dikenal = danger. */
|
||||
public const array STATUS_TONE = ['Aktif' => 'success', 'Lulus' => 'accent'];
|
||||
|
||||
public function __construct(private readonly StudyResults $results) {}
|
||||
|
||||
/**
|
||||
* Mahasiswa bimbingan akademik.
|
||||
*
|
||||
* @return Collection<int, array<string, mixed>>
|
||||
*/
|
||||
public function students(int $iddosen): Collection
|
||||
{
|
||||
return $this->db()->table('t_mahasiswa as m')
|
||||
->leftJoin('t_angkatanmhs as g', 'g.idangkatan', '=', 'm.idangkatan')
|
||||
->leftJoin('t_bagian as b', 'b.idbagian', '=', 'm.idprogdi')
|
||||
->where('m.idpa', $iddosen)
|
||||
->orderByDesc('g.tahun')->orderBy('m.nim')
|
||||
->get(['m.idmahasiswa', 'm.nim', 'm.nama', 'm.stataktif', 'g.tahun', 'b.namabagian'])
|
||||
->map(fn (object $r): array => [
|
||||
'idmahasiswa' => (int) $r->idmahasiswa,
|
||||
'nim' => trim((string) $r->nim),
|
||||
'nama' => trim((string) $r->nama),
|
||||
'angkatan' => $r->tahun === null ? null : (int) $r->tahun,
|
||||
'prodi' => filled($r->namabagian) ? trim($r->namabagian) : '-',
|
||||
'pa' => null,
|
||||
'status' => self::STATUS[(int) $r->stataktif] ?? 'Status '.(int) $r->stataktif,
|
||||
]);
|
||||
}
|
||||
|
||||
/** IPK dan SKS ditempuh (transkrip), dihitung per mahasiswa. @return array{ipk: float|null, sks: int} */
|
||||
public function academicSummary(int $idmahasiswa): array
|
||||
{
|
||||
$transcript = $this->results->transcript($idmahasiswa);
|
||||
|
||||
return ['ipk' => $transcript['ipk'], 'sks' => (int) $transcript['sks']];
|
||||
}
|
||||
|
||||
/** IPS tiap semester berurutan dari yang tertua. @return list<float> */
|
||||
public function semesterScores(int $idmahasiswa): array
|
||||
{
|
||||
return $this->results->semesters($idmahasiswa)->reverse()->pluck('ips')->map(fn (mixed $v): float => (float) $v)->values()->all();
|
||||
}
|
||||
|
||||
/**
|
||||
* KRS semester berjalan mahasiswa bimbingan: satu baris per mahasiswa yang punya KRS di periode aktif prodinya.
|
||||
*
|
||||
* @return Collection<int, array<string, mixed>>
|
||||
*/
|
||||
public function krsList(int $iddosen): Collection
|
||||
{
|
||||
$rows = $this->db()->table('t_kst as k')
|
||||
->join('t_mahasiswa as m', 'm.idmahasiswa', '=', 'k.idmahasiswa')
|
||||
->join('t_periodekuliahaktif as a', fn ($join) => $join->on('a.idprogdi', '=', 'm.idprogdi')->on('a.idperiode', '=', 'k.idperiode'))
|
||||
->join('t_periodekuliah as p', 'p.idperiode', '=', 'k.idperiode')
|
||||
->join('t_matakuliah as mk', 'mk.idmatakuliah', '=', 'k.idmatakuliah')
|
||||
->leftJoin('t_angkatanmhs as g', 'g.idangkatan', '=', 'm.idangkatan')
|
||||
->where('m.idpa', $iddosen)
|
||||
->where('k.stat', '<>', self::KRS_CANCELLED)
|
||||
->groupBy('m.idmahasiswa', 'm.nim', 'm.nama', 'p.thakad', 'p.semester', 'p.perkuliahan', 'g.tahun', 'g.semester')
|
||||
->orderBy('m.nim')
|
||||
->selectRaw('m.idmahasiswa, m.nim, m.nama, p.thakad, p.semester, p.perkuliahan, g.tahun, g.semester as smt_masuk, sum(mk.sks) as sks, count(*) as jumlah, sum(case when k.stat = 0 then 1 else 0 end) as menunggu, min(k.tanggal) as diajukan')
|
||||
->get();
|
||||
|
||||
return $rows->map(fn (object $r): array => $this->krsRow($r));
|
||||
}
|
||||
|
||||
/**
|
||||
* Detail KRS satu mahasiswa bimbingan beserta mata kuliah dan jadwalnya; null bila bukan bimbingan atau tanpa KRS.
|
||||
*
|
||||
* @return array<string, mixed>|null
|
||||
*/
|
||||
public function krsDetail(int $iddosen, int $idmahasiswa): ?array
|
||||
{
|
||||
$row = $this->krsList($iddosen)->firstWhere('id', $idmahasiswa);
|
||||
|
||||
if ($row === null) {
|
||||
return null;
|
||||
}
|
||||
|
||||
$ctx = $this->context($idmahasiswa);
|
||||
$items = $this->db()->table('t_kst as k')
|
||||
->join('t_jadwal as j', 'j.idjadwal', '=', 'k.idjadwal')
|
||||
->join('t_matakuliah as m', 'm.idmatakuliah', '=', 'k.idmatakuliah')
|
||||
->where('k.idmahasiswa', $idmahasiswa)->where('k.idperiode', $ctx->idperiode)->where('k.stat', '<>', self::KRS_CANCELLED)
|
||||
->orderBy('m.namamk')
|
||||
->get(['k.idkst', 'k.idjadwal', 'k.stat', 'm.kodemk', 'm.namamk', 'm.sks', 'j.kelas']);
|
||||
|
||||
$slots = $this->db()->table('t_jadwaltemu as t')
|
||||
->leftJoin('t_jadwalruangkuliah as r', 'r.idjadwaltemu', '=', 't.idjadwaltemu')
|
||||
->leftJoin('t_ruang as ru', 'ru.idruang', '=', 'r.idruang')
|
||||
->whereIn('t.idjadwal', $items->pluck('idjadwal')->all())
|
||||
->orderBy('t.hari')->orderBy('t.mulai')
|
||||
->get(['t.idjadwal', 't.hari', 't.mulai', 't.selesai', 'ru.namaruang'])
|
||||
->filter(fn (object $s): bool => LegacyFormat::dayName($s->hari) !== null)
|
||||
->groupBy('idjadwal')
|
||||
->map(fn (Collection $rows): string => $rows->map(fn (object $s): string => LegacyFormat::dayName($s->hari).', '.LegacyFormat::time($s->mulai).'–'.LegacyFormat::time($s->selesai).(filled($s->namaruang) ? ', '.trim($s->namaruang) : ''))->unique()->implode('; '));
|
||||
|
||||
$maks = $this->db()->scalar('select f_maxsks(?, ?, ?, ?)', [$idmahasiswa, $ctx->idprogdi, $ctx->idkurikulum, $ctx->idperiode]);
|
||||
|
||||
return [
|
||||
...$row,
|
||||
'maks_sks' => $maks === null ? null : (int) $maks,
|
||||
'ipk' => $this->results->ipk($idmahasiswa),
|
||||
'items' => $items->map(fn (object $i): array => [
|
||||
'kode' => trim((string) $i->kodemk),
|
||||
'matkul' => trim((string) $i->namamk),
|
||||
'kelas' => trim((string) $i->kelas),
|
||||
'sks' => (int) $i->sks,
|
||||
'jadwal' => $slots[$i->idjadwal] ?? 'Tanpa jadwal tatap muka',
|
||||
'menunggu' => (int) $i->stat === self::KRS_PENDING,
|
||||
])->values(),
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Setujui seluruh mata kuliah yang masih menunggu.
|
||||
*
|
||||
* @throws LecturerActionException
|
||||
*/
|
||||
public function approve(int $iddosen, int $idmahasiswa): int
|
||||
{
|
||||
$ctx = $this->pendingContext($iddosen, $idmahasiswa);
|
||||
|
||||
return $this->db()->table('t_kst')
|
||||
->where('idmahasiswa', $idmahasiswa)->where('idperiode', $ctx->idperiode)->where('stat', self::KRS_PENDING)
|
||||
->update(['stat' => 1]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Tolak: hapus mata kuliah yang masih menunggu lewat f_hapuslirs (act 1), agar mahasiswa dapat mengisi ulang.
|
||||
*
|
||||
* @throws LecturerActionException
|
||||
*/
|
||||
public function reject(int $iddosen, int $idmahasiswa): int
|
||||
{
|
||||
$ctx = $this->pendingContext($iddosen, $idmahasiswa);
|
||||
|
||||
$pending = $this->db()->table('t_kst')
|
||||
->where('idmahasiswa', $idmahasiswa)->where('idperiode', $ctx->idperiode)->where('stat', self::KRS_PENDING)
|
||||
->pluck('idkst');
|
||||
|
||||
foreach ($pending as $idkst) {
|
||||
$result = trim((string) $this->db()->scalar('select f_hapuslirs(?, ?, ?, ?, ?, cast(? as smallint))', [
|
||||
$idkst, $idmahasiswa, $ctx->idperiode, $ctx->idprogdi, $ctx->idangkatan, 1,
|
||||
]));
|
||||
|
||||
if ($result !== '') {
|
||||
throw new LecturerActionException('KRS tidak dapat dikembalikan: '.$result);
|
||||
}
|
||||
}
|
||||
|
||||
return $pending->count();
|
||||
}
|
||||
|
||||
/**
|
||||
* Skripsi yang dibimbing dosen (pembimbing 1 atau 2), terbaru lebih dulu.
|
||||
*
|
||||
* @return Collection<int, array<string, mixed>>
|
||||
*/
|
||||
public function theses(int $iddosen): Collection
|
||||
{
|
||||
return $this->db()->table('t_skripsi as s')
|
||||
->join('t_mahasiswa as m', 'm.idmahasiswa', '=', 's.idmahasiswa')
|
||||
->where(fn ($q) => $q->where('s.pembimbing1', $iddosen)->orWhere('s.pembimbing2', $iddosen))
|
||||
// Tanpa tanggal lulus dan mahasiswa sudah tidak aktif = riwayat lama yang tidak pernah dilengkapi.
|
||||
->where(fn ($q) => $q->whereNotNull('s.tgllulus')->orWhere('m.stataktif', 1))
|
||||
->orderByRaw('case when s.tgllulus is null then 0 else 1 end')
|
||||
->orderByDesc('s.tgllulus')->orderBy('m.nim')
|
||||
->limit(200)
|
||||
->get(['s.judul', 's.tglmulai', 's.tgllulus', 's.pembimbing1', 'm.nim', 'm.nama', 'm.stataktif'])
|
||||
->map(fn (object $r): array => [
|
||||
'nim' => trim((string) $r->nim),
|
||||
'nama' => trim((string) $r->nama),
|
||||
'judul' => filled($r->judul) ? trim($r->judul) : 'Judul belum diisi',
|
||||
'peran' => (int) $r->pembimbing1 === $iddosen ? 'Pembimbing 1' : 'Pembimbing 2',
|
||||
'mulai' => $this->validDate($r->tglmulai),
|
||||
'lulus' => $this->validDate($r->tgllulus),
|
||||
'selesai' => $r->tgllulus !== null,
|
||||
]);
|
||||
}
|
||||
|
||||
/** Tanggal di luar 1990–2099 (salah ketik data lama) dianggap kosong. */
|
||||
private function validDate(mixed $date): ?string
|
||||
{
|
||||
if ($date === null) {
|
||||
return null;
|
||||
}
|
||||
|
||||
$year = (int) Carbon::parse($date)->year;
|
||||
|
||||
return $year >= 1990 && $year <= 2099 ? (string) $date : null;
|
||||
}
|
||||
|
||||
/** @return array<string, mixed> */
|
||||
private function krsRow(object $r): array
|
||||
{
|
||||
$menunggu = (int) $r->menunggu;
|
||||
|
||||
return [
|
||||
'id' => (int) $r->idmahasiswa,
|
||||
'nim' => trim((string) $r->nim),
|
||||
'nama' => trim((string) $r->nama),
|
||||
'semester_ke' => LegacyFormat::semesterNumber($r->tahun, $r->smt_masuk, $r->thakad, $r->semester),
|
||||
'periode' => LegacyFormat::periodLabel($r->thakad, $r->semester, $r->perkuliahan),
|
||||
'sks_diambil' => (int) $r->sks,
|
||||
'maks_sks' => null,
|
||||
'mata_kuliah' => (int) $r->jumlah,
|
||||
'diajukan' => $r->diajukan === null ? null : Carbon::parse($r->diajukan)->toDateString(),
|
||||
'status' => $menunggu > 0 ? 'Menunggu persetujuan' : 'Disetujui',
|
||||
'tone' => $menunggu > 0 ? 'gold' : 'success',
|
||||
'catatan' => null,
|
||||
];
|
||||
}
|
||||
|
||||
/** Konteks KRS mahasiswa bimbingan; pelanggaran kepemilikan atau KRS tanpa yang menunggu ditolak. */
|
||||
private function pendingContext(int $iddosen, int $idmahasiswa): object
|
||||
{
|
||||
$row = $this->krsList($iddosen)->firstWhere('id', $idmahasiswa)
|
||||
?? throw new LecturerActionException('KRS ini tidak ditemukan di antara mahasiswa bimbingan Anda.');
|
||||
|
||||
if ($row['status'] !== 'Menunggu persetujuan') {
|
||||
throw new LecturerActionException('KRS ini sudah diproses sebelumnya.');
|
||||
}
|
||||
|
||||
return $this->context($idmahasiswa);
|
||||
}
|
||||
|
||||
private function context(int $idmahasiswa): object
|
||||
{
|
||||
return $this->db()->table('t_mahasiswa as m')
|
||||
->join('t_periodekuliahaktif as a', 'a.idprogdi', '=', 'm.idprogdi')
|
||||
->where('m.idmahasiswa', $idmahasiswa)
|
||||
->first(['m.idprogdi', 'm.idkurikulum', 'm.idangkatan', 'a.idperiode']);
|
||||
}
|
||||
|
||||
private function db(): ConnectionInterface
|
||||
{
|
||||
return DB::connection('untan');
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,8 @@
|
||||
<?php
|
||||
|
||||
namespace App\Support\Legacy;
|
||||
|
||||
use RuntimeException;
|
||||
|
||||
/** Aksi dosen ditolak (presensi, nilai, atau KRS); pesannya ditampilkan apa adanya. */
|
||||
class LecturerActionException extends RuntimeException {}
|
||||
@@ -0,0 +1,474 @@
|
||||
<?php
|
||||
|
||||
namespace App\Support\Legacy;
|
||||
|
||||
use Illuminate\Database\ConnectionInterface;
|
||||
use Illuminate\Support\Carbon;
|
||||
use Illuminate\Support\Collection;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
use Illuminate\Support\Str;
|
||||
|
||||
/**
|
||||
* Kelas yang diampu dosen di DB lama: t_jadwaldosen -> t_jadwal, peserta = t_kst disetujui (stat 1/3).
|
||||
* Penulisan (presensi, nilai, kunci nilai) hanya untuk kelas milik dosen itu, lewat fungsi DB lama:
|
||||
* f_nilai_sp (t_kst.absen/tugas/uts/uas + nilai akhir) dan f_jadwal_flag_cetak_sp (terbitkan nilai).
|
||||
*
|
||||
* Presensi hanya tersimpan sebagai jumlah pertemuan hadir (t_kst.absen) terhadap t_jadwal.jmlpertemuan.
|
||||
* Nilai akhir = (kehadiran% x bobotkehadiran + tugas x bobottugas + uts x bobotuts + uas x bobotuas) / 100, cocok dengan
|
||||
* 99,8% nilai terbit periode 2023/2024 Ganjil. Huruf dan bobot dari t_rangenilai pola 7, skala yang paling banyak dipakai
|
||||
* (cocok 87%); prodi dengan skala lain perlu penyesuaian oleh operator.
|
||||
*/
|
||||
class LecturerClasses
|
||||
{
|
||||
/** t_kst.stat: 1/3 disetujui. */
|
||||
private const array APPROVED = [1, 3];
|
||||
|
||||
/** t_rangenilai.nopola yang dipakai untuk huruf dan bobot. */
|
||||
public const int SCALE = 7;
|
||||
|
||||
/** Periode terbaru yang punya kelas dosen ini tetapi tidak melampaui periode aktif mana pun. */
|
||||
public function period(int $iddosen): ?array
|
||||
{
|
||||
$id = $this->db()->table('t_jadwaldosen as d')
|
||||
->join('t_jadwal as j', 'j.idjadwal', '=', 'd.idjadwal')
|
||||
->where('d.iddosen', $iddosen)
|
||||
->where('j.idperiode', '<=', $this->db()->table('t_periodekuliahaktif')->max('idperiode') ?? 0)
|
||||
->max('j.idperiode');
|
||||
|
||||
return $id === null ? null : $this->periodInfo((int) $id);
|
||||
}
|
||||
|
||||
/** @return array{id: int, label: string}|null */
|
||||
public function periodInfo(int $id): ?array
|
||||
{
|
||||
$row = $this->db()->table('t_periodekuliah')->where('idperiode', $id)->first(['thakad', 'semester', 'perkuliahan']);
|
||||
|
||||
return $row === null ? null : ['id' => $id, 'label' => LegacyFormat::periodLabel($row->thakad, $row->semester, $row->perkuliahan)];
|
||||
}
|
||||
|
||||
/**
|
||||
* Kelas dosen pada satu periode.
|
||||
*
|
||||
* @return Collection<int, array<string, mixed>>
|
||||
*/
|
||||
public function classes(int $iddosen, int $periode): Collection
|
||||
{
|
||||
$rows = $this->db()->table('t_jadwaldosen as d')
|
||||
->join('t_jadwal as j', 'j.idjadwal', '=', 'd.idjadwal')
|
||||
->join('t_matakuliah as m', 'm.idmatakuliah', '=', 'j.idmatakuliah')
|
||||
->where('d.iddosen', $iddosen)
|
||||
->where('j.idperiode', $periode)
|
||||
->orderBy('m.namamk')->orderBy('j.kelas')
|
||||
->get([
|
||||
'j.idjadwal', 'j.idprogdi', 'j.idperiode', 'j.kelas', 'j.kapasitas', 'j.jmlpertemuan', 'j.flag_cetak',
|
||||
'j.bobotkehadiran', 'j.bobottugas', 'j.bobotuts', 'j.bobotuas',
|
||||
'j.pka', 'j.pkb', 'j.pkc', 'j.pkd', 'j.pke', 'j.sistempenilaian', 'j.filter_kehadiran',
|
||||
'm.kodemk', 'm.namamk', 'm.sks',
|
||||
]);
|
||||
|
||||
if ($rows->isEmpty()) {
|
||||
return collect();
|
||||
}
|
||||
|
||||
$ids = $rows->pluck('idjadwal')->unique()->values();
|
||||
$slots = $this->slots($ids);
|
||||
$peserta = $this->db()->table('t_kst')->whereIn('idjadwal', $ids)->whereIn('stat', self::APPROVED)
|
||||
->selectRaw('idjadwal, count(*) as jumlah')->groupBy('idjadwal')->pluck('jumlah', 'idjadwal');
|
||||
$window = $this->gradingWindows($rows);
|
||||
|
||||
return $rows->unique('idjadwal')->map(function (object $row) use ($slots, $peserta, $window): array {
|
||||
$slot = $slots[$row->idjadwal] ?? [];
|
||||
|
||||
return [
|
||||
'id' => (int) $row->idjadwal,
|
||||
'kode' => trim((string) $row->kodemk),
|
||||
'matkul' => trim((string) $row->namamk),
|
||||
'kelas' => trim((string) $row->kelas),
|
||||
'label' => trim((string) $row->kodemk).' '.trim((string) $row->namamk).' ('.trim((string) $row->kelas).')',
|
||||
'sks' => (int) $row->sks,
|
||||
'slots' => $slot,
|
||||
'jadwal' => collect($slot)->map(fn (array $s): string => $s['hari'].', '.$s['jam'])->implode('; ') ?: 'Belum dijadwalkan',
|
||||
'ruang' => collect($slot)->pluck('ruang')->filter()->unique()->implode(', ') ?: '-',
|
||||
'peserta' => (int) ($peserta[$row->idjadwal] ?? 0),
|
||||
'kapasitas' => (int) $row->kapasitas > 0 ? (int) $row->kapasitas : null,
|
||||
'pertemuan' => (int) $row->jmlpertemuan > 0 ? (int) $row->jmlpertemuan : null,
|
||||
'dikunci' => (bool) $row->flag_cetak,
|
||||
'bobot' => [
|
||||
'kehadiran' => (int) $row->bobotkehadiran, 'tugas' => (int) $row->bobottugas,
|
||||
'uts' => (int) $row->bobotuts, 'uas' => (int) $row->bobotuas,
|
||||
],
|
||||
// Kolom pengaturan lain diteruskan apa adanya ke f_bobotnilai agar tidak tertimpa.
|
||||
'pengaturan_lain' => [
|
||||
'pka' => $row->pka, 'pkb' => $row->pkb, 'pkc' => $row->pkc, 'pkd' => $row->pkd, 'pke' => $row->pke,
|
||||
'sistem' => $row->sistempenilaian ?? 0, 'filter' => (bool) $row->filter_kehadiran,
|
||||
],
|
||||
'jendela_nilai' => $window[$row->idprogdi.'|'.$row->idperiode] ?? null,
|
||||
];
|
||||
})->values();
|
||||
}
|
||||
|
||||
/** Satu kelas milik dosen, atau null. @return array<string, mixed>|null */
|
||||
public function find(int $iddosen, int $periode, int $idjadwal): ?array
|
||||
{
|
||||
return $this->classes($iddosen, $periode)->firstWhere('id', $idjadwal);
|
||||
}
|
||||
|
||||
/**
|
||||
* Peserta kelas (KRS disetujui) beserta komponen nilai.
|
||||
*
|
||||
* @return Collection<int, array<string, mixed>>
|
||||
*/
|
||||
public function students(int $idjadwal): Collection
|
||||
{
|
||||
return $this->db()->table('t_kst as k')
|
||||
->join('t_mahasiswa as m', 'm.idmahasiswa', '=', 'k.idmahasiswa')
|
||||
->where('k.idjadwal', $idjadwal)->whereIn('k.stat', self::APPROVED)
|
||||
->orderBy('m.nim')
|
||||
->get(['k.idkst', 'k.absen', 'k.tugas', 'k.uts', 'k.uas', 'k.nilaitotal', 'k.nilaimutu', 'k.nilaihuruf', 'm.nim', 'm.nama'])
|
||||
->map(fn (object $r): array => [
|
||||
'idkst' => (int) $r->idkst,
|
||||
'nim' => trim((string) $r->nim),
|
||||
'nama' => trim((string) $r->nama),
|
||||
'hadir' => $r->absen === null ? null : (int) round((float) $r->absen),
|
||||
'tugas' => $this->num($r->tugas),
|
||||
'uts' => $this->num($r->uts),
|
||||
'uas' => $this->num($r->uas),
|
||||
'total' => $this->num($r->nilaitotal),
|
||||
'mutu' => $this->num($r->nilaimutu),
|
||||
'huruf' => filled($r->nilaihuruf) ? trim($r->nilaihuruf) : null,
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Simpan jumlah pertemuan hadir per peserta; nilai akhir dihitung ulang bila komponen lengkap dan nilai belum terbit
|
||||
* atau masih dalam masa penilaian.
|
||||
*
|
||||
* @param array<int, int|string|null> $hadir idkst => jumlah hadir
|
||||
*
|
||||
* @throws LecturerActionException
|
||||
*/
|
||||
public function saveAttendance(array $class, array $hadir, string $actor): int
|
||||
{
|
||||
if ($class['dikunci']) {
|
||||
throw new LecturerActionException('Nilai kelas ini sudah dikunci, sehingga presensi tidak dapat diubah.');
|
||||
}
|
||||
|
||||
if ($class['pertemuan'] === null) {
|
||||
throw new LecturerActionException('Jumlah pertemuan kelas ini belum ditetapkan, sehingga presensi belum dapat diisi.');
|
||||
}
|
||||
|
||||
$students = $this->students($class['id'])->keyBy('idkst');
|
||||
$saved = 0;
|
||||
|
||||
foreach ($hadir as $idkst => $value) {
|
||||
$student = $students[(int) $idkst] ?? throw new LecturerActionException('Ada peserta yang bukan anggota kelas ini.');
|
||||
|
||||
if ($value === null || $value === '') {
|
||||
continue;
|
||||
}
|
||||
|
||||
if (! is_numeric($value) || (int) $value < 0 || (int) $value > $class['pertemuan']) {
|
||||
throw new LecturerActionException("Jumlah hadir {$student['nama']} harus 0 sampai {$class['pertemuan']}.");
|
||||
}
|
||||
|
||||
$this->write($class, $student, ['hadir' => (int) $value] + $student, $actor);
|
||||
$saved++;
|
||||
}
|
||||
|
||||
return $saved;
|
||||
}
|
||||
|
||||
/**
|
||||
* Simpan nilai tugas, UTS, dan UAS per peserta. Hanya dalam masa penilaian prodi dan sebelum nilai dikunci.
|
||||
*
|
||||
* @param array<int, array{tugas?: mixed, uts?: mixed, uas?: mixed}> $nilai idkst => komponen
|
||||
*
|
||||
* @throws LecturerActionException
|
||||
*/
|
||||
public function saveGrades(array $class, array $nilai, string $actor): int
|
||||
{
|
||||
$this->assertEditable($class);
|
||||
|
||||
$students = $this->students($class['id'])->keyBy('idkst');
|
||||
$saved = 0;
|
||||
|
||||
foreach ($nilai as $idkst => $components) {
|
||||
$student = $students[(int) $idkst] ?? throw new LecturerActionException('Ada peserta yang bukan anggota kelas ini.');
|
||||
$new = $student;
|
||||
|
||||
foreach (['tugas', 'uts', 'uas'] as $key) {
|
||||
$value = $components[$key] ?? null;
|
||||
$new[$key] = $value === null || $value === '' ? null : round((float) $value, 2);
|
||||
}
|
||||
|
||||
if ($new['tugas'] === $student['tugas'] && $new['uts'] === $student['uts'] && $new['uas'] === $student['uas']) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$this->write($class, $student, $new, $actor);
|
||||
$saved++;
|
||||
}
|
||||
|
||||
return $saved;
|
||||
}
|
||||
|
||||
/**
|
||||
* Atur jumlah pertemuan dan bobot penilaian kelas lewat f_bobotnilai, lalu hitung ulang nilai akhir peserta yang
|
||||
* komponennya lengkap. Total bobot harus 100.
|
||||
*
|
||||
* @param array{kehadiran: int, tugas: int, uts: int, uas: int} $bobot
|
||||
*
|
||||
* @throws LecturerActionException
|
||||
*/
|
||||
public function saveSettings(array $class, int $pertemuan, array $bobot, string $actor): void
|
||||
{
|
||||
if ($class['dikunci']) {
|
||||
throw new LecturerActionException('Nilai kelas ini sudah dikunci, sehingga pengaturan penilaian tidak dapat diubah.');
|
||||
}
|
||||
|
||||
if ($pertemuan < 1 || $pertemuan > 40) {
|
||||
throw new LecturerActionException('Jumlah pertemuan harus 1 sampai 40.');
|
||||
}
|
||||
|
||||
if (array_sum($bobot) !== 100) {
|
||||
throw new LecturerActionException('Total bobot kehadiran, tugas, UTS, dan UAS harus 100%.');
|
||||
}
|
||||
|
||||
$other = $class['pengaturan_lain'];
|
||||
$this->db()->select('select f_bobotnilai(?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, cast(? as boolean), ?, ?)', [
|
||||
$class['id'], $bobot['kehadiran'], $bobot['tugas'], $bobot['uts'], $bobot['uas'], $pertemuan,
|
||||
$other['pka'], $other['pkb'], $other['pkc'], $other['pkd'], $other['pke'], $other['sistem'],
|
||||
$other['filter'] ? 1 : 0, $this->app(), $this->actor($actor),
|
||||
]);
|
||||
|
||||
$updated = [...$class, 'pertemuan' => $pertemuan, 'bobot' => $bobot];
|
||||
foreach ($this->students($class['id']) as $student) {
|
||||
if ($student['hadir'] !== null && $student['tugas'] !== null && $student['uts'] !== null && $student['uas'] !== null) {
|
||||
$this->write($updated, $student, $student, $actor);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Kunci (terbitkan) nilai kelas lewat f_jadwal_flag_cetak_sp; mahasiswa baru melihatnya setelah ini.
|
||||
*
|
||||
* @throws LecturerActionException
|
||||
*/
|
||||
public function publish(array $class, string $actor): void
|
||||
{
|
||||
$this->assertEditable($class);
|
||||
|
||||
$students = $this->students($class['id']);
|
||||
|
||||
if ($students->isEmpty()) {
|
||||
throw new LecturerActionException('Kelas ini belum memiliki peserta.');
|
||||
}
|
||||
|
||||
$incomplete = $students->whereNull('huruf')->count();
|
||||
if ($incomplete > 0) {
|
||||
throw new LecturerActionException("Nilai belum lengkap untuk {$incomplete} peserta. Lengkapi presensi, tugas, UTS, dan UAS dulu.");
|
||||
}
|
||||
|
||||
$this->db()->select('select f_jadwal_flag_cetak_sp(?, true, ?, ?)', [$class['id'], $this->app(), $this->actor($actor)]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Nilai akhir, huruf, dan bobot dari komponen; null bila ada komponen kosong atau pertemuan belum ditetapkan.
|
||||
*
|
||||
* @param array<string, int> $bobot
|
||||
* @return array{total: float, mutu: float, huruf: string}|null
|
||||
*/
|
||||
public function grade(array $bobot, ?int $pertemuan, ?int $hadir, ?float $tugas, ?float $uts, ?float $uas): ?array
|
||||
{
|
||||
if ($pertemuan === null || $hadir === null || $tugas === null || $uts === null || $uas === null) {
|
||||
return null;
|
||||
}
|
||||
|
||||
$kehadiran = min($hadir / $pertemuan * 100, 100);
|
||||
$total = round(($kehadiran * $bobot['kehadiran'] + $tugas * $bobot['tugas'] + $uts * $bobot['uts'] + $uas * $bobot['uas']) / 100, 3);
|
||||
|
||||
foreach ($this->scale() as $range) {
|
||||
if ($total >= $range['dari']) {
|
||||
return ['total' => $total, 'mutu' => $range['mutu'], 'huruf' => $range['huruf']];
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Skala nilai (batas bawah menurun).
|
||||
*
|
||||
* @return list<array{dari: float, huruf: string, mutu: float}>
|
||||
*/
|
||||
public function scale(): array
|
||||
{
|
||||
return $this->db()->table('t_rangenilai')->where('nopola', self::SCALE)->orderByDesc('nawal')
|
||||
->get(['nawal', 'nhuruf', 'nmutu'])
|
||||
->map(fn (object $r): array => ['dari' => (float) $r->nawal, 'huruf' => trim((string) $r->nhuruf), 'mutu' => (float) $r->nmutu])
|
||||
->all();
|
||||
}
|
||||
|
||||
/**
|
||||
* Riwayat mengajar per periode: kelas, peserta, SKS, rata-rata bobot nilai terbit, dan kehadiran.
|
||||
*
|
||||
* @return Collection<int, array<string, mixed>>
|
||||
*/
|
||||
public function history(int $iddosen, int $limit = 12): Collection
|
||||
{
|
||||
$latest = $this->db()->table('t_periodekuliahaktif')->max('idperiode') ?? 0;
|
||||
|
||||
$rows = $this->db()->table('t_jadwaldosen as d')
|
||||
->join('t_jadwal as j', 'j.idjadwal', '=', 'd.idjadwal')
|
||||
->join('t_matakuliah as m', 'm.idmatakuliah', '=', 'j.idmatakuliah')
|
||||
->where('d.iddosen', $iddosen)->where('j.idperiode', '<=', $latest)
|
||||
->get(['j.idjadwal', 'j.idperiode', 'j.jmlpertemuan', 'j.flag_cetak', 'm.namamk', 'm.sks'])
|
||||
->unique('idjadwal');
|
||||
|
||||
if ($rows->isEmpty()) {
|
||||
return collect();
|
||||
}
|
||||
|
||||
$periods = $rows->pluck('idperiode')->unique()->sortDesc()->take($limit)->values();
|
||||
$rows = $rows->whereIn('idperiode', $periods->all());
|
||||
|
||||
$stats = $this->db()->table('t_kst')->whereIn('idjadwal', $rows->pluck('idjadwal')->all())->whereIn('stat', self::APPROVED)
|
||||
->selectRaw('idjadwal, count(*) as jumlah, sum(case when nilaihuruf is not null then nilaimutu else 0 end) as mutu, sum(case when nilaihuruf is not null then 1 else 0 end) as bernilai, sum(absen) as hadir, sum(case when absen is not null then 1 else 0 end) as terisi')
|
||||
->groupBy('idjadwal')->get()->keyBy('idjadwal');
|
||||
|
||||
$labels = $this->db()->table('t_periodekuliah')->whereIn('idperiode', $periods->all())->get(['idperiode', 'thakad', 'semester', 'perkuliahan'])
|
||||
->mapWithKeys(fn (object $p): array => [(int) $p->idperiode => LegacyFormat::periodLabel($p->thakad, $p->semester, $p->perkuliahan)]);
|
||||
|
||||
return $periods->map(function (int|string $id) use ($rows, $stats, $labels): array {
|
||||
$kelas = $rows->where('idperiode', $id);
|
||||
$s = $kelas->map(fn (object $r) => $stats[$r->idjadwal] ?? null)->filter();
|
||||
$bernilai = (int) $s->sum('bernilai');
|
||||
$hadirMax = $kelas->sum(fn (object $r): int => (int) $r->jmlpertemuan * (int) ($stats[$r->idjadwal]->terisi ?? 0));
|
||||
|
||||
return [
|
||||
'semester' => $labels[(int) $id] ?? 'Periode '.$id,
|
||||
'kelas' => $kelas->count(),
|
||||
'mahasiswa' => (int) $s->sum('jumlah'),
|
||||
'sks' => (int) $kelas->sum('sks'),
|
||||
'rata_nilai' => $bernilai > 0 ? round($s->sum('mutu') / $bernilai, 2) : null,
|
||||
'kehadiran' => $hadirMax > 0 ? (int) round($s->sum('hadir') / $hadirMax * 100) : null,
|
||||
'matkul' => $kelas->pluck('namamk')->map(fn (string $n): string => trim($n))->unique()->implode(', '),
|
||||
];
|
||||
});
|
||||
}
|
||||
|
||||
/** Persentase kehadiran rata-rata per kelas (peserta dengan presensi terisi), untuk dashboard. */
|
||||
public function attendanceByClass(Collection $classes): Collection
|
||||
{
|
||||
if ($classes->isEmpty()) {
|
||||
return collect();
|
||||
}
|
||||
|
||||
$rows = $this->db()->table('t_kst')->whereIn('idjadwal', $classes->pluck('id')->all())->whereIn('stat', self::APPROVED)->whereNotNull('absen')
|
||||
->selectRaw('idjadwal, sum(absen) as hadir, count(*) as jumlah')->groupBy('idjadwal')->get()->keyBy('idjadwal');
|
||||
|
||||
return $classes->filter(fn (array $c): bool => $c['pertemuan'] !== null && isset($rows[$c['id']]))
|
||||
->mapWithKeys(fn (array $c): array => [$c['kode'] => min((int) round($rows[$c['id']]->hadir / ($c['pertemuan'] * $rows[$c['id']]->jumlah) * 100), 100)]);
|
||||
}
|
||||
|
||||
/** Sebaran huruf nilai peserta pada kelas-kelas (yang sudah bernilai). @return array<string, int> */
|
||||
public function gradeDistribution(Collection $classes): array
|
||||
{
|
||||
if ($classes->isEmpty()) {
|
||||
return [];
|
||||
}
|
||||
|
||||
return $this->db()->table('t_kst')->whereIn('idjadwal', $classes->pluck('id')->all())->whereIn('stat', self::APPROVED)->whereNotNull('nilaihuruf')
|
||||
->selectRaw('nilaihuruf, count(*) as jumlah')->groupBy('nilaihuruf')->orderBy('nilaihuruf')->pluck('jumlah', 'nilaihuruf')
|
||||
->mapWithKeys(fn (int|string $n, string $huruf): array => [trim($huruf) => (int) $n])->all();
|
||||
}
|
||||
|
||||
/**
|
||||
* Tulis satu baris peserta lewat f_nilai_sp; komponen yang berubah memicu perhitungan ulang nilai akhir.
|
||||
*
|
||||
* @param array<string, mixed> $student
|
||||
* @param array<string, mixed> $new
|
||||
*/
|
||||
private function write(array $class, array $student, array $new, string $actor): void
|
||||
{
|
||||
$graded = $this->grade($class['bobot'], $class['pertemuan'], $new['hadir'], $new['tugas'], $new['uts'], $new['uas']);
|
||||
|
||||
$this->db()->select('select f_nilai_sp(?, ?, ?, ?, ?, ?, ?, ?, ?, ?)', [
|
||||
$student['idkst'], $new['hadir'], $new['tugas'], $new['uts'], $new['uas'],
|
||||
$graded['total'] ?? null, $graded['mutu'] ?? null, $graded['huruf'] ?? null,
|
||||
$this->app(), $this->actor($actor),
|
||||
]);
|
||||
}
|
||||
|
||||
/** @throws LecturerActionException */
|
||||
private function assertEditable(array $class): void
|
||||
{
|
||||
if ($class['dikunci']) {
|
||||
throw new LecturerActionException('Nilai kelas ini sudah dikunci dan tidak dapat diubah.');
|
||||
}
|
||||
|
||||
$window = $class['jendela_nilai'];
|
||||
if ($window === null || now()->lt($window['mulai']) || now()->gt($window['akhir'])) {
|
||||
throw new LecturerActionException('Masa penilaian program studi untuk kelas ini sedang ditutup.');
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Masa penilaian per prodi dan periode (t_periodenilai), seperti f_is_nilai_editable.
|
||||
*
|
||||
* @return array<string, array{mulai: Carbon, akhir: Carbon}>
|
||||
*/
|
||||
private function gradingWindows(Collection $rows): array
|
||||
{
|
||||
return $this->db()->table('t_periodenilai')
|
||||
->whereIn('idperiode', $rows->pluck('idperiode')->unique()->all())
|
||||
->whereIn('idprogdi', $rows->pluck('idprogdi')->unique()->all())
|
||||
->get(['idperiode', 'idprogdi', 'mulai', 'akhir'])
|
||||
->mapWithKeys(fn (object $w): array => [$w->idprogdi.'|'.$w->idperiode => [
|
||||
'mulai' => Carbon::parse($w->mulai)->startOfDay(),
|
||||
'akhir' => Carbon::parse($w->akhir)->endOfDay(),
|
||||
]])->all();
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Collection<int, int> $ids
|
||||
* @return Collection<int, list<array{hari: string, jam: string, ruang: string|null}>>
|
||||
*/
|
||||
private function slots(Collection $ids): Collection
|
||||
{
|
||||
return $this->db()->table('t_jadwaltemu as t')
|
||||
->leftJoin('t_jadwalruangkuliah as r', 'r.idjadwaltemu', '=', 't.idjadwaltemu')
|
||||
->leftJoin('t_ruang as ru', 'ru.idruang', '=', 'r.idruang')
|
||||
->whereIn('t.idjadwal', $ids)
|
||||
->orderBy('t.hari')->orderBy('t.mulai')
|
||||
->get(['t.idjadwal', 't.hari', 't.mulai', 't.selesai', 'ru.namaruang'])
|
||||
->filter(fn (object $row): bool => LegacyFormat::dayName($row->hari) !== null)
|
||||
->groupBy('idjadwal')
|
||||
->map(fn (Collection $rows): array => $rows->map(fn (object $row): array => [
|
||||
'hari' => LegacyFormat::dayName($row->hari),
|
||||
'jam' => LegacyFormat::time($row->mulai).'–'.LegacyFormat::time($row->selesai),
|
||||
'ruang' => filled($row->namaruang) ? trim($row->namaruang) : null,
|
||||
])->unique()->values()->all());
|
||||
}
|
||||
|
||||
private function num(mixed $value): ?float
|
||||
{
|
||||
return $value === null ? null : round((float) $value, 2);
|
||||
}
|
||||
|
||||
/** t_transkrip.uname dan beberapa kolom audit lain hanya 15 karakter, lebih pendek dari NIP. */
|
||||
private function actor(string $username): string
|
||||
{
|
||||
return Str::substr($username, 0, 15);
|
||||
}
|
||||
|
||||
private function app(): string
|
||||
{
|
||||
return Str::substr((string) config('app.name'), 0, 20);
|
||||
}
|
||||
|
||||
private function db(): ConnectionInterface
|
||||
{
|
||||
return DB::connection('untan');
|
||||
}
|
||||
}
|
||||
@@ -5,7 +5,7 @@ namespace App\Support\Legacy;
|
||||
use App\Enums\Role;
|
||||
|
||||
/**
|
||||
* Pemetaan akun SIAKAD lama ke role baru. Satu akun = satu role, urutan prioritas:
|
||||
* Pemetaan akun SIAKAD lama ke role baru. Role bawaan = prioritas tertinggi (pemilih peran dapat beralih ke role lain milik akun), urutan prioritas:
|
||||
* superuser, admin, staf (operator), dosen, otoritas lain (operator).
|
||||
*/
|
||||
final class LegacyRole
|
||||
@@ -27,29 +27,44 @@ final class LegacyRole
|
||||
private const int DOSEN = 2;
|
||||
|
||||
/**
|
||||
* Pegawai tanpa otoritas dan bukan dosen tidak punya role (login ditolak).
|
||||
* Role bawaan akun (yang pertama dari all()). Pegawai tanpa otoritas dan bukan dosen tidak punya role (login ditolak).
|
||||
*
|
||||
* @param list<int> $otoritas idotoritas dari t_otoritasuser
|
||||
* @param bool $isDosen pegawai tercatat di t_dosen
|
||||
*/
|
||||
public static function resolve(int $jenis, array $otoritas, bool $isDosen): ?Role
|
||||
{
|
||||
return self::all($jenis, $otoritas, $isDosen)[0] ?? null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Semua role yang boleh dipakai akun (untuk pemilih peran), berurutan menurut prioritas: superuser, admin, staf (operator),
|
||||
* dosen, lalu operator karena otoritas lain. Tiap role hanya muncul bila akun memang punya otoritasnya.
|
||||
*
|
||||
* @param list<int> $otoritas
|
||||
* @return list<Role>
|
||||
*/
|
||||
public static function all(int $jenis, array $otoritas, bool $isDosen): array
|
||||
{
|
||||
if ($jenis === self::JENIS_MAHASISWA) {
|
||||
return Role::Mahasiswa;
|
||||
return [Role::Mahasiswa];
|
||||
}
|
||||
|
||||
if ($jenis !== self::JENIS_PEGAWAI) {
|
||||
return null;
|
||||
return [];
|
||||
}
|
||||
|
||||
return match (true) {
|
||||
self::hasAny($otoritas, self::SUPERUSER) => Role::Superuser,
|
||||
self::hasAny($otoritas, self::ADMIN) => Role::Admin,
|
||||
self::hasAny($otoritas, self::OPERATOR) => Role::Operator,
|
||||
$isDosen || in_array(self::DOSEN, $otoritas, true) => Role::Dosen,
|
||||
$otoritas !== [] => Role::Operator,
|
||||
default => null,
|
||||
};
|
||||
$known = [...self::SUPERUSER, ...self::ADMIN, ...self::OPERATOR, self::DOSEN];
|
||||
|
||||
$roles = array_filter([
|
||||
self::hasAny($otoritas, self::SUPERUSER) ? Role::Superuser : null,
|
||||
self::hasAny($otoritas, self::ADMIN) ? Role::Admin : null,
|
||||
self::hasAny($otoritas, self::OPERATOR) ? Role::Operator : null,
|
||||
$isDosen || in_array(self::DOSEN, $otoritas, true) ? Role::Dosen : null,
|
||||
array_diff($otoritas, $known) !== [] ? Role::Operator : null,
|
||||
]);
|
||||
|
||||
return array_values(array_unique($roles, SORT_REGULAR));
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -3,17 +3,22 @@
|
||||
namespace App\Support\Prototype;
|
||||
|
||||
use App\Enums\Role;
|
||||
use App\Models\Legacy\Account;
|
||||
use App\Models\User;
|
||||
|
||||
/**
|
||||
* Contoh hak akses ganda untuk tampilan "Ganti peran" (prototipe, belum ada tabel hak akses).
|
||||
* Nantinya diganti daftar peran milik akun dari basis data.
|
||||
* Daftar peran untuk pemilih peran. Akun DB lama: role yang benar-benar dimiliki akun (LegacyRole::all).
|
||||
* Akun demo: contoh hak akses ganda (prototipe, peralihan belum aktif).
|
||||
*/
|
||||
class RoleAccess
|
||||
{
|
||||
/** @return list<Role> peran aktif lebih dulu, lalu peran lain yang dimiliki akun. */
|
||||
public static function for(User $user): array
|
||||
{
|
||||
if ($user instanceof Account) {
|
||||
return [$user->role, ...array_values(array_filter($user->availableRoles, fn (Role $role): bool => $role !== $user->role))];
|
||||
}
|
||||
|
||||
$others = match ($user->role) {
|
||||
Role::Superuser => [Role::Admin, Role::Operator, Role::Dosen, Role::Mahasiswa],
|
||||
Role::Admin => [Role::Operator],
|
||||
|
||||
Reference in New Issue
Block a user