partial fix for teacher class progress
API CI/CD / Validate (composer + pint) (push) Successful in 3m9s
API CI/CD / Test (PHPUnit) (push) Failing after 5m6s
API CI/CD / Build frontend assets (push) Successful in 1m2s
API CI/CD / Security audit (push) Failing after 49s
API CI/CD / Deploy to shared hosting (PHP) (push) Has been skipped
API CI/CD / Validate (composer + pint) (push) Successful in 3m9s
API CI/CD / Test (PHPUnit) (push) Failing after 5m6s
API CI/CD / Build frontend assets (push) Successful in 1m2s
API CI/CD / Security audit (push) Failing after 49s
API CI/CD / Deploy to shared hosting (PHP) (push) Has been skipped
This commit is contained in:
@@ -59,15 +59,23 @@ class ClassProgressController extends BaseApiController
|
||||
return $auth;
|
||||
}
|
||||
|
||||
$schoolYear = (string) (Configuration::getConfig('school_year') ?? '');
|
||||
$semester = (string) (Configuration::getConfig('semester') ?? '');
|
||||
$schoolYear = trim((string) $request->query('school_year', Configuration::getConfig('school_year') ?? ''));
|
||||
$semester = trim((string) $request->query('semester', Configuration::getConfig('semester') ?? ''));
|
||||
$assignments = $this->queryService->teacherAssignments($auth, $schoolYear, $semester);
|
||||
|
||||
$requestedClassId = (int) ($request->validated('class_id') ?? 0);
|
||||
$activeClassId = $requestedClassId > 0 ? $requestedClassId : (int) ($assignments[0]['class_id'] ?? 0);
|
||||
$requestedClassSectionId = (int) $request->query('class_section_id', 0);
|
||||
$requestedAssignment = $requestedClassSectionId > 0
|
||||
? collect($assignments)->first(
|
||||
fn (array $assignment) => (int) ($assignment['class_section_id'] ?? 0) === $requestedClassSectionId
|
||||
)
|
||||
: null;
|
||||
$activeClassId = $requestedClassId > 0
|
||||
? $requestedClassId
|
||||
: (int) (($requestedAssignment['class_id'] ?? null) ?: ($assignments[0]['class_id'] ?? 0));
|
||||
$activeAssignment = collect($assignments)->first(
|
||||
fn (array $assignment) => (int) ($assignment['class_id'] ?? 0) === $activeClassId
|
||||
) ?? ($assignments[0] ?? []);
|
||||
) ?? $requestedAssignment ?? ($assignments[0] ?? []);
|
||||
$sundayCount = (int) ($request->validated('sunday_count') ?? 12);
|
||||
$payload = $this->buildMetaPayload($activeClassId > 0 ? $activeClassId : null, $sundayCount, $schoolYear, $semester);
|
||||
$payload['classes'] = $assignments;
|
||||
@@ -294,6 +302,7 @@ class ClassProgressController extends BaseApiController
|
||||
'status_options' => $this->metaService->statusOptions(),
|
||||
'sunday_options' => $this->metaService->sundayOptionsAlignedWithCi($sundayCount),
|
||||
'curriculum' => $this->metaService->curriculumOptions($classId, $meta['school_year'] ?? null),
|
||||
'unit_options' => $this->metaService->unitOptions($classId, $meta['school_year'] ?? null),
|
||||
'meta' => $meta,
|
||||
];
|
||||
}
|
||||
|
||||
@@ -10,7 +10,7 @@ class SubjectCurriculum extends BaseModel
|
||||
{
|
||||
protected $table = 'subject_curriculum_items';
|
||||
|
||||
protected $fillable = ['class_id', 'subject', 'unit_number', 'unit_title', 'chapter_name', 'created_at', 'updated_at'];
|
||||
protected $fillable = ['class_id', 'school_year', 'subject', 'unit_number', 'unit_title', 'chapter_name', 'created_at', 'updated_at'];
|
||||
|
||||
public $timestamps = true;
|
||||
|
||||
@@ -54,7 +54,11 @@ class SubjectCurriculum extends BaseModel
|
||||
return $q;
|
||||
}
|
||||
|
||||
return $q->where('school_year', $schoolYear);
|
||||
return $q->where(function (Builder $yearQuery) use ($schoolYear) {
|
||||
$yearQuery->where('school_year', $schoolYear)
|
||||
->orWhereNull('school_year')
|
||||
->orWhere('school_year', '');
|
||||
});
|
||||
}
|
||||
|
||||
public function scopeOrdered(Builder $q): Builder
|
||||
|
||||
@@ -151,4 +151,51 @@ class ClassProgressMetaService
|
||||
|
||||
return $options;
|
||||
}
|
||||
|
||||
public function unitOptions(?int $classId, ?string $schoolYear = null): array
|
||||
{
|
||||
$curriculum = $this->curriculumOptions($classId, $schoolYear);
|
||||
$units = [];
|
||||
|
||||
foreach ($curriculum as $slug => $rows) {
|
||||
$seen = [];
|
||||
$units[$slug] = [];
|
||||
|
||||
foreach ($rows as $row) {
|
||||
$unitNumber = $row->unit_number ?? null;
|
||||
$unitTitle = trim((string) ($row->unit_title ?? ''));
|
||||
|
||||
if ($unitNumber === null && $unitTitle === '') {
|
||||
continue;
|
||||
}
|
||||
|
||||
$key = ((string) $unitNumber).'|'.$unitTitle;
|
||||
if (isset($seen[$key])) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$seen[$key] = true;
|
||||
$units[$slug][] = [
|
||||
'unit_number' => $unitNumber !== null ? (int) $unitNumber : null,
|
||||
'unit_title' => $unitTitle,
|
||||
'label' => $this->formatUnitLabel($unitNumber !== null ? (int) $unitNumber : null, $unitTitle),
|
||||
];
|
||||
}
|
||||
}
|
||||
|
||||
return $units;
|
||||
}
|
||||
|
||||
private function formatUnitLabel(?int $unitNumber, string $unitTitle): string
|
||||
{
|
||||
if ($unitNumber !== null && $unitTitle !== '') {
|
||||
return 'Unit '.$unitNumber.' - '.$unitTitle;
|
||||
}
|
||||
|
||||
if ($unitNumber !== null) {
|
||||
return 'Unit '.$unitNumber;
|
||||
}
|
||||
|
||||
return $unitTitle;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user