fix navbar and age mismatch
This commit is contained in:
@@ -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(
|
||||
|
||||
@@ -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);
|
||||
|
||||
Reference in New Issue
Block a user