diff --git a/app/Filament/Resources/Learning/ClassSessions/Pages/ListCourseSessions.php b/app/Filament/Resources/Learning/ClassSessions/Pages/ListCourseSessions.php index 4c9c633..4c0a12d 100644 --- a/app/Filament/Resources/Learning/ClassSessions/Pages/ListCourseSessions.php +++ b/app/Filament/Resources/Learning/ClassSessions/Pages/ListCourseSessions.php @@ -10,6 +10,7 @@ use App\Filament\Support\SystemNotification; use App\Models\ClassSession; use App\Models\Course; +use App\Models\Student; use Filament\Actions\Action; use Filament\Actions\Concerns\InteractsWithActions; use Filament\Actions\Contracts\HasActions; @@ -48,6 +49,10 @@ public function course(): Course #[Computed] public function sessions(): Collection { + $totalActiveStudents = Student::query() + ->whereHas('user', fn ($q) => $q->where('is_active', true)) + ->count(); + return $this->course->classSessions() ->withCount(['attendances', 'materials', 'assignments']) ->orderBy('session_number', 'asc') @@ -58,6 +63,8 @@ public function sessions(): Collection 'date_formatted' => $session->date->translatedFormat('l, d F Y'), 'time_range' => $session->start_time->format('H:i').' - '.$session->end_time->format('H:i'), 'attendances_count' => $session->attendances_count, + 'total_students' => $totalActiveStudents, + 'attendance_percentage' => $totalActiveStudents > 0 ? round(($session->attendances_count / $totalActiveStudents) * 100) : 0, 'materials_count' => $session->materials_count, 'assignments_count' => $session->assignments_count, ]); diff --git a/app/Filament/Resources/Learning/ClassSessions/Pages/ManageClassSessions.php b/app/Filament/Resources/Learning/ClassSessions/Pages/ManageClassSessions.php index 976b032..681d4d0 100644 --- a/app/Filament/Resources/Learning/ClassSessions/Pages/ManageClassSessions.php +++ b/app/Filament/Resources/Learning/ClassSessions/Pages/ManageClassSessions.php @@ -5,6 +5,7 @@ use App\Filament\Resources\Learning\ClassSessions\ClassSessionResource; use App\Models\ClassSession; use App\Models\Course; +use App\Models\Student; use App\Settings\GeneralSettings; use Filament\Actions\Action; use Filament\Actions\Concerns\InteractsWithActions; @@ -60,12 +61,18 @@ public function form(Schema $schema): Schema #[Computed] public function todaySessions(): Collection { + $totalActiveStudents = Student::query() + ->whereHas('user', fn ($q) => $q->where('is_active', true)) + ->count(); + return ClassSession::query() ->whereDate('date', now()) ->with(['course']) - ->withCount('attendances') + ->withCount(['attendances', 'materials', 'assignments']) ->get() - ->map(function ($session) { + ->map(function ($session) use ($totalActiveStudents) { + $percentage = $totalActiveStudents > 0 ? round(($session->attendances_count / $totalActiveStudents) * 100) : 0; + return (object) [ 'id' => $session->id, 'is_pending' => false, @@ -75,6 +82,10 @@ public function todaySessions(): Collection 'lecturer' => $session->course->lecturer ?? '-', 'time_range' => $session->start_time->format('H:i').' - '.$session->end_time->format('H:i'), 'attendances_count' => $session->attendances_count, + 'total_students' => $totalActiveStudents, + 'attendance_percentage' => $percentage, + 'materials_count' => $session->materials_count, + 'assignments_count' => $session->assignments_count, 'url' => ClassSessionResource::getUrl('course', ['courseId' => $session->course_id]), // Pre-calculated classes @@ -92,7 +103,7 @@ public function courses(): Collection { $query = Course::query() ->where('semester', app(GeneralSettings::class)->current_semester) - ->with(['classSessions' => fn ($q) => $q->orderBy('session_number', 'asc')]); + ->with(['classSessions', 'studyGroups.students.user']); if ($this->search) { $query->where(function ($q) { @@ -102,16 +113,23 @@ public function courses(): Collection }); } + $totalActiveStudents = Student::query() + ->whereHas('user', fn ($q) => $q->where('is_active', true)) + ->count(); + return $query->get() ->sortBy('name') - ->map(fn ($course) => (object) [ - 'id' => $course->id, - 'name' => $course->name, - 'code' => $course->code, - 'lecturer' => $course->lecturer ?? 'Dosen Belum Ditentukan', - 'sessions_count' => $course->classSessions->count(), - 'url' => ClassSessionResource::getUrl('course', ['courseId' => $course->id]), - ]); + ->map(function ($course) use ($totalActiveStudents) { + return (object) [ + 'id' => $course->id, + 'name' => $course->name, + 'code' => $course->code, + 'lecturer' => $course->lecturer ?? 'Dosen Belum Ditentukan', + 'sessions_count' => $course->classSessions->count(), + 'total_students' => $totalActiveStudents, + 'url' => ClassSessionResource::getUrl('course', ['courseId' => $course->id]), + ]; + }); } public function viewAttendanceAction(): Action diff --git a/resources/views/filament/resources/learning/class-sessions/index.blade.php b/resources/views/filament/resources/learning/class-sessions/index.blade.php index b804696..ab29caf 100644 --- a/resources/views/filament/resources/learning/class-sessions/index.blade.php +++ b/resources/views/filament/resources/learning/class-sessions/index.blade.php @@ -41,6 +41,16 @@ {{ $session->time_range }} +
+
+ + {{ $session->materials_count }} Materi +
+
+ + {{ $session->assignments_count }} Tugas +
+
@if ($session->is_pending)
@@ -57,15 +67,20 @@ class="mt-2 flex items-center gap-1.5 text-[10px] text-gray-400 dark:text-gray-5
@else -
- - {{ $session->attendances_count }} - - - Hadir - +
+
+ + {{ $session->attendances_count }}/{{ $session->total_students }} + +
+
+
+ + {{ $session->attendance_percentage }}% Hadir + +
@endif
diff --git a/resources/views/filament/resources/learning/class-sessions/show.blade.php b/resources/views/filament/resources/learning/class-sessions/show.blade.php index 265a86b..1e3ca5d 100644 --- a/resources/views/filament/resources/learning/class-sessions/show.blade.php +++ b/resources/views/filament/resources/learning/class-sessions/show.blade.php @@ -22,10 +22,19 @@ class="flex flex-wrap items-center gap-x-4 gap-y-1 text-sm text-gray-500 dark:te {{ $session->time_range }} -
- - {{ $session->attendances_count }} Presensi +
+
+ + {{ $session->attendances_count }}/{{ $session->total_students }} Presensi +
+
+
+
+
+ {{ $session->attendance_percentage }}% +