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
+32 -42
View File
@@ -3,6 +3,7 @@
namespace App\Models;
use Illuminate\Database\Eloquent\Builder;
use App\Models\BaseModel;
use Illuminate\Database\Eloquent\Relations\BelongsTo;
use Illuminate\Support\Facades\DB;
@@ -20,30 +21,30 @@ class TeacherClass extends BaseModel
'updated_at',
'created_at',
];
public $timestamps = true;
protected $casts = [
'teacher_id' => 'integer',
'teacher_id' => 'integer',
'class_section_id' => 'integer',
'updated_by' => 'integer',
'created_at' => 'datetime',
'updated_at' => 'datetime',
'updated_by' => 'integer',
'created_at' => 'datetime',
'updated_at' => 'datetime',
];
/* ============================================================
* Constants
* ============================================================
*/
public const POS_MAIN = 'main';
public const POS_TA = 'ta';
public const POS_TA = 'ta';
public static function allowedPositions(): array
{
return [self::POS_MAIN, self::POS_TA];
}
/* ============================================================
* Relationships (optional)
* ============================================================
@@ -137,15 +138,15 @@ class TeacherClass extends BaseModel
return $rows->map(function ($r) use ($semester) {
return [
'class_section_pk' => isset($r->class_section_pk) ? (int) $r->class_section_pk : null,
'class_section_id' => (int) $r->class_section_id,
'class_section_pk' => isset($r->class_section_pk) ? (int) $r->class_section_pk : null,
'class_section_id' => (int) $r->class_section_id,
'class_section_name' => (string) $r->class_section_name,
'class_id' => isset($r->class_id) ? (int) $r->class_id : null,
'class_name' => $r->class_name ?? null,
'teacher_id' => (int) $r->teacher_id,
'teacher_role' => ucfirst((string) $r->position), // Main / Ta
'school_year' => (string) $r->school_year,
'semester' => $semester,
'class_id' => isset($r->class_id) ? (int) $r->class_id : null,
'class_name' => $r->class_name ?? null,
'teacher_id' => (int) $r->teacher_id,
'teacher_role' => ucfirst((string) $r->position), // Main / Ta
'school_year' => (string) $r->school_year,
'semester' => $semester,
];
})->all();
}
@@ -213,21 +214,15 @@ class TeacherClass extends BaseModel
$classSectionName = trim($classSectionName);
if (str_contains($classSectionName, ',')) {
$parts = array_values(array_filter(array_map('trim', explode(',', $classSectionName))));
if (! empty($parts)) {
$classSectionName = $parts[0];
}
}
if ($classSectionName === '') {
return null;
if (!empty($parts)) $classSectionName = $parts[0];
}
if ($classSectionName === '') return null;
$sectionCode = DB::table('classSection')
->where('class_section_name', $classSectionName)
->value('class_section_id');
if (! $sectionCode) {
return null;
}
if (!$sectionCode) return null;
$teacherId = DB::table('teacher_class')
->where('class_section_id', $sectionCode)
@@ -269,7 +264,7 @@ class TeacherClass extends BaseModel
?int $updatedBy = null
): bool {
$position = strtolower(trim($position));
if (! in_array($position, self::allowedPositions(), true)) {
if (!in_array($position, self::allowedPositions(), true)) {
throw new \InvalidArgumentException('Position must be either "main" or "ta".');
}
@@ -277,10 +272,10 @@ class TeacherClass extends BaseModel
static::query()->updateOrCreate(
[
'teacher_id' => $teacherId,
'teacher_id' => $teacherId,
'class_section_id' => $sectionCode,
'school_year' => $schoolYear,
'position' => $position,
'school_year' => $schoolYear,
'position' => $position,
],
[
'updated_by' => $updatedBy,
@@ -314,7 +309,7 @@ class TeacherClass extends BaseModel
* Returns rows: class_section_id, teacher_id, position, firstname, lastname
*
* @param int|null $alsoSectionCode When teacher_class rows use the section PK while $sectionCode
* is the business code (or the reverse), pass the other id.
* is the business code (or the reverse), pass the other id.
* @param bool $requireSemester When false, ignore semester (legacy DBs with blank/wrong tc.semester).
*/
public static function assignedForSectionTerm(
@@ -365,7 +360,6 @@ class TeacherClass extends BaseModel
foreach (static::assignedForSectionTerm($sectionCode, $semester, $schoolYear, $alsoSectionCode, $requireSemester) as $r) {
$out[(int) $r['teacher_id']] = $r;
}
return $out;
}
@@ -383,11 +377,9 @@ class TeacherClass extends BaseModel
->orderByRaw("CASE tc.position WHEN 'main' THEN 0 WHEN 'ta' THEN 1 ELSE 2 END")
->orderBy('u.firstname', 'asc');
if (! empty($onlySectionCodes)) {
if (!empty($onlySectionCodes)) {
$ids = array_values(array_unique(array_filter(array_map('intval', $onlySectionCodes))));
if (! empty($ids)) {
$q->whereIn('tc.class_section_id', $ids);
}
if (!empty($ids)) $q->whereIn('tc.class_section_id', $ids);
}
$rows = $q->get()->map(fn ($r) => (array) $r)->all();
@@ -395,9 +387,7 @@ class TeacherClass extends BaseModel
$out = [];
foreach ($rows as $r) {
$code = (int) ($r['class_section_id'] ?? 0);
if ($code <= 0) {
continue;
}
if ($code <= 0) continue;
$out[$code][] = $r;
}
@@ -413,12 +403,12 @@ class TeacherClass extends BaseModel
$req = $updating ? 'sometimes' : 'required';
return [
'teacher_id' => [$req, 'integer', 'min:1', 'exists:users,id'],
'teacher_id' => [$req, 'integer', 'min:1', 'exists:users,id'],
'class_section_id' => [$req, 'integer', 'min:1'],
'semester' => [$req, 'string', 'max:25'],
'school_year' => [$req, 'string', 'max:9'],
'position' => [$req, 'string', 'in:'.implode(',', self::allowedPositions())],
'updated_by' => ['nullable', 'integer'],
'semester' => [$req, 'string', 'max:25'],
'school_year' => [$req, 'string', 'max:9'],
'position' => [$req, 'string', 'in:' . implode(',', self::allowedPositions())],
'updated_by' => ['nullable', 'integer'],
];
}
}