diff --git a/app/Controllers/View/AssignmentController.php b/app/Controllers/View/AssignmentController.php index 27af370..e8b7d80 100644 --- a/app/Controllers/View/AssignmentController.php +++ b/app/Controllers/View/AssignmentController.php @@ -9,6 +9,7 @@ use App\Models\StudentModel; use App\Models\TeacherModel; use App\Models\ClassSectionModel; use App\Models\ConfigurationModel; +use App\Support\Enrollment\EnrollmentEligibility; use Config\Database; class AssignmentController extends BaseController @@ -177,11 +178,13 @@ class AssignmentController extends BaseController continue; } + $calculatedAge = EnrollmentEligibility::ageOnSeptemberFirst($student['dob'] ?? null, $year); + $students[] = [ 'id' => (int)$student['id'], 'firstname' => esc($student['firstname']), 'lastname' => esc($student['lastname']), - 'age' => esc($student['age']), + 'age' => esc((string)($calculatedAge ?? ($student['age'] ?? ''))), 'gender' => esc($student['gender']), 'registration_grade' => esc($student['registration_grade']), 'photo_consent' => esc($student['photo_consent'] ? 'Yes' : 'No'), diff --git a/app/Controllers/View/NavBuilderController.php b/app/Controllers/View/NavBuilderController.php index 283fa0a..6375008 100644 --- a/app/Controllers/View/NavBuilderController.php +++ b/app/Controllers/View/NavBuilderController.php @@ -391,7 +391,7 @@ public function save() } unset($node); - $this->sortTreeByOrder($tree); + $this->sortTreeAlpha($tree); $flatAlpha = $all; usort($flatAlpha, fn($a, $b) => strnatcasecmp( diff --git a/app/Services/NavbarService.php b/app/Services/NavbarService.php index ede7593..0030c01 100644 --- a/app/Services/NavbarService.php +++ b/app/Services/NavbarService.php @@ -29,7 +29,9 @@ class NavbarService $allowedIds = $this->mapModel->getNavItemIdsForRoles($roles); if (empty($allowedIds)) return []; - // Load all enabled items, then filter. The builder controls this order. + // Load all enabled items, then filter. + // The displayed sidebar is alphabetized after the tree is built so + // new menu items fall into place without relying on manual sort_order. $rows = $this->navModel->where('is_enabled', 1) ->orderBy('sort_order', 'ASC') ->orderBy('label', 'ASC') @@ -57,34 +59,22 @@ class NavbarService } unset($node); - $this->sortTreeByOrder($tree); + $this->sortTreeAlphabetically($tree); $this->cache->save($cacheKey, $tree, 300); // 5 minutes return $tree; } - private function sortTreeByOrder(array &$nodes): void + private function sortTreeAlphabetically(array &$nodes): void { - usort($nodes, function ($a, $b) { - $order = ((int) ($a['sort_order'] ?? 0)) <=> ((int) ($b['sort_order'] ?? 0)); - if ($order !== 0) { - return $order; - } - - $label = strnatcasecmp( - $this->labelSortKey((string) ($a['label'] ?? '')), - $this->labelSortKey((string) ($b['label'] ?? '')) - ); - if ($label !== 0) { - return $label; - } - - return ((int) ($a['id'] ?? 0)) <=> ((int) ($b['id'] ?? 0)); - }); + usort($nodes, fn ($a, $b) => strnatcasecmp( + $this->labelSortKey((string) ($a['label'] ?? '')), + $this->labelSortKey((string) ($b['label'] ?? '')) + )); foreach ($nodes as &$node) { if (!empty($node['children']) && is_array($node['children'])) { - $this->sortTreeByOrder($node['children']); + $this->sortTreeAlphabetically($node['children']); } } unset($node);