fix parent pages and teachers and admin
API CI/CD / Validate (composer + pint) (push) Successful in 3m8s
API CI/CD / Build frontend assets (push) Successful in 1m2s
API CI/CD / Test (PHPUnit) (push) Failing after 6m5s
API CI/CD / Security audit (push) Failing after 52s
API CI/CD / Deploy to shared hosting (PHP) (push) Has been skipped
API CI/CD / Validate (composer + pint) (push) Successful in 3m8s
API CI/CD / Build frontend assets (push) Successful in 1m2s
API CI/CD / Test (PHPUnit) (push) Failing after 6m5s
API CI/CD / Security audit (push) Failing after 52s
API CI/CD / Deploy to shared hosting (PHP) (push) Has been skipped
This commit is contained in:
@@ -25,6 +25,11 @@ class ClassProgressQueryService
|
||||
|
||||
public function listReports(User $user, array $filters): LengthAwarePaginator
|
||||
{
|
||||
$filterSectionIds = [];
|
||||
if (! empty($filters['class_section_id'])) {
|
||||
$filterSectionIds = $this->equivalentClassSectionIds((int) $filters['class_section_id']);
|
||||
}
|
||||
|
||||
$query = ClassProgressReport::query()
|
||||
->with(['classSection', 'teacher'])
|
||||
->orderBy($filters['sort_by'] ?? 'week_start', $filters['sort_dir'] ?? 'desc');
|
||||
@@ -44,22 +49,19 @@ class ClassProgressQueryService
|
||||
$query->whereRaw('1 = 0');
|
||||
}
|
||||
} else {
|
||||
$relaxedSectionIds = TeacherClass::distinctSectionIdsForTeacher((int) $user->id);
|
||||
$relaxedSectionIds = TeacherClass::distinctAccessibleSectionIdsForTeacher((int) $user->id);
|
||||
|
||||
if (! empty($filters['class_section_id'])) {
|
||||
$sid = (int) $filters['class_section_id'];
|
||||
$requestedSectionIds = $filterSectionIds !== [] ? $filterSectionIds : [(int) $filters['class_section_id']];
|
||||
// Section filter: if this user has ever taught the section, show all rows for that section
|
||||
// (legacy DB often has `class_progress_reports` without matching current-year `teacher_class`).
|
||||
if (! in_array($sid, $relaxedSectionIds, true)) {
|
||||
$query->where('teacher_id', (int) $user->id);
|
||||
if (array_intersect($requestedSectionIds, $relaxedSectionIds) === []) {
|
||||
$query->whereRaw('1 = 0');
|
||||
}
|
||||
} elseif ($relaxedSectionIds !== []) {
|
||||
$query->whereIn('class_section_id', $relaxedSectionIds);
|
||||
} else {
|
||||
$query->where(function ($q) use ($user, $relaxedSectionIds) {
|
||||
$q->where('teacher_id', (int) $user->id);
|
||||
if ($relaxedSectionIds !== []) {
|
||||
$q->orWhereIn('class_section_id', $relaxedSectionIds);
|
||||
}
|
||||
});
|
||||
$query->where('teacher_id', (int) $user->id);
|
||||
}
|
||||
}
|
||||
} elseif (! empty($filters['teacher_id'])) {
|
||||
@@ -67,7 +69,10 @@ class ClassProgressQueryService
|
||||
}
|
||||
|
||||
if (! empty($filters['class_section_id'])) {
|
||||
$query->where('class_section_id', (int) $filters['class_section_id']);
|
||||
$query->whereIn(
|
||||
'class_section_id',
|
||||
$filterSectionIds !== [] ? $filterSectionIds : [(int) $filters['class_section_id']]
|
||||
);
|
||||
}
|
||||
|
||||
if (! empty($filters['subject'])) {
|
||||
@@ -203,7 +208,12 @@ class ClassProgressQueryService
|
||||
$schoolYear = (string) (config('school.school_year') ?? '');
|
||||
}
|
||||
|
||||
return TeacherClass::getClassAssignmentsByUserId($user->id, $schoolYear, $semester);
|
||||
$assignments = $this->teacherAssignmentsForTerm($user, $schoolYear !== '' ? $schoolYear : null);
|
||||
if ($assignments !== []) {
|
||||
return $assignments;
|
||||
}
|
||||
|
||||
return $this->teacherAssignmentsForTerm($user, null);
|
||||
}
|
||||
|
||||
public function meta(?string $schoolYear = null, ?string $semester = null): array
|
||||
@@ -258,6 +268,119 @@ class ClassProgressQueryService
|
||||
return $options[$status] ?? 'Unknown';
|
||||
}
|
||||
|
||||
/**
|
||||
* Resolve the logged-in teacher's real assignment rows. The join accepts both
|
||||
* legacy section identifiers used in this codebase.
|
||||
*
|
||||
* @return list<array<string, mixed>>
|
||||
*/
|
||||
private function teacherAssignmentsForTerm(User $user, ?string $schoolYear): array
|
||||
{
|
||||
if (! Schema::hasTable('classSection') || ! Schema::hasTable('teacher_class')) {
|
||||
return [];
|
||||
}
|
||||
|
||||
$teacherClassHasSchoolYear = Schema::hasColumn('teacher_class', 'school_year');
|
||||
$teacherClassHasSemester = Schema::hasColumn('teacher_class', 'semester');
|
||||
$schoolYearSelect = $teacherClassHasSchoolYear
|
||||
? 'COALESCE(NULLIF(tc.school_year, ""), cs_code.school_year, cs_pk.school_year) AS school_year'
|
||||
: 'COALESCE(cs_code.school_year, cs_pk.school_year) AS school_year';
|
||||
$semesterSelect = $teacherClassHasSemester
|
||||
? 'COALESCE(NULLIF(tc.semester, ""), cs_code.semester, cs_pk.semester) AS semester'
|
||||
: 'COALESCE(cs_code.semester, cs_pk.semester) AS semester';
|
||||
|
||||
$query = DB::table('teacher_class as tc')
|
||||
->selectRaw("
|
||||
COALESCE(cs_code.class_section_name, cs_pk.class_section_name) AS class_section_name,
|
||||
COALESCE(cs_code.id, cs_pk.id) AS class_section_pk,
|
||||
COALESCE(cs_code.class_section_id, cs_pk.class_section_id) AS class_section_id,
|
||||
c.id AS class_id,
|
||||
c.class_name,
|
||||
tc.teacher_id,
|
||||
tc.position,
|
||||
{$schoolYearSelect},
|
||||
{$semesterSelect}
|
||||
")
|
||||
->leftJoin('classSection as cs_code', 'tc.class_section_id', '=', 'cs_code.class_section_id')
|
||||
->leftJoin('classSection as cs_pk', function ($join) {
|
||||
$join->on('tc.class_section_id', '=', 'cs_pk.id')
|
||||
->whereNull('cs_code.class_section_id');
|
||||
})
|
||||
->leftJoin('classes as c', DB::raw('COALESCE(cs_code.class_id, cs_pk.class_id)'), '=', 'c.id')
|
||||
->where('tc.teacher_id', (int) $user->id)
|
||||
->whereNotNull('tc.class_section_id')
|
||||
->whereRaw('COALESCE(cs_code.class_section_id, cs_pk.class_section_id) IS NOT NULL');
|
||||
|
||||
if ($schoolYear !== null && $schoolYear !== '') {
|
||||
if ($teacherClassHasSchoolYear) {
|
||||
$query->where(function ($yearQuery) use ($schoolYear) {
|
||||
$yearQuery->where('tc.school_year', $schoolYear)
|
||||
->orWhere(function ($legacyYearQuery) use ($schoolYear) {
|
||||
$legacyYearQuery->where(function ($blankYearQuery) {
|
||||
$blankYearQuery->whereNull('tc.school_year')
|
||||
->orWhere('tc.school_year', '');
|
||||
})->whereRaw('COALESCE(cs_code.school_year, cs_pk.school_year) = ?', [$schoolYear]);
|
||||
});
|
||||
});
|
||||
} else {
|
||||
$query->whereRaw('COALESCE(cs_code.school_year, cs_pk.school_year) = ?', [$schoolYear]);
|
||||
}
|
||||
}
|
||||
|
||||
return $query
|
||||
->orderByRaw("CASE tc.position WHEN 'main' THEN 0 WHEN 'ta' THEN 1 ELSE 2 END")
|
||||
->orderByRaw('COALESCE(cs_code.class_section_name, cs_pk.class_section_name) ASC')
|
||||
->get()
|
||||
->map(fn ($row) => [
|
||||
'class_section_pk' => isset($row->class_section_pk) ? (int) $row->class_section_pk : null,
|
||||
'class_section_id' => (int) $row->class_section_id,
|
||||
'class_section_name' => (string) $row->class_section_name,
|
||||
'class_id' => isset($row->class_id) ? (int) $row->class_id : null,
|
||||
'class_name' => $row->class_name ?? null,
|
||||
'teacher_id' => (int) $row->teacher_id,
|
||||
'teacher_role' => ucfirst((string) $row->position),
|
||||
'school_year' => $row->school_year ?? null,
|
||||
'semester' => $row->semester ?? null,
|
||||
])
|
||||
->unique('class_section_id')
|
||||
->values()
|
||||
->all();
|
||||
}
|
||||
|
||||
/**
|
||||
* @return list<int>
|
||||
*/
|
||||
private function equivalentClassSectionIds(int $classSectionId): array
|
||||
{
|
||||
if ($classSectionId <= 0) {
|
||||
return [];
|
||||
}
|
||||
|
||||
$ids = [$classSectionId => true];
|
||||
if (! Schema::hasTable('classSection')) {
|
||||
return [$classSectionId];
|
||||
}
|
||||
|
||||
$rows = DB::table('classSection')
|
||||
->select('id', 'class_section_id')
|
||||
->where('class_section_id', $classSectionId)
|
||||
->orWhere('id', $classSectionId)
|
||||
->get();
|
||||
|
||||
foreach ($rows as $row) {
|
||||
foreach ([(int) $row->id, (int) $row->class_section_id] as $id) {
|
||||
if ($id > 0) {
|
||||
$ids[$id] = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$ids = array_map('intval', array_keys($ids));
|
||||
sort($ids);
|
||||
|
||||
return $ids;
|
||||
}
|
||||
|
||||
private function isAdmin(User $user): bool
|
||||
{
|
||||
$roles = $user->roles()
|
||||
@@ -339,7 +462,7 @@ class ClassProgressQueryService
|
||||
|
||||
return in_array(
|
||||
(int) $report->class_section_id,
|
||||
TeacherClass::distinctSectionIdsForTeacher((int) $user->id),
|
||||
TeacherClass::distinctAccessibleSectionIdsForTeacher((int) $user->id),
|
||||
true
|
||||
);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user