126 lines
4.2 KiB
PHP
126 lines
4.2 KiB
PHP
<?php
|
|
|
|
namespace App\Http\Controllers\Dosen;
|
|
|
|
use App\Http\Controllers\Dosen\Concerns\UsesLegacyLecturer;
|
|
use App\Http\Controllers\Prototype\ResourceController;
|
|
use App\Support\Legacy\AcademicAdvising;
|
|
use App\Support\Prototype\DosenData;
|
|
use Illuminate\Contracts\View\View;
|
|
use Illuminate\Support\Collection;
|
|
|
|
class BimbinganController extends ResourceController
|
|
{
|
|
use UsesLegacyLecturer;
|
|
|
|
/** @var array<int, array{ipk: float|null, sks: int}> */
|
|
private array $summaries = [];
|
|
|
|
protected function rows(): Collection
|
|
{
|
|
return $this->isLegacy()
|
|
? app(AcademicAdvising::class)->students($this->lecturerId())
|
|
: DosenData::bimbingan();
|
|
}
|
|
|
|
protected function keyName(): string
|
|
{
|
|
return 'nim';
|
|
}
|
|
|
|
protected function satuStyle(): bool
|
|
{
|
|
return true;
|
|
}
|
|
|
|
protected function routeBase(): string
|
|
{
|
|
return 'dosen.bimbingan';
|
|
}
|
|
|
|
protected function names(): array
|
|
{
|
|
return ['singular' => 'Mahasiswa', 'plural' => 'Mahasiswa bimbingan', 'description' => 'Mahasiswa yang Anda bimbing sebagai dosen pembimbing akademik.'];
|
|
}
|
|
|
|
protected function abilities(): array
|
|
{
|
|
return ['create' => false, 'show' => true, 'edit' => false, 'delete' => false];
|
|
}
|
|
|
|
protected function search(): array
|
|
{
|
|
return ['nim', 'nama'];
|
|
}
|
|
|
|
protected function filters(): array
|
|
{
|
|
$rows = $this->rows();
|
|
$status = $rows->pluck('status')->unique()->mapWithKeys(fn (string $s): array => [$s => $s])->all();
|
|
$angkatan = $rows->pluck('angkatan')->filter()->unique()->sortDesc()->mapWithKeys(fn (int $a): array => [(string) $a => (string) $a])->all();
|
|
|
|
return [
|
|
['name' => 'status', 'label' => 'Status', 'options' => $status],
|
|
['name' => 'angkatan', 'label' => 'Angkatan', 'options' => $angkatan],
|
|
];
|
|
}
|
|
|
|
/** IPK dan SKS DB lama dihitung hanya untuk baris yang tampil (satu query per mahasiswa). */
|
|
private function summary(array $row): array
|
|
{
|
|
return $this->summaries[$row['idmahasiswa']] ??= app(AcademicAdvising::class)->academicSummary($row['idmahasiswa']);
|
|
}
|
|
|
|
protected function columns(): array
|
|
{
|
|
$legacy = $this->isLegacy();
|
|
|
|
return [
|
|
['label' => 'NIM', 'key' => 'nim'],
|
|
['label' => 'Nama', 'key' => 'nama'],
|
|
['label' => 'Angkatan', 'key' => 'angkatan', 'class' => 'num'],
|
|
['label' => 'IPK', 'value' => function (array $r) use ($legacy): string {
|
|
$ipk = $legacy ? $this->summary($r)['ipk'] : $r['ipk'];
|
|
|
|
return $ipk === null ? '-' : DosenData::angka($ipk);
|
|
}, 'class' => 'num'],
|
|
['label' => 'SKS', 'value' => fn (array $r): string => (string) ($legacy ? $this->summary($r)['sks'] : $r['sks']), 'class' => 'num'],
|
|
['label' => 'Status', 'key' => 'status', 'badge' => fn (array $r): string => match ($r['status']) {
|
|
'Aktif' => 'success', 'Cuti' => 'gold', 'Lulus' => 'accent', default => 'danger',
|
|
}],
|
|
];
|
|
}
|
|
|
|
protected function fields(?array $row): array
|
|
{
|
|
return [];
|
|
}
|
|
|
|
public function show(string $record): View
|
|
{
|
|
$mhs = $this->find($record);
|
|
|
|
if ($this->isLegacy()) {
|
|
$advising = app(AcademicAdvising::class);
|
|
$ips = $advising->semesterScores($mhs['idmahasiswa']);
|
|
|
|
return view('dosen.bimbingan.show-legacy', [
|
|
'mhs' => $mhs + $advising->academicSummary($mhs['idmahasiswa']),
|
|
'ips' => $ips,
|
|
'labels' => collect($ips)->keys()->map(fn (int $i): string => 'Sem '.($i + 1))->all(),
|
|
'krs' => $advising->krsList($this->lecturerId())->firstWhere('id', $mhs['idmahasiswa']),
|
|
]);
|
|
}
|
|
|
|
$ips = DosenData::ipsRiwayat($mhs['nim']);
|
|
|
|
return view('dosen.bimbingan.show', [
|
|
'mhs' => $mhs,
|
|
'ips' => $ips,
|
|
'labels' => collect($ips)->keys()->map(fn (int $i): string => 'Sem '.($i + 1))->all(),
|
|
'krs' => DosenData::krsBimbingan()->firstWhere('nim', $mhs['nim']),
|
|
'skripsi' => DosenData::skripsi()->firstWhere('nim', $mhs['nim']),
|
|
]);
|
|
}
|
|
}
|