Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
100.00% |
26 / 26 |
|
100.00% |
1 / 1 |
CRAP | |
100.00% |
1 / 1 |
| UserPilotTemplateHelper | |
100.00% |
26 / 26 |
|
100.00% |
1 / 1 |
4 | |
100.00% |
1 / 1 |
| userPilotCode | |
100.00% |
26 / 26 |
|
100.00% |
1 / 1 |
4 | |||
| 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\helpers; |
| 22 | |
| 23 | use common_exception_Error; |
| 24 | use oat\tao\model\session\Dto\UserPilotDto; |
| 25 | |
| 26 | class UserPilotTemplateHelper extends Layout |
| 27 | { |
| 28 | public const USER_PILOT_TEMPLATE = 'blocks/userpilot.tpl'; |
| 29 | |
| 30 | /** |
| 31 | * @throws common_exception_Error |
| 32 | */ |
| 33 | public static function userPilotCode(UserPilotDto $dto): void |
| 34 | { |
| 35 | $userPilotToken = getenv('USER_PILOT_TOKEN'); |
| 36 | if (!$userPilotToken || !method_exists(self::$templateClass, 'inc')) { |
| 37 | return; |
| 38 | } |
| 39 | |
| 40 | if (!$dto->getUserId()) { |
| 41 | return; |
| 42 | } |
| 43 | |
| 44 | call_user_func( |
| 45 | [self::$templateClass, 'inc'], |
| 46 | self::USER_PILOT_TEMPLATE, |
| 47 | 'tao', |
| 48 | [ |
| 49 | 'userpilot_data' => [ |
| 50 | 'token' => $userPilotToken, |
| 51 | 'user' => [ |
| 52 | 'id' => $dto->getUserId(), |
| 53 | 'name' => $dto->getUserName(), |
| 54 | 'login' => $dto->getUserLogin(), |
| 55 | 'email' => $dto->getUserEmail(), |
| 56 | 'roles' => join(',', $dto->getUserRoles()), |
| 57 | 'interface_language' => $dto->getInterfaceLanguage(), |
| 58 | ], |
| 59 | 'tenant' => [ |
| 60 | 'id' => $dto->getTenantId(), |
| 61 | ] |
| 62 | ], |
| 63 | ] |
| 64 | ); |
| 65 | } |
| 66 | } |