Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
100.00% covered (success)
100.00%
21 / 21
100.00% covered (success)
100.00%
2 / 2
CRAP
100.00% covered (success)
100.00%
1 / 1
StickyFaqsController
100.00% covered (success)
100.00%
21 / 21
100.00% covered (success)
100.00%
2 / 2
3
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%
20 / 20
100.00% covered (success)
100.00%
1 / 1
2
1<?php
2
3/**
4 * The Sticky FAQs Administration 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 <thorsten@phpmyfaq.de>
12 * @copyright 2024-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     2024-12-02
16 */
17
18declare(strict_types=1);
19
20namespace phpMyFAQ\Controller\Administration;
21
22use phpMyFAQ\Core\Exception;
23use phpMyFAQ\Enums\PermissionType;
24use phpMyFAQ\Faq;
25use phpMyFAQ\Session\Token;
26use phpMyFAQ\Translation;
27use Symfony\Component\HttpFoundation\Request;
28use Symfony\Component\HttpFoundation\Response;
29use Symfony\Component\Routing\Attribute\Route;
30use Twig\Error\LoaderError;
31
32final class StickyFaqsController extends AbstractAdministrationController
33{
34    public function __construct(
35        private readonly Faq $faq,
36    ) {
37        parent::__construct();
38    }
39
40    /**
41     * @throws Exception
42     * @throws LoaderError
43     * @throws \Exception
44     */
45    #[Route(path: '/sticky-faqs', name: 'admin.content.sticky-faqs', methods: ['GET'])]
46    public function index(Request $request): Response
47    {
48        $this->userHasPermission(PermissionType::FAQ_EDIT);
49
50        $customOrdering = $this->configuration->get(item: 'records.orderStickyFaqsCustom');
51
52        return $this->render('@admin/content/sticky-faqs.twig', [
53            ...$this->getHeader($request),
54            ...$this->getFooter(),
55            'stickyFAQsHeader' => Translation::get(key: 'stickyRecordsHeader'),
56            'stickyData' => $this->faq->getStickyFaqsData(),
57            'sortableDisabled' => $customOrdering === false ? 'sortable-disabled' : '',
58            'orderingStickyFaqsActivated' => $this->configuration->get(item: 'records.orderStickyFaqsCustom'),
59            'alertMessageStickyFaqsDeactivated' => Translation::get(key: 'msgOrderStickyFaqsCustomDeactivated'),
60            'alertMessageNoStickyRecords' => Translation::get(key: 'msgNoStickyFaqs'),
61            'msgRemoveSticky' => Translation::get(key: 'msgTooltipUnstick'),
62            'msgConfirmUnstick' => Translation::get(key: 'msgConfirmUnstick'),
63            'msgSuccessUnstick' => Translation::get(key: 'msgStickyRemoved'),
64            'msgConfirmAction' => Translation::get(key: 'msgConfirmAction'),
65            'msgCancel' => Translation::get(key: 'ad_gen_cancel'),
66            'msgConfirm' => Translation::get(key: 'ad_gen_save'),
67            'csrfToken' => Token::getInstance($this->session)->getTokenString('order-stickyfaqs'),
68            'csrfTokenApi' => Token::getInstance($this->session)->getTokenString('pmf-csrf-token'),
69        ]);
70    }
71}