diff --git a/app/Console/Commands/GenerateDailySessions.php b/app/Console/Commands/GenerateDailySessions.php
new file mode 100644
index 0000000..f7646f6
--- /dev/null
+++ b/app/Console/Commands/GenerateDailySessions.php
@@ -0,0 +1,55 @@
+dayOfWeekIso; // 1 (Mon) - 7 (Sun)
+ $currentSemester = app(\App\Settings\GeneralSettings::class)->current_semester;
+
+ $schedules = \App\Models\CourseSchedule::query()
+ ->where('day_of_week', $dayOfWeek)
+ ->whereHas('course', function ($query) use ($currentSemester) {
+ $query->where('semester', $currentSemester);
+ })
+ ->get();
+
+ $count = 0;
+ foreach ($schedules as $schedule) {
+ $exists = \App\Models\ClassSession::where('course_id', $schedule->course_id)
+ ->whereDate('date', now())
+ ->exists();
+
+ if (! $exists) {
+ $lastSession = \App\Models\ClassSession::where('course_id', $schedule->course_id)->max('session_number');
+
+ \App\Models\ClassSession::create([
+ 'course_id' => $schedule->course_id,
+ 'session_number' => ($lastSession ?? 0) + 1,
+ 'date' => now()->toDateString(),
+ 'start_time' => $schedule->start_time,
+ 'end_time' => $schedule->end_time,
+ ]);
+ $count++;
+ }
+ }
+
+ $this->info("Generated {$count} sessions for ".now()->toDateString());
+ }
+}
diff --git a/app/Filament/Resources/Learning/ClassSessions/Pages/ManageClassSessions.php b/app/Filament/Resources/Learning/ClassSessions/Pages/ManageClassSessions.php
index 7a7401a..68356a0 100644
--- a/app/Filament/Resources/Learning/ClassSessions/Pages/ManageClassSessions.php
+++ b/app/Filament/Resources/Learning/ClassSessions/Pages/ManageClassSessions.php
@@ -3,7 +3,6 @@
namespace App\Filament\Resources\Learning\ClassSessions\Pages;
use App\Filament\Actions\Cheerful\DeleteAction;
-use App\Filament\Actions\Cheerful\EditAction;
use App\Filament\Resources\Learning\ClassSessions\ClassSessionResource;
use App\Models\ClassSession;
use App\Models\Course;
@@ -17,7 +16,6 @@
use Filament\Forms\Contracts\HasForms;
use Filament\Resources\Pages\Page;
use Filament\Schemas\Schema;
-use Filament\Support\Enums\Width;
use Illuminate\Support\Collection;
class ManageClassSessions extends Page implements HasActions, HasForms
@@ -58,59 +56,12 @@ protected function getHeaderActions(): array
return [];
}
- public function editSessionAction(): Action
- {
- return EditAction::make('editSession')
- ->record(fn (array $arguments) => ClassSession::find($arguments['session']))
- ->modalWidth(Width::TwoExtraLarge);
- }
-
public function deleteSessionAction(): Action
{
return DeleteAction::make('deleteSession')
->record(fn (array $arguments) => ClassSession::find($arguments['session']));
}
- public function generateTodaySessionAction(): Action
- {
- return Action::make('generateTodaySession')
- ->label('Generate Sesi')
- ->icon('heroicon-o-sparkles')
- ->color('primary')
- ->requiresConfirmation()
- ->modalHeading('Generate Sesi Hari Ini?')
- ->modalDescription('Sistem akan membuat sesi baru secara otomatis berdasarkan jadwal aktif.')
- ->modalSubmitActionLabel('Generate Sekarang')
- ->action(function (array $arguments) {
- $courseId = $arguments['course'];
- $schedule = CourseSchedule::where('course_id', $courseId)->first();
-
- if (! $schedule) {
- \Filament\Notifications\Notification::make()
- ->title('Jadwal Tidak Ditemukan')
- ->danger()
- ->send();
-
- return;
- }
-
- $lastSession = ClassSession::where('course_id', $courseId)->max('session_number');
-
- ClassSession::create([
- 'course_id' => $courseId,
- 'session_number' => ($lastSession ?? 0) + 1,
- 'date' => now()->toDateString(),
- 'start_time' => $schedule->start_time,
- 'end_time' => $schedule->end_time,
- ]);
-
- \Filament\Notifications\Notification::make()
- ->title('Sesi Berhasil Digenerate')
- ->success()
- ->send();
- });
- }
-
public function getTodaySessions(): Collection
{
$dayOfWeek = now()->dayOfWeekIso; // 1 (Mon) - 7 (Sun)
@@ -120,7 +71,10 @@ public function getTodaySessions(): Collection
->whereHas('course', function ($query) {
$query->where('semester', app(GeneralSettings::class)->current_semester);
})
- ->with(['course', 'course.classSessions' => fn ($q) => $q->whereDate('date', now())])
+ ->with([
+ 'course',
+ 'course.classSessions' => fn ($q) => $q->whereDate('date', now())->withCount('attendances'),
+ ])
->orderBy('start_time', 'asc')
->get();
@@ -135,6 +89,7 @@ public function getTodaySessions(): Collection
'end_time' => $schedule->end_time,
'title' => $session?->title,
'is_pending' => ! $session,
+ 'attendances_count' => $session?->attendances_count ?? 0,
];
});
}
diff --git a/resources/views/filament/pages/learning/class-session/index.blade.php b/resources/views/filament/pages/learning/class-session/index.blade.php
index 1a3f92c..a679f1d 100644
--- a/resources/views/filament/pages/learning/class-session/index.blade.php
+++ b/resources/views/filament/pages/learning/class-session/index.blade.php
@@ -15,21 +15,31 @@
Sesi Hari Ini