diff --git a/app/Controllers/ParentProgressController.php b/app/Controllers/ParentProgressController.php index e32aede..de6f577 100644 --- a/app/Controllers/ParentProgressController.php +++ b/app/Controllers/ParentProgressController.php @@ -29,18 +29,12 @@ class ParentProgressController extends BaseController public function index() { - $sectionIds = $this->getParentSectionIds(); - $sectionOptions = $this->buildSectionOptions($sectionIds); + $students = $this->getParentStudents(); + $sectionIds = array_values(array_unique(array_filter(array_map( + static fn (array $student): int => (int) ($student['class_section_id'] ?? 0), + $students + )))); $subjectSections = ClassProgressController::SUBJECT_SECTIONS; - $selectedSectionId = (int) $this->request->getGet('class_section_id'); - $validSectionIds = array_keys($sectionOptions); - - if ($selectedSectionId === 0 && ! empty($validSectionIds)) { - $selectedSectionId = $validSectionIds[0]; - } - if ($selectedSectionId && ! in_array($selectedSectionId, $validSectionIds, true)) { - $selectedSectionId = $validSectionIds[0] ?? null; - } $rows = []; if (! empty($sectionIds)) { @@ -50,23 +44,32 @@ class ParentProgressController extends BaseController ->join('users u', 'u.id = class_progress_reports.teacher_id', 'left') ->whereIn('class_progress_reports.class_section_id', $sectionIds); - if ($selectedSectionId) { - $builder->where('class_progress_reports.class_section_id', $selectedSectionId); - } - $rows = $builder ->orderBy('week_start', 'DESC') ->findAll(); } - $reportGroups = $this->groupReportsByWeek($rows); + $studentReportGroups = []; + foreach ($students as $student) { + $studentId = (int) ($student['student_id'] ?? 0); + if ($studentId === 0) { + continue; + } + $classSectionId = (int) ($student['class_section_id'] ?? 0); + $studentRows = $classSectionId + ? array_values(array_filter( + $rows, + static fn (array $row): bool => (int) ($row['class_section_id'] ?? 0) === $classSectionId + )) + : []; + $studentReportGroups[$studentId] = $this->groupReportsByWeek($studentRows); + } return view('parent/class_progress_list', [ - 'reportGroups' => $reportGroups, + 'students' => $students, + 'studentReportGroups' => $studentReportGroups, 'subjectSections' => $subjectSections, - 'classSectionOptions' => $sectionOptions, - 'selectedSectionId' => $selectedSectionId, - 'hasSections' => ! empty($sectionIds), + 'hasStudents' => ! empty($students), ]); } @@ -198,20 +201,53 @@ class ParentProgressController extends BaseController return $options; } + protected function getParentStudents(): array + { + $parentId = (int) session()->get('user_id'); + if ($parentId === 0) { + return []; + } + + $rows = $this->db->table('enrollments e') + ->select('e.student_id, e.class_section_id, e.updated_at, e.created_at, s.firstname, s.lastname, cs.class_section_name') + ->join('students s', 's.id = e.student_id') + ->join('classSection cs', 'cs.class_section_id = e.class_section_id', 'left') + ->where('e.parent_id', $parentId) + ->where('e.is_withdrawn', 0) + ->orderBy('e.updated_at', 'DESC') + ->orderBy('e.created_at', 'DESC') + ->get() + ->getResultArray(); + + $students = []; + foreach ($rows as $row) { + $studentId = (int) ($row['student_id'] ?? 0); + if ($studentId === 0 || isset($students[$studentId])) { + continue; + } + $students[$studentId] = $row; + } + + return array_values($students); + } + protected function groupReportsByWeek(array $rows): array { $reportGroups = []; foreach ($rows as $row) { $row['status_label'] = ClassProgressController::STATUS_OPTIONS[$row['status']] ?? 'Unknown'; - $key = $row['week_start'] ?? ''; - if ($key === '') { + $weekStart = $row['week_start'] ?? ''; + $sectionId = (int) ($row['class_section_id'] ?? 0); + if ($weekStart === '' || $sectionId === 0) { continue; } + $key = $weekStart . ':' . $sectionId; if (! isset($reportGroups[$key])) { $reportGroups[$key] = [ 'week_start' => $row['week_start'] ?? '', 'week_end' => $row['week_end'] ?? '', 'class_section_name' => $row['class_section_name'] ?? '', + 'class_section_id' => $sectionId, 'reports' => [], ]; } diff --git a/app/Views/parent/class_progress_list.php b/app/Views/parent/class_progress_list.php index 4baba69..de73821 100644 --- a/app/Views/parent/class_progress_list.php +++ b/app/Views/parent/class_progress_list.php @@ -7,79 +7,105 @@
Review the weekly reports your child’s teachers submit.
- Reports are grouped by Sunday; click any row to read the full details. + Reports are grouped by student; click a name to expand weekly details.
- +
We couldn’t find any current enrollment for your account. Once your child is assigned to a Sunday class, their teacher’s progress reports will appear here.
- -
No reports submitted yet.
- -
-
- - - - - - - - - - - - - - - - - - -
WeekSubjectsDetails
-
- -
Class:
- -
-
- $section): ?> - -
-
- - -
-
- -
-
- -
-
- - View Weekly Details - -
-
+ +
+ $student): ?> + +
+

+ +

+
+
+ +
No reports submitted yet.
+ +
+ + + + + + + + + + + + + + + + + + +
WeekSubjectsDetails
+
+
+
+ $section): ?> + +
+
+ + +
+
+ +
+
+ +
+
+ + View Weekly Details + +
+
+ +
+
+
+
diff --git a/app/Views/rolepermission/assign_role.php b/app/Views/rolepermission/assign_role.php index 9c295fa..af8e1a9 100644 --- a/app/Views/rolepermission/assign_role.php +++ b/app/Views/rolepermission/assign_role.php @@ -250,6 +250,30 @@ modalInstance.show(); }; + const renderNameCell = (user) => { + const td = document.createElement('td'); + const fullName = `${user?.firstname ?? ''} ${user?.lastname ?? ''}`.trim(); + const label = fullName !== '' ? fullName : '—'; + const roleList = Array.isArray(user?.roles) + ? user.roles.map((role) => (role || '').toString().toLowerCase()) + : []; + const isParent = roleList.includes('parent'); + const uid = Number(user?.id || 0); + + if (isParent && uid > 0) { + const link = document.createElement('a'); + link.href = '#'; + link.className = 'text-decoration-none'; + link.setAttribute('data-family-guardian-id', String(uid)); + link.textContent = label; + td.appendChild(link); + return td; + } + + td.textContent = label; + return td; + }; + const renderTable = () => { if (!tableBody) return; @@ -280,9 +304,7 @@ accountCell.textContent = user.account_id ?? ''; row.appendChild(accountCell); - const nameCell = document.createElement('td'); - nameCell.textContent = `${user.firstname ?? ''} ${user.lastname ?? ''}`.trim(); - row.appendChild(nameCell); + row.appendChild(renderNameCell(user)); const emailCell = document.createElement('td'); emailCell.textContent = user.email ?? '';