fix navbar and age mismatch
Deploy to Shared Hosting / Shared hosting deploy (push) Failing after 2m15s
Tests / PHPUnit (push) Successful in 2m23s

This commit is contained in:
root
2026-09-07 18:06:37 -04:00
parent ede7fd947a
commit 2d5b151234
3 changed files with 15 additions and 22 deletions
@@ -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'),
@@ -391,7 +391,7 @@ public function save()
}
unset($node);
$this->sortTreeByOrder($tree);
$this->sortTreeAlpha($tree);
$flatAlpha = $all;
usort($flatAlpha, fn($a, $b) => strnatcasecmp(
+10 -20
View File
@@ -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);