Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
100.00% covered (success)
100.00%
27 / 27
100.00% covered (success)
100.00%
2 / 2
CRAP
100.00% covered (success)
100.00%
1 / 1
OverviewController
100.00% covered (success)
100.00%
27 / 27
100.00% covered (success)
100.00%
2 / 2
2
100.00% covered (success)
100.00%
1 / 1
 __construct
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 index
100.00% covered (success)
100.00%
26 / 26
100.00% covered (success)
100.00%
1 / 1
1
1<?php
2
3declare(strict_types=1);
4
5/**
6 * Overview Controller
7 *
8 * This Source Code Form is subject to the terms of the Mozilla Public License,
9 * v. 2.0. If a copy of the MPL was not distributed with this file, You can
10 * obtain one at https://mozilla.org/MPL/2.0/.
11 *
12 * @package   phpMyFAQ
13 * @author    Thorsten Rinne <thorsten@phpmyfaq.de>
14 * @copyright 2015-2026 phpMyFAQ Team
15 * @license   https://www.mozilla.org/MPL/2.0/ Mozilla Public License Version 2.0
16 * @link      https://www.phpmyfaq.de
17 * @since     2015-09-27
18 */
19
20namespace phpMyFAQ\Controller\Frontend;
21
22use phpMyFAQ\Category;
23use phpMyFAQ\Core\Exception;
24use phpMyFAQ\Faq;
25use phpMyFAQ\Helper\FaqHelper;
26use phpMyFAQ\Translation;
27use phpMyFAQ\Twig\Extensions\CategoryNameTwigExtension;
28use phpMyFAQ\Twig\Extensions\CreateLinkTwigExtension;
29use phpMyFAQ\Twig\Extensions\FaqTwigExtension;
30use phpMyFAQ\User\CurrentUser;
31use phpMyFAQ\User\UserSession;
32use Symfony\Component\HttpFoundation\Request;
33use Symfony\Component\HttpFoundation\Response;
34use Symfony\Component\Routing\Attribute\Route;
35use Twig\Error\LoaderError;
36use Twig\Extension\AttributeExtension;
37
38final class OverviewController extends AbstractFrontController
39{
40    public function __construct(
41        private readonly UserSession $faqSession,
42        private readonly FaqHelper $faqHelper,
43        private readonly Faq $faq,
44    ) {
45        parent::__construct();
46    }
47
48    /**
49     * @throws Exception
50     * @throws LoaderError
51     * @throws \Exception
52     */
53    #[Route(path: '/overview.html', name: 'public.overview', methods: ['GET'])]
54    public function index(Request $request): Response
55    {
56        $this->faqSession->setCurrentUser($this->currentUser);
57        $this->faqSession->userTracking('overview', 0);
58
59        [$currentUser, $currentGroups] = CurrentUser::getCurrentUserGroupId($this->currentUser);
60
61        $category = new Category($this->configuration, $currentGroups, true);
62        $category->setUser($currentUser)->setGroups($currentGroups);
63
64        $this->faq->setUser($currentUser);
65        $this->faq->setGroups($currentGroups);
66
67        $this->addExtension(new AttributeExtension(CategoryNameTwigExtension::class));
68        $this->addExtension(new AttributeExtension(CreateLinkTwigExtension::class));
69        $this->addExtension(new AttributeExtension(FaqTwigExtension::class));
70        return $this->render('overview.twig', [
71            ...$this->getHeader($request),
72            'title' => sprintf('%s - %s', Translation::getString(key: 'faqOverview'), $this->configuration->getTitle()),
73            'metaDescription' => sprintf(
74                Translation::getString(key: 'msgOverviewMetaDesc'),
75                $this->configuration->getTitle(),
76            ),
77            'pageHeader' => Translation::get(key: 'faqOverview'),
78            'faqOverview' => $this->faqHelper->createOverview(
79                $category,
80                $this->faq,
81                $this->configuration->getLanguage()->getLanguage(),
82            ),
83            'msgAuthor' => Translation::get(key: 'msgAuthor'),
84            'msgLastUpdateArticle' => Translation::get(key: 'msgLastUpdateArticle'),
85        ]);
86    }
87}