From acca87c77b3e596a0dc784daa43e1d257c7b91dd Mon Sep 17 00:00:00 2001 From: root Date: Sat, 9 May 2026 15:51:34 -0400 Subject: [PATCH] fix tracking attendance --- .../View/AttendanceTrackingController.php | 56 ++++++++++++++++++- 1 file changed, 54 insertions(+), 2 deletions(-) diff --git a/app/Controllers/View/AttendanceTrackingController.php b/app/Controllers/View/AttendanceTrackingController.php index 00f11e5..bb1f765 100644 --- a/app/Controllers/View/AttendanceTrackingController.php +++ b/app/Controllers/View/AttendanceTrackingController.php @@ -2003,6 +2003,58 @@ class AttendanceTrackingController extends BaseController return [$subject, $body]; } + private function buildFallbackTemplate(string $code, string $variant, array $context): array + { + $studentName = (string) ($context['{{student_name}}'] ?? 'the student'); + $incident = (string) ($context['{{incident_date}}'] ?? date('Y-m-d')); + $parentName = (string) ($context['{{parent_name}}'] ?? 'Parent/Guardian'); + $phone = (string) ($context['{{school_phone}}'] ?? 'the school office'); + $voicemail = (string) ($context['{{voicemail_phone}}'] ?? 'your voicemail'); + + $subject = match (true) { + str_starts_with($code, 'ABS_1') => 'Attendance Notice: Unreported Absence', + str_starts_with($code, 'ABS_2') => 'Attendance Follow-Up: Two Consecutive Absences', + str_starts_with($code, 'ABS_3') => 'Attendance Follow-Up: Three Absences', + str_starts_with($code, 'LATE_2') => 'Attendance Notice: Repeated Lateness', + str_starts_with($code, 'LATE_3'), + str_starts_with($code, 'LATE_4'), + str_starts_with($code, 'MIX') => 'Attendance Follow-Up: Repeated Lateness and Absence', + default => 'Attendance Notice', + }; + + $intro = "

Insha Allah this email finds you well"; + if ($variant === 'answered') { + $intro .= ", {$parentName}. Jazakum Allahu khayran for taking the time to speak with us today.

"; + } elseif ($variant === 'no_answer') { + $intro .= ".

We tried to reach you but could not connect and left a voice message at {$voicemail}.

"; + } else { + $intro .= ".

"; + } + + $details = match (true) { + str_starts_with($code, 'ABS_1') + => "

This is to let you know that {$studentName} was absent on {$incident} without prior notice.

", + str_starts_with($code, 'ABS_2') + => "

This is a reminder that {$studentName} has had repeated absences, most recently on {$incident}, without prior notice.

", + str_starts_with($code, 'ABS_3') + => "

This is a reminder that {$studentName} has been absent three times, most recently on {$incident}, without prior notice.

", + str_starts_with($code, 'LATE_2') + => "

This is a reminder that {$studentName} has been late multiple times, most recently on {$incident}.

", + str_starts_with($code, 'LATE_3'), + str_starts_with($code, 'LATE_4') + => "

This is a follow-up that {$studentName} has had repeated lateness concerns, most recently on {$incident}.

", + str_starts_with($code, 'MIX') + => "

This is a follow-up that {$studentName} has had a mix of repeated lateness and absence concerns, most recently on {$incident}.

", + default + => "

We'd like to inform you about {$studentName}'s recent attendance concern dated {$incident}.

", + }; + + $closing = "

If your child will be absent or late due to illness or family commitments, please let us know ahead of time.

" + . "

You can email/call/text us at {$phone}.

"; + + return [$subject, $intro . $details . $closing]; + } + public function compose() { @@ -2033,8 +2085,8 @@ class AttendanceTrackingController extends BaseController $rendered = $this->renderTemplate($code, $variant, $ctx); if (!$rendered) { - return redirect()->to(site_url('attendance/violations')) - ->with('error', 'Template not found for ' . $code . ' (' . $variant . ').'); + log_message('warning', 'Attendance email template missing; using fallback compose body. code=' . $code . ' variant=' . $variant); + $rendered = $this->buildFallbackTemplate($code, $variant, $ctx); } [$subject, $body] = $rendered;