Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
100.00% |
15 / 15 |
|
100.00% |
2 / 2 |
CRAP | |
100.00% |
1 / 1 |
| UserHelper | |
100.00% |
15 / 15 |
|
100.00% |
2 / 2 |
4 | |
100.00% |
1 / 1 |
| __construct | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| getAllUsersForTemplate | |
100.00% |
14 / 14 |
|
100.00% |
1 / 1 |
3 | |||
| 1 | <?php |
| 2 | |
| 3 | /** |
| 4 | * Helper class for phpMyFAQ user. |
| 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\Helper |
| 11 | * @author Thorsten Rinne <thorsten@phpmyfaq.de> |
| 12 | * @copyright 2021-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 2021-03-14 |
| 16 | */ |
| 17 | |
| 18 | declare(strict_types=1); |
| 19 | |
| 20 | namespace phpMyFAQ\Helper; |
| 21 | |
| 22 | use phpMyFAQ\User; |
| 23 | |
| 24 | /** |
| 25 | * Class UserHelper |
| 26 | * |
| 27 | * @package phpMyFAQ\Helper |
| 28 | */ |
| 29 | readonly class UserHelper |
| 30 | { |
| 31 | /** |
| 32 | * UserHelper constructor. |
| 33 | */ |
| 34 | public function __construct( |
| 35 | private User $user, |
| 36 | ) { |
| 37 | } |
| 38 | |
| 39 | /** |
| 40 | * Get all users in <option> tags. |
| 41 | * |
| 42 | * @param int $selectedId Selected user ID |
| 43 | * @param bool $allowBlockedUsers Allow blocked users as well, e.g., in admin |
| 44 | * @return array Array of users with 'id', 'selected', 'displayName', and 'login' keys |
| 45 | */ |
| 46 | public function getAllUsersForTemplate(int $selectedId = 1, bool $allowBlockedUsers = false): array |
| 47 | { |
| 48 | $users = []; |
| 49 | $user = clone $this->user; |
| 50 | $allUserIds = $user->getAllUsers(true, $allowBlockedUsers); |
| 51 | |
| 52 | foreach ($allUserIds as $allUserId) { |
| 53 | if ($allUserId === -1) { |
| 54 | continue; |
| 55 | } |
| 56 | |
| 57 | $user->getUserById($allUserId); |
| 58 | $users[] = [ |
| 59 | 'id' => $allUserId, |
| 60 | 'selected' => $allUserId === $selectedId, |
| 61 | 'displayName' => $user->getUserData('display_name'), |
| 62 | 'login' => $user->getLogin(), |
| 63 | ]; |
| 64 | } |
| 65 | |
| 66 | return $users; |
| 67 | } |
| 68 | } |