Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
0.00% |
0 / 48 |
|
0.00% |
0 / 7 |
CRAP | |
0.00% |
0 / 1 |
| KvLtiUser | |
0.00% |
0 / 48 |
|
0.00% |
0 / 7 |
272 | |
0.00% |
0 / 1 |
| __construct | |
0.00% |
0 / 7 |
|
0.00% |
0 / 1 |
2 | |||
| getIdentifier | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
| setIdentifier | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
| getPropertyValues | |
0.00% |
0 / 25 |
|
0.00% |
0 / 1 |
90 | |||
| getPropertiesValues | |
0.00% |
0 / 4 |
|
0.00% |
0 / 1 |
6 | |||
| refresh | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
| jsonSerialize | |
0.00% |
0 / 9 |
|
0.00% |
0 / 1 |
2 | |||
| 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) 2018 (original work) Open Assessment Technologies SA (under the project TAO-PRODUCT); |
| 19 | * |
| 20 | * |
| 21 | */ |
| 22 | |
| 23 | namespace oat\taoLti\models\classes\user; |
| 24 | |
| 25 | use oat\generis\model\GenerisRdf; |
| 26 | use oat\generis\model\OntologyRdfs; |
| 27 | use Zend\ServiceManager\ServiceLocatorAwareInterface; |
| 28 | use Zend\ServiceManager\ServiceLocatorAwareTrait; |
| 29 | |
| 30 | /** |
| 31 | * Class KvLtiUser |
| 32 | * @package oat\taoLti\models\classes\user |
| 33 | */ |
| 34 | class KvLtiUser extends \common_user_User implements ServiceLocatorAwareInterface, \JsonSerializable |
| 35 | { |
| 36 | use ServiceLocatorAwareTrait; |
| 37 | |
| 38 | public const USER_IDENTIFIER = 'identifier'; |
| 39 | |
| 40 | /** |
| 41 | * Local representation of user |
| 42 | * @var \core_kernel_classes_Resource |
| 43 | */ |
| 44 | private $userUri; |
| 45 | |
| 46 | /** |
| 47 | * Cache of the current user's lti roles |
| 48 | * @var array |
| 49 | */ |
| 50 | protected $taoRoles; |
| 51 | |
| 52 | private $language; |
| 53 | |
| 54 | private $firstname; |
| 55 | |
| 56 | private $lastname; |
| 57 | |
| 58 | private $email; |
| 59 | |
| 60 | private $label; |
| 61 | |
| 62 | /** |
| 63 | * KvLtiUser constructor. |
| 64 | * @param $data |
| 65 | */ |
| 66 | public function __construct($data) |
| 67 | { |
| 68 | $this->userUri = $data[self::USER_IDENTIFIER] ?? null; |
| 69 | $this->taoRoles = $data[GenerisRdf::PROPERTY_USER_ROLES] ?? []; |
| 70 | $this->language = $data[GenerisRdf::PROPERTY_USER_UILG] ?? null; |
| 71 | $this->label = $data[OntologyRdfs::RDFS_LABEL] ?? null; |
| 72 | $this->firstname = $data[GenerisRdf::PROPERTY_USER_FIRSTNAME] ?? null; |
| 73 | $this->lastname = $data[GenerisRdf::PROPERTY_USER_LASTNAME] ?? null; |
| 74 | $this->email = $data[GenerisRdf::PROPERTY_USER_MAIL] ?? null; |
| 75 | } |
| 76 | |
| 77 | /** |
| 78 | * (non-PHPdoc) |
| 79 | * @see \common_user_User::getIdentifier() |
| 80 | */ |
| 81 | public function getIdentifier() |
| 82 | { |
| 83 | return $this->userUri; |
| 84 | } |
| 85 | |
| 86 | public function setIdentifier($userId) |
| 87 | { |
| 88 | $this->userUri = $userId; |
| 89 | } |
| 90 | |
| 91 | /** |
| 92 | * (non-PHPdoc) |
| 93 | * @see \common_user_User::getPropertyValues() |
| 94 | */ |
| 95 | public function getPropertyValues($property) |
| 96 | { |
| 97 | $returnValue = null; |
| 98 | switch ($property) { |
| 99 | case GenerisRdf::PROPERTY_USER_DEFLG: |
| 100 | $returnValue = [DEFAULT_LANG]; |
| 101 | break; |
| 102 | case GenerisRdf::PROPERTY_USER_UILG: |
| 103 | $returnValue = [new \core_kernel_classes_Literal($this->language)]; |
| 104 | break; |
| 105 | case GenerisRdf::PROPERTY_USER_ROLES: |
| 106 | $returnValue = $this->taoRoles; |
| 107 | break; |
| 108 | case GenerisRdf::PROPERTY_USER_FIRSTNAME: |
| 109 | $returnValue = [new \core_kernel_classes_Literal($this->firstname)]; |
| 110 | break; |
| 111 | case GenerisRdf::PROPERTY_USER_LASTNAME: |
| 112 | $returnValue = [new \core_kernel_classes_Literal($this->lastname)]; |
| 113 | break; |
| 114 | case OntologyRdfs::RDFS_LABEL: |
| 115 | $returnValue = [new \core_kernel_classes_Literal($this->label)]; |
| 116 | break; |
| 117 | case GenerisRdf::PROPERTY_USER_MAIL: |
| 118 | $returnValue = [new \core_kernel_classes_Literal($this->email)]; |
| 119 | break; |
| 120 | default: |
| 121 | \common_Logger::d('Unkown property ' . $property . ' requested from ' . __CLASS__); |
| 122 | $returnValue = []; |
| 123 | } |
| 124 | return $returnValue; |
| 125 | } |
| 126 | |
| 127 | /** |
| 128 | * @param $properties |
| 129 | * @return array |
| 130 | */ |
| 131 | public function getPropertiesValues($properties) |
| 132 | { |
| 133 | $returnValues = []; |
| 134 | foreach ($properties as $property) { |
| 135 | $returnValues[$property] = $this->getPropertyValues($property); |
| 136 | } |
| 137 | return $returnValues; |
| 138 | } |
| 139 | |
| 140 | |
| 141 | /** |
| 142 | * (non-PHPdoc) |
| 143 | * @see \common_user_User::refresh() |
| 144 | */ |
| 145 | public function refresh() |
| 146 | { |
| 147 | // nothing to do |
| 148 | } |
| 149 | |
| 150 | /** |
| 151 | * @return array |
| 152 | */ |
| 153 | public function jsonSerialize() |
| 154 | { |
| 155 | return [ |
| 156 | self::USER_IDENTIFIER => $this->userUri, |
| 157 | GenerisRdf::PROPERTY_USER_ROLES => $this->taoRoles, |
| 158 | GenerisRdf::PROPERTY_USER_UILG => $this->language, |
| 159 | GenerisRdf::PROPERTY_USER_FIRSTNAME => $this->firstname, |
| 160 | GenerisRdf::PROPERTY_USER_LASTNAME => $this->lastname, |
| 161 | GenerisRdf::PROPERTY_USER_MAIL => $this->email, |
| 162 | OntologyRdfs::RDFS_LABEL => $this->label, |
| 163 | ]; |
| 164 | } |
| 165 | } |