Fix Pint formatting

This commit is contained in:
root
2026-06-09 01:25:14 -04:00
parent 6be4875c5e
commit 20a0b6c4e5
1485 changed files with 11318 additions and 10273 deletions
@@ -4,27 +4,25 @@ namespace App\Services\AttendanceTracking;
use App\Models\AttendanceEmailTemplate;
use App\Support\MailHtml;
use Illuminate\Support\Str;
class AttendanceEmailComposerService
{
public function __construct(
protected AttendanceEmailTemplate $attendanceEmailTemplateModel
) {
}
) {}
public function buildTemplateContext(array $violation, ?array $parent = null): array
{
$studentName = (string) ($violation['name'] ?? '');
$incident = (string) ($violation['last_date'] ?? date('Y-m-d'));
$incident = (string) ($violation['last_date'] ?? date('Y-m-d'));
return [
'{{parent_name}}' => (string) ($parent['parent_name'] ?? 'Parent/Guardian'),
'{{student_name}}' => $studentName,
'{{incident_date}}' => $incident,
'{{school_phone}}' => '978-364-0219',
'{{parent_name}}' => (string) ($parent['parent_name'] ?? 'Parent/Guardian'),
'{{student_name}}' => $studentName,
'{{incident_date}}' => $incident,
'{{school_phone}}' => '978-364-0219',
'{{voicemail_phone}}' => (string) ($parent['phone'] ?? '—'),
'{{class_time}}' => '10:00 AM',
'{{class_time}}' => '10:00 AM',
];
}
@@ -42,7 +40,7 @@ class AttendanceEmailComposerService
->where('is_active', 1)
->first();
if (!$row) {
if (! $row) {
$row = $this->attendanceEmailTemplateModel->query()
->where('code', $code)
->where('variant', 'default')
@@ -53,12 +51,12 @@ class AttendanceEmailComposerService
$row = $row?->toArray();
}
if (!$row) {
if (! $row) {
return null;
}
$subject = strtr($row['subject'], $context);
$body = strtr($row['body_html'], $context);
$body = strtr($row['body_html'], $context);
return [$subject, $body];
}
@@ -70,35 +68,35 @@ class AttendanceEmailComposerService
public function pickVariant(string $code, ?string $globalVariantOverride = null): string
{
if (!empty($globalVariantOverride)) {
if (! empty($globalVariantOverride)) {
return $globalVariantOverride;
}
return match ($code) {
'ABS_2', 'ABS_2_IN3W' => 'no_answer',
default => 'default',
default => 'default',
};
}
public function buildFallbackAutoEmail(string $code, array $violation, string $parentName = ''): array
{
$subject = match ($code) {
'ABS_1' => 'Attendance Notice: Unreported Absence',
'ABS_1' => 'Attendance Notice: Unreported Absence',
'LATE_2' => 'Attendance Notice: Repeated Lateness',
default => 'Attendance Notice',
default => 'Attendance Notice',
};
$studentName = (string) ($violation['name'] ?? '');
$date = (string) ($violation['last_date'] ?? date('Y-m-d'));
$date = (string) ($violation['last_date'] ?? date('Y-m-d'));
$body = "<p>Dear " . ($parentName ?: 'Parent/Guardian') . "</p>"
. "<p>We'd like to inform you about your student's recent attendance:</p>"
. "<ul>"
. "<li><strong>Student:</strong> {$studentName}</li>"
. "<li><strong>Issue:</strong> " . (string) ($violation['violation'] ?? '') . "</li>"
. "<li><strong>As of:</strong> {$date}</li>"
. "</ul>"
. "<p>If you have any questions, please contact the school office.</p>";
$body = '<p>Dear '.($parentName ?: 'Parent/Guardian').'</p>'
."<p>We'd like to inform you about your student's recent attendance:</p>"
.'<ul>'
."<li><strong>Student:</strong> {$studentName}</li>"
.'<li><strong>Issue:</strong> '.(string) ($violation['violation'] ?? '').'</li>'
."<li><strong>As of:</strong> {$date}</li>"
.'</ul>'
.'<p>If you have any questions, please contact the school office.</p>';
return [$subject, $body];
}
@@ -134,7 +132,8 @@ class AttendanceEmailComposerService
static function ($m) {
$url = $m[0];
$urlAttr = htmlspecialchars($url, ENT_QUOTES | ENT_SUBSTITUTE, 'UTF-8');
return '<a href="' . $urlAttr . '" target="_blank" rel="noopener noreferrer">' . $url . '</a>';
return '<a href="'.$urlAttr.'" target="_blank" rel="noopener noreferrer">'.$url.'</a>';
},
$escaped
);
@@ -142,8 +141,9 @@ class AttendanceEmailComposerService
$paragraphs = preg_split("/\n{2,}/", $escaped);
$paragraphs = array_map(static function ($p) {
$p = preg_replace("/\n/", "<br>", $p);
return '<p>' . $p . '</p>';
$p = preg_replace("/\n/", '<br>', $p);
return '<p>'.$p.'</p>';
}, $paragraphs);
return implode("\n", $paragraphs);
@@ -152,10 +152,10 @@ class AttendanceEmailComposerService
public function renderAutoEmailFor(array $violation, ?array $parent = null): ?array
{
$code = (string) ($violation['violation_code'] ?? $violation['code'] ?? '');
$ctx = $this->buildTemplateContext($violation, $parent);
$tpl = $this->renderTemplate($code, 'default', $ctx);
$ctx = $this->buildTemplateContext($violation, $parent);
$tpl = $this->renderTemplate($code, 'default', $ctx);
if (!$tpl) {
if (! $tpl) {
return $this->buildFallbackAutoEmail($code, $violation, (string) ($parent['parent_name'] ?? ''));
}
@@ -176,21 +176,21 @@ class AttendanceEmailComposerService
: date('Y-m-d');
$violation = [
'id' => $studentId,
'name' => trim(($student['firstname'] ?? '') . ' ' . ($student['lastname'] ?? '')),
'last_date' => $lastDate,
'violation' => $code,
'id' => $studentId,
'name' => trim(($student['firstname'] ?? '').' '.($student['lastname'] ?? '')),
'last_date' => $lastDate,
'violation' => $code,
'violation_code' => $code,
];
$ctx = $this->buildTemplateContext($violation, $primaryParent);
$rendered = $this->renderTemplate($code, $variant, $ctx);
if (!$rendered) {
if (! $rendered) {
return [
'success' => false,
'message' => "Template not found for {$code} ({$variant}).",
'status' => 404,
'status' => 404,
];
}
@@ -198,19 +198,19 @@ class AttendanceEmailComposerService
return [
'success' => true,
'data' => [
'student_id' => $studentId,
'student_name' => $violation['name'],
'parent_email' => (string) ($primaryParent['email'] ?? ''),
'parent_name' => (string) ($primaryParent['parent_name'] ?? ''),
'data' => [
'student_id' => $studentId,
'student_name' => $violation['name'],
'parent_email' => (string) ($primaryParent['email'] ?? ''),
'parent_name' => (string) ($primaryParent['parent_name'] ?? ''),
'secondary_email' => (string) ($secondaryParent['email'] ?? ''),
'secondary_name' => (string) ($secondaryParent['parent_name'] ?? ''),
'code' => $code,
'variant' => $variant,
'subject' => $subject,
'body_html' => $body,
'incident_date' => $lastDate,
'secondary_name' => (string) ($secondaryParent['parent_name'] ?? ''),
'code' => $code,
'variant' => $variant,
'subject' => $subject,
'body_html' => $body,
'incident_date' => $lastDate,
],
];
}
}
}