Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
65.52% |
19 / 29 |
|
42.86% |
3 / 7 |
CRAP | |
0.00% |
0 / 1 |
| Lti1p3User | |
65.52% |
19 / 29 |
|
42.86% |
3 / 7 |
28.85 | |
0.00% |
0 / 1 |
| __construct | |
100.00% |
5 / 5 |
|
100.00% |
1 / 1 |
3 | |||
| getRegistrationId | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| setRegistrationId | |
100.00% |
2 / 2 |
|
100.00% |
1 / 1 |
1 | |||
| setUserFirstTimeUri | |
0.00% |
0 / 2 |
|
0.00% |
0 / 1 |
2 | |||
| setUserLatestExtension | |
0.00% |
0 / 2 |
|
0.00% |
0 / 1 |
2 | |||
| determineTaoRoles | |
91.67% |
11 / 12 |
|
0.00% |
0 / 1 |
5.01 | |||
| getPropertyValues | |
0.00% |
0 / 5 |
|
0.00% |
0 / 1 |
30 | |||
| 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) 2021-2022 (original work) Open Assessment Technologies SA; |
| 19 | */ |
| 20 | |
| 21 | declare(strict_types=1); |
| 22 | |
| 23 | namespace oat\taoLti\models\classes\user; |
| 24 | |
| 25 | use oat\tao\model\TaoOntology; |
| 26 | use oat\taoLti\models\classes\LtiLaunchData; |
| 27 | use oat\taoLti\models\classes\LtiRoles; |
| 28 | use oat\taoLti\models\classes\LtiUtils; |
| 29 | use oat\taoLti\models\classes\LtiVariableMissingException; |
| 30 | |
| 31 | class Lti1p3User extends LtiUser |
| 32 | { |
| 33 | /** @var string */ |
| 34 | private $registrationId = null; |
| 35 | private ?string $userFirstTimeUri = null; |
| 36 | private ?string $userLatestExtension = null; |
| 37 | |
| 38 | /** |
| 39 | * @param LtiLaunchData $launchData |
| 40 | * @throws \common_Exception |
| 41 | * @throws \common_exception_Error |
| 42 | * @throws LtiVariableMissingException |
| 43 | */ |
| 44 | public function __construct($launchData, string $userUri = null) |
| 45 | { |
| 46 | if ($userUri === null) { |
| 47 | $userUri = $launchData->hasVariable(LtiLaunchData::USER_ID) |
| 48 | ? $launchData->getVariable(LtiLaunchData::USER_ID) |
| 49 | : self::ANONYMOUS_USER_URI; |
| 50 | } |
| 51 | |
| 52 | parent::__construct($launchData, $userUri); |
| 53 | } |
| 54 | |
| 55 | public function getRegistrationId(): ?string |
| 56 | { |
| 57 | return $this->registrationId; |
| 58 | } |
| 59 | |
| 60 | public function setRegistrationId(string $registrationId): self |
| 61 | { |
| 62 | $this->registrationId = $registrationId; |
| 63 | |
| 64 | return $this; |
| 65 | } |
| 66 | |
| 67 | public function setUserFirstTimeUri(string $userFirstTimeUri): self |
| 68 | { |
| 69 | $this->userFirstTimeUri = $userFirstTimeUri; |
| 70 | |
| 71 | return $this; |
| 72 | } |
| 73 | |
| 74 | public function setUserLatestExtension(string $userLatestExtension): self |
| 75 | { |
| 76 | $this->userLatestExtension = $userLatestExtension; |
| 77 | |
| 78 | return $this; |
| 79 | } |
| 80 | |
| 81 | /** |
| 82 | * Calculate your primary tao roles from the launch data |
| 83 | * |
| 84 | * @param LtiLaunchData $ltiLaunchData |
| 85 | * @return array |
| 86 | * @throws \common_Exception |
| 87 | * @throws \common_exception_Error |
| 88 | */ |
| 89 | protected function determineTaoRoles(LtiLaunchData $ltiLaunchData) |
| 90 | { |
| 91 | $roles = []; |
| 92 | $ltiRoles = []; |
| 93 | |
| 94 | if ($ltiLaunchData->hasVariable(LtiLaunchData::ROLES)) { |
| 95 | $ltiRoles = $ltiLaunchData->getUserRoles(); |
| 96 | foreach ($ltiRoles as $role) { |
| 97 | $taoRole = LtiUtils::mapLTIRole2TaoRole($role); |
| 98 | if (!is_null($taoRole)) { |
| 99 | $roles[] = $taoRole; |
| 100 | } |
| 101 | } |
| 102 | $roles = array_unique($roles); |
| 103 | } |
| 104 | |
| 105 | if (empty($roles)) { |
| 106 | $roles[] = LtiRoles::INSTANCE_LTI_BASE; |
| 107 | } |
| 108 | |
| 109 | return array_merge($roles, $ltiRoles); |
| 110 | } |
| 111 | |
| 112 | public function getPropertyValues($property) |
| 113 | { |
| 114 | if ($property === TaoOntology::PROPERTY_USER_FIRST_TIME && !empty($this->userFirstTimeUri)) { |
| 115 | return [$this->userFirstTimeUri]; |
| 116 | } |
| 117 | |
| 118 | if ($property === TaoOntology::PROPERTY_USER_LAST_EXTENSION && !empty($this->userLatestExtension)) { |
| 119 | return [$this->userLatestExtension]; |
| 120 | } |
| 121 | |
| 122 | return parent::getPropertyValues($property); |
| 123 | } |
| 124 | } |