academico-sis /
academico
| 1 | <?php |
||
| 2 | |||
| 3 | namespace App\Jobs; |
||
| 4 | |||
| 5 | use App\Mail\AbsenceNotification; |
||
| 6 | use App\Models\Attendance; |
||
| 7 | use Illuminate\Bus\Queueable; |
||
| 8 | use Illuminate\Contracts\Queue\ShouldQueue; |
||
| 9 | use Illuminate\Foundation\Bus\Dispatchable; |
||
| 10 | use Illuminate\Queue\InteractsWithQueue; |
||
| 11 | use Illuminate\Queue\SerializesModels; |
||
| 12 | use Illuminate\Support\Facades\Mail; |
||
| 13 | |||
| 14 | class WatchAttendance implements ShouldQueue |
||
| 15 | { |
||
| 16 | use Dispatchable; |
||
| 17 | use InteractsWithQueue; |
||
| 18 | use Queueable; |
||
| 19 | use SerializesModels; |
||
|
0 ignored issues
–
show
introduced
by
Loading history...
|
|||
| 20 | |||
| 21 | public int $tries = 5; |
||
| 22 | |||
| 23 | public function __construct(protected Attendance $attendance) |
||
| 24 | { |
||
| 25 | } |
||
| 26 | |||
| 27 | /** |
||
| 28 | * Execute the job. |
||
| 29 | * |
||
| 30 | * @return void |
||
| 31 | */ |
||
| 32 | public function handle() |
||
| 33 | { |
||
| 34 | if ($this->attendance->attendance_type_id == 4) { |
||
| 35 | // if so, send an email |
||
| 36 | $student = $this->attendance->student; |
||
| 37 | |||
| 38 | // CC to the teacher and the administration |
||
| 39 | $otherRecipients = []; |
||
| 40 | |||
| 41 | if ($this->attendance->event->teacher->email !== null) { |
||
| 42 | array_push($otherRecipients, ['email' => $this->attendance->event->teacher->email]); |
||
| 43 | } |
||
| 44 | |||
| 45 | if (config('settings.manager_email') !== null) { |
||
| 46 | array_push($otherRecipients, ['email' => explode(',', config('settings.manager_email'))]); |
||
| 47 | } |
||
| 48 | |||
| 49 | // also send to the student's contacts |
||
| 50 | foreach ($this->attendance->student->contacts as $contact) { |
||
| 51 | array_push($otherRecipients, ['email' => $contact->email]); |
||
| 52 | } |
||
| 53 | |||
| 54 | Mail::to($student->user->email) |
||
| 55 | ->locale($student->user->locale) |
||
| 56 | ->cc($otherRecipients) |
||
| 57 | ->queue(new AbsenceNotification($this->attendance->event, $student->user)); |
||
| 58 | } |
||
| 59 | } |
||
| 60 | } |
||
| 61 |