Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
100.00% |
19 / 19 |
|
100.00% |
2 / 2 |
CRAP | |
100.00% |
1 / 1 |
| ReportRepository | |
100.00% |
19 / 19 |
|
100.00% |
2 / 2 |
6 | |
100.00% |
1 / 1 |
| __construct | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| fetchAllReportData | |
100.00% |
18 / 18 |
|
100.00% |
1 / 1 |
5 | |||
| 1 | <?php |
| 2 | |
| 3 | /** |
| 4 | * Report Repository. |
| 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 2025-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 2025-11-30 |
| 16 | */ |
| 17 | |
| 18 | declare(strict_types=1); |
| 19 | |
| 20 | namespace phpMyFAQ\Administration; |
| 21 | |
| 22 | use phpMyFAQ\Configuration; |
| 23 | use phpMyFAQ\Database; |
| 24 | |
| 25 | readonly class ReportRepository |
| 26 | { |
| 27 | public function __construct( |
| 28 | private Configuration $configuration, |
| 29 | ) { |
| 30 | } |
| 31 | |
| 32 | /** |
| 33 | * Fetches all FAQ data with related information for reporting. |
| 34 | * |
| 35 | * @return array<int, \stdClass> |
| 36 | */ |
| 37 | public function fetchAllReportData(): array |
| 38 | { |
| 39 | $query = sprintf( |
| 40 | ' |
| 41 | SELECT |
| 42 | fd.id AS id, |
| 43 | fd.lang AS lang, |
| 44 | fcr.category_id AS category_id, |
| 45 | c.name as category_name, |
| 46 | c.parent_id as parent_id, |
| 47 | fd.sticky AS sticky, |
| 48 | fd.thema AS question, |
| 49 | fd.author AS original_author, |
| 50 | fd.updated AS updated, |
| 51 | fv.visits AS visits, |
| 52 | u.display_name AS last_author |
| 53 | FROM |
| 54 | %sfaqdata fd |
| 55 | LEFT JOIN |
| 56 | %sfaqcategoryrelations fcr |
| 57 | ON |
| 58 | (fd.id = fcr.record_id AND fd.lang = fcr.record_lang) |
| 59 | LEFT JOIN |
| 60 | %sfaqvisits fv |
| 61 | ON |
| 62 | (fd.id = fv.id AND fd.lang = fv.lang) |
| 63 | LEFT JOIN |
| 64 | %sfaqchanges as fc |
| 65 | ON |
| 66 | (fd.id = fc.id AND fd.lang = fc.lang) |
| 67 | LEFT JOIN |
| 68 | %sfaquserdata as u |
| 69 | ON |
| 70 | (u.user_id = fc.usr) |
| 71 | LEFT JOIN |
| 72 | %sfaqcategories as c |
| 73 | ON |
| 74 | (c.id = fcr.category_id AND c.lang = fcr.record_lang) |
| 75 | ORDER BY |
| 76 | fd.id |
| 77 | ASC', |
| 78 | Database::getTablePrefix(), |
| 79 | Database::getTablePrefix(), |
| 80 | Database::getTablePrefix(), |
| 81 | Database::getTablePrefix(), |
| 82 | Database::getTablePrefix(), |
| 83 | Database::getTablePrefix(), |
| 84 | ); |
| 85 | |
| 86 | $result = $this->configuration->getDb()->query($query); |
| 87 | |
| 88 | $rows = []; |
| 89 | while (true) { |
| 90 | $row = $this->configuration->getDb()->fetchObject($result); |
| 91 | if ($row === false || $row === null || $row === []) { |
| 92 | break; |
| 93 | } |
| 94 | |
| 95 | $rows[] = $row; |
| 96 | } |
| 97 | |
| 98 | return $rows; |
| 99 | } |
| 100 | } |