Commit af0946b7 authored by Mahmoud Aglan's avatar Mahmoud Aglan

Auto-regenerate attendance records when participant reactivated

When a participant goes from suspended/frozen/inactive → active,
the listener now regenerates expected attendance records for all
their active enrollments' future sessions.

Previously, reactivated participants were invisible in attendance
because records were only generated at session creation time.
Co-Authored-By: 's avatarClaude Opus 4.6 <noreply@anthropic.com>
parent 86da35b4
<?php
namespace App\Domain\Attendance\Listeners;
use App\Domain\Attendance\Services\AttendanceGenerationService;
use App\Domain\Training\Events\ParticipantStatusChanged;
use App\Domain\Training\Models\Enrollment;
use Illuminate\Contracts\Queue\ShouldQueue;
class RegenerateAttendanceOnReactivation implements ShouldQueue
{
public function __construct(
private AttendanceGenerationService $generationService,
) {}
public function handle(ParticipantStatusChanged $event): void
{
if ($event->newStatus !== 'active') {
return;
}
if (!in_array($event->oldStatus, ['suspended', 'frozen', 'inactive'])) {
return;
}
$enrollments = Enrollment::where('participant_id', $event->participant->id)
->where('status', 'active')
->get();
foreach ($enrollments as $enrollment) {
$this->generationService->generateForEnrollment($enrollment);
}
}
}
...@@ -86,6 +86,7 @@ class EventServiceProvider extends ServiceProvider ...@@ -86,6 +86,7 @@ class EventServiceProvider extends ServiceProvider
], ],
\App\Domain\Training\Events\ParticipantStatusChanged::class => [ \App\Domain\Training\Events\ParticipantStatusChanged::class => [
\App\Domain\Training\Listeners\SendParticipantStatusChangedNotification::class, \App\Domain\Training\Listeners\SendParticipantStatusChangedNotification::class,
\App\Domain\Attendance\Listeners\RegenerateAttendanceOnReactivation::class,
], ],
\App\Domain\Training\Events\EvaluationShared::class => [ \App\Domain\Training\Events\EvaluationShared::class => [
\App\Domain\Training\Listeners\SendEvaluationSharedNotification::class, \App\Domain\Training\Listeners\SendEvaluationSharedNotification::class,
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment