From 3ec452b1fc6d38009a20d5e58bc5aca989a07e54 Mon Sep 17 00:00:00 2001 From: RetasyaSalsabila Date: Sun, 15 Mar 2026 20:20:22 +0700 Subject: [PATCH] notif & sidebar fixed --- .../Admin/NotifikasiController.php | 53 ++++ .../Controllers/Guru/NotifikasiController.php | 45 +++ .../Siswa/NotifikasiController.php | 60 ++++ resources/views/admin/layouts/app.blade.php | 297 ++++++++++++------ resources/views/guru/layouts/app.blade.php | 240 ++++++-------- resources/views/siswa/layouts/app.blade.php | 297 +++++++----------- routes/web.php | 31 +- 7 files changed, 583 insertions(+), 440 deletions(-) create mode 100644 app/Http/Controllers/Admin/NotifikasiController.php create mode 100644 app/Http/Controllers/Guru/NotifikasiController.php create mode 100644 app/Http/Controllers/Siswa/NotifikasiController.php diff --git a/app/Http/Controllers/Admin/NotifikasiController.php b/app/Http/Controllers/Admin/NotifikasiController.php new file mode 100644 index 0000000..ddf9e0d --- /dev/null +++ b/app/Http/Controllers/Admin/NotifikasiController.php @@ -0,0 +1,53 @@ +subDays(7); + + // Materi baru dari semua guru + $materiBaru = Materi::with(['mengajar.guru', 'mengajar.mapel', 'mengajar.kelas']) + ->where('created_at', '>=', $since) + ->orderBy('created_at', 'desc') + ->get() + ->map(fn($m) => [ + 'type' => 'materi', + 'title' => 'Materi Diunggah', + 'message' => optional($m->mengajar->guru)->nama . ' mengupload: ' . $m->judul_materi, + 'sub' => optional($m->mengajar->mapel)->nama_mapel . ' · ' . optional($m->mengajar->kelas)->nama_kelas, + 'time' => $m->created_at->diffForHumans(), + 'time_raw'=> $m->created_at->toIso8601String(), + ]); + + // Tugas baru dari semua guru + $tugasBaru = Tugas::with(['mengajar.guru', 'mengajar.mapel', 'mengajar.kelas']) + ->where('created_at', '>=', $since) + ->orderBy('created_at', 'desc') + ->get() + ->map(fn($t) => [ + 'type' => 'tugas', + 'title' => 'Tugas Dibuat', + 'message' => optional($t->mengajar->guru)->nama . ' membuat: ' . $t->judul_tugas, + 'sub' => optional($t->mengajar->mapel)->nama_mapel . ' · ' . optional($t->mengajar->kelas)->nama_kelas, + 'time' => $t->created_at->diffForHumans(), + 'time_raw'=> $t->created_at->toIso8601String(), + ]); + + $notifications = $materiBaru->concat($tugasBaru) + ->sortByDesc('time_raw') + ->values(); + + return response()->json([ + 'count' => $notifications->count(), + 'notifications' => $notifications, + ]); + } +} \ No newline at end of file diff --git a/app/Http/Controllers/Guru/NotifikasiController.php b/app/Http/Controllers/Guru/NotifikasiController.php new file mode 100644 index 0000000..b3113d4 --- /dev/null +++ b/app/Http/Controllers/Guru/NotifikasiController.php @@ -0,0 +1,45 @@ +user(); + $since = Carbon::now()->subDays(7); + + $idMengajars = Mengajar::where('id_guru', $guru->id_guru) + ->pluck('id_mengajar'); + + // Ambil id_tugas dari mengajar guru ini + $idTugas = \App\Models\Tugas::whereIn('id_mengajar', $idMengajars) + ->pluck('id_tugas'); + + // Pengumpulan tugas terbaru + $pengumpulan = PengumpulanTugas::with(['siswa', 'tugas.mengajar.mapel']) + ->whereIn('id_tugas', $idTugas) + ->where('created_at', '>=', $since) + ->orderBy('created_at', 'desc') + ->get() + ->map(fn($p) => [ + 'type' => 'pengumpulan', + 'title' => 'Tugas Dikumpulkan', + 'message' => optional($p->siswa)->nama . ' mengumpulkan: ' . optional($p->tugas)->judul_tugas, + 'status' => $p->status, + 'time' => $p->created_at->diffForHumans(), + 'time_raw'=> $p->created_at->toIso8601String(), + ]); + + return response()->json([ + 'count' => $pengumpulan->count(), + 'notifications' => $pengumpulan->values(), + ]); + } +} \ No newline at end of file diff --git a/app/Http/Controllers/Siswa/NotifikasiController.php b/app/Http/Controllers/Siswa/NotifikasiController.php new file mode 100644 index 0000000..238874b --- /dev/null +++ b/app/Http/Controllers/Siswa/NotifikasiController.php @@ -0,0 +1,60 @@ +user(); + $since = Carbon::now()->subDays(7); + + // ID mengajar untuk kelas siswa ini + $idMengajars = Mengajar::where('id_kelas', $siswa->id_kelas) + ->pluck('id_mengajar'); + + // Materi baru + $materiBaru = Materi::with(['mengajar.mapel', 'mengajar.kelas']) + ->whereIn('id_mengajar', $idMengajars) + ->where('created_at', '>=', $since) + ->orderBy('created_at', 'desc') + ->get() + ->map(fn($m) => [ + 'type' => 'materi', + 'title' => 'Materi Baru', + 'message' => optional($m->mengajar->mapel)->nama_mapel . ': ' . $m->judul_materi, + 'time' => $m->created_at->diffForHumans(), + 'time_raw'=> $m->created_at->toIso8601String(), + ]); + + // Tugas baru + $tugasBaru = Tugas::with(['mengajar.mapel', 'mengajar.kelas']) + ->whereIn('id_mengajar', $idMengajars) + ->where('created_at', '>=', $since) + ->orderBy('created_at', 'desc') + ->get() + ->map(fn($t) => [ + 'type' => 'tugas', + 'title' => 'Tugas Baru', + 'message' => optional($t->mengajar->mapel)->nama_mapel . ': ' . $t->judul_tugas, + 'time' => $t->created_at->diffForHumans(), + 'time_raw'=> $t->created_at->toIso8601String(), + ]); + + $notifications = $materiBaru->concat($tugasBaru) + ->sortByDesc('time_raw') + ->values(); + + return response()->json([ + 'count' => $notifications->count(), + 'notifications' => $notifications, + ]); + } +} \ No newline at end of file diff --git a/resources/views/admin/layouts/app.blade.php b/resources/views/admin/layouts/app.blade.php index b0d8469..74e906b 100644 --- a/resources/views/admin/layouts/app.blade.php +++ b/resources/views/admin/layouts/app.blade.php @@ -10,71 +10,141 @@ - @stack('styles') @@ -117,12 +186,10 @@ - -