diff --git a/collections.sqlite b/collections.sqlite.backup similarity index 100% rename from collections.sqlite rename to collections.sqlite.backup diff --git a/config.php b/config.php index 4d615ad..ee13014 100755 --- a/config.php +++ b/config.php @@ -19,7 +19,6 @@ $loader = new \Twig\Loader\FilesystemLoader(__DIR__ . '/templates'); $twig = new \Twig\Environment($loader, [ // 'cache' => __DIR__ . '/cache/twig', // Uncomment for production 'debug' => true, - 'max_recursion' => 100, ]); // --- Translation Setup --- diff --git a/public/index.php b/public/index.php index 668c535..624f94e 100755 --- a/public/index.php +++ b/public/index.php @@ -44,6 +44,59 @@ $router->addRoute('GET', '/api/categories', [CategoryController::class, 'listCat $router->addRoute('GET', '/api/categories/list', [CategoryController::class, 'listCategoriesJson']); $router->addRoute('GET', '/api/categories/{id}', [CategoryController::class, 'getCategory']); $router->addRoute('GET', '/api/parts', [ItemController::class, 'renderAddForm']); +$router->addRoute('GET', '/api/tree', function() { + try { + $db = App\Database\Database::getInstance(); + $categories = App\Models\Category::getAll($db); + + function build_category_tree($categories, $parentId = null, &$visited = [], $depth = 0, &$nodeCount = 0) { + if ($depth > 5 || $nodeCount > 100) return []; + $tree = []; + foreach ($categories as $cat) { + if ($cat['parent_id'] == $parentId && !in_array($cat['id'], $visited)) { + $visited[] = $cat['id']; + $node = [ + 'id' => $cat['id'], + 'name' => $cat['name'], + 'children' => build_category_tree($categories, $cat['id'], $visited, $depth + 1, $nodeCount) + ]; + $tree[] = $node; + $nodeCount++; + if ($nodeCount > 100) break; + } + } + return $tree; + } + + function render_category_tree($nodes, $depth = 0) { + if ($depth > 5) return ''; + $html = ''; + foreach ($nodes as $node) { + $html .= '