input('notify'); if (!is_array($notify)) { return [ 'success' => false, 'message' => 'Select at least one teacher to notify.', 'status' => 422, ]; } $missingItemsPayload = $request->input('missing_items', []); $targets = $this->extractTargets($notify); if (empty($targets)) { return [ 'success' => false, 'message' => 'Select at least one teacher to notify.', 'status' => 422, ]; } $teacherIds = array_values(array_unique(array_column($targets, 'teacher_id'))); $classSectionIds = array_values(array_unique(array_column($targets, 'class_section_id'))); $classSections = ClassSection::query() ->select('class_section_id', 'class_section_name') ->whereIn('class_section_id', $classSectionIds) ->get() ->keyBy('class_section_id'); $teachers = User::query() ->select('id', 'firstname', 'lastname', 'email') ->whereIn('id', $teacherIds) ->get() ->keyBy('id'); $adminUser = User::find($adminId); $adminName = trim(($adminUser->firstname ?? '') . ' ' . ($adminUser->lastname ?? '')) ?: 'Administrator'; $scoreUrl = url('/'); $sentCount = 0; $failCount = 0; foreach ($targets as $target) { $classSectionId = (int) $target['class_section_id']; $teacherId = (int) $target['teacher_id']; $teacher = $teachers->get($teacherId); $sectionName = $classSections->get($classSectionId)?->class_section_name ?? "Section {$classSectionId}"; $teacherName = trim(($teacher->firstname ?? '') . ' ' . ($teacher->lastname ?? '')) ?: 'Teacher'; $missingPayload = $missingItemsPayload[$classSectionId][$teacherId] ?? ''; $missingItems = $this->support->parseMissingItemsPayload((string) $missingPayload); $missingNote = !empty($missingItems) ? '
Outstanding items: ' . e($this->support->formatMissingItemsText($missingItems)) . '.
' : 'Our records show no outstanding submissions for this section, but please verify if anything still needs attention.
'; $subject = "Reminder: Complete submissions for {$sectionName}"; $body = "Dear {$teacherName},
" . "Administration is gently reminding you to wrap up any remaining score submissions and/or comments for {$sectionName}.
" . $missingNote . "Visit Teacher Score Submission to address any remaining items.
" . "Thank you,
{$adminName}