From 53b0bd6894d8c462a81ddb5e86bbb49afd473bd6 Mon Sep 17 00:00:00 2001 From: Krzysiej Date: Sun, 25 Jan 2026 11:33:58 +0100 Subject: [PATCH] Star working on category tree --- src/Twig/AppExtension.php | 34 ++++++++++++++++++++++++++++++--- templates/productList.html.twig | 9 +++++++-- 2 files changed, 38 insertions(+), 5 deletions(-) diff --git a/src/Twig/AppExtension.php b/src/Twig/AppExtension.php index 1a08554..3208b73 100644 --- a/src/Twig/AppExtension.php +++ b/src/Twig/AppExtension.php @@ -2,11 +2,11 @@ namespace Krzysiej\RyobiCrawler\Twig; -use Illuminate\Database\Eloquent\Builder; use Illuminate\Database\Eloquent\Collection; use Krzysiej\RyobiCrawler\Models\Price; use Krzysiej\RyobiCrawler\Models\Product; use Krzysiej\RyobiCrawler\Models\Stock; +use Symfony\Component\Routing\RouterInterface; use Twig\Extension\AbstractExtension; use Twig\TwigFilter; use Twig\TwigFunction; @@ -15,6 +15,10 @@ use function Symfony\Component\Clock\now; class AppExtension extends AbstractExtension { + public function __construct(public RouterInterface $route) + { + } + public function getFunctions(): array { return [ @@ -23,6 +27,7 @@ class AppExtension extends AbstractExtension new TwigFunction('newCount', [$this, 'newCount']), new TwigFunction('discontinuedCount', [$this, 'discontinuedCount']), new TwigFunction('lowestPriceCount', [$this, 'lowestPriceCount']), + new TwigFunction('renderCategoryTree', [$this, 'renderCategoryTree']), ]; } @@ -56,7 +61,7 @@ class AppExtension extends AbstractExtension public function lowestPriceCount(): int { return Product::whereRaw('priceCurrent = priceLowest') - ->whereRaw('lastSeen = "'.now()->format('Y-m-d').'"') + ->whereRaw('lastSeen = "' . now()->format('Y-m-d') . '"') ->whereRaw('priceCurrent < productStandardPrice') ->count(); } @@ -65,4 +70,27 @@ class AppExtension extends AbstractExtension { return $items->first(fn($item) => str_starts_with($item->created_at, $date)); } -} \ No newline at end of file + + public function renderCategoryTree($categories, $level = 0): string + { + $tree = ''; + if ($level == 0) { + $tree .= ''; + } + return $tree; + + } +} diff --git a/templates/productList.html.twig b/templates/productList.html.twig index 1d349f5..71d1c92 100644 --- a/templates/productList.html.twig +++ b/templates/productList.html.twig @@ -1,7 +1,12 @@ {% extends "template.html.twig" %} {% block content %} -{% cache 'list_' ~ listType %} +{#{% cache 'list_' ~ listType %}#} + +{% if listType starts with 'category_' %} + {{ renderCategoryTree(categoryTree) | raw }} +{% endif %} +
@@ -66,5 +71,5 @@ {% endfor %}
-{% endcache %} +{#{% endcache %}#} {% endblock %}