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
+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);