Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
100.00% |
31 / 31 |
|
100.00% |
1 / 1 |
CRAP | |
100.00% |
1 / 1 |
| AdminLogController | |
100.00% |
31 / 31 |
|
100.00% |
1 / 1 |
1 | |
100.00% |
1 / 1 |
| index | |
100.00% |
31 / 31 |
|
100.00% |
1 / 1 |
1 | |||
| 1 | <?php |
| 2 | |
| 3 | /** |
| 4 | * The Administration admin log 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-26 |
| 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\Filter; |
| 25 | use phpMyFAQ\Pagination; |
| 26 | use phpMyFAQ\Pagination\UrlConfig; |
| 27 | use phpMyFAQ\Session\Token; |
| 28 | use phpMyFAQ\Translation; |
| 29 | use phpMyFAQ\Twig\Extensions\UserNameTwigExtension; |
| 30 | use Symfony\Component\HttpFoundation\Request; |
| 31 | use Symfony\Component\HttpFoundation\Response; |
| 32 | use Symfony\Component\Routing\Attribute\Route; |
| 33 | use Twig\Error\LoaderError; |
| 34 | use Twig\Extension\AttributeExtension; |
| 35 | use Twig\Extra\Intl\IntlExtension; |
| 36 | |
| 37 | final class AdminLogController extends AbstractAdministrationController |
| 38 | { |
| 39 | /** |
| 40 | * @throws LoaderError |
| 41 | * @throws Exception |
| 42 | * @throws \Exception |
| 43 | */ |
| 44 | #[Route(path: '/statistics/admin-log', name: 'admin.statistics.admin-log', methods: ['GET'])] |
| 45 | public function index(Request $request): Response |
| 46 | { |
| 47 | $this->userHasPermission(PermissionType::STATISTICS_ADMINLOG); |
| 48 | |
| 49 | $itemsPerPage = 15; |
| 50 | $page = Filter::filterVar($request->query->get('page'), FILTER_VALIDATE_INT, 1); |
| 51 | |
| 52 | $pagination = new Pagination( |
| 53 | baseUrl: $request->getUri(), |
| 54 | total: $this->adminLog->getNumberOfEntries(), |
| 55 | perPage: $itemsPerPage, |
| 56 | urlConfig: new UrlConfig(pageParamName: 'page'), |
| 57 | ); |
| 58 | |
| 59 | $loggingData = $this->adminLog->getAll(); |
| 60 | |
| 61 | $offset = ($page - 1) * $itemsPerPage; |
| 62 | $currentItems = array_slice($loggingData, $offset, $itemsPerPage); |
| 63 | |
| 64 | $this->addExtension(new IntlExtension()); |
| 65 | $this->addExtension(new AttributeExtension(UserNameTwigExtension::class)); |
| 66 | return $this->render('@admin/statistics/admin-log.twig', [ |
| 67 | ...$this->getHeader($request), |
| 68 | ...$this->getFooter(), |
| 69 | 'headerAdminLog' => Translation::get(key: 'ad_menu_adminlog'), |
| 70 | 'buttonExportAdminLog' => Translation::get(key: 'msgAdminLogExportCsv'), |
| 71 | 'buttonDeleteAdminLog' => Translation::get(key: 'ad_adminlog_del_older_30d'), |
| 72 | 'csrfExportAdminLogToken' => Token::getInstance($this->session)->getTokenString('export-adminlog'), |
| 73 | 'csrfVerifyAdminLogToken' => Token::getInstance($this->session)->getTokenString('admin-log-verify'), |
| 74 | 'csrfDeleteAdminLogToken' => Token::getInstance($this->session)->getTokenString('delete-adminlog'), |
| 75 | 'currentLocale' => $this->configuration->getLanguage()->getLanguage(), |
| 76 | 'pagination' => $pagination->render(), |
| 77 | 'msgId' => Translation::get(key: 'ad_categ_id'), |
| 78 | 'msgDate' => Translation::get(key: 'ad_adminlog_date'), |
| 79 | 'msgUser' => Translation::get(key: 'ad_adminlog_user'), |
| 80 | 'msgIp' => Translation::get(key: 'ad_adminlog_ip'), |
| 81 | 'loggingData' => $currentItems, |
| 82 | ]); |
| 83 | } |
| 84 | } |