fix gitlab tests

This commit is contained in:
root
2026-06-09 02:32:58 -04:00
parent 20a0b6c4e5
commit 6def9993da
1489 changed files with 10449 additions and 11356 deletions
@@ -6,6 +6,7 @@ use App\Models\BelowSixtyDecision;
use App\Models\CurrentFlag;
use App\Models\ParentMeetingSchedule;
use App\Models\ScoreComment;
use App\Models\Student;
use App\Models\StudentDecision;
use Illuminate\Support\Facades\DB;
use Illuminate\Support\Facades\Event;
@@ -57,7 +58,7 @@ class GradingBelowSixtyService
$studentIds = array_values(array_filter($studentIds, static fn ($id) => $id > 0));
$commentMap = [];
if (! empty($studentIds)) {
if (!empty($studentIds)) {
$commentRows = ScoreComment::query()
->select('student_id', 'comment', 'created_at')
->where('score_type', 'general')
@@ -68,14 +69,14 @@ class GradingBelowSixtyService
->get();
foreach ($commentRows as $row) {
$sid = (int) $row->student_id;
if ($sid > 0 && ! isset($commentMap[$sid])) {
if ($sid > 0 && !isset($commentMap[$sid])) {
$commentMap[$sid] = (string) ($row->comment ?? '');
}
}
}
$statusMap = [];
if (! empty($studentIds)) {
if (!empty($studentIds)) {
$flagRows = CurrentFlag::query()
->select('student_id', 'flag_state')
->where('flag', 'grade')
@@ -109,7 +110,7 @@ class GradingBelowSixtyService
throw new RuntimeException('Student record not found for the selected term.');
}
$studentName = trim((string) ($row['firstname'] ?? '').' '.(string) ($row['lastname'] ?? ''));
$studentName = trim((string) ($row['firstname'] ?? '') . ' ' . (string) ($row['lastname'] ?? ''));
$subject = $this->buildBelowSixtySubject($studentName, $semester, $schoolYear);
$parentName = $this->fetchBelowSixtyParentName($studentId);
@@ -145,7 +146,7 @@ class GradingBelowSixtyService
public function updateStatus(int $studentId, string $semester, string $schoolYear, string $status, string $note, ?int $userId): void
{
$status = ucfirst(strtolower($status));
if (! in_array($status, ['Open', 'Closed'], true)) {
if (!in_array($status, ['Open', 'Closed'], true)) {
throw new RuntimeException('Invalid status.');
}
@@ -169,22 +170,21 @@ class GradingBelowSixtyService
$data['updated_by_open'] = $userId;
if ($note !== '') {
$prev = (string) ($existing->open_description ?? '');
$data['open_description'] = trim($prev.PHP_EOL.$note);
$data['open_description'] = trim($prev . PHP_EOL . $note);
}
} else {
$data['updated_by_closed'] = $userId;
if ($note !== '') {
$prev = (string) ($existing->close_description ?? '');
$data['close_description'] = trim($prev.PHP_EOL.$note);
$data['close_description'] = trim($prev . PHP_EOL . $note);
}
}
$existing->update($data);
return;
}
$row = $this->fetchBelowSixtyEmailRow($studentId, $schoolYear, $semester);
$studentName = trim((string) ($row['firstname'] ?? '').' '.(string) ($row['lastname'] ?? ''));
$studentName = trim((string) ($row['firstname'] ?? '') . ' ' . (string) ($row['lastname'] ?? ''));
$grade = (string) ($row['class_section_name'] ?? '');
$data = [
'student_id' => $studentId,
@@ -298,7 +298,7 @@ class GradingBelowSixtyService
continue;
}
if (! isset($studentMap[$studentId])) {
if (!isset($studentMap[$studentId])) {
$studentMap[$studentId] = [
'student_id' => $studentId,
'school_id' => $row->school_id,
@@ -355,7 +355,7 @@ class GradingBelowSixtyService
$certificateMap = [];
foreach ($certificateRows as $row) {
$studentId = (int) ($row->student_id ?? 0);
if ($studentId > 0 && ! isset($certificateMap[$studentId])) {
if ($studentId > 0 && !isset($certificateMap[$studentId])) {
$certificateMap[$studentId] = (string) ($row->certificate_number ?? '');
}
}
@@ -522,8 +522,8 @@ class GradingBelowSixtyService
}
$subject = 'Whole Year Academic Decision — '
.(string) ($context['student_name'] ?? 'Student')
.' ('.$schoolYear.')';
. (string) ($context['student_name'] ?? 'Student')
. ' (' . $schoolYear . ')';
return [
'student_id' => $studentId,
@@ -553,8 +553,8 @@ class GradingBelowSixtyService
$resolvedSubject = trim((string) $subject);
if ($resolvedSubject === '') {
$resolvedSubject = 'Whole Year Academic Decision — '
.(string) ($context['student_name'] ?? 'Student')
.' ('.$schoolYear.')';
. (string) ($context['student_name'] ?? 'Student')
. ' (' . $schoolYear . ')';
}
$payload = [
@@ -628,7 +628,7 @@ class GradingBelowSixtyService
continue;
}
if (! isset($studentMap[$studentId])) {
if (!isset($studentMap[$studentId])) {
$studentMap[$studentId] = [
'school_id' => $row->school_id,
'firstname' => $row->firstname,
@@ -661,7 +661,7 @@ class GradingBelowSixtyService
if ($studentId <= 0) {
continue;
}
if (! isset($belowMap[$studentId]) || trim((string) ($belowMap[$studentId]->decision ?? '')) === '') {
if (!isset($belowMap[$studentId]) || trim((string) ($belowMap[$studentId]->decision ?? '')) === '') {
$belowMap[$studentId] = $row;
}
}
@@ -754,7 +754,7 @@ class GradingBelowSixtyService
return [
'rows' => $rows,
'generated' => ! empty($savedMap),
'generated' => !empty($savedMap),
'school_year' => $schoolYear,
];
}
@@ -789,7 +789,7 @@ class GradingBelowSixtyService
continue;
}
if (! isset($studentMap[$studentId])) {
if (!isset($studentMap[$studentId])) {
$studentMap[$studentId] = [
'firstname' => $row->firstname,
'lastname' => $row->lastname,
@@ -818,7 +818,7 @@ class GradingBelowSixtyService
if ($studentId <= 0) {
continue;
}
if (! isset($belowMap[$studentId]) || trim((string) ($belowMap[$studentId]->decision ?? '')) === '') {
if (!isset($belowMap[$studentId]) || trim((string) ($belowMap[$studentId]->decision ?? '')) === '') {
$belowMap[$studentId] = $row;
}
}
@@ -912,7 +912,7 @@ class GradingBelowSixtyService
->whereRaw('LOWER(TRIM(ss.semester)) = ?', [$semesterKey])
->first();
if (! $row) {
if (!$row) {
return [];
}
@@ -972,7 +972,7 @@ class GradingBelowSixtyService
];
}
if (! empty($semesters)) {
if (!empty($semesters)) {
$commentRows = DB::table('score_comments')
->select('semester', 'score_type', 'comment', 'created_at')
->where('student_id', $studentId)
@@ -987,7 +987,7 @@ class GradingBelowSixtyService
foreach ($commentRows as $row) {
$semester = ucfirst(strtolower(trim((string) ($row->semester ?? ''))));
$type = strtolower(trim((string) ($row->score_type ?? 'general')));
if (isset($semesters[$semester]) && ! isset($semesters[$semester]['comments'][$type])) {
if (isset($semesters[$semester]) && !isset($semesters[$semester]['comments'][$type])) {
$semesters[$semester]['comments'][$type] = (string) ($row->comment ?? '');
}
}
@@ -1001,24 +1001,23 @@ class GradingBelowSixtyService
$parentName = 'Parent/Guardian';
try {
$rows = DB::select(
'SELECT u.firstname, u.lastname
"SELECT u.firstname, u.lastname
FROM family_students fs
JOIN family_guardians fg ON fg.family_id = fs.family_id
JOIN users u ON u.id = fg.user_id
WHERE fs.student_id = ?
ORDER BY fg.is_primary DESC, u.lastname, u.firstname
LIMIT 1',
LIMIT 1",
[$studentId]
);
if (! empty($rows[0])) {
$candidate = trim((string) ($rows[0]->firstname ?? '').' '.(string) ($rows[0]->lastname ?? ''));
if (!empty($rows[0])) {
$candidate = trim((string) ($rows[0]->firstname ?? '') . ' ' . (string) ($rows[0]->lastname ?? ''));
if ($candidate !== '') {
$parentName = $candidate;
}
}
} catch (\Throwable $e) {
}
return $parentName;
}
@@ -1042,7 +1041,7 @@ class GradingBelowSixtyService
];
}
$studentName = trim((string) ($student->firstname ?? '').' '.(string) ($student->lastname ?? ''));
$studentName = trim((string) ($student->firstname ?? '') . ' ' . (string) ($student->lastname ?? ''));
if ($studentName === '') {
$studentName = 'Student';
}
@@ -1141,22 +1140,22 @@ class GradingBelowSixtyService
$html = '
<p>Dear Parent/Guardian,</p>
<p>
This message is regarding <strong>'.e($studentName).'</strong>
for the <strong>'.e($schoolYear).'</strong> school year.
This message is regarding <strong>' . e($studentName) . '</strong>
for the <strong>' . e($schoolYear) . '</strong> school year.
</p>
<p>
Class: <strong>'.e($classSectionName !== '' ? $classSectionName : 'N/A').'</strong><br>
Fall Score: <strong>'.e($fallText).'</strong><br>
Spring Score: <strong>'.e($springText).'</strong><br>
Whole-Year Score: <strong>'.e($yearText).'</strong><br>
Decision: <strong>'.e($decision).'</strong>
Class: <strong>' . e($classSectionName !== '' ? $classSectionName : 'N/A') . '</strong><br>
Fall Score: <strong>' . e($fallText) . '</strong><br>
Spring Score: <strong>' . e($springText) . '</strong><br>
Whole-Year Score: <strong>' . e($yearText) . '</strong><br>
Decision: <strong>' . e($decision) . '</strong>
</p>';
if ($notes !== '') {
$html .= '
<p>
<strong>Decision Notes:</strong><br>
'.nl2br(e($notes)).'
' . nl2br(e($notes)) . '
</p>';
}
@@ -1313,9 +1312,9 @@ class GradingBelowSixtyService
$classSectionName = trim((string) ($semester['class_section_name'] ?? ''));
$html .= '
<p style="margin-top:16px;margin-bottom:6px;">
<strong>'.e($semesterName).' Semester</strong>';
<strong>' . e($semesterName) . ' Semester</strong>';
if ($classSectionName !== '') {
$html .= ' — '.e($classSectionName);
$html .= ' — ' . e($classSectionName);
}
$html .= '
</p>
@@ -1330,7 +1329,7 @@ class GradingBelowSixtyService
$hasScoreRow = false;
foreach ($scoreLabels as $key => $label) {
if (! array_key_exists($key, $semester)) {
if (!array_key_exists($key, $semester)) {
continue;
}
$value = $semester[$key];
@@ -1341,13 +1340,13 @@ class GradingBelowSixtyService
$fontWeight = $key === 'semester_score' ? 'font-weight:bold;' : '';
$html .= '
<tr>
<td>'.e($label).'</td>
<td align="right" style="'.$fontWeight.'">'.e($scoreText).'</td>
<td>' . e($label) . '</td>
<td align="right" style="' . $fontWeight . '">' . e($scoreText) . '</td>
</tr>';
$hasScoreRow = true;
}
if (! $hasScoreRow) {
if (!$hasScoreRow) {
$html .= '
<tr>
<td colspan="2">No scores recorded.</td>
@@ -1359,7 +1358,7 @@ class GradingBelowSixtyService
</table>';
$comments = is_array($semester['comments'] ?? null) ? $semester['comments'] : [];
if (! empty($comments)) {
if (!empty($comments)) {
$deduped = [];
$seen = [];
foreach ($comments as $type => $text) {
@@ -1368,7 +1367,7 @@ class GradingBelowSixtyService
continue;
}
$label = $commentTypeLabels[$type] ?? (string) $type;
$hash = $label.'|'.$text;
$hash = $label . '|' . $text;
if (isset($seen[$hash])) {
continue;
}
@@ -1376,13 +1375,13 @@ class GradingBelowSixtyService
$deduped[] = ['label' => $label, 'text' => $text];
}
if (! empty($deduped)) {
if (!empty($deduped)) {
$html .= '<p style="margin:8px 0 4px;"><strong>Comments</strong></p>';
foreach ($deduped as $comment) {
$html .= '
<p style="margin:4px 0 8px;padding:8px;background:#f8f9fa;border-left:4px solid #999;">
<strong>'.e($comment['label']).':</strong><br>
'.nl2br(e($comment['text'])).'
<strong>' . e($comment['label']) . ':</strong><br>
' . nl2br(e($comment['text'])) . '
</p>';
}
}
@@ -1396,12 +1395,11 @@ class GradingBelowSixtyService
{
$subject = 'Student Performance Alert';
if ($studentName !== '') {
$subject .= ' — '.$studentName;
$subject .= ' — ' . $studentName;
}
if ($semester !== '' || $schoolYear !== '') {
$subject .= ' ('.trim($semester.' '.$schoolYear).')';
$subject .= ' (' . trim($semester . ' ' . $schoolYear) . ')';
}
return $subject;
}
@@ -1416,18 +1414,18 @@ class GradingBelowSixtyService
$parentUserId = null;
try {
$pRows = DB::select(
'SELECT u.id AS user_id, u.firstname, u.lastname
"SELECT u.id AS user_id, u.firstname, u.lastname
FROM family_students fs
JOIN family_guardians fg ON fg.family_id = fs.family_id
JOIN users u ON u.id = fg.user_id
WHERE fs.student_id = ?
ORDER BY fg.is_primary DESC, u.lastname, u.firstname
LIMIT 1',
LIMIT 1",
[$studentId]
);
if (! empty($pRows[0])) {
if (!empty($pRows[0])) {
$parentUserId = (int) ($pRows[0]->user_id ?? 0) ?: null;
$parentName = trim((string) ($pRows[0]->firstname ?? '').' '.(string) ($pRows[0]->lastname ?? ''));
$parentName = trim((string) ($pRows[0]->firstname ?? '') . ' ' . (string) ($pRows[0]->lastname ?? ''));
if ($parentName === '') {
$parentName = 'Parent/Guardian';
}
@@ -1438,16 +1436,16 @@ class GradingBelowSixtyService
if ($parentUserId === null) {
try {
$srow = DB::selectOne(
'SELECT s.parent_id, u.firstname, u.lastname
"SELECT s.parent_id, u.firstname, u.lastname
FROM students s
LEFT JOIN users u ON u.id = s.parent_id
WHERE s.id = ?
LIMIT 1',
LIMIT 1",
[$studentId]
);
if (! empty($srow)) {
if (!empty($srow)) {
$parentUserId = (int) ($srow->parent_id ?? 0) ?: null;
$fallbackName = trim((string) ($srow->firstname ?? '').' '.(string) ($srow->lastname ?? ''));
$fallbackName = trim((string) ($srow->firstname ?? '') . ' ' . (string) ($srow->lastname ?? ''));
if ($fallbackName !== '') {
$parentName = $fallbackName;
}
@@ -1456,7 +1454,7 @@ class GradingBelowSixtyService
}
}
$studentName = trim((string) ($row['firstname'] ?? '').' '.(string) ($row['lastname'] ?? ''));
$studentName = trim((string) ($row['firstname'] ?? '') . ' ' . (string) ($row['lastname'] ?? ''));
return [
'student_name' => $studentName !== '' ? $studentName : 'Student',