Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
100.00% |
24 / 24 |
|
100.00% |
2 / 2 |
CRAP | |
100.00% |
1 / 1 |
| RecentUsers | |
100.00% |
24 / 24 |
|
100.00% |
2 / 2 |
8 | |
100.00% |
1 / 1 |
| __construct | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| getList | |
100.00% |
23 / 23 |
|
100.00% |
1 / 1 |
7 | |||
| 1 | <?php |
| 2 | |
| 3 | /** |
| 4 | * Service to fetch the recent registered users for admin dashboard widgets. |
| 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-01 |
| 16 | */ |
| 17 | |
| 18 | declare(strict_types=1); |
| 19 | |
| 20 | namespace phpMyFAQ\Administration; |
| 21 | |
| 22 | use phpMyFAQ\Configuration; |
| 23 | use phpMyFAQ\Database; |
| 24 | use phpMyFAQ\Date; |
| 25 | |
| 26 | final readonly class RecentUsers |
| 27 | { |
| 28 | public function __construct( |
| 29 | private Configuration $configuration, |
| 30 | ) { |
| 31 | } |
| 32 | |
| 33 | /** |
| 34 | * Returns recent users for the admin dashboard. |
| 35 | * |
| 36 | * @return array<int, array<string, mixed>> |
| 37 | */ |
| 38 | public function getList(int $limit = 5): array |
| 39 | { |
| 40 | $users = []; |
| 41 | $databaseDriver = $this->configuration->getDb(); |
| 42 | |
| 43 | $query = sprintf( |
| 44 | 'SELECT fu.user_id, fu.login, fu.member_since, fud.display_name FROM %sfaquser fu LEFT JOIN %sfaquserdata fud ' |
| 45 | . 'ON (fud.user_id = fu.user_id) WHERE fu.user_id <> -1 ORDER BY fu.member_since DESC', |
| 46 | Database::getTablePrefix(), |
| 47 | Database::getTablePrefix(), |
| 48 | ); |
| 49 | |
| 50 | $result = $databaseDriver->query($query, 0, $limit); |
| 51 | if ($result) { |
| 52 | while (true) { |
| 53 | $row = $databaseDriver->fetchArray($result); |
| 54 | if ($row === false || $row === null || $row === []) { |
| 55 | break; |
| 56 | } |
| 57 | |
| 58 | $users[] = [ |
| 59 | 'id' => (int) ($row['user_id'] ?? 0), |
| 60 | 'login' => (string) ($row['login'] ?? ''), |
| 61 | 'display_name' => (string) ($row['display_name'] ?? ''), |
| 62 | 'member_since_iso' => ($row['member_since'] ?? '') === '' |
| 63 | ? '' |
| 64 | : Date::createIsoDate((string) $row['member_since']), |
| 65 | ]; |
| 66 | } |
| 67 | } |
| 68 | |
| 69 | return $users; |
| 70 | } |
| 71 | } |