This commit is contained in:
2026-07-12 19:21:35 +02:00
parent f2d944b117
commit 41cb412cb0
49 changed files with 3170 additions and 52 deletions
+6 -3
View File
@@ -60,15 +60,17 @@ class CategoryModel extends Model
$indent = "\u{00A0}\u{00A0}\u{00A0}\u{00A0}"; // 4x twarda spacja na poziom
$out = [];
$walk = static function (int $parentId, int $depth) use (&$walk, &$out, $childrenByParent, $indent): void {
$walk = static function (int $parentId, int $depth, string $parentPath) use (&$walk, &$out, $childrenByParent, $indent): void {
foreach ($childrenByParent[$parentId] ?? [] as $c) {
$c['depth'] = $depth;
$c['indent_label'] = str_repeat($indent, $depth) . $c['name'];
// Pelna sciezka "Nadrzedna → Podrzedna" — jednoznaczna nawet gdy JS uciasnie wciecia.
$c['path_label'] = $parentPath === '' ? $c['name'] : $parentPath . ' → ' . $c['name'];
$out[] = $c;
$walk((int) $c['id'], $depth + 1);
$walk((int) $c['id'], $depth + 1, $c['path_label']);
}
};
$walk(0, 0);
$walk(0, 0, '');
// Sieroty (np. rodzic odfiltrowany typem) — dopnij na koncu bez wciecia
$seen = array_column($out, null, 'id');
@@ -76,6 +78,7 @@ class CategoryModel extends Model
if (! isset($seen[$c['id']])) {
$c['depth'] = 0;
$c['indent_label'] = $c['name'];
$c['path_label'] = $c['name'];
$out[] = $c;
}
}