From 207042de99cefd5fd2b8529bb5661b373a5f3ad9 Mon Sep 17 00:00:00 2001 From: Krzysiej Date: Fri, 23 Jan 2026 11:24:46 +0100 Subject: [PATCH] Star working on category tree --- src/Controller/CategoryController.php | 41 ++------------------------- 1 file changed, 3 insertions(+), 38 deletions(-) diff --git a/src/Controller/CategoryController.php b/src/Controller/CategoryController.php index bceb0ae..e600fd8 100644 --- a/src/Controller/CategoryController.php +++ b/src/Controller/CategoryController.php @@ -29,57 +29,22 @@ final class CategoryController extends BaseController foreach ($products as $product) { $categoriesTree = $this->addToTree($product->categories, $categoriesTree); - dump($categoriesTree); } - dd($categoriesTree); - - dd(); - return $this->render('productList.html.twig', ['products' => $products, 'listType' => 'category_' . $category]); } private function addToTree(array $categories, mixed $categoriesTree) { -// $tree = [ -// "Elektronarzędzia" => [ -// "Maszyny i narzędzia do cięcia" => [ -// "Pilarki tarczowe" => [] -// -// ] -// ] -// ]; -// dump($tree); -// $test = &$tree['Elektronarzędzia']; -// $test = &$test['Maszyny i narzędzia do cięcia']; -// $test = &$test['Maszyny i narzędzia do cięcia2']; -// $test = &$test['Maszyny i narzędzia do cięcia3']; -// $test['node'] = []; -// dump( -// $tree -// ); -// -// $tree2 = []; -// $tree2['Elektronarzędzia'] = []; -// $tree2['Elektronarzędzia']['Maszyny i narzędzia do cięcia'] = []; - - $tmp = &$categoriesTree; foreach ($categories as $category) { - if (empty($tmp[$category])) { - $tmp[$category] = []; - $tmp = &$tmp[$category]; - } else { - $tmp = &$tmp[$category]; + $tmp[$category] = ['count' => 0]; } + $tmp = &$tmp[$category]; + $tmp['count']++; } - dump($categoriesTree); - - return $categoriesTree; } - - }