diff --git a/.idea/sonarlint/issuestore/3/8/38ac5fc300d52f94b369e87fbb1937abe29f831f b/.idea/sonarlint/issuestore/3/8/38ac5fc300d52f94b369e87fbb1937abe29f831f new file mode 100644 index 0000000000000000000000000000000000000000..e69de29bb2d1d6434b8b29ae775ad8c2e48c5391 diff --git a/.idea/sonarlint/issuestore/index.pb b/.idea/sonarlint/issuestore/index.pb index b6bd383fba48b306652314f6a74176bf887010fd..75525eea3e78241804013b290d483acee3848202 100644 --- a/.idea/sonarlint/issuestore/index.pb +++ b/.idea/sonarlint/issuestore/index.pb @@ -1,3 +1,5 @@ Q -!src/Controller/HomeController.php,a\d\ad8b439416d1e02614f47c5b471c7c4e587dca82 \ No newline at end of file +!src/Controller/HomeController.php,a\d\ad8b439416d1e02614f47c5b471c7c4e587dca82 +H +templates/home.html.twig,3\8\38ac5fc300d52f94b369e87fbb1937abe29f831f \ No newline at end of file diff --git a/.idea/sonarlint/securityhotspotstore/3/8/38ac5fc300d52f94b369e87fbb1937abe29f831f b/.idea/sonarlint/securityhotspotstore/3/8/38ac5fc300d52f94b369e87fbb1937abe29f831f new file mode 100644 index 0000000000000000000000000000000000000000..e69de29bb2d1d6434b8b29ae775ad8c2e48c5391 diff --git a/.idea/sonarlint/securityhotspotstore/index.pb b/.idea/sonarlint/securityhotspotstore/index.pb index b6bd383fba48b306652314f6a74176bf887010fd..75525eea3e78241804013b290d483acee3848202 100644 --- a/.idea/sonarlint/securityhotspotstore/index.pb +++ b/.idea/sonarlint/securityhotspotstore/index.pb @@ -1,3 +1,5 @@ Q -!src/Controller/HomeController.php,a\d\ad8b439416d1e02614f47c5b471c7c4e587dca82 \ No newline at end of file +!src/Controller/HomeController.php,a\d\ad8b439416d1e02614f47c5b471c7c4e587dca82 +H +templates/home.html.twig,3\8\38ac5fc300d52f94b369e87fbb1937abe29f831f \ No newline at end of file diff --git a/src/Controller/HomeController.php b/src/Controller/HomeController.php index 455f3e5958c6b759a20685aefcf60cc135a9cf82..ce5e43e9d94c60bbf5f8e35fab910dfcba1f0890 100644 --- a/src/Controller/HomeController.php +++ b/src/Controller/HomeController.php @@ -8,19 +8,46 @@ use Symfony\Component\Routing\Attribute\Route; class HomeController extends AbstractController { - private function uniqElements(array $array): array { - return array_unique($array, SORT_REGULAR); + 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; } + #[Route('/', name: 'home')] public function home(): Response { - $arr = [ - ['laravel', 'php'], - ['codeigniter', 'php'], - ['laravel', 'php'], - ['c++', 'java'], + $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,], ]; - return $this->json($this->uniqElements($arr)); + + return $this->render('home.html.twig', ['menu' => $this->prepareMenu($aMenu)]); } } diff --git a/templates/home.html.twig b/templates/home.html.twig index 60456d99db53f4677fae8ee380f7050ccf1853fb..9baaf00b56202c0678d0032d0311ab647a9fe3a5 100644 --- a/templates/home.html.twig +++ b/templates/home.html.twig @@ -1,12 +1,12 @@ {% block body %} - <h1>Сортировка маÑÑива:</h1> - <form method="POST"> - {{ dump(array) }} - {% for key1, value1 in array %} - {% for key2, value2 in value1 %} - <input type="hidden" name="array[][]" value="{{ value2 }}"> + <ul> + {% for value in menu %} + {% if value.depth == 0 %} + <h2>{{ value.name }}</h2> + {% for val in value.submenu %} + <li>{{ val.name }}</li> {% endfor %} - {% endfor %} - <button type="submit">Отправить маÑÑив</button> - </form> + {% endif %} + {% endfor %} + </ul> {% endblock %} \ No newline at end of file