Skip to content

Commit 54babf5

Browse files
committed
refactor: migrated start page (#3834)
1 parent 9a0ccac commit 54babf5

File tree

3 files changed

+109
-95
lines changed

3 files changed

+109
-95
lines changed
Lines changed: 103 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,103 @@
1+
<?php
2+
3+
/**
4+
* Start page Controller
5+
*
6+
* This Source Code Form is subject to the terms of the Mozilla Public License,
7+
* v. 2.0. If a copy of the MPL was not distributed with this file, You can
8+
* obtain one at https://mozilla.org/MPL/2.0/.
9+
*
10+
* @package phpMyFAQ
11+
* @author Thorsten Rinne <[email protected]>
12+
* @copyright 2002-2026 phpMyFAQ Team
13+
* @license https://www.mozilla.org/MPL/2.0/ Mozilla Public License Version 2.0
14+
* @link https://www.phpmyfaq.de
15+
* @since 2002-08-23
16+
*/
17+
18+
declare(strict_types=1);
19+
20+
namespace phpMyFAQ\Controller\Frontend;
21+
22+
use phpMyFAQ\Category\Startpage;
23+
use phpMyFAQ\Core\Exception;
24+
use phpMyFAQ\Faq\Statistics;
25+
use phpMyFAQ\Filter;
26+
use phpMyFAQ\Language\Plurals;
27+
use phpMyFAQ\News;
28+
use phpMyFAQ\Translation;
29+
use phpMyFAQ\Twig\Extensions\TagNameTwigExtension;
30+
use phpMyFAQ\User\CurrentUser;
31+
use Symfony\Component\HttpFoundation\Request;
32+
use Symfony\Component\HttpFoundation\Response;
33+
use Symfony\Component\Routing\Attribute\Route;
34+
use Twig\Extension\AttributeExtension;
35+
36+
final class StartpageController extends AbstractFrontController
37+
{
38+
/**
39+
* Displays the start page with categories, Top 10, and latest messages.
40+
*
41+
* @throws Exception
42+
* @throws \Exception
43+
*/
44+
#[Route(path: '/', name: 'public.index')]
45+
public function index(Request $request): Response
46+
{
47+
$news = new News($this->configuration);
48+
$plr = new Plurals();
49+
$faqStatistics = new Statistics($this->configuration);
50+
51+
[$currentUser, $currentGroups] = CurrentUser::getCurrentUserGroupId($this->currentUser);
52+
53+
$startPageCategory = new Startpage($this->configuration);
54+
$startPageCategory
55+
->setLanguage($this->configuration->getLanguage()->getLanguage())
56+
->setUser($currentUser)
57+
->setGroups($currentGroups);
58+
59+
$startPageCategories = $startPageCategory->getCategories();
60+
61+
// Get top ten parameter
62+
$param = $this->configuration->get('records.orderingPopularFaqs') === 'visits' ? 'visits' : 'voted';
63+
64+
$faq = $this->container->get('phpmyfaq.faq');
65+
$faq->setUser($currentUser);
66+
$faq->setGroups($currentGroups);
67+
68+
$tags = $this->container->get('phpmyfaq.tags');
69+
$tags->setUser($currentUser)->setGroups($currentGroups);
70+
71+
$faqSystem = $this->container->get('phpmyfaq.system');
72+
$categoryId = Filter::filterVar($request->query->get('cat'), FILTER_VALIDATE_INT, 0);
73+
74+
$this->addExtension(new AttributeExtension(TagNameTwigExtension::class));
75+
return $this->render('startpage.twig', [
76+
...$this->getHeader($request),
77+
'baseHref' => $faqSystem->getSystemUri($this->configuration),
78+
'title' => $this->configuration->getTitle(),
79+
'pageHeader' => $this->configuration->getTitle(),
80+
'startPageCategories' => (is_countable($startPageCategories) ? count($startPageCategories) : 0) > 0,
81+
'startPageCategoryDecks' => $startPageCategories,
82+
'stickyRecordsHeader' => Translation::get(key: 'stickyRecordsHeader'),
83+
'stickyRecordsList' => $faq->getStickyFaqsData(),
84+
'writeTopTenHeader' => Translation::get(key: 'msgTopTen'),
85+
'topRecordsList' => $faqStatistics->getTopTen($param),
86+
'errorMsgTopTen' => Translation::get(key: 'err_noTopTen'),
87+
'writeNewestHeader' => Translation::get(key: 'msgLatestArticles'),
88+
'latestRecordsList' => $faqStatistics->getLatest(),
89+
'errorMsgLatest' => Translation::get(key: 'msgErrorNoRecords'),
90+
'msgTrendingFAQs' => Translation::get(key: 'msgTrendingFAQs'),
91+
'trendingRecordsList' => $faqStatistics->getTrending(),
92+
'errorMsgTrendingFaqs' => Translation::get(key: 'msgErrorNoRecords'),
93+
'msgNewsHeader' => Translation::get(key: 'newsArchive'),
94+
'newsList' => $news->getAll(),
95+
'writeNumberOfArticles' => $plr->getMsg(
96+
'plmsgHomeArticlesOnline',
97+
$faqStatistics->totalFaqs($this->configuration->getLanguage()->getLanguage()),
98+
),
99+
'msgTags' => Translation::get(key: 'msgPopularTags'),
100+
'tagsList' => $tags->getPopularTags(12),
101+
]);
102+
}
103+
}

phpmyfaq/src/public-routes.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
use phpMyFAQ\Controller\Frontend\PdfController;
3030
use phpMyFAQ\Controller\Frontend\PrivacyController;
3131
use phpMyFAQ\Controller\Frontend\SitemapController as FrontendSitemapController;
32+
use phpMyFAQ\Controller\Frontend\StartpageController;
3233
use phpMyFAQ\Controller\Frontend\UserController;
3334
use phpMyFAQ\Controller\Frontend\WebAuthnController;
3435
use phpMyFAQ\Controller\LlmsController;
@@ -90,6 +91,11 @@
9091
'controller' => [PrivacyController::class, 'index'],
9192
'methods' => 'GET',
9293
],
94+
'public.index' => [
95+
'path' => '/',
96+
'controller' => [StartpageController::class, 'index'],
97+
'methods' => 'GET',
98+
],
9399
'public.user.register' => [
94100
'path' => '/user/register',
95101
'controller' => [UserController::class, 'register'],

phpmyfaq/startpage.php

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

0 commit comments

Comments
 (0)