Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
100.00% |
49 / 49 |
|
100.00% |
2 / 2 |
CRAP | |
100.00% |
1 / 1 |
| OpenQuestionsController | |
100.00% |
49 / 49 |
|
100.00% |
2 / 2 |
6 | |
100.00% |
1 / 1 |
| __construct | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| index | |
100.00% |
48 / 48 |
|
100.00% |
1 / 1 |
5 | |||
| 1 | <?php |
| 2 | |
| 3 | /** |
| 4 | * The Open Question 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 | |
| 18 | declare(strict_types=1); |
| 19 | |
| 20 | namespace phpMyFAQ\Controller\Administration; |
| 21 | |
| 22 | use phpMyFAQ\Core\Exception; |
| 23 | use phpMyFAQ\Enums\PermissionType; |
| 24 | use phpMyFAQ\Question; |
| 25 | use phpMyFAQ\Session\Token; |
| 26 | use phpMyFAQ\Translation; |
| 27 | use phpMyFAQ\Twig\Extensions\CategoryNameTwigExtension; |
| 28 | use Symfony\Component\HttpFoundation\Request; |
| 29 | use Symfony\Component\HttpFoundation\Response; |
| 30 | use Symfony\Component\Routing\Attribute\Route; |
| 31 | use Twig\Error\LoaderError; |
| 32 | use Twig\Extension\AttributeExtension; |
| 33 | use Twig\Extra\Intl\IntlExtension; |
| 34 | |
| 35 | final class OpenQuestionsController extends AbstractAdministrationController |
| 36 | { |
| 37 | public function __construct( |
| 38 | private readonly Question $question, |
| 39 | ) { |
| 40 | parent::__construct(); |
| 41 | } |
| 42 | |
| 43 | /** |
| 44 | * @throws Exception |
| 45 | * @throws LoaderError |
| 46 | */ |
| 47 | #[Route(path: '/questions', name: 'admin.questions', methods: ['GET'])] |
| 48 | public function index(Request $request): Response |
| 49 | { |
| 50 | $this->userHasPermission(PermissionType::QUESTION_DELETE); |
| 51 | |
| 52 | $question = $this->question; |
| 53 | $currentLang = $this->configuration->getLanguage()->getLanguage(); |
| 54 | $questions = $question->getAll(); |
| 55 | $allQuestions = $question->getAll(true, ''); |
| 56 | $otherLangsData = []; |
| 57 | $otherCount = 0; |
| 58 | |
| 59 | foreach ($allQuestions as $q) { |
| 60 | $langCode = $q->getLanguage(); |
| 61 | |
| 62 | if ($langCode !== $currentLang) { |
| 63 | $otherCount++; |
| 64 | |
| 65 | $longName = $langCode; |
| 66 | if (class_exists('\Locale')) { |
| 67 | $longName = \Locale::getDisplayLanguage($langCode, $currentLang); |
| 68 | } |
| 69 | |
| 70 | if (!array_key_exists($langCode, $otherLangsData)) { |
| 71 | $otherLangsData[$langCode] = [ |
| 72 | 'label' => $longName, |
| 73 | 'count' => 0, |
| 74 | ]; |
| 75 | } |
| 76 | $otherLangsData[$langCode]['count']++; |
| 77 | } |
| 78 | } |
| 79 | |
| 80 | $this->addExtension(new IntlExtension()); |
| 81 | $this->addExtension(new AttributeExtension(CategoryNameTwigExtension::class)); |
| 82 | return $this->render('@admin/content/open-questions.twig', [ |
| 83 | ...$this->getHeader($request), |
| 84 | ...$this->getFooter(), |
| 85 | 'msgOpenQuestions' => Translation::get(key: 'msgOpenQuestions'), |
| 86 | 'csrfTokenDeleteQuestion' => Token::getInstance($this->session)->getTokenString('delete-questions'), |
| 87 | 'currentLocale' => $currentLang, |
| 88 | 'msgQuestion' => Translation::get(key: 'msgQuestion'), |
| 89 | 'msgVisibility' => Translation::get(key: 'ad_entry_visibility'), |
| 90 | 'questions' => $questions, |
| 91 | 'otherCount' => $otherCount, |
| 92 | 'otherLangsData' => $otherLangsData, |
| 93 | 'yes' => Translation::get(key: 'ad_gen_yes'), |
| 94 | 'no' => Translation::get(key: 'ad_gen_no'), |
| 95 | 'enableCloseQuestion' => $this->configuration->get(item: 'records.enableCloseQuestion'), |
| 96 | 'msg2answerFAQ' => Translation::get(key: 'msg2answerFAQ'), |
| 97 | 'msgTakeQuestion' => Translation::get(key: 'ad_ques_take'), |
| 98 | 'csrfTokenToggleVisibility' => Token::getInstance($this->session)->getTokenString( |
| 99 | 'toggle-question-visibility', |
| 100 | ), |
| 101 | 'msgDeleteAllOpenQuestions' => Translation::get(key: 'msgDelete'), |
| 102 | 'msgAttention' => Translation::get(key: 'msgAttention'), |
| 103 | 'msgOtherQuestionsDesc' => Translation::get(key: 'msgOtherQuestionsDesc'), |
| 104 | 'msgOtherQuestionDesc' => Translation::get(key: 'msgOtherQuestionDesc'), |
| 105 | 'msgChangeLanguageHint' => Translation::get(key: 'msgChangeLanguageHint'), |
| 106 | 'msgOpenQuestion' => Translation::get(key: 'msgOpenQuestion'), |
| 107 | ]); |
| 108 | } |
| 109 | } |