Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
0.00% |
0 / 8 |
|
0.00% |
0 / 4 |
CRAP | |
0.00% |
0 / 1 |
| OntologyUserMapper | |
0.00% |
0 / 8 |
|
0.00% |
0 / 4 |
90 | |
0.00% |
0 / 1 |
| formatValue | |
0.00% |
0 / 5 |
|
0.00% |
0 / 1 |
42 | |||
| getPasswordHashService | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
| getLanguageService | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
| getPlainPassword | |
0.00% |
0 / 1 |
|
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 | namespace oat\tao\model\user\import; |
| 22 | |
| 23 | use oat\generis\model\OntologyAwareTrait; |
| 24 | use oat\generis\model\user\UserRdf; |
| 25 | use oat\tao\model\import\service\OntologyMapper; |
| 26 | use tao_models_classes_LanguageService; |
| 27 | |
| 28 | class OntologyUserMapper extends OntologyMapper implements UserMapperInterface |
| 29 | { |
| 30 | use OntologyAwareTrait; |
| 31 | |
| 32 | /** @var string */ |
| 33 | protected $plainPassword; |
| 34 | |
| 35 | /** |
| 36 | * @param string $key |
| 37 | * @param string $value |
| 38 | * @return string |
| 39 | * @throws \oat\generis\model\user\PasswordConstraintsException |
| 40 | */ |
| 41 | protected function formatValue($key, $value) |
| 42 | { |
| 43 | switch ($key) { |
| 44 | case UserRdf::PROPERTY_PASSWORD: |
| 45 | $this->plainPassword = $value; |
| 46 | return $this->getPasswordHashService()->encrypt($value); |
| 47 | case UserRdf::PROPERTY_UILG: |
| 48 | case UserRdf::PROPERTY_DEFLG: |
| 49 | $val = $this->getLanguageService()->getLanguageByCode($value); |
| 50 | return $val === null ? $value : $val->getUri(); |
| 51 | default: |
| 52 | return $value; |
| 53 | } |
| 54 | } |
| 55 | |
| 56 | /** |
| 57 | * @return \helpers_PasswordHash |
| 58 | */ |
| 59 | protected function getPasswordHashService() |
| 60 | { |
| 61 | return \core_kernel_users_Service::getPasswordHash(); |
| 62 | } |
| 63 | |
| 64 | /** |
| 65 | * @return tao_models_classes_LanguageService |
| 66 | */ |
| 67 | protected function getLanguageService() |
| 68 | { |
| 69 | return tao_models_classes_LanguageService::singleton(); |
| 70 | } |
| 71 | |
| 72 | /** |
| 73 | * Get the plain password |
| 74 | * |
| 75 | * @return string|null |
| 76 | */ |
| 77 | public function getPlainPassword() |
| 78 | { |
| 79 | return $this->plainPassword; |
| 80 | } |
| 81 | } |