This commit is contained in:
@@ -39,7 +39,13 @@ class AdminProgressController extends BaseController
|
||||
|
||||
public function index()
|
||||
{
|
||||
$schoolYear = trim((string) ($this->request->getGet('school_year') ?? ''));
|
||||
if ($schoolYear === '') {
|
||||
$schoolYear = $this->currentSchoolYearName((string) ($this->configModel->getConfig('school_year') ?? ''));
|
||||
}
|
||||
|
||||
$filters = [
|
||||
'school_year' => $schoolYear,
|
||||
'from' => (string) $this->request->getGet('from'),
|
||||
'to' => (string) $this->request->getGet('to'),
|
||||
'class_section_id' => (string) $this->request->getGet('class_section_id'),
|
||||
@@ -51,6 +57,8 @@ class AdminProgressController extends BaseController
|
||||
->join('classSection cs', 'cs.class_section_id = class_progress_reports.class_section_id', 'left')
|
||||
->join('users u', 'u.id = class_progress_reports.teacher_id', 'left');
|
||||
|
||||
$this->applyProgressSchoolYearScope($builder, $schoolYear);
|
||||
|
||||
if ($filters['from']) {
|
||||
$builder->where('week_start >=', $filters['from']);
|
||||
}
|
||||
@@ -91,16 +99,17 @@ class AdminProgressController extends BaseController
|
||||
$reportGroupsBySection[$sectionId] = $groups;
|
||||
}
|
||||
|
||||
$classSections = $this->classSectionModel->getClassSections();
|
||||
$studentCounts = $this->studentClassModel->getStudentCountsBySection();
|
||||
$filteredSections = array_values(array_filter($classSections, function ($section) use ($studentCounts) {
|
||||
$classSections = $this->classSectionsForYear($schoolYear, $rows);
|
||||
$studentCounts = $this->studentClassModel->getStudentCountsBySection($schoolYear !== '' ? $schoolYear : null);
|
||||
$filteredSections = array_values(array_filter($classSections, function ($section) use ($studentCounts, $reportGroupsBySection) {
|
||||
$sectionId = (int) ($section['class_section_id'] ?? 0);
|
||||
return isset($studentCounts[$sectionId]) && $studentCounts[$sectionId] > 0;
|
||||
return (isset($studentCounts[$sectionId]) && $studentCounts[$sectionId] > 0)
|
||||
|| isset($reportGroupsBySection[$sectionId]);
|
||||
}));
|
||||
|
||||
$filterStart = $this->normalizeDate($filters['from'] ?? '');
|
||||
$filterEnd = $this->normalizeDate($filters['to'] ?? '');
|
||||
[$dateList, $noSchoolDays, $totalPassedDays, $passedDatesSet] = $this->buildSemesterDates();
|
||||
[$dateList, $noSchoolDays, $totalPassedDays, $passedDatesSet] = $this->buildSemesterDates($schoolYear);
|
||||
[$expectedDays, $activeDatesSet] = $this->resolveExpectedDays(
|
||||
$dateList,
|
||||
$noSchoolDays,
|
||||
@@ -132,6 +141,8 @@ class AdminProgressController extends BaseController
|
||||
return view('admin/class_progress_list', [
|
||||
'reportGroupsBySection' => $reportGroupsBySection,
|
||||
'filters' => $filters,
|
||||
'schoolYear' => $schoolYear,
|
||||
'schoolYears' => $this->availableSchoolYears($schoolYear),
|
||||
'classSections' => $filteredSections,
|
||||
'statusOptions' => ClassProgressController::STATUS_OPTIONS,
|
||||
'subjectSections' => ClassProgressController::SUBJECT_SECTIONS,
|
||||
@@ -142,6 +153,162 @@ class AdminProgressController extends BaseController
|
||||
]);
|
||||
}
|
||||
|
||||
private function classSectionsForYear(string $schoolYear, array $reportRows = []): array
|
||||
{
|
||||
$db = db_connect();
|
||||
|
||||
if ($schoolYear !== '' && $db->fieldExists('school_year', 'classSection')) {
|
||||
$sections = $db->table('classSection')
|
||||
->select('classSection.class_section_id, classSection.class_section_name, classes.class_name')
|
||||
->join('classes', 'classSection.class_id = classes.id', 'left')
|
||||
->where('classSection.school_year', $schoolYear)
|
||||
->orderBy('classSection.class_section_name', 'ASC')
|
||||
->get()
|
||||
->getResultArray();
|
||||
} else {
|
||||
$sections = $this->classSectionModel->getClassSections();
|
||||
}
|
||||
|
||||
$sectionsById = [];
|
||||
foreach ($sections as $section) {
|
||||
$sectionId = (int) ($section['class_section_id'] ?? 0);
|
||||
if ($sectionId > 0) {
|
||||
$sectionsById[$sectionId] = $section;
|
||||
}
|
||||
}
|
||||
|
||||
foreach ($reportRows as $row) {
|
||||
$sectionId = (int) ($row['class_section_id'] ?? 0);
|
||||
if ($sectionId <= 0 || isset($sectionsById[$sectionId])) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$sectionsById[$sectionId] = [
|
||||
'class_section_id' => $sectionId,
|
||||
'class_section_name' => (string) ($row['class_section_name'] ?? ('Section #' . $sectionId)),
|
||||
'class_name' => '',
|
||||
];
|
||||
}
|
||||
|
||||
uasort($sectionsById, static function (array $a, array $b): int {
|
||||
return strnatcasecmp((string) ($a['class_section_name'] ?? ''), (string) ($b['class_section_name'] ?? ''));
|
||||
});
|
||||
|
||||
return array_values($sectionsById);
|
||||
}
|
||||
|
||||
private function applyProgressSchoolYearScope($builder, string $schoolYear): void
|
||||
{
|
||||
if ($schoolYear === '') {
|
||||
return;
|
||||
}
|
||||
|
||||
$db = db_connect();
|
||||
$hasReportYear = $db->fieldExists('school_year', 'class_progress_reports');
|
||||
$hasSectionYear = $db->fieldExists('school_year', 'classSection');
|
||||
[$rangeStart, $rangeEnd] = $this->semesterRangeService->getSchoolYearRange($schoolYear);
|
||||
|
||||
if ($hasReportYear) {
|
||||
if ($this->hasAnyExplicitProgressSchoolYearRows()) {
|
||||
$builder->where('class_progress_reports.school_year', $schoolYear);
|
||||
return;
|
||||
}
|
||||
|
||||
if ($rangeStart !== '' && $rangeEnd !== '') {
|
||||
$builder
|
||||
->groupStart()
|
||||
->groupStart()
|
||||
->where('class_progress_reports.school_year IS NULL', null, false)
|
||||
->orWhere('class_progress_reports.school_year', '')
|
||||
->groupEnd()
|
||||
->where('class_progress_reports.week_start >=', $rangeStart)
|
||||
->where('class_progress_reports.week_start <=', $rangeEnd)
|
||||
->groupEnd();
|
||||
return;
|
||||
}
|
||||
|
||||
$builder->where('class_progress_reports.school_year', $schoolYear);
|
||||
return;
|
||||
}
|
||||
|
||||
if ($hasSectionYear) {
|
||||
$builder->where('cs.school_year', $schoolYear);
|
||||
return;
|
||||
}
|
||||
|
||||
if ($rangeStart !== '' && $rangeEnd !== '') {
|
||||
$builder
|
||||
->where('class_progress_reports.week_start >=', $rangeStart)
|
||||
->where('class_progress_reports.week_start <=', $rangeEnd);
|
||||
}
|
||||
}
|
||||
|
||||
private function hasAnyExplicitProgressSchoolYearRows(): bool
|
||||
{
|
||||
try {
|
||||
return db_connect()
|
||||
->table('class_progress_reports')
|
||||
->where('school_year IS NOT NULL', null, false)
|
||||
->where('school_year !=', '')
|
||||
->limit(1)
|
||||
->get()
|
||||
->getRowArray() !== null;
|
||||
} catch (\Throwable $e) {
|
||||
log_message('warning', 'Unable to check explicit progress school-year rows: {message}', [
|
||||
'message' => $e->getMessage(),
|
||||
]);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
private function availableSchoolYears(string $selectedYear): array
|
||||
{
|
||||
$years = [];
|
||||
$addYear = static function (mixed $value) use (&$years): void {
|
||||
$year = trim((string) $value);
|
||||
if ($year !== '' && ! in_array($year, $years, true)) {
|
||||
$years[] = $year;
|
||||
}
|
||||
};
|
||||
|
||||
$addYear($selectedYear);
|
||||
$addYear($this->currentSchoolYearName((string) ($this->configModel->getConfig('school_year') ?? '')));
|
||||
|
||||
$db = db_connect();
|
||||
foreach ([
|
||||
['table' => 'school_years', 'column' => 'name'],
|
||||
['table' => 'class_progress_reports', 'column' => 'school_year'],
|
||||
['table' => 'classSection', 'column' => 'school_year'],
|
||||
['table' => 'student_class', 'column' => 'school_year'],
|
||||
] as $source) {
|
||||
try {
|
||||
if (! $db->tableExists($source['table']) || ! $db->fieldExists($source['column'], $source['table'])) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$rows = $db->table($source['table'])
|
||||
->select($source['column'])
|
||||
->distinct()
|
||||
->where($source['column'] . ' IS NOT NULL', null, false)
|
||||
->orderBy($source['column'], 'DESC')
|
||||
->get()
|
||||
->getResultArray();
|
||||
|
||||
foreach ($rows as $row) {
|
||||
$addYear($row[$source['column']] ?? '');
|
||||
}
|
||||
} catch (\Throwable $e) {
|
||||
log_message('warning', 'Unable to load school-year options for admin progress: {message}', [
|
||||
'message' => $e->getMessage(),
|
||||
]);
|
||||
}
|
||||
}
|
||||
|
||||
rsort($years, SORT_NATURAL);
|
||||
|
||||
return $years;
|
||||
}
|
||||
|
||||
public function view($id)
|
||||
{
|
||||
$row = $this->reportModel
|
||||
@@ -277,11 +444,15 @@ class AdminProgressController extends BaseController
|
||||
return checkdate($m, $d, $y) ? $value : '';
|
||||
}
|
||||
|
||||
protected function buildSemesterDates(): array
|
||||
protected function buildSemesterDates(?string $schoolYear = null): array
|
||||
{
|
||||
$schoolYear = (string) ($this->configModel->getConfig('school_year') ?? '');
|
||||
$schoolYear = trim((string) ($schoolYear ?? ''));
|
||||
if ($schoolYear === '') {
|
||||
$schoolYear = $this->currentSchoolYearName((string) ($this->configModel->getConfig('school_year') ?? ''));
|
||||
}
|
||||
|
||||
$semester = (string) ($this->configModel->getConfig('semester') ?? '');
|
||||
$schoolYearForRange = $schoolYear !== '' ? $schoolYear : (string) ($this->configModel->getConfig('school_year') ?? '');
|
||||
$schoolYearForRange = $schoolYear !== '' ? $schoolYear : $this->currentSchoolYearName((string) ($this->configModel->getConfig('school_year') ?? ''));
|
||||
[$rangeStart, $rangeEnd] = $this->semesterRangeService->getSchoolYearRange($schoolYearForRange);
|
||||
$semesterNorm = $this->semesterRangeService->normalizeSemester($semester);
|
||||
if ($semesterNorm !== '' && $schoolYearForRange !== '') {
|
||||
|
||||
Reference in New Issue
Block a user