fix financial and certificates
This commit is contained in:
@@ -43,7 +43,11 @@ class NavBuilderService
|
||||
$this->sortTreeAlpha($tree);
|
||||
|
||||
$flatAlpha = $all;
|
||||
usort($flatAlpha, fn ($a, $b) => strnatcasecmp($this->labelKey($a['label'] ?? ''), $this->labelKey($b['label'] ?? '')));
|
||||
usort($flatAlpha, function ($a, $b) {
|
||||
$result = strnatcasecmp($this->labelKey($a['label'] ?? ''), $this->labelKey($b['label'] ?? ''));
|
||||
|
||||
return $result !== 0 ? $result : ((int) ($a['id'] ?? 0) <=> (int) ($b['id'] ?? 0));
|
||||
});
|
||||
|
||||
$roleAssignments = $this->buildRoleAssignments();
|
||||
$flattened = $this->flattenTreeForResponse($tree, $roleAssignments);
|
||||
@@ -109,6 +113,8 @@ class NavBuilderService
|
||||
'nav_item_id' => $navItemId,
|
||||
]);
|
||||
}
|
||||
|
||||
$this->normalizeSortOrdersAlphabetically();
|
||||
});
|
||||
|
||||
$this->navbarService->clearCache();
|
||||
@@ -118,7 +124,16 @@ class NavBuilderService
|
||||
|
||||
public function delete(int $id): bool
|
||||
{
|
||||
$deleted = (bool) NavItem::query()->whereKey($id)->delete();
|
||||
$deleted = false;
|
||||
|
||||
DB::transaction(function () use ($id, &$deleted): void {
|
||||
$deleted = (bool) NavItem::query()->whereKey($id)->delete();
|
||||
|
||||
if ($deleted) {
|
||||
$this->normalizeSortOrdersAlphabetically();
|
||||
}
|
||||
});
|
||||
|
||||
$this->navbarService->clearCache();
|
||||
|
||||
return $deleted;
|
||||
@@ -126,15 +141,39 @@ class NavBuilderService
|
||||
|
||||
public function reorder(array $orders): void
|
||||
{
|
||||
DB::transaction(function () use ($orders): void {
|
||||
foreach ($orders as $id => $order) {
|
||||
NavItem::query()->whereKey((int) $id)->update(['sort_order' => (int) $order]);
|
||||
}
|
||||
DB::transaction(function (): void {
|
||||
$this->normalizeSortOrdersAlphabetically();
|
||||
});
|
||||
|
||||
$this->navbarService->clearCache();
|
||||
}
|
||||
|
||||
private function normalizeSortOrdersAlphabetically(): void
|
||||
{
|
||||
$rows = NavItem::query()
|
||||
->select(['id', 'menu_parent_id', 'label'])
|
||||
->orderBy('menu_parent_id', 'asc')
|
||||
->orderBy('label', 'asc')
|
||||
->orderBy('id', 'asc')
|
||||
->get()
|
||||
->groupBy(fn ($row) => $row->menu_parent_id === null ? 'root' : (string) $row->menu_parent_id);
|
||||
|
||||
foreach ($rows as $siblings) {
|
||||
$ordered = $siblings->values()->all();
|
||||
usort($ordered, function ($a, $b) {
|
||||
$result = strnatcasecmp($this->labelKey((string) ($a->label ?? '')), $this->labelKey((string) ($b->label ?? '')));
|
||||
|
||||
return $result !== 0 ? $result : ((int) $a->id <=> (int) $b->id);
|
||||
});
|
||||
|
||||
foreach ($ordered as $index => $item) {
|
||||
NavItem::query()
|
||||
->whereKey((int) $item->id)
|
||||
->update(['sort_order' => ($index + 1) * 10]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private function buildRoleAssignments(): array
|
||||
{
|
||||
$rows = RoleNavItem::query()
|
||||
@@ -205,7 +244,11 @@ class NavBuilderService
|
||||
|
||||
private function sortTreeAlpha(array &$nodes): void
|
||||
{
|
||||
usort($nodes, fn ($a, $b) => strnatcasecmp($this->labelKey($a['label'] ?? ''), $this->labelKey($b['label'] ?? '')));
|
||||
usort($nodes, function ($a, $b) {
|
||||
$result = strnatcasecmp($this->labelKey($a['label'] ?? ''), $this->labelKey($b['label'] ?? ''));
|
||||
|
||||
return $result !== 0 ? $result : ((int) ($a['id'] ?? 0) <=> (int) ($b['id'] ?? 0));
|
||||
});
|
||||
foreach ($nodes as &$node) {
|
||||
if (!empty($node['children'])) {
|
||||
$this->sortTreeAlpha($node['children']);
|
||||
|
||||
Reference in New Issue
Block a user