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
+72 -86
View File
@@ -2,6 +2,7 @@
namespace App\Models;
use App\Models\BaseModel;
use Illuminate\Support\Carbon;
use Illuminate\Support\Facades\DB;
@@ -25,11 +26,11 @@ class AttendanceTracking extends BaseModel
];
protected $casts = [
'student_id' => 'integer',
'date' => 'datetime', // legacy dateFormat = datetime
'is_reported' => 'integer',
'is_notified' => 'integer',
'notif_counter' => 'integer',
'student_id' => 'integer',
'date' => 'datetime', // legacy dateFormat = datetime
'is_reported' => 'integer',
'is_notified' => 'integer',
'notif_counter' => 'integer',
];
/* ----------------------- Helpers ----------------------- */
@@ -41,7 +42,7 @@ class AttendanceTracking extends BaseModel
return $date;
}
if (preg_match('/^\d{4}-\d{2}-\d{2}$/', $date)) {
return $date.' 00:00:00';
return $date . ' 00:00:00';
}
try {
@@ -60,7 +61,6 @@ class AttendanceTracking extends BaseModel
if ($schoolYear !== null && $schoolYear !== '') {
$q->where('school_year', $schoolYear);
}
return $q;
}
@@ -77,8 +77,8 @@ class AttendanceTracking extends BaseModel
$y = (int) $d->format('Y');
$semester = ($m >= 8 && $m <= 12) ? 'Fall' : 'Spring';
$startY = ($m >= 8) ? $y : $y - 1;
$endY = $startY + 1;
$startY = ($m >= 8) ? $y : $y - 1;
$endY = $startY + 1;
return [$semester, sprintf('%d-%d', $startY, $endY)];
}
@@ -89,7 +89,6 @@ class AttendanceTracking extends BaseModel
$day = substr($ymd, 0, 10);
$start = Carbon::parse($day, 'UTC')->startOfDay();
$endEx = Carbon::parse($day, 'UTC')->addDay()->startOfDay(); // exclusive
return [$start, $endEx];
}
@@ -112,19 +111,19 @@ class AttendanceTracking extends BaseModel
if ($semester === null || $schoolYear === null) {
[$sem, $yr] = static::deriveTermFromDate($dt);
$semester = $semester ?? $sem;
$semester = $semester ?? $sem;
$schoolYear = $schoolYear ?? $yr;
}
$row = static::create([
'student_id' => $studentId,
'date' => $dt,
'is_reported' => $isExcused ? 1 : 0,
'reason' => $reason,
'is_notified' => 0,
'notif_counter' => 0,
'semester' => $semester,
'school_year' => $schoolYear,
'student_id' => $studentId,
'date' => $dt,
'is_reported' => $isExcused ? 1 : 0,
'reason' => $reason,
'is_notified' => 0,
'notif_counter' => 0,
'semester' => $semester,
'school_year' => $schoolYear,
]);
return (int) $row->id;
@@ -145,7 +144,7 @@ class AttendanceTracking extends BaseModel
if ($startDate) {
if (preg_match('/^\d{4}-\d{2}-\d{2}$/', $startDate)) {
[$start] = static::dayRange($startDate);
[$start, ] = static::dayRange($startDate);
$q->where('date', '>=', $start);
} else {
$q->where('date', '>=', static::normalizeDateTime($startDate));
@@ -202,7 +201,7 @@ class AttendanceTracking extends BaseModel
?string $schoolYear = null
): bool {
$startDay = Carbon::now('UTC')->subDays($days)->toDateString();
[$start] = static::dayRange($startDay);
[$start, ] = static::dayRange($startDay);
$q = static::query()
->where('student_id', $studentId)
@@ -232,17 +231,13 @@ class AttendanceTracking extends BaseModel
$absences = $q->orderByDesc('date')->limit($threshold)->get()->toArray();
if (count($absences) < $threshold) {
return false;
}
if (count($absences) < $threshold) return false;
for ($i = 0; $i < $threshold - 1; $i++) {
$d1 = new \DateTime($absences[$i]['date']);
$d2 = new \DateTime($absences[$i + 1]['date']);
$diffDays = (int) $d2->diff($d1)->format('%a');
if ($diffDays !== 7) {
return false;
}
if ($diffDays !== 7) return false;
}
return true;
@@ -269,13 +264,11 @@ class AttendanceTracking extends BaseModel
$records = $q->orderByDesc('date')->limit($weeksStreak)->get()->toArray();
if (count($records) < $weeksStreak) {
return false;
}
if (count($records) < $weeksStreak) return false;
$count = 0;
foreach ($records as $r) {
if ((int) ($r['is_reported'] ?? 0) === 0 && (int) ($r['is_notified'] ?? 0) === 0) {
if ((int)($r['is_reported'] ?? 0) === 0 && (int)($r['is_notified'] ?? 0) === 0) {
$count++;
}
}
@@ -304,9 +297,9 @@ class AttendanceTracking extends BaseModel
$last = $q3->orderByDesc('date')->first();
return [
'total_absences' => $total,
'total_absences' => $total,
'unexcused_absences' => $unexcused,
'last_absence' => $last ? $last->toArray() : null,
'last_absence' => $last ? $last->toArray() : null,
];
}
@@ -320,10 +313,7 @@ class AttendanceTracking extends BaseModel
) {
$q = static::query();
static::applyTermFilters($q, $semester, $schoolYear);
if ($limit > 0) {
$q->limit($limit);
}
if ($limit > 0) $q->limit($limit);
return $q->orderByDesc('date')->get();
}
@@ -345,8 +335,8 @@ class AttendanceTracking extends BaseModel
$students = (int) $q3->distinct('student_id')->count('student_id');
return [
'total_absences' => $total,
'unexcused_absences' => $unexcused,
'total_absences' => $total,
'unexcused_absences' => $unexcused,
'students_with_absences' => $students,
];
}
@@ -362,28 +352,26 @@ class AttendanceTracking extends BaseModel
foreach ($studentsWithViolations as $student) {
if (empty($student['absences'])) {
$results['skipped']++;
continue;
}
foreach ($student['absences'] as $absence) {
$ymd = substr((string) ($absence['date'] ?? now()->toDateString()), 0, 10);
$ymd = substr((string)($absence['date'] ?? now()->toDateString()), 0, 10);
[$start, $endEx] = static::dayRange($ymd);
$data = [
'student_id' => (int) ($student['id'] ?? 0),
'date' => static::normalizeDateTime($ymd),
'is_reported' => 0,
'reason' => (string) ($student['violation'] ?? ''),
'is_notified' => 0,
'notif_counter' => 0,
'semester' => $semester,
'school_year' => $schoolYear,
'student_id' => (int)($student['id'] ?? 0),
'date' => static::normalizeDateTime($ymd),
'is_reported' => 0,
'reason' => (string)($student['violation'] ?? ''),
'is_notified' => 0,
'notif_counter' => 0,
'semester' => $semester,
'school_year' => $schoolYear,
];
if ($data['student_id'] <= 0) {
$results['skipped']++;
continue;
}
@@ -403,8 +391,8 @@ class AttendanceTracking extends BaseModel
$existing->fill($data)->save();
$results['updated']++;
if (! empty($existing->is_notified)) {
static::resetNotification((int) $existing->id);
if (!empty($existing->is_notified)) {
static::resetNotification((int)$existing->id);
$results['notified']++;
}
} else {
@@ -416,7 +404,7 @@ class AttendanceTracking extends BaseModel
// Only match standalone "4"
if (preg_match('/\b4\b/', $data['reason'])) {
static::markAsNotified((int) $new->id);
static::markAsNotified((int)$new->id);
$results['notified']++;
}
}
@@ -439,8 +427,8 @@ class AttendanceTracking extends BaseModel
->whereKey($id)
->update([
'notif_counter' => DB::raw('COALESCE(notif_counter,0)+1'),
'is_notified' => 1,
'updated_at' => now(),
'is_notified' => 1,
'updated_at' => now(),
]);
return $affected > 0;
@@ -451,9 +439,9 @@ class AttendanceTracking extends BaseModel
$affected = static::query()
->whereKey($id)
->update([
'is_notified' => 0,
'is_notified' => 0,
'notif_counter' => 0,
'updated_at' => now(),
'updated_at' => now(),
]);
return $affected >= 0;
@@ -475,7 +463,7 @@ class AttendanceTracking extends BaseModel
// Here we require term to be passed or derived from date.
if ($semester === null || $schoolYear === null) {
[$sem, $yr] = static::deriveTermFromDate($ymd);
$semester = $semester ?? $sem;
$semester = $semester ?? $sem;
$schoolYear = $schoolYear ?? $yr;
}
@@ -487,33 +475,33 @@ class AttendanceTracking extends BaseModel
->where('semester', $semester)
->where('school_year', $schoolYear)
->where('date', '>=', $start)
->where('date', '<', $endEx)
->where('date', '<', $endEx)
->where('reason', 'like', "%{$code}%")
->orderByDesc('date')
->first();
// 2) Fallback: match by day only
if (! $row) {
if (!$row) {
$row = static::query()
->where('student_id', $studentId)
->where('semester', $semester)
->where('school_year', $schoolYear)
->where('date', '>=', $start)
->where('date', '<', $endEx)
->where('date', '<', $endEx)
->orderByDesc('date')
->first();
}
if ($row) {
$counter = ((int) ($row->notif_counter ?? 0)) + 1;
$counter = ((int)($row->notif_counter ?? 0)) + 1;
$affected = static::query()
->whereKey((int) $row->id)
->whereKey((int)$row->id)
->update([
'is_notified' => 1,
'is_notified' => 1,
'notif_counter' => $counter,
'is_reported' => 0,
'updated_at' => now(),
'is_reported' => 0,
'updated_at' => now(),
]);
return $affected > 0;
@@ -521,18 +509,18 @@ class AttendanceTracking extends BaseModel
// Insert a row so future runs see it as notified
$created = static::create([
'student_id' => $studentId,
'date' => static::normalizeDateTime($ymd),
'is_reported' => 0,
'reason' => $code,
'is_notified' => 1,
'notif_counter' => 1,
'semester' => $semester,
'school_year' => $schoolYear,
'note' => null,
'student_id' => $studentId,
'date' => static::normalizeDateTime($ymd),
'is_reported' => 0,
'reason' => $code,
'is_notified' => 1,
'notif_counter' => 1,
'semester' => $semester,
'school_year' => $schoolYear,
'note' => null,
]);
return ! empty($created->id);
return !empty($created->id);
}
/**
@@ -550,11 +538,11 @@ class AttendanceTracking extends BaseModel
->where('student_id', $studentId)
->where('school_year', $schoolYear);
if (! empty($semester)) {
if (!empty($semester)) {
$q->where('semester', $semester);
}
if (! empty($lastDate)) {
if (!empty($lastDate)) {
$q->where('date', '<=', static::normalizeDateTime($lastDate));
}
@@ -562,20 +550,18 @@ class AttendanceTracking extends BaseModel
->orderByDesc('date')
->first();
if (! $row) {
return 0;
}
if (!$row) return 0;
$counter = ((int) ($row->notif_counter ?? 0)) + 1;
$counter = ((int)($row->notif_counter ?? 0)) + 1;
$affected = static::query()
->whereKey((int) $row->id)
->whereKey((int)$row->id)
->update([
'is_notified' => 1,
'is_notified' => 1,
'notif_counter' => $counter,
'updated_at' => now(),
'updated_at' => now(),
]);
return $affected > 0 ? 1 : 0;
}
}
}