Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
100.00% covered (success)
100.00%
32 / 32
100.00% covered (success)
100.00%
2 / 2
CRAP
100.00% covered (success)
100.00%
1 / 1
ExportController
100.00% covered (success)
100.00%
32 / 32
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%
31 / 31
100.00% covered (success)
100.00%
1 / 1
1
1<?php
2
3/**
4 * The Administration Export 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-11-23
16 */
17
18declare(strict_types=1);
19
20namespace phpMyFAQ\Controller\Administration;
21
22use phpMyFAQ\Category;
23use phpMyFAQ\Core\Exception;
24use phpMyFAQ\Database;
25use phpMyFAQ\Enums\PermissionType;
26use phpMyFAQ\Helper\CategoryHelper;
27use phpMyFAQ\Session\Token;
28use phpMyFAQ\Translation;
29use phpMyFAQ\User\CurrentUser;
30use Symfony\Component\HttpFoundation\HeaderUtils;
31use Symfony\Component\HttpFoundation\Request;
32use Symfony\Component\HttpFoundation\Response;
33use Symfony\Component\Routing\Attribute\Route;
34use Twig\Error\LoaderError;
35
36final class ExportController extends AbstractAdministrationController
37{
38    public function __construct(
39        private readonly CategoryHelper $categoryHelper,
40    ) {
41        parent::__construct();
42    }
43
44    /**
45     * @throws Exception
46     * @throws LoaderError
47     * @throws \Exception
48     */
49    #[Route(path: '/export', name: 'admin.export', methods: ['GET'])]
50    public function index(Request $request): Response
51    {
52        $this->userHasPermission(PermissionType::EXPORT);
53
54        [$currentUser, $currentGroups] = CurrentUser::getCurrentUserGroupId($this->currentUser);
55
56        $category = new Category($this->configuration, [], false);
57        $category->setUser($currentUser);
58        $category->setGroups($currentGroups);
59        $category->buildCategoryTree();
60
61        $this->categoryHelper->setCategory($category);
62
63        return $this->render('@admin/import-export/export.twig', [
64            ...$this->getHeader($request),
65            ...$this->getFooter(),
66            'adminHeaderExport' => Translation::get(key: 'ad_menu_export'),
67            'hasNoFaqs' => Database::checkOnEmptyTable('faqdata'),
68            'errorMessageNoFaqs' => Translation::get(key: 'msgErrorNoRecords'),
69            'hasCategories' => !Database::checkOnEmptyTable('faqcategories'),
70            'headerCategories' => Translation::get(key: 'ad_export_which_cat'),
71            'msgCategory' => Translation::get(key: 'msgCategory'),
72            'msgAllCategories' => Translation::get(key: 'msgShowAllCategories'),
73            'categoryTree' => $category->getCategoryTree(),
74            'selectedCategories' => 0,
75            'msgWithSubCategories' => Translation::get(key: 'ad_export_cat_downwards'),
76            'headerExportType' => Translation::get(key: 'ad_export_type'),
77            'msgChooseExportType' => Translation::get(key: 'ad_export_type_choose'),
78            'msgViewType' => Translation::get(key: 'ad_export_download_view'),
79            'msgDownloadType' => HeaderUtils::DISPOSITION_ATTACHMENT,
80            'msgDownload' => Translation::get(key: 'ad_export_download'),
81            'msgInlineType' => HeaderUtils::DISPOSITION_INLINE,
82            'msgInline' => Translation::get(key: 'ad_export_view'),
83            'buttonReset' => Translation::get(key: 'ad_config_reset'),
84            'buttonExport' => Translation::get(key: 'ad_menu_export'),
85            'csrfToken' => Token::getInstance($this->session)->getTokenString('export'),
86        ]);
87    }
88}