Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
0.00% |
0 / 34 |
|
0.00% |
0 / 7 |
CRAP | |
0.00% |
0 / 1 |
| core_kernel_users_GenerisUser | |
0.00% |
0 / 34 |
|
0.00% |
0 / 7 |
240 | |
0.00% |
0 / 1 |
| __construct | |
0.00% |
0 / 2 |
|
0.00% |
0 / 1 |
2 | |||
| getIdentifier | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
| getUserResource | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
| getPropertyValues | |
0.00% |
0 / 5 |
|
0.00% |
0 / 1 |
12 | |||
| getUncached | |
0.00% |
0 / 6 |
|
0.00% |
0 / 1 |
30 | |||
| findLanguage | |
0.00% |
0 / 14 |
|
0.00% |
0 / 1 |
12 | |||
| refresh | |
0.00% |
0 / 5 |
|
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) 2017 (original work) Open Assessment Technologies SA (under the project TAO-PRODUCT); |
| 19 | * |
| 20 | * |
| 21 | */ |
| 22 | |
| 23 | use oat\generis\model\GenerisRdf; |
| 24 | use oat\generis\model\kernel\users\UserInternalInterface; |
| 25 | use oat\generis\model\OntologyRdf; |
| 26 | |
| 27 | /** |
| 28 | * Authentication adapter interface to be implemented by authentication methodes |
| 29 | * |
| 30 | * @access public |
| 31 | * @author Joel Bout, <joel@taotesting.com> |
| 32 | * @package generis |
| 33 | * |
| 34 | * phpcs:disable Squiz.Classes.ValidClassName.NotCamelCaps |
| 35 | */ |
| 36 | class core_kernel_users_GenerisUser extends common_user_User implements UserInternalInterface |
| 37 | { |
| 38 | /** |
| 39 | * @var string identifier of user |
| 40 | */ |
| 41 | private $identifier; |
| 42 | |
| 43 | private $cache; |
| 44 | |
| 45 | private $cachedProperties = [ |
| 46 | GenerisRdf::PROPERTY_USER_DEFLG, |
| 47 | GenerisRdf::PROPERTY_USER_ROLES, |
| 48 | GenerisRdf::PROPERTY_USER_UILG, |
| 49 | GenerisRdf::PROPERTY_USER_FIRSTNAME, |
| 50 | GenerisRdf::PROPERTY_USER_LASTNAME, |
| 51 | GenerisRdf::PROPERTY_USER_LOGIN, |
| 52 | GenerisRdf::PROPERTY_USER_TIMEZONE, |
| 53 | ]; |
| 54 | |
| 55 | public function __construct(core_kernel_classes_Resource $user) |
| 56 | { |
| 57 | $this->identifier = $user->getUri(); |
| 58 | // load datalanguage to prevent cycle later on |
| 59 | $this->getPropertyValues(GenerisRdf::PROPERTY_USER_DEFLG); |
| 60 | } |
| 61 | |
| 62 | public function getIdentifier() |
| 63 | { |
| 64 | return $this->identifier; |
| 65 | } |
| 66 | |
| 67 | private function getUserResource() |
| 68 | { |
| 69 | return new core_kernel_classes_Resource($this->getIdentifier()); |
| 70 | } |
| 71 | |
| 72 | public function getPropertyValues($property) |
| 73 | { |
| 74 | if (!in_array($property, $this->cachedProperties)) { |
| 75 | return $this->getUncached($property); |
| 76 | } elseif (!isset($this->cache[$property])) { |
| 77 | $this->cache[$property] = $this->getUncached($property); |
| 78 | } |
| 79 | |
| 80 | return $this->cache[$property]; |
| 81 | } |
| 82 | |
| 83 | private function getUncached($property) |
| 84 | { |
| 85 | switch ($property) { |
| 86 | case GenerisRdf::PROPERTY_USER_DEFLG: |
| 87 | $lang = $this->findLanguage($property); |
| 88 | |
| 89 | return $lang ?: [DEFAULT_ANONYMOUS_INTERFACE_LANG]; |
| 90 | |
| 91 | case GenerisRdf::PROPERTY_USER_UILG: |
| 92 | return $this->findLanguage($property); |
| 93 | |
| 94 | default: |
| 95 | return $this->getUserResource()->getPropertyValues(new core_kernel_classes_Property($property)); |
| 96 | } |
| 97 | } |
| 98 | |
| 99 | /** |
| 100 | * @return array|string[] |
| 101 | * @throws common_Exception |
| 102 | * @throws core_kernel_classes_EmptyProperty |
| 103 | * @throws core_kernel_persistence_Exception |
| 104 | */ |
| 105 | private function findLanguage(string $propertyURI): array |
| 106 | { |
| 107 | $language = []; |
| 108 | $resource = $this->getUserResource()->getOnePropertyValue( |
| 109 | new core_kernel_classes_Property($propertyURI) |
| 110 | ); |
| 111 | |
| 112 | if (is_null($resource)) { |
| 113 | return $language; |
| 114 | } |
| 115 | |
| 116 | if (!$resource instanceof core_kernel_classes_Resource) { |
| 117 | common_Logger::w("Language {$resource} is not a resource"); |
| 118 | |
| 119 | return $language; |
| 120 | } |
| 121 | |
| 122 | return [ |
| 123 | (string) $resource->getUniquePropertyValue( |
| 124 | new core_kernel_classes_Property(OntologyRdf::RDF_VALUE) |
| 125 | ) |
| 126 | ]; |
| 127 | } |
| 128 | |
| 129 | public function refresh() |
| 130 | { |
| 131 | $this->roles = false; |
| 132 | $this->cache = [ |
| 133 | GenerisRdf::PROPERTY_USER_DEFLG => $this->getUncached(GenerisRdf::PROPERTY_USER_DEFLG) |
| 134 | ]; |
| 135 | return true; |
| 136 | } |
| 137 | } |