Skip to content
Snippets Groups Projects
Commit b4966b44 authored by Адлан Шамавов's avatar Адлан Шамавов
Browse files

add howDaysToNy

parent f47c6e5c
No related branches found
No related tags found
1 merge request!5Ptps controller 5
Showing with 22 additions and 47 deletions
......@@ -2,4 +2,10 @@
Q
!src/Controller/HomeController.php,a\d\ad8b439416d1e02614f47c5b471c7c4e587dca82
H
templates/home.html.twig,3\8\38ac5fc300d52f94b369e87fbb1937abe29f831f
\ No newline at end of file
templates/home.html.twig,3\8\38ac5fc300d52f94b369e87fbb1937abe29f831f
V
&assets/controllers/hello_controller.js,b\5\b5aea0f996f6645c77ef6ac38e15316374d0fba2
C
assets/bootstrap.js,0\3\03141036569b5869397180192f8b98c1360e1556
E
assets/styles/app.css,5\8\58d82e459ad700473925afc6a4d3ceb1cbdfdf19
\ No newline at end of file
......@@ -2,4 +2,10 @@
Q
!src/Controller/HomeController.php,a\d\ad8b439416d1e02614f47c5b471c7c4e587dca82
H
templates/home.html.twig,3\8\38ac5fc300d52f94b369e87fbb1937abe29f831f
\ No newline at end of file
templates/home.html.twig,3\8\38ac5fc300d52f94b369e87fbb1937abe29f831f
V
&assets/controllers/hello_controller.js,b\5\b5aea0f996f6645c77ef6ac38e15316374d0fba2
C
assets/bootstrap.js,0\3\03141036569b5869397180192f8b98c1360e1556
E
assets/styles/app.css,5\8\58d82e459ad700473925afc6a4d3ceb1cbdfdf19
\ No newline at end of file
......@@ -2,52 +2,24 @@
namespace App\Controller;
use DateTimeImmutable;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\Routing\Attribute\Route;
class HomeController extends AbstractController
{
private function prepareMenu(array $aMenu): array {
$result = [];
foreach ($aMenu as $arr) {
if ($arr['depth'] === 0) {
$result[] = array(
'name' => $arr['name'],
'depth' => $arr['depth'],
'submenu' => []
);
continue;
}
$result[array_key_last($result)]['submenu'][] = array(
'name' => $arr['name'],
'depth' => $arr['depth'],
);
}
return $result;
private function howDaysToNy(DateTimeImmutable $date): int {
$endYear = date("Y-12-31", date_timestamp_get($date));
$dateInterval = date_diff(new DateTimeImmutable($endYear), $date);
return $dateInterval->format("%a") + 1;
}
#[Route('/', name: 'home')]
public function home(): Response
{
$aMenu = [
['name' => 'Смартфоны и гаджеты','depth' => 0,],
['name' => 'Смартфоны, мобильные телефоны','depth' => 1,],
['name' => 'Планшеты','depth' => 1,],
['name' => 'Наушники и гарнитуры','depth' => 1,],
['name' => 'Компьютеры и ноутбуки','depth' => 0,],
['name' => 'Ноутбуки и аксессуары','depth' => 1,],
['name' => 'Компьютеры и мониторы','depth' => 1,],
['name' => 'Компьютерные комплектующие','depth' => 1,],
['name' => 'Техника для дома','depth' => 0,],
['name' => 'Техника для уборки','depth' => 1,],
['name' => 'Товары для ухода за одеждой','depth' => 1,],
['name' => 'Аксессуары для техники','depth' => 1,],
['name' => 'Товары для дома и кухни','depth' => 0,],
['name' => 'Посуда','depth' => 1,],
];
$count = $this->howDaysToNy(new DateTimeImmutable());
return $this->render('home.html.twig', ['menu' => $this->prepareMenu($aMenu)]);
return $this->render('home.html.twig', ['count' => $count]);
}
}
{% block body %}
<ul>
{% for value in menu %}
{% if value.depth == 0 %}
<h2>{{ value.name }}</h2>
{% for val in value.submenu %}
<li>{{ val.name }}</li>
{% endfor %}
{% endif %}
{% endfor %}
</ul>
<h1>Кол-во дней до НГ: {{ count }}</h1>
{% endblock %}
\ No newline at end of file
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment