fix teacher and parent routes

This commit is contained in:
root
2026-04-24 02:12:01 -04:00
parent 5128c74892
commit 7216cb2885
36 changed files with 1575 additions and 49 deletions
@@ -115,7 +115,7 @@ class ClassPreparationCalculatorService
$schoolYear = $schoolYear ?: (string) Configuration::getConfig('school_year');
$baseQuery = DB::table('teacher_class')
->select('COUNT(*) AS cnt')
->selectRaw('COUNT(*) AS cnt')
->where('class_section_id', $classSectionId)
->whereIn('position', ['main', 'ta']);
@@ -52,12 +52,12 @@ class ParentAttendanceReportCalendarService
$rows = DB::table('calendar_events')
->select('date')
->where('no_school', 1)
->groupStart()
->where('school_year', $schoolYear)
->orWhere('school_year IS NULL', null, false)
->groupEnd()
->where('date >=', $rangeStartStr)
->where('date <=', $rangeEndStr)
->where(function ($query) use ($schoolYear) {
$query->where('school_year', $schoolYear)
->orWhereNull('school_year');
})
->where('date', '>=', $rangeStartStr)
->where('date', '<=', $rangeEndStr)
->get()
->toArray();
+31
View File
@@ -5,6 +5,7 @@ namespace App\Services\Scores;
use App\Models\GradingLock;
use App\Models\MissingScoreOverride;
use App\Models\Student;
use App\Models\TeacherClass;
use Illuminate\Support\Facades\DB;
class ExamScoreService
@@ -13,6 +14,36 @@ class ExamScoreService
{
}
public function resolveClassSectionIdForTeacher(int $teacherId, ?int $requestedClassSectionId, ?string $schoolYearInput): ?int
{
if ($teacherId <= 0) {
return null;
}
$schoolYear = $this->term->schoolYear($schoolYearInput);
$query = TeacherClass::query()->where('teacher_id', $teacherId);
if ($schoolYear !== '') {
$query->where('school_year', $schoolYear);
}
$allowedIds = $query->pluck('class_section_id')
->map(fn ($v) => (int) $v)
->filter(fn ($v) => $v > 0)
->unique()
->values()
->all();
if ($allowedIds === []) {
return null;
}
if ($requestedClassSectionId !== null && $requestedClassSectionId > 0 && in_array($requestedClassSectionId, $allowedIds, true)) {
return $requestedClassSectionId;
}
return $allowedIds[0];
}
public function list(string $table, int $classSectionId, ?string $semester, ?string $schoolYear): array
{
$semester = $this->term->semesterLabel($semester);
@@ -7,6 +7,7 @@ use App\Models\Homework;
use App\Models\MissingScoreOverride;
use App\Models\Student;
use App\Models\StudentClass;
use App\Models\TeacherClass;
class HomeworkScoreService
{
@@ -14,6 +15,40 @@ class HomeworkScoreService
{
}
/**
* When the client omits class_section_id (legacy teacher portal), use the teacher's assignment
* for the requested school year, same idea as ScoreDashboardService::overview.
*/
public function resolveClassSectionIdForTeacher(int $teacherId, ?int $requestedClassSectionId, ?string $schoolYearInput): ?int
{
if ($teacherId <= 0) {
return null;
}
$schoolYear = $this->term->schoolYear($schoolYearInput);
$query = TeacherClass::query()->where('teacher_id', $teacherId);
if ($schoolYear !== '') {
$query->where('school_year', $schoolYear);
}
$allowedIds = $query->pluck('class_section_id')
->map(fn ($v) => (int) $v)
->filter(fn ($v) => $v > 0)
->unique()
->values()
->all();
if ($allowedIds === []) {
return null;
}
if ($requestedClassSectionId !== null && $requestedClassSectionId > 0 && in_array($requestedClassSectionId, $allowedIds, true)) {
return $requestedClassSectionId;
}
return $allowedIds[0];
}
public function list(int $classSectionId, ?string $semester, ?string $schoolYear): array
{
$semester = $this->term->semesterLabel($semester);
@@ -7,6 +7,7 @@ use App\Models\MissingScoreOverride;
use App\Models\Participation;
use App\Models\Student;
use App\Models\StudentClass;
use App\Models\TeacherClass;
class ParticipationScoreService
{
@@ -14,6 +15,36 @@ class ParticipationScoreService
{
}
public function resolveClassSectionIdForTeacher(int $teacherId, ?int $requestedClassSectionId, ?string $schoolYearInput): ?int
{
if ($teacherId <= 0) {
return null;
}
$schoolYear = $this->term->schoolYear($schoolYearInput);
$query = TeacherClass::query()->where('teacher_id', $teacherId);
if ($schoolYear !== '') {
$query->where('school_year', $schoolYear);
}
$allowedIds = $query->pluck('class_section_id')
->map(fn ($v) => (int) $v)
->filter(fn ($v) => $v > 0)
->unique()
->values()
->all();
if ($allowedIds === []) {
return null;
}
if ($requestedClassSectionId !== null && $requestedClassSectionId > 0 && in_array($requestedClassSectionId, $allowedIds, true)) {
return $requestedClassSectionId;
}
return $allowedIds[0];
}
public function list(int $classSectionId, ?string $semester, ?string $schoolYear): array
{
$semester = $this->term->semesterLabel($semester);
@@ -7,6 +7,7 @@ use App\Models\MissingScoreOverride;
use App\Models\Project;
use App\Models\Student;
use App\Models\StudentClass;
use App\Models\TeacherClass;
use Illuminate\Support\Facades\DB;
class ProjectScoreService
@@ -15,6 +16,36 @@ class ProjectScoreService
{
}
public function resolveClassSectionIdForTeacher(int $teacherId, ?int $requestedClassSectionId, ?string $schoolYearInput): ?int
{
if ($teacherId <= 0) {
return null;
}
$schoolYear = $this->term->schoolYear($schoolYearInput);
$query = TeacherClass::query()->where('teacher_id', $teacherId);
if ($schoolYear !== '') {
$query->where('school_year', $schoolYear);
}
$allowedIds = $query->pluck('class_section_id')
->map(fn ($v) => (int) $v)
->filter(fn ($v) => $v > 0)
->unique()
->values()
->all();
if ($allowedIds === []) {
return null;
}
if ($requestedClassSectionId !== null && $requestedClassSectionId > 0 && in_array($requestedClassSectionId, $allowedIds, true)) {
return $requestedClassSectionId;
}
return $allowedIds[0];
}
public function list(int $classSectionId, ?string $semester, ?string $schoolYear): array
{
$semester = $this->term->semesterLabel($semester);
+31
View File
@@ -7,6 +7,7 @@ use App\Models\MissingScoreOverride;
use App\Models\Quiz;
use App\Models\Student;
use App\Models\StudentClass;
use App\Models\TeacherClass;
class QuizScoreService
{
@@ -14,6 +15,36 @@ class QuizScoreService
{
}
public function resolveClassSectionIdForTeacher(int $teacherId, ?int $requestedClassSectionId, ?string $schoolYearInput): ?int
{
if ($teacherId <= 0) {
return null;
}
$schoolYear = $this->term->schoolYear($schoolYearInput);
$query = TeacherClass::query()->where('teacher_id', $teacherId);
if ($schoolYear !== '') {
$query->where('school_year', $schoolYear);
}
$allowedIds = $query->pluck('class_section_id')
->map(fn ($v) => (int) $v)
->filter(fn ($v) => $v > 0)
->unique()
->values()
->all();
if ($allowedIds === []) {
return null;
}
if ($requestedClassSectionId !== null && $requestedClassSectionId > 0 && in_array($requestedClassSectionId, $allowedIds, true)) {
return $requestedClassSectionId;
}
return $allowedIds[0];
}
public function list(int $classSectionId, ?string $semester, ?string $schoolYear): array
{
$semester = $this->term->semesterLabel($semester);