Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
Total | |
100.00% |
21 / 21 |
|
100.00% |
8 / 8 |
CRAP | |
100.00% |
1 / 1 |
UserPilotDto | |
100.00% |
21 / 21 |
|
100.00% |
8 / 8 |
14 | |
100.00% |
1 / 1 |
__construct | |
100.00% |
14 / 14 |
|
100.00% |
1 / 1 |
7 | |||
getUserId | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
getUserLogin | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
getUserName | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
getUserEmail | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
getInterfaceLanguage | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
getUserRoles | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
getTenantId | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 |
1 | <?php |
2 | |
3 | /** |
4 | * This program is free software; you can redistribute it and/or |
5 | * modify it under the terms of the GNU General Public License |
6 | * as published by the Free Software Foundation; under version 2 |
7 | * of the License (non-upgradable). |
8 | * |
9 | * This program is distributed in the hope that it will be useful, |
10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
12 | * GNU General Public License for more details. |
13 | * |
14 | * You should have received a copy of the GNU General Public License |
15 | * along with this program; if not, write to the Free Software |
16 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. |
17 | * |
18 | * Copyright (c) 2024 (original work) Open Assessment Technologies SA; |
19 | */ |
20 | |
21 | namespace oat\tao\model\session\Dto; |
22 | |
23 | use common_session_Session; |
24 | use oat\tao\model\session\Context\TenantDataSessionContext; |
25 | use oat\tao\model\session\Context\UserDataSessionContext; |
26 | |
27 | class UserPilotDto |
28 | { |
29 | public const NOT_AVAILABLE = 'N/A'; |
30 | public const DEFAULT_LOCALE = 'en-US'; |
31 | private ?string $userId = null; |
32 | private ?string $userName = null; |
33 | private ?string $userLogin = null; |
34 | private ?string $userEmail = null; |
35 | private ?string $interfaceLanguage = null; |
36 | private array $userRoles = []; |
37 | private ?string $tenantId = null; |
38 | |
39 | public function __construct($session = null) |
40 | { |
41 | if ($session instanceof common_session_Session) { |
42 | $contexts = $session->getContexts() ?? []; |
43 | foreach ($contexts as $context) { |
44 | if ($context instanceof UserDataSessionContext) { |
45 | $this->userId = $context->getUserId(); |
46 | $this->userLogin = $context->getUserLogin() ?? self::NOT_AVAILABLE; |
47 | $this->userName = $context->getUserName() ?? self::NOT_AVAILABLE; |
48 | $this->userEmail = $context->getUserEmail() ?? self::NOT_AVAILABLE; |
49 | $this->interfaceLanguage = $context->getLocale() ?? self::DEFAULT_LOCALE; |
50 | } elseif ($context instanceof TenantDataSessionContext) { |
51 | $this->tenantId = $context->getTenantId(); |
52 | } |
53 | } |
54 | |
55 | if (null !== $this->userId && null !== $this->tenantId) { |
56 | $this->userId = $this->tenantId . '|' . $this->userId; |
57 | } |
58 | |
59 | $this->userRoles = $session->getUserRoles() ?? []; |
60 | } |
61 | } |
62 | |
63 | public function getUserId(): ?string |
64 | { |
65 | return $this->userId; |
66 | } |
67 | |
68 | public function getUserLogin(): ?string |
69 | { |
70 | return $this->userLogin; |
71 | } |
72 | |
73 | public function getUserName(): ?string |
74 | { |
75 | return $this->userName; |
76 | } |
77 | |
78 | public function getUserEmail(): ?string |
79 | { |
80 | return $this->userEmail; |
81 | } |
82 | |
83 | public function getInterfaceLanguage(): ?string |
84 | { |
85 | return $this->interfaceLanguage; |
86 | } |
87 | |
88 | public function getUserRoles(): array |
89 | { |
90 | return $this->userRoles; |
91 | } |
92 | |
93 | public function getTenantId(): ?string |
94 | { |
95 | return $this->tenantId; |
96 | } |
97 | } |