use App\Mail\AbsenceNotification;
use App\Models\Attendance;
use Illuminate\Bus\Queueable;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Foundation\Bus\Dispatchable;
use Illuminate\Queue\InteractsWithQueue;
use Illuminate\Queue\SerializesModels;
use Illuminate\Support\Facades\Mail;
class WatchAttendance implements ShouldQueue
{
use Dispatchable;
use InteractsWithQueue;
use Queueable;
use SerializesModels;
public $tries = 5;
public function __construct(protected Attendance $attendance)
{
}
public function handle()
{
if ($this->attendance->attendance_type_id == 4) {
$student = $this->attendance->student;
$otherRecipients = [];
if ($this->attendance->event->teacher->email !== null) {
array_push($otherRecipients, ['email' => $this->attendance->event->teacher->email]);
}
if (config('settings.manager_email') !== null) {
array_push($otherRecipients, ['email' => explode(',', config('settings.manager_email'))]);
}
foreach ($this->attendance->student->contacts as $contact) {
array_push($otherRecipients, ['email' => $contact->email]);
}
Mail::to($student->user->email)
->locale($student->user->locale)
->cc($otherRecipients)
->queue(new AbsenceNotification($this->attendance->event, $student->user));
}
}
}