add tests batch 20
This commit is contained in:
@@ -13,7 +13,8 @@ class SchoolCalendarNotificationService
|
||||
public function __construct(
|
||||
private EmailService $emailService,
|
||||
private ApplicationUrlService $urls,
|
||||
) {}
|
||||
) {
|
||||
}
|
||||
|
||||
public function notify(array $event, array $targets): array
|
||||
{
|
||||
@@ -26,7 +27,7 @@ class SchoolCalendarNotificationService
|
||||
|
||||
$results = [];
|
||||
foreach ($targets as $group => $enabled) {
|
||||
if (! $enabled) {
|
||||
if (!$enabled) {
|
||||
continue;
|
||||
}
|
||||
|
||||
@@ -34,13 +35,12 @@ class SchoolCalendarNotificationService
|
||||
if (empty($emails)) {
|
||||
Log::warning("SchoolCalendar: no recipient emails for {$group}.");
|
||||
$results[$group] = null;
|
||||
|
||||
continue;
|
||||
}
|
||||
|
||||
$to = $emails[0] ?? '';
|
||||
$ok = $this->emailService->send($to, $subject, $body, 'general', [], $emails);
|
||||
if (! $ok) {
|
||||
if (!$ok) {
|
||||
Log::warning("SchoolCalendar: failed to send calendar notification to {$group}.");
|
||||
}
|
||||
$results[$group] = $ok;
|
||||
@@ -52,9 +52,8 @@ class SchoolCalendarNotificationService
|
||||
private function buildSubject(array $event): string
|
||||
{
|
||||
$title = trim((string) ($event['title'] ?? 'School Calendar Update'));
|
||||
$typeSegment = ! empty($event['event_type']) ? ' ('.$event['event_type'].')' : '';
|
||||
|
||||
return 'School Calendar: '.$title.$typeSegment;
|
||||
$typeSegment = !empty($event['event_type']) ? ' (' . $event['event_type'] . ')' : '';
|
||||
return 'School Calendar: ' . $title . $typeSegment;
|
||||
}
|
||||
|
||||
private function buildBody(array $event): string
|
||||
@@ -64,12 +63,12 @@ class SchoolCalendarNotificationService
|
||||
$date = (string) ($event['date'] ?? '');
|
||||
$description = trim((string) ($event['description'] ?? ''));
|
||||
|
||||
$body = '<h3>'.e($title).'</h3>';
|
||||
$body .= '<p><strong>Date:</strong> '.e($date).'</p>';
|
||||
$body = '<h3>' . e($title) . '</h3>';
|
||||
$body .= '<p><strong>Date:</strong> ' . e($date) . '</p>';
|
||||
if ($description !== '') {
|
||||
$body .= '<p>'.nl2br(e($description)).'</p>';
|
||||
$body .= '<p>' . nl2br(e($description)) . '</p>';
|
||||
}
|
||||
$body .= '<p><a href="'.e($calendarUrl).'">View calendar</a></p>';
|
||||
$body .= '<p><a href="' . e($calendarUrl) . '">View calendar</a></p>';
|
||||
|
||||
return $body;
|
||||
}
|
||||
@@ -89,19 +88,18 @@ class SchoolCalendarNotificationService
|
||||
$emails = [];
|
||||
foreach ($rows as $row) {
|
||||
$email = trim((string) ($row['email'] ?? ''));
|
||||
if ($email === '' || ! filter_var($email, FILTER_VALIDATE_EMAIL)) {
|
||||
if ($email === '' || !filter_var($email, FILTER_VALIDATE_EMAIL)) {
|
||||
continue;
|
||||
}
|
||||
$emails[$email] = true;
|
||||
}
|
||||
|
||||
return array_values(array_keys($emails));
|
||||
}
|
||||
|
||||
private function fetchAdminRows(): array
|
||||
{
|
||||
$excluded = ['guest', 'teacher', 'teacher_assistant', 'parent'];
|
||||
$escaped = array_map(static fn ($value) => "'".addslashes($value)."'", $excluded);
|
||||
$escaped = array_map(static fn ($value) => "'" . addslashes($value) . "'", $excluded);
|
||||
$excludedList = implode(', ', $escaped);
|
||||
|
||||
$builder = DB::table('users as u')
|
||||
|
||||
Reference in New Issue
Block a user