From d73086231fb5cfd6866d8520bad94e96351a02af Mon Sep 17 00:00:00 2001 From: ghost Date: Wed, 4 Oct 2023 19:20:34 +0300 Subject: [PATCH] draft activity feature #4 --- src/Controller/UserController.php | 34 +++++----------------- src/Repository/UserRepository.php | 9 ++++++ src/Service/UserService.php | 25 ++++++++++++++++ templates/default/user/dashboard.html.twig | 23 +++++++++++++++ 4 files changed, 65 insertions(+), 26 deletions(-) create mode 100644 templates/default/user/dashboard.html.twig diff --git a/src/Controller/UserController.php b/src/Controller/UserController.php index 8b9b5be..2b543bc 100644 --- a/src/Controller/UserController.php +++ b/src/Controller/UserController.php @@ -129,18 +129,6 @@ class UserController extends AbstractController ); } - // Generate identicon - $identicon = new \Jdenticon\Identicon(); - - $identicon->setValue($user->getAddress()); - $identicon->setSize(48); - $identicon->setStyle( - [ - 'backgroundColor' => 'rgba(255, 255, 255, 0)', - 'padding' => 0 - ] - ); - // Render template return $this->render( 'default/user/profile.html.twig', @@ -156,7 +144,10 @@ class UserController extends AbstractController 'added' => $timeService->ago( $user->getAdded() ), - 'identicon' => $identicon->getImageDataUri('webp'), + 'identicon' => $userService->identicon( + $user->getAddress(), + 48 + ), ], 'locales' => explode('|', $this->getParameter('app.locales')) ] @@ -185,18 +176,6 @@ class UserController extends AbstractController throw $this->createNotFoundException(); } - // Generate identicon - $identicon = new \Jdenticon\Identicon(); - - $identicon->setValue($user->getAddress()); - $identicon->setSize(48); - $identicon->setStyle( - [ - 'backgroundColor' => 'rgba(255, 255, 255, 0)', - 'padding' => 0 - ] - ); - // Render template return $this->render( 'default/user/info.html.twig', @@ -212,7 +191,10 @@ class UserController extends AbstractController 'added' => $timeService->ago( $user->getAdded() ), - 'identicon' => $identicon->getImageDataUri('webp'), + 'identicon' => $userService->identicon( + $user->getAddress(), + 48 + ), ] ] ); diff --git a/src/Repository/UserRepository.php b/src/Repository/UserRepository.php index 49896f3..202d56d 100644 --- a/src/Repository/UserRepository.php +++ b/src/Repository/UserRepository.php @@ -40,4 +40,13 @@ class UserRepository extends ServiceEntityRepository ->getOneOrNullResult() ; } + + public function findAllByAddedFieldDesc(): array + { + return $this->createQueryBuilder('u') + ->orderBy('u.added', 'DESC') + ->getQuery() + ->getResult() + ; + } } diff --git a/src/Service/UserService.php b/src/Service/UserService.php index 856fa9e..033c459 100644 --- a/src/Service/UserService.php +++ b/src/Service/UserService.php @@ -58,6 +58,31 @@ class UserService return $this->userRepository->findOneByIdField($id); } + public function getAllByAddedFieldDesc(): array + { + return $this->userRepository->findAllByAddedFieldDesc(); + } + + public function identicon( + mixed $value, + int $size = 16, + array $style = + [ + 'backgroundColor' => 'rgba(255, 255, 255, 0)', + 'padding' => 0 + ], + string $format = 'webp' + ): string + { + $identicon = new \Jdenticon\Identicon(); + + $identicon->setValue($value); + $identicon->setSize($size); + $identicon->setStyle($style); + + return $identicon->getImageDataUri($format); + } + public function save(User $user) : void { $this->entityManager->persist($user); diff --git a/templates/default/user/dashboard.html.twig b/templates/default/user/dashboard.html.twig new file mode 100644 index 0000000..0fa8921 --- /dev/null +++ b/templates/default/user/dashboard.html.twig @@ -0,0 +1,23 @@ +{% extends 'default/layout.html.twig' %} +{% block title %}{{ 'Last activity'|trans }} - {{ name }}{% endblock %} +{% block main_content %} + {% for activity in activities %} +
+
+
+ + {{ 'identicon'|trans }} + + {% if activity.type == 'join' %} + {{ 'joined'|trans }} {{ name }} + {% endif %} +
+
+ {{ activity.added }} +
+
+
+ {% endfor %} +{% endblock %} \ No newline at end of file