From b4966b44947733e3777d3294bb713faed06a8df9 Mon Sep 17 00:00:00 2001 From: "a.shamavov" <a.shamavov@iqdev.digital> Date: Mon, 8 Apr 2024 16:43:27 +0500 Subject: [PATCH] add howDaysToNy --- .../03141036569b5869397180192f8b98c1360e1556 | 0 .../58d82e459ad700473925afc6a4d3ceb1cbdfdf19 | 0 .../b5aea0f996f6645c77ef6ac38e15316374d0fba2 | 0 .idea/sonarlint/issuestore/index.pb | 8 +++- .../03141036569b5869397180192f8b98c1360e1556 | 0 .../58d82e459ad700473925afc6a4d3ceb1cbdfdf19 | 0 .../b5aea0f996f6645c77ef6ac38e15316374d0fba2 | 0 .idea/sonarlint/securityhotspotstore/index.pb | 8 +++- src/Controller/HomeController.php | 42 ++++--------------- templates/home.html.twig | 11 +---- 10 files changed, 22 insertions(+), 47 deletions(-) create mode 100644 .idea/sonarlint/issuestore/0/3/03141036569b5869397180192f8b98c1360e1556 create mode 100644 .idea/sonarlint/issuestore/5/8/58d82e459ad700473925afc6a4d3ceb1cbdfdf19 create mode 100644 .idea/sonarlint/issuestore/b/5/b5aea0f996f6645c77ef6ac38e15316374d0fba2 create mode 100644 .idea/sonarlint/securityhotspotstore/0/3/03141036569b5869397180192f8b98c1360e1556 create mode 100644 .idea/sonarlint/securityhotspotstore/5/8/58d82e459ad700473925afc6a4d3ceb1cbdfdf19 create mode 100644 .idea/sonarlint/securityhotspotstore/b/5/b5aea0f996f6645c77ef6ac38e15316374d0fba2 diff --git a/.idea/sonarlint/issuestore/0/3/03141036569b5869397180192f8b98c1360e1556 b/.idea/sonarlint/issuestore/0/3/03141036569b5869397180192f8b98c1360e1556 new file mode 100644 index 0000000..e69de29 diff --git a/.idea/sonarlint/issuestore/5/8/58d82e459ad700473925afc6a4d3ceb1cbdfdf19 b/.idea/sonarlint/issuestore/5/8/58d82e459ad700473925afc6a4d3ceb1cbdfdf19 new file mode 100644 index 0000000..e69de29 diff --git a/.idea/sonarlint/issuestore/b/5/b5aea0f996f6645c77ef6ac38e15316374d0fba2 b/.idea/sonarlint/issuestore/b/5/b5aea0f996f6645c77ef6ac38e15316374d0fba2 new file mode 100644 index 0000000..e69de29 diff --git a/.idea/sonarlint/issuestore/index.pb b/.idea/sonarlint/issuestore/index.pb index 75525ee..bc34c28 100644 --- a/.idea/sonarlint/issuestore/index.pb +++ b/.idea/sonarlint/issuestore/index.pb @@ -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 diff --git a/.idea/sonarlint/securityhotspotstore/0/3/03141036569b5869397180192f8b98c1360e1556 b/.idea/sonarlint/securityhotspotstore/0/3/03141036569b5869397180192f8b98c1360e1556 new file mode 100644 index 0000000..e69de29 diff --git a/.idea/sonarlint/securityhotspotstore/5/8/58d82e459ad700473925afc6a4d3ceb1cbdfdf19 b/.idea/sonarlint/securityhotspotstore/5/8/58d82e459ad700473925afc6a4d3ceb1cbdfdf19 new file mode 100644 index 0000000..e69de29 diff --git a/.idea/sonarlint/securityhotspotstore/b/5/b5aea0f996f6645c77ef6ac38e15316374d0fba2 b/.idea/sonarlint/securityhotspotstore/b/5/b5aea0f996f6645c77ef6ac38e15316374d0fba2 new file mode 100644 index 0000000..e69de29 diff --git a/.idea/sonarlint/securityhotspotstore/index.pb b/.idea/sonarlint/securityhotspotstore/index.pb index 75525ee..bc34c28 100644 --- a/.idea/sonarlint/securityhotspotstore/index.pb +++ b/.idea/sonarlint/securityhotspotstore/index.pb @@ -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 diff --git a/src/Controller/HomeController.php b/src/Controller/HomeController.php index ce5e43e..c0b1db0 100644 --- a/src/Controller/HomeController.php +++ b/src/Controller/HomeController.php @@ -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]); } } diff --git a/templates/home.html.twig b/templates/home.html.twig index 9baaf00..6ce69c6 100644 --- a/templates/home.html.twig +++ b/templates/home.html.twig @@ -1,12 +1,3 @@ {% 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 -- GitLab