Add new items listing and counting
This commit is contained in:
22
src/Controller/NewController.php
Normal file
22
src/Controller/NewController.php
Normal file
@@ -0,0 +1,22 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace Krzysiej\RyobiCrawler\Controller;
|
||||||
|
|
||||||
|
use Illuminate\Database\Eloquent\Builder;
|
||||||
|
use Krzysiej\RyobiCrawler\Models\Product;
|
||||||
|
use Symfony\Component\HttpFoundation\Response;
|
||||||
|
use Symfony\Component\Routing\Attribute\Route;
|
||||||
|
|
||||||
|
final class NewController extends BaseController
|
||||||
|
{
|
||||||
|
#[Route('/promos', name: 'app_new')]
|
||||||
|
public function __invoke(): Response
|
||||||
|
{
|
||||||
|
$products = Product::whereHas('created_at', now()->subDays(30)->format('Y-m-d'))
|
||||||
|
->orderByDesc('starred')
|
||||||
|
->orderByDesc('created_by')
|
||||||
|
->with(['currentPrice'])
|
||||||
|
->get();
|
||||||
|
return $this->render('productList.html.twig', ['products' => $products]);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -32,6 +32,11 @@ class AppExtension extends AbstractExtension
|
|||||||
return Product::whereHas('currentPrice', fn(Builder $query) => $query->whereColumn('price', '<', 'productStandardPrice'))->with(['currentPrice'])->count();
|
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
|
public function findByCreatedAtDate(Collection $items, string $date): Stock|Price|null
|
||||||
{
|
{
|
||||||
return $items->first(fn($item) => str_starts_with($item->created_at, $date));
|
return $items->first(fn($item) => str_starts_with($item->created_at, $date));
|
||||||
|
|||||||
@@ -20,6 +20,7 @@
|
|||||||
<ul class="navbar-nav me-auto mb-2 mb-lg-0">
|
<ul class="navbar-nav me-auto mb-2 mb-lg-0">
|
||||||
<li class="nav-item">
|
<li class="nav-item">
|
||||||
<a class="nav-link active" aria-current="page" href="{{ path('app_promos') }}">Promos <span class="badge text-bg-secondary">{{ promosCount() }}</span></a>
|
<a class="nav-link active" aria-current="page" href="{{ path('app_promos') }}">Promos <span class="badge text-bg-secondary">{{ promosCount() }}</span></a>
|
||||||
|
<a class="nav-link active" aria-current="page" href="{{ path('app_new') }}">New in last 30 days<span class="badge text-bg-secondary">{{ newCount() }}</span></a>
|
||||||
</li>
|
</li>
|
||||||
</ul>
|
</ul>
|
||||||
<form class="d-flex col-lg-6 col-sm-8" role="search" action="{{ path('app_search') }}">
|
<form class="d-flex col-lg-6 col-sm-8" role="search" action="{{ path('app_search') }}">
|
||||||
|
|||||||
Reference in New Issue
Block a user