Temporarily disable tree building to fix 500 errors, likely due to database issues
This commit is contained in:
parent
03e2e2b13a
commit
953f831ab9
63
config.php
63
config.php
@ -48,68 +48,5 @@ $twig->addGlobal('delete_part_confirm', $translator->trans('Are you sure you wan
|
|||||||
$twig->addGlobal('delete_category_confirm', $translator->trans('Are you sure you want to delete this category?'));
|
$twig->addGlobal('delete_category_confirm', $translator->trans('Are you sure you want to delete this category?'));
|
||||||
|
|
||||||
// Build category tree for sidebar
|
// Build category tree for sidebar
|
||||||
try {
|
|
||||||
$db = App\Database\Database::getInstance();
|
|
||||||
$categories = App\Models\Category::getAll($db);
|
|
||||||
$items = App\Models\Item::getAll($db);
|
|
||||||
|
|
||||||
function buildTree($categories, $items, $parentId = null, &$visited = [], $depth = 0) {
|
|
||||||
if ($depth > 5) return []; // Limit depth
|
|
||||||
$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' => buildTree($categories, $items, $cat['id'], $visited, $depth + 1),
|
|
||||||
'items' => []
|
|
||||||
];
|
|
||||||
// Limit items to 20 per category
|
|
||||||
$itemCount = 0;
|
|
||||||
foreach ($items as $item) {
|
|
||||||
if ($item['category_id'] == $cat['id'] && $itemCount < 20) {
|
|
||||||
$node['items'][] = $item;
|
|
||||||
$itemCount++;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
$tree[] = $node;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return $tree;
|
|
||||||
}
|
|
||||||
|
|
||||||
$categoryTree = buildTree($categories, $items);
|
|
||||||
|
|
||||||
function renderTree($nodes, $depth = 0) {
|
|
||||||
if ($depth > 5) return '';
|
|
||||||
$html = '';
|
|
||||||
foreach ($nodes as $node) {
|
|
||||||
$html .= '<li>';
|
|
||||||
$html .= '<span class="category" onclick="toggleCategory(this)">' . htmlspecialchars($node['name']) . '</span>';
|
|
||||||
if (!empty($node['children'])) {
|
|
||||||
$html .= '<ul style="display: none;">';
|
|
||||||
$html .= renderTree($node['children'], $depth + 1);
|
|
||||||
$html .= '</ul>';
|
|
||||||
}
|
|
||||||
if (!empty($node['items'])) {
|
|
||||||
$html .= '<ul class="items">';
|
|
||||||
foreach ($node['items'] as $item) {
|
|
||||||
$html .= '<li><a href="#" onclick="editItem(' . (int)$item['id'] . ')" class="item-link">' . htmlspecialchars($item['name']) . '</a></li>';
|
|
||||||
}
|
|
||||||
$html .= '</ul>';
|
|
||||||
}
|
|
||||||
$html .= '</li>';
|
|
||||||
}
|
|
||||||
return $html;
|
|
||||||
}
|
|
||||||
|
|
||||||
$sidebarHtml = '<ul class="category-tree">' . renderTree($categoryTree) . '</ul>';
|
|
||||||
if (strlen($sidebarHtml) > 50000) { // If too large, use menu
|
|
||||||
$sidebarHtml = '<ul class="nav flex-column nav-pills"><li class="nav-item"><a class="nav-link" href="#" data-route="/">Overview</a></li><li class="nav-item"><a class="nav-link" href="#" data-route="/categories">Categories</a></li><li class="nav-item"><a class="nav-link" href="#" data-route="/parts">Parts</a></li></ul>';
|
$sidebarHtml = '<ul class="nav flex-column nav-pills"><li class="nav-item"><a class="nav-link" href="#" data-route="/">Overview</a></li><li class="nav-item"><a class="nav-link" href="#" data-route="/categories">Categories</a></li><li class="nav-item"><a class="nav-link" href="#" data-route="/parts">Parts</a></li></ul>';
|
||||||
}
|
|
||||||
} catch (Exception $e) {
|
|
||||||
error_log('Error building category tree: ' . $e->getMessage());
|
|
||||||
$sidebarHtml = '<ul class="nav flex-column nav-pills"><li class="nav-item"><a class="nav-link" href="#" data-route="/">Overview</a></li><li class="nav-item"><a class="nav-link" href="#" data-route="/categories">Categories</a></li><li class="nav-item"><a class="nav-link" href="#" data-route="/parts">Parts</a></li></ul>';
|
|
||||||
}
|
|
||||||
$twig->addGlobal('sidebar_html', $sidebarHtml);
|
$twig->addGlobal('sidebar_html', $sidebarHtml);
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user