add tests batch 20

This commit is contained in:
root
2026-06-09 01:03:53 -04:00
parent 95efb9652e
commit 6be4875c5e
1502 changed files with 13797 additions and 11313 deletions
@@ -11,7 +11,9 @@ use Illuminate\Support\Facades\Schema;
class StudentAssignmentService
{
public function __construct(private StudentConfigService $configService) {}
public function __construct(private StudentConfigService $configService)
{
}
public function assignClasses(int $studentId, array $classSectionIds, bool $isEventOnly, ?int $userId = null): array
{
@@ -25,7 +27,7 @@ class StudentAssignmentService
}
$student = Student::query()->find($studentId);
if (! $student) {
if (!$student) {
return ['ok' => false, 'message' => 'Student not found.'];
}
@@ -45,7 +47,7 @@ class StudentAssignmentService
}
$missing = array_diff($classSectionIds, array_keys($sectionMap));
if (! empty($missing)) {
if (!empty($missing)) {
return ['ok' => false, 'message' => 'One or more selected classes do not exist.'];
}
@@ -103,7 +105,7 @@ class StudentAssignmentService
}
}
if (! $isEventOnly) {
if (!$isEventOnly) {
$enrollment = Enrollment::query()
->where('student_id', $studentId)
->where('school_year', $schoolYear)
@@ -141,12 +143,12 @@ class StudentAssignmentService
$displayNames = [];
foreach ($classSectionIds as $classSectionId) {
$section = $sectionMap[$classSectionId] ?? null;
if (! $section) {
if (!$section) {
continue;
}
$name = (string) ($section['class_section_name'] ?? '');
if ($name === '') {
$name = 'Section #'.$classSectionId;
$name = 'Section #' . $classSectionId;
}
$displayNames[] = $name;
}
@@ -178,7 +180,7 @@ class StudentAssignmentService
->where('school_year', $schoolYear)
->first();
if (! $row) {
if (!$row) {
return ['ok' => false, 'message' => 'Assignment not found for this student/class.'];
}
@@ -210,7 +212,7 @@ class StudentAssignmentService
->first();
if ($enrollment) {
$newClassId = ! empty($remainingIds) ? $remainingIds[0] : null;
$newClassId = !empty($remainingIds) ? $remainingIds[0] : null;
if ((int) $enrollment->class_section_id === $classSectionId || $newClassId !== null) {
$enrollment->update([
'class_section_id' => $newClassId,
@@ -296,7 +298,7 @@ class StudentAssignmentService
$payload['updated_by'] = $modifiedBy;
}
$results[$table.'_updated'] = DB::table($table)
$results[$table . '_updated'] = DB::table($table)
->where('student_id', $studentId)
->where('semester', $semester)
->where('school_year', $schoolYear)
@@ -310,7 +312,6 @@ class StudentAssignmentService
{
$values = array_map('intval', $ids);
$values = array_values(array_unique(array_filter($values, static fn ($v) => $v > 0)));
return $values;
}
}
@@ -9,7 +9,9 @@ use Illuminate\Support\Facades\DB;
class StudentAutoDistributionService
{
public function __construct(private StudentConfigService $configService) {}
public function __construct(private StudentConfigService $configService)
{
}
public function promotionTotals(?string $schoolYear = null): array
{
@@ -28,7 +30,6 @@ class StudentAutoDistributionService
$name = strtolower($nameRaw);
if ($name === 'kg' || $name === 'youth') {
$wanted[] = $row;
continue;
}
if (ctype_digit($name)) {
@@ -166,7 +167,6 @@ class StudentAutoDistributionService
$bestIdx = $idx;
}
}
return $bestIdx;
};
@@ -10,7 +10,9 @@ use Illuminate\Support\Facades\DB;
class StudentDirectoryService
{
public function __construct(private StudentConfigService $configService) {}
public function __construct(private StudentConfigService $configService)
{
}
public function assignmentData(?string $schoolYear = null): array
{
@@ -53,7 +55,7 @@ class StudentDirectoryService
$studentId = (int) ($student['id'] ?? 0);
$sectionNames = StudentClass::getClassSectionsByStudentIdWithFlags($studentId, $schoolYear, true);
$sectionIds = StudentClass::getClassSectionIdsByStudentId($studentId, $schoolYear);
$sectionDisplay = ! empty($sectionNames) ? implode(', ', $sectionNames) : '';
$sectionDisplay = !empty($sectionNames) ? implode(', ', $sectionNames) : '';
$parentId = (int) ($student['parent_id'] ?? 0);
$emergencyInfo = $parentId > 0
@@ -62,7 +64,7 @@ class StudentDirectoryService
$studentData[] = [
'student_id' => $studentId,
'name' => trim(($student['firstname'] ?? '').' '.($student['lastname'] ?? '')),
'name' => trim(($student['firstname'] ?? '') . ' ' . ($student['lastname'] ?? '')),
'age' => $student['age'] ?? 'N/A',
'email' => $emergencyInfo['email'] ?? '',
'phone' => $emergencyInfo['cellphone'] ?? '',
@@ -147,10 +149,9 @@ class StudentDirectoryService
$names = $classMap[$studentId] ?? [];
$names = array_values(array_unique(array_filter($names)));
$student['class_sections'] = $names;
$student['class_section_name'] = ! empty($names) ? implode(', ', $names) : 'No class assigned';
$student['class_section_name'] = !empty($names) ? implode(', ', $names) : 'No class assigned';
}
unset($student);
return $students;
};
@@ -187,7 +188,7 @@ class StudentDirectoryService
'school_year',
])
->when($selectedYear !== '', fn ($q) => $q->where('school_year', $selectedYear))
->when(! empty($parentIds), fn ($q) => $q->whereIn('parent_id', $parentIds))
->when(!empty($parentIds), fn ($q) => $q->whereIn('parent_id', $parentIds))
->orderBy('lastname')
->orderBy('firstname')
->get()
@@ -12,7 +12,7 @@ class StudentProfileService
public function updateStudent(int $studentId, array $payload): array
{
$student = Student::query()->find($studentId);
if (! $student) {
if (!$student) {
return ['ok' => false, 'message' => 'Student not found.'];
}
@@ -43,7 +43,7 @@ class StudentProfileService
$shouldSyncAllergies = array_key_exists('allergies', $payload);
DB::transaction(function () use ($student, $studentData, $conditions, $allergies): void {
if (! empty($studentData)) {
if (!empty($studentData)) {
$student->update($studentData);
}
@@ -84,7 +84,7 @@ class StudentProfileService
private function syncHealthList(int $studentId, string $modelClass, string $field, array $newValues): void
{
$model = new $modelClass;
$model = new $modelClass();
$rows = $model->newQuery()->where('student_id', $studentId)->get(['id', $field])->toArray();
$current = [];
@@ -111,14 +111,14 @@ class StudentProfileService
$toDeleteKeys = array_diff(array_keys($current), array_keys($incoming));
$toInsertKeys = array_diff(array_keys($incoming), array_keys($current));
if (! empty($toDeleteKeys)) {
if (!empty($toDeleteKeys)) {
$ids = array_map(fn ($key) => $byId[$key], $toDeleteKeys);
if (! empty($ids)) {
if (!empty($ids)) {
$model->newQuery()->whereIn('id', $ids)->delete();
}
}
if (! empty($toInsertKeys)) {
if (!empty($toInsertKeys)) {
$batch = [];
foreach ($toInsertKeys as $key) {
$batch[] = [
@@ -126,7 +126,7 @@ class StudentProfileService
$field => $incoming[$key],
];
}
if (! empty($batch)) {
if (!empty($batch)) {
$model->newQuery()->insert($batch);
}
}
@@ -146,7 +146,7 @@ class StudentScoreCardService
->where('id', $studentId)
->first();
if (! $student) {
if (!$student) {
return ['ok' => false, 'message' => 'Student not found.'];
}
@@ -177,7 +177,6 @@ class StudentScoreCardService
if ($ay !== $by) {
return strcmp($by, $ay);
}
return strcmp((string) ($a['semester'] ?? ''), (string) ($b['semester'] ?? ''));
});
@@ -185,7 +184,7 @@ class StudentScoreCardService
foreach ($rows as $row) {
$year = (string) ($row['school_year'] ?? '');
$score = $row['semester_score'] ?? null;
if ($year === '' || ! is_numeric($score)) {
if ($year === '' || !is_numeric($score)) {
continue;
}
$yearScoreMap[$year][] = (float) $score;
@@ -225,14 +224,14 @@ class StudentScoreCardService
if ($commentVal === '') {
continue;
}
$key = $year.'|'.$semester;
$key = $year . '|' . $semester;
$commentMap[$key][$type] = $commentVal;
}
foreach ($rows as &$row) {
$year = (string) ($row['school_year'] ?? '');
$semester = strtolower(trim((string) ($row['semester'] ?? '')));
$row['comments'] = $commentMap[$year.'|'.$semester] ?? [];
$row['comments'] = $commentMap[$year . '|' . $semester] ?? [];
$row['year_score'] = $yearAvg[$year] ?? null;
}
unset($row);
@@ -8,7 +8,9 @@ use App\Models\StudentClass;
class StudentStatusService
{
public function __construct(private StudentConfigService $configService) {}
public function __construct(private StudentConfigService $configService)
{
}
public function setActive(int $studentId, bool $isActive, ?int $userId = null): array
{
@@ -17,7 +19,7 @@ class StudentStatusService
$schoolYear = (string) ($context['school_year'] ?? '');
$student = Student::query()->find($studentId);
if (! $student) {
if (!$student) {
return ['ok' => false, 'message' => 'Student not found.'];
}
@@ -34,7 +36,7 @@ class StudentStatusService
->when($schoolYear !== '', fn ($q) => $q->where('school_year', $schoolYear))
->first();
if (! $hasCurrentClass) {
if (!$hasCurrentClass) {
$lastClass = StudentClass::query()
->where('student_id', $studentId)
->orderByDesc('updated_at')
@@ -57,7 +59,7 @@ class StudentStatusService
$classLabel = ClassSection::getClassSectionNameBySectionId($restoreClassId);
if ($classLabel) {
$message .= ' Class assignment restored to '.$classLabel.'.';
$message .= ' Class assignment restored to ' . $classLabel . '.';
}
} else {
$message .= ' No class assignment found for the current term.';