Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
100.00% covered (success)
100.00%
23 / 23
100.00% covered (success)
100.00%
2 / 2
CRAP
100.00% covered (success)
100.00%
1 / 1
GlossaryController
100.00% covered (success)
100.00%
23 / 23
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%
22 / 22
100.00% covered (success)
100.00%
1 / 1
1
1<?php
2
3/**
4 * The Administration glossary 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-01
16 */
17
18declare(strict_types=1);
19
20namespace phpMyFAQ\Controller\Administration;
21
22use phpMyFAQ\Core\Exception;
23use phpMyFAQ\Enums\PermissionType;
24use phpMyFAQ\Glossary;
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 GlossaryController extends AbstractAdministrationController
33{
34    public function __construct(
35        private readonly Glossary $glossary,
36    ) {
37        parent::__construct();
38    }
39
40    /**
41     * @throws LoaderError
42     * @throws Exception
43     * @throws \Exception
44     */
45    #[Route(path: '/glossary', name: 'admin.glossary', methods: ['GET'])]
46    public function index(Request $request): Response
47    {
48        $this->userHasPermission(PermissionType::GLOSSARY_ADD);
49        $this->userHasPermission(PermissionType::GLOSSARY_EDIT);
50        $this->userHasPermission(PermissionType::GLOSSARY_DELETE);
51
52        $this->glossary->setLanguage($this->configuration->getLanguage()->getLanguage());
53
54        return $this->render('@admin/content/glossary.twig', [
55            ...$this->getHeader($request),
56            ...$this->getFooter(),
57            'adminHeaderGlossary' => Translation::get(key: 'ad_menu_glossary'),
58            'msgAddGlossary' => Translation::get(key: 'ad_glossary_add'),
59            'msgGlossaryItem' => Translation::get(key: 'ad_glossary_item'),
60            'msgGlossaryDefinition' => Translation::get(key: 'ad_glossary_definition'),
61            'glossaryItems' => $this->glossary->fetchAll(),
62            'buttonDelete' => Translation::get(key: 'msgDelete'),
63            'csrfTokenDelete' => Token::getInstance($this->session)->getTokenString('delete-glossary'),
64            'currentLanguage' => $this->configuration->getLanguage()->getLanguage(),
65            'addGlossaryTitle' => Translation::get(key: 'ad_glossary_add'),
66            'addGlossaryCsrfTokenInput' => Token::getInstance($this->session)->getTokenInput('add-glossary'),
67            'closeModal' => Translation::get(key: 'ad_att_close'),
68            'saveModal' => Translation::get(key: 'ad_gen_save'),
69            'updateGlossaryTitle' => Translation::get(key: 'ad_glossary_edit'),
70            'updateGlossaryCsrfToken' => Token::getInstance($this->session)->getTokenString('update-glossary'),
71        ]);
72    }
73}