From 14104f61a4bde91f1c98181e49cb37602c9bebda Mon Sep 17 00:00:00 2001 From: krzysiej Date: Sun, 5 Jan 2025 16:19:49 +0100 Subject: [PATCH 1/3] Add new items listing and counting --- src/Controller/NewController.php | 22 ++++++++++++++++++++++ src/Twig/AppExtension.php | 5 +++++ templates/template.html.twig | 1 + 3 files changed, 28 insertions(+) create mode 100644 src/Controller/NewController.php diff --git a/src/Controller/NewController.php b/src/Controller/NewController.php new file mode 100644 index 0000000..f52b0f9 --- /dev/null +++ b/src/Controller/NewController.php @@ -0,0 +1,22 @@ +subDays(30)->format('Y-m-d')) + ->orderByDesc('starred') + ->orderByDesc('created_by') + ->with(['currentPrice']) + ->get(); + return $this->render('productList.html.twig', ['products' => $products]); + } +} diff --git a/src/Twig/AppExtension.php b/src/Twig/AppExtension.php index 0376fbd..719ab1a 100644 --- a/src/Twig/AppExtension.php +++ b/src/Twig/AppExtension.php @@ -32,6 +32,11 @@ class AppExtension extends AbstractExtension return Product::whereHas('currentPrice', fn(Builder $query) => $query->whereColumn('price', '<', 'productStandardPrice'))->with(['currentPrice'])->count(); } + public function newCount(): int + { + return Product::whereHas('created_at', now()->subDays(30)->format('Y-m-d'))->count(); + } + public function findByCreatedAtDate(Collection $items, string $date): Stock|Price|null { return $items->first(fn($item) => str_starts_with($item->created_at, $date)); diff --git a/templates/template.html.twig b/templates/template.html.twig index beadfaf..4c7e459 100644 --- a/templates/template.html.twig +++ b/templates/template.html.twig @@ -20,6 +20,7 @@