Point Docker and Coolify compose to the Laravel rebuild app so mahasiswa, dosen, and admin flows are served from the new Laravel public entrypoint.
80 lines
3.4 KiB
PHP
80 lines
3.4 KiB
PHP
<?php
|
|
|
|
namespace App\Http\Controllers\Dashboard;
|
|
|
|
use App\Http\Controllers\Controller;
|
|
use App\Support\AdminNavigation;
|
|
use Illuminate\Http\Request;
|
|
use Illuminate\Support\Carbon;
|
|
use Illuminate\Support\Facades\DB;
|
|
use Illuminate\View\View;
|
|
|
|
class AdminDashboardController extends Controller
|
|
{
|
|
public function __invoke(Request $request): View
|
|
{
|
|
$auth = $request->session()->get('legacy_auth');
|
|
|
|
abort_unless(($auth['role'] ?? null) === 'admin', 403);
|
|
|
|
$user = $auth['user'];
|
|
$isSuper = ($user['lvl'] ?? null) === 'S';
|
|
|
|
$stats = $isSuper ? [
|
|
['label' => 'Fakultas', 'value' => (string) DB::table('tbfakultas')->count(), 'note' => 'Total data fakultas pada basis data SPOTA.'],
|
|
['label' => 'Jurusan', 'value' => (string) DB::table('tbjurusan')->count(), 'note' => 'Total data jurusan lintas fakultas.'],
|
|
['label' => 'Program Studi', 'value' => (string) DB::table('tbprodi')->count(), 'note' => 'Total program studi yang tercatat.'],
|
|
['label' => 'Admin Aktif', 'value' => (string) DB::table('tbadmin')->where('aktif', 'Y')->count(), 'note' => 'Akun administrator aktif.'],
|
|
] : [
|
|
['label' => 'Mahasiswa', 'value' => (string) DB::table('tbmhs')->where('idProdi', $user['prodi'])->count(), 'note' => 'Data mahasiswa pada program studi admin.'],
|
|
['label' => 'Dosen', 'value' => (string) DB::table('tbdosen')->where('idProdi', $user['prodi'])->count(), 'note' => 'Data dosen pada program studi admin.'],
|
|
['label' => 'Draft Praoutline', 'value' => (string) DB::table('tbpraoutline')->where('idProdi', $user['prodi'])->count(), 'note' => 'Total draft praoutline program studi.'],
|
|
['label' => 'Jadwal Publish', 'value' => (string) DB::table('tbjadwal')->where('idProdi', $user['prodi'])->where('publish', 'Y')->count(), 'note' => 'Jadwal seminar/sidang yang dipublikasi.'],
|
|
];
|
|
|
|
$schedules = DB::table('tbjadwal as tj')
|
|
->leftJoin('tbmhs as tm', 'tj.idMhs', '=', 'tm.idmhs')
|
|
->select(['tj.jenis', 'tj.start', 'tj.ruangan', 'tm.nmLengkap as mahasiswa'])
|
|
->when(! $isSuper, fn ($query) => $query->where('tj.idProdi', $user['prodi']))
|
|
->whereNotNull('tj.start')
|
|
->orderByDesc('tj.start')
|
|
->limit(6)
|
|
->get()
|
|
->map(fn ($item) => [
|
|
'jenis' => $this->scheduleLabel($item->jenis),
|
|
'tanggal' => $this->formatDateTime($item->start),
|
|
'ruangan' => $item->ruangan ?: '-',
|
|
'mahasiswa' => $item->mahasiswa ?: '-',
|
|
])
|
|
->all();
|
|
|
|
return view('dashboard.admin', [
|
|
'title' => 'Dashboard Admin | SPOTA Rebuild',
|
|
'user' => $user,
|
|
'sidebar' => AdminNavigation::build($user),
|
|
'pageDate' => Carbon::now()->locale('id')->translatedFormat('j F Y, H:i'),
|
|
'stats' => $stats,
|
|
'schedules' => $schedules,
|
|
]);
|
|
}
|
|
|
|
private function scheduleLabel(?string $jenis): string
|
|
{
|
|
return match ($jenis) {
|
|
'Sidang' => 'Sidang',
|
|
'Outline' => 'Outline',
|
|
'SidHas' => 'Seminar Hasil',
|
|
default => $jenis ?? 'Jadwal',
|
|
};
|
|
}
|
|
|
|
private function formatDateTime(?string $value): string
|
|
{
|
|
if (! $value) {
|
|
return '-';
|
|
}
|
|
|
|
return Carbon::parse($value)->locale('id')->translatedFormat('j F Y, H:i');
|
|
}
|
|
}
|