Skip to content

Commit cb48e5c

Browse files
committed
refactor: migrated user bookmarks page (#3834)
1 parent 814e218 commit cb48e5c

File tree

3 files changed

+41
-55
lines changed

3 files changed

+41
-55
lines changed

phpmyfaq/bookmarks.php

Lines changed: 0 additions & 55 deletions
This file was deleted.

phpmyfaq/src/phpMyFAQ/Controller/Frontend/UserController.php

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,11 @@
2020

2121
namespace phpMyFAQ\Controller\Frontend;
2222

23+
use phpMyFAQ\Bookmark;
2324
use phpMyFAQ\Core\Exception;
2425
use phpMyFAQ\Session\Token;
26+
use phpMyFAQ\Translation;
27+
use Symfony\Component\HttpFoundation\RedirectResponse;
2528
use Symfony\Component\HttpFoundation\Request;
2629
use Symfony\Component\HttpFoundation\Response;
2730
use Symfony\Component\Routing\Attribute\Route;
@@ -37,6 +40,10 @@ final class UserController extends AbstractFrontController
3740
#[Route(path: '/user/request-removal', name: 'public.user.request-removal')]
3841
public function requestRemoval(Request $request): Response
3942
{
43+
if (!$this->currentUser->isLoggedIn()) {
44+
return new RedirectResponse($this->configuration->getDefaultUrl());
45+
}
46+
4047
$faqSession = $this->container->get('phpmyfaq.user.session');
4148
$faqSession->setCurrentUser($this->currentUser);
4249
$faqSession->userTracking('request_removal', 0);
@@ -54,4 +61,33 @@ public function requestRemoval(Request $request): Response
5461
'defaultLoginName' => $this->currentUser->getUserId() > 0 ? $this->currentUser->getLogin() : '',
5562
]);
5663
}
64+
65+
/**
66+
* Displays the user's bookmarks page.
67+
*
68+
* @throws Exception
69+
* @throws \Exception
70+
*/
71+
#[Route(path: '/user/bookmarks', name: 'public.user.bookmarks')]
72+
public function bookmarks(Request $request): Response
73+
{
74+
if (!$this->currentUser->isLoggedIn()) {
75+
return new RedirectResponse($this->configuration->getDefaultUrl());
76+
}
77+
78+
$faqSession = $this->container->get('phpmyfaq.user.session');
79+
$faqSession->setCurrentUser($this->currentUser);
80+
$faqSession->userTracking('bookmarks', 0);
81+
82+
$bookmark = new Bookmark($this->configuration, $this->currentUser);
83+
$session = $this->container->get('session');
84+
85+
return $this->render('bookmarks.twig', [
86+
...$this->getHeader($request),
87+
'title' => sprintf('%s - %s', Translation::get(key: 'msgBookmarks'), $this->configuration->getTitle()),
88+
'bookmarksList' => $bookmark->getBookmarkList(),
89+
'csrfTokenDeleteBookmark' => Token::getInstance($session)->getTokenString('delete-bookmark'),
90+
'csrfTokenDeleteAllBookmarks' => Token::getInstance($session)->getTokenString('delete-all-bookmarks'),
91+
]);
92+
}
5793
}

phpmyfaq/src/public-routes.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,11 @@
8383
'controller' => [UserController::class, 'requestRemoval'],
8484
'methods' => 'GET',
8585
],
86+
'public.user.bookmarks' => [
87+
'path' => '/user/bookmarks',
88+
'controller' => [UserController::class, 'bookmarks'],
89+
'methods' => 'GET',
90+
],
8691
'public.sitemap' => [
8792
'path' => '/sitemap/{letter}/{language}.html',
8893
'controller' => [FrontendSitemapController::class, 'index'],

0 commit comments

Comments
 (0)