From 8ee25d3a301b38b3db5e04a32715f29335ff8244 Mon Sep 17 00:00:00 2001 From: ghost Date: Wed, 4 Oct 2023 19:17:43 +0300 Subject: [PATCH] move dashboard relations to the user controller --- src/Controller/DashboardController.php | 43 ---------------- src/Controller/UserController.php | 56 +++++++++++++++++++++ templates/default/dashboard/index.html.twig | 2 - templates/default/layout.html.twig | 2 +- templates/default/user/module.html.twig | 4 +- 5 files changed, 59 insertions(+), 48 deletions(-) delete mode 100644 src/Controller/DashboardController.php delete mode 100644 templates/default/dashboard/index.html.twig diff --git a/src/Controller/DashboardController.php b/src/Controller/DashboardController.php deleted file mode 100644 index 817fd3b..0000000 --- a/src/Controller/DashboardController.php +++ /dev/null @@ -1,43 +0,0 @@ -init( - $request->getClientIp() - ); - - return $this->redirectToRoute( - 'dashboard_index', - [ - '_locale' => $user->getLocale() - ] - ); - } - - #[Route( - '/{_locale}', - name: 'dashboard_index' - )] - public function index(Request $request): Response - { - return $this->render( - 'default/dashboard/index.html.twig' - ); - } -} \ No newline at end of file diff --git a/src/Controller/UserController.php b/src/Controller/UserController.php index af88166..8b9b5be 100644 --- a/src/Controller/UserController.php +++ b/src/Controller/UserController.php @@ -12,6 +12,62 @@ use App\Service\TimeService; class UserController extends AbstractController { + #[Route('/')] + public function root( + Request $request, + UserService $userService + ): Response + { + $user = $userService->init( + $request->getClientIp() + ); + + return $this->redirectToRoute( + 'user_dashboard', + [ + '_locale' => $user->getLocale() + ] + ); + } + + #[Route( + '/{_locale}', + name: 'user_dashboard' + )] + public function index( + Request $request, + UserService $userService, + TimeService $timeService + ): Response + { + $activities = []; + foreach ($userService->getAllByAddedFieldDesc() as $user) + { + $activities[] = + [ + 'user' => + [ + 'id' => $user->getId(), + 'identicon' => $userService->identicon( + $user->getAddress(), + 24 + ) + ], + 'type' => 'join', + 'added' => $timeService->ago( + $user->getAdded() + ) + ]; + } + + return $this->render( + 'default/user/dashboard.html.twig', + [ + 'activities' => $activities + ] + ); + } + #[Route( '/{_locale}/profile', name: 'user_profile', diff --git a/templates/default/dashboard/index.html.twig b/templates/default/dashboard/index.html.twig deleted file mode 100644 index fe403d6..0000000 --- a/templates/default/dashboard/index.html.twig +++ /dev/null @@ -1,2 +0,0 @@ -{% extends 'default/layout.html.twig' %} -{% block title %}{{ 'Home'|trans }} - {{ name }}{% endblock %} \ No newline at end of file diff --git a/templates/default/layout.html.twig b/templates/default/layout.html.twig index 837a2eb..159563a 100644 --- a/templates/default/layout.html.twig +++ b/templates/default/layout.html.twig @@ -13,7 +13,7 @@
- {% block header_search %} diff --git a/templates/default/user/module.html.twig b/templates/default/user/module.html.twig index 366eb66..1dbd40f 100644 --- a/templates/default/user/module.html.twig +++ b/templates/default/user/module.html.twig @@ -1,6 +1,6 @@
- {% if route == 'dashboard_index' %} + {% if route == 'user_dashboard' %} @@ -10,7 +10,7 @@ {% else %} - +