Browse Source

draft activity feature #4

main
ghost 1 year ago
parent
commit
d73086231f
  1. 34
      src/Controller/UserController.php
  2. 9
      src/Repository/UserRepository.php
  3. 25
      src/Service/UserService.php
  4. 23
      templates/default/user/dashboard.html.twig

34
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 // Render template
return $this->render( return $this->render(
'default/user/profile.html.twig', 'default/user/profile.html.twig',
@ -156,7 +144,10 @@ class UserController extends AbstractController
'added' => $timeService->ago( 'added' => $timeService->ago(
$user->getAdded() $user->getAdded()
), ),
'identicon' => $identicon->getImageDataUri('webp'), 'identicon' => $userService->identicon(
$user->getAddress(),
48
),
], ],
'locales' => explode('|', $this->getParameter('app.locales')) 'locales' => explode('|', $this->getParameter('app.locales'))
] ]
@ -185,18 +176,6 @@ class UserController extends AbstractController
throw $this->createNotFoundException(); 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 // Render template
return $this->render( return $this->render(
'default/user/info.html.twig', 'default/user/info.html.twig',
@ -212,7 +191,10 @@ class UserController extends AbstractController
'added' => $timeService->ago( 'added' => $timeService->ago(
$user->getAdded() $user->getAdded()
), ),
'identicon' => $identicon->getImageDataUri('webp'), 'identicon' => $userService->identicon(
$user->getAddress(),
48
),
] ]
] ]
); );

9
src/Repository/UserRepository.php

@ -40,4 +40,13 @@ class UserRepository extends ServiceEntityRepository
->getOneOrNullResult() ->getOneOrNullResult()
; ;
} }
public function findAllByAddedFieldDesc(): array
{
return $this->createQueryBuilder('u')
->orderBy('u.added', 'DESC')
->getQuery()
->getResult()
;
}
} }

25
src/Service/UserService.php

@ -58,6 +58,31 @@ class UserService
return $this->userRepository->findOneByIdField($id); 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 public function save(User $user) : void
{ {
$this->entityManager->persist($user); $this->entityManager->persist($user);

23
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 %}
<div class="padding-16-px margin-y-8-px border-radius-3-px background-color-night">
<div class="row">
<div class="column width-80">
<a href="{{ path('user_info', {'id': activity.user.id}) }}">
<img class="vertical-align-middle border-radius-50 border-default border-width-2-px margin-r-8-px"
src="{{ activity.user.identicon }}"
alt="{{ 'identicon'|trans }}" />
</a>
{% if activity.type == 'join' %}
{{ 'joined'|trans }} {{ name }}
{% endif %}
</div>
<div class="column width-20 text-right padding-y-4-px">
{{ activity.added }}
</div>
</div>
</div>
{% endfor %}
{% endblock %}
Loading…
Cancel
Save