Compare commits
6 Commits
5832ac583f
...
feature/or
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
2e4c79c87a | ||
| 6246ad8692 | |||
|
|
d18abc6159 | ||
|
|
c947e470af | ||
|
|
8eeba225ed | ||
|
|
9b6bcd22be |
@@ -2,7 +2,9 @@
|
|||||||
|
|
||||||
namespace Krzysiej\RyobiCrawler\Controller;
|
namespace Krzysiej\RyobiCrawler\Controller;
|
||||||
|
|
||||||
|
use Illuminate\Database\Eloquent\Builder;
|
||||||
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
|
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
|
||||||
|
use Symfony\Component\HttpFoundation\Request;
|
||||||
use Twig\Environment;
|
use Twig\Environment;
|
||||||
use Illuminate\Database\Capsule\Manager as Capsule;
|
use Illuminate\Database\Capsule\Manager as Capsule;
|
||||||
|
|
||||||
@@ -17,4 +19,19 @@ class BaseController extends AbstractController
|
|||||||
$capsule->setAsGlobal();
|
$capsule->setAsGlobal();
|
||||||
$capsule->bootEloquent();
|
$capsule->bootEloquent();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
protected function handleOrderProducts(Builder $builder, Request $request): Builder
|
||||||
|
{
|
||||||
|
$builder->orderByDesc('starred')->orderByDesc('created_by');
|
||||||
|
if ($request->query->get('order')) {
|
||||||
|
$orderField = $request->query->get('order');
|
||||||
|
$direction = 'desc';
|
||||||
|
if (str_starts_with($orderField, '-')) {
|
||||||
|
$direction = 'asc';
|
||||||
|
}
|
||||||
|
$builder->orderBy($request->query->get('order'), $direction);
|
||||||
|
}
|
||||||
|
|
||||||
|
return $builder;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -3,18 +3,17 @@
|
|||||||
namespace Krzysiej\RyobiCrawler\Controller;
|
namespace Krzysiej\RyobiCrawler\Controller;
|
||||||
|
|
||||||
use Krzysiej\RyobiCrawler\Models\Product;
|
use Krzysiej\RyobiCrawler\Models\Product;
|
||||||
|
use Symfony\Component\HttpFoundation\Request;
|
||||||
use Symfony\Component\HttpFoundation\Response;
|
use Symfony\Component\HttpFoundation\Response;
|
||||||
use Symfony\Component\Routing\Attribute\Route;
|
use Symfony\Component\Routing\Attribute\Route;
|
||||||
|
|
||||||
final class IndexController extends BaseController
|
final class IndexController extends BaseController
|
||||||
{
|
{
|
||||||
#[Route('/', name: 'app_home')]
|
#[Route('/', name: 'app_home')]
|
||||||
public function __invoke(): Response
|
public function __invoke(Request $request): Response
|
||||||
{
|
{
|
||||||
$products = Product::with(['currentStock', 'price'])
|
$products = Product::with(['currentStock', 'price', 'currentPrice']);
|
||||||
->orderByDesc('starred')
|
$products = $this->handleOrderProducts($products, $request)->get();
|
||||||
->orderByDesc('created_by')
|
|
||||||
->get();
|
|
||||||
return $this->render('productList.html.twig', ['products' => $products]);
|
return $this->render('productList.html.twig', ['products' => $products]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -16,6 +16,7 @@ final class NewController extends BaseController
|
|||||||
{
|
{
|
||||||
$products = Product::where('created_at', '>', now()->modify('-30 days')->format('Y-m-d'))
|
$products = Product::where('created_at', '>', now()->modify('-30 days')->format('Y-m-d'))
|
||||||
->orderByDesc('starred')
|
->orderByDesc('starred')
|
||||||
|
->orderByDesc('name')
|
||||||
->orderByDesc('created_by')
|
->orderByDesc('created_by')
|
||||||
->with(['currentPrice'])
|
->with(['currentPrice'])
|
||||||
->get();
|
->get();
|
||||||
|
|||||||
@@ -1,57 +1,60 @@
|
|||||||
{% extends "template.html.twig" %}
|
{% extends "template.html.twig" %}
|
||||||
|
|
||||||
{% block content %}
|
{% block content %}
|
||||||
<table class='table table-hover'>
|
<div class="table-responsive">
|
||||||
<tr>
|
<table class='table table-hover'>
|
||||||
<td class="align-middle font-weight-bold h3"><a class="text-warning text-decoration-none"
|
<tr>
|
||||||
href="{{ path('app_star', {'productId': product.id}) }}">{% if product.starred %}★{% else %} ☆ {% endif %}</a></td>
|
<td class="align-middle font-weight-bold h3"><a class="text-warning text-decoration-none"
|
||||||
<td><img src='{{ product.image }}&width=150' class='border rounded p-1' alt='{{ product.name }}'/></td>
|
href="{{ path('app_star', {'productId': product.id}) }}">{% if product.starred %}★{% else %} ☆ {% endif %}</a></td>
|
||||||
<td>
|
<td><img src='{{ product.image }}&width=150' class='border rounded p-1' alt='{{ product.name }}'/></td>
|
||||||
<a href='{{ path('app_product', {'productId': product.id}) }}' class="text-decoration-none">{{ product.name }}</a>
|
<td>
|
||||||
<span class="badge text-bg-light">{{ product.subTitle }}</span>
|
<a href='{{ path('app_product', {'productId': product.id}) }}' class="text-decoration-none">{{ product.name }}</a>
|
||||||
</td>
|
<span class="badge text-bg-light">{{ product.subTitle }}</span>
|
||||||
<td>
|
</td>
|
||||||
<nav aria-label="breadcrumb" style="--bs-breadcrumb-divider: '>';" >
|
<td>
|
||||||
<ol class="breadcrumb">
|
<nav aria-label="breadcrumb" style="--bs-breadcrumb-divider: '>';">
|
||||||
{% for category in product.categories %}
|
<ol class="breadcrumb">
|
||||||
<li class="breadcrumb-item" aria-current="page"><a class="breadcrumb-item text-decoration-none" href="{{ path('app_category', {'category': category}) }}">{{ category }}</a></li>
|
{% for category in product.categories %}
|
||||||
{% endfor %}
|
<li class="breadcrumb-item" aria-current="page"><a class="breadcrumb-item text-decoration-none"
|
||||||
</ol>
|
href="{{ path('app_category', {'category': category}) }}">{{ category }}</a></li>
|
||||||
</nav>
|
{% endfor %}
|
||||||
</td>
|
</ol>
|
||||||
<td><a href='https://pl.ryobitools.eu/{{ product.url }}'>link</a></td>
|
</nav>
|
||||||
</tr>
|
</td>
|
||||||
<tr>
|
<td><a href='https://pl.ryobitools.eu/{{ product.url }}'>link</a></td>
|
||||||
<td colspan="5">
|
</tr>
|
||||||
<div style="width: 800px;">
|
<tr>
|
||||||
<canvas id="price"></canvas>
|
<td colspan="5">
|
||||||
</div>
|
<div style="width: 800px;">
|
||||||
</td>
|
<canvas id="price"></canvas>
|
||||||
</tr>
|
</div>
|
||||||
<tr>
|
</td>
|
||||||
<td colspan="5">
|
</tr>
|
||||||
<table class='table table-hover table-sm mb-0'>
|
<tr>
|
||||||
<thead>
|
<td colspan="5">
|
||||||
<tr>
|
<table class='table table-hover table-sm mb-0'>
|
||||||
<th>price</th>
|
<thead>
|
||||||
<th>lowest product price in 30 days</th>
|
|
||||||
<th colspan='2'>standard price</th>
|
|
||||||
<th>Stock</th>
|
|
||||||
</tr>
|
|
||||||
</thead>
|
|
||||||
{% for price in product.price %}
|
|
||||||
<tr>
|
<tr>
|
||||||
<td>{{ price.price | format_currency('PLN', {}, 'pl') }}</td>
|
<th>price</th>
|
||||||
<td>{{ price.lowestProductPrice30Days | format_currency('PLN', {}, 'pl') }}</td>
|
<th>lowest product price in 30 days</th>
|
||||||
<td>{{ price.productStandardPrice | format_currency('PLN', {}, 'pl') }}</td>
|
<th colspan='2'>standard price</th>
|
||||||
<td>{{ price.created_at }}</td>
|
<th>Stock</th>
|
||||||
<td>{{ (product.stock | findByCreatedAtDate(price.created_at | slice(0,10))).stock ?? '' }}</td>
|
|
||||||
</tr>
|
</tr>
|
||||||
{% endfor %}
|
</thead>
|
||||||
</table>
|
{% for price in product.price %}
|
||||||
</td>
|
<tr>
|
||||||
</tr>
|
<td>{{ price.price | format_currency('PLN', {}, 'pl') }}</td>
|
||||||
</table>
|
<td>{{ price.lowestProductPrice30Days | format_currency('PLN', {}, 'pl') }}</td>
|
||||||
|
<td>{{ price.productStandardPrice | format_currency('PLN', {}, 'pl') }}</td>
|
||||||
|
<td>{{ price.created_at }}</td>
|
||||||
|
<td>{{ (product.stock | findByCreatedAtDate(price.created_at | slice(0,10))).stock ?? '' }}</td>
|
||||||
|
</tr>
|
||||||
|
{% endfor %}
|
||||||
|
</table>
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
|
</table>
|
||||||
|
</div>
|
||||||
<script src="https://cdn.jsdelivr.net/npm/chart.js"></script>
|
<script src="https://cdn.jsdelivr.net/npm/chart.js"></script>
|
||||||
|
|
||||||
<script>
|
<script>
|
||||||
|
|||||||
@@ -1,15 +1,17 @@
|
|||||||
{% extends "template.html.twig" %}
|
{% extends "template.html.twig" %}
|
||||||
|
|
||||||
{% block content %}
|
{% block content %}
|
||||||
|
<div class="table-responsive">
|
||||||
|
{{ app.request.get('order') }}
|
||||||
<table class='table table-hover'>
|
<table class='table table-hover'>
|
||||||
<thead>
|
<thead>
|
||||||
<tr>
|
<tr>
|
||||||
<th></th>
|
<th></th>
|
||||||
<th></th>
|
<th></th>
|
||||||
<th>Name</th>
|
<th><a href="{{ path( app.request.get('_route') , {'order': app.request.get('order') is same as('-name')?'name':'-name'|default('-name')}) }}">Name</a></th>
|
||||||
<th>Categories</th>
|
<th>Categories</th>
|
||||||
<th></th>
|
<th></th>
|
||||||
<th>Price</th>
|
<th><a href="{{ path( app.request.get('_route') , {'order': app.request.get('order') is same as('-price')?'price':'-price'|default('-price')}) }}">Price</a></th>
|
||||||
<th></th>
|
<th></th>
|
||||||
</tr>
|
</tr>
|
||||||
</thead>
|
</thead>
|
||||||
@@ -55,4 +57,5 @@
|
|||||||
</tr>
|
</tr>
|
||||||
{% endfor %}
|
{% endfor %}
|
||||||
</table>
|
</table>
|
||||||
|
</div>
|
||||||
{% endblock %}
|
{% endblock %}
|
||||||
Reference in New Issue
Block a user