Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
5.26% |
1 / 19 |
|
33.33% |
1 / 3 |
CRAP | |
0.00% |
0 / 1 |
| LtiRestApiService | |
5.26% |
1 / 19 |
|
33.33% |
1 / 3 |
36.61 | |
0.00% |
0 / 1 |
| getClassService | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| getUserId | |
0.00% |
0 / 11 |
|
0.00% |
0 / 1 |
12 | |||
| createFromArray | |
0.00% |
0 / 7 |
|
0.00% |
0 / 1 |
6 | |||
| 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) 2013 (original work) Open Assessment Technologies SA (under the project TAO-PRODUCT); |
| 19 | * |
| 20 | */ |
| 21 | |
| 22 | namespace oat\taoLti\models\classes; |
| 23 | |
| 24 | use oat\generis\model\OntologyRdfs; |
| 25 | use oat\taoLti\models\classes\user\LtiUserService; |
| 26 | use Zend\ServiceManager\ServiceLocatorAwareTrait; |
| 27 | use Zend\ServiceManager\ServiceLocatorAwareInterface; |
| 28 | |
| 29 | class LtiRestApiService extends \tao_models_classes_CrudService implements ServiceLocatorAwareInterface |
| 30 | { |
| 31 | use ServiceLocatorAwareTrait; |
| 32 | |
| 33 | protected function getClassService() |
| 34 | { |
| 35 | return $this->getServiceLocator()->get(ConsumerService::class); |
| 36 | } |
| 37 | |
| 38 | /** |
| 39 | * Get common user uri associated to Lti user id |
| 40 | * |
| 41 | * @param $id string Identifier of LTI user |
| 42 | * @param $key string Oauth LTI consumer key |
| 43 | * @return array|null |
| 44 | * @throws \common_Exception |
| 45 | * @throws \tao_models_classes_oauth_Exception |
| 46 | */ |
| 47 | public function getUserId($id, $key) |
| 48 | { |
| 49 | $dataStore = new \tao_models_classes_oauth_DataStore(); |
| 50 | try { |
| 51 | /** @var \core_kernel_classes_Resource $consumerResource */ |
| 52 | $consumerResource = $dataStore->findOauthConsumerResource($key); |
| 53 | } catch (\tao_models_classes_oauth_Exception $e) { |
| 54 | throw new \common_exception_NotFound($e->getMessage()); |
| 55 | } |
| 56 | |
| 57 | /** @var LtiUserService $service */ |
| 58 | $service = $this->getServiceLocator()->get(LtiUserService::SERVICE_ID); |
| 59 | $userIdentifier = $service->getUserIdentifier($id, $consumerResource); |
| 60 | |
| 61 | if (is_null($userIdentifier)) { |
| 62 | return null; |
| 63 | } |
| 64 | |
| 65 | return [ |
| 66 | 'id' => $userIdentifier |
| 67 | ]; |
| 68 | } |
| 69 | |
| 70 | public function createFromArray(array $propertiesValues) |
| 71 | { |
| 72 | if (array_key_exists(OntologyRdfs::RDFS_LABEL, $propertiesValues)) { |
| 73 | $label = $propertiesValues[OntologyRdfs::RDFS_LABEL]; |
| 74 | } else { |
| 75 | $label = ''; |
| 76 | } |
| 77 | unset($propertiesValues[OntologyRdfs::RDFS_LABEL]); |
| 78 | |
| 79 | $propertiesValues['classUri'] = ConsumerService::CLASS_URI; |
| 80 | |
| 81 | $resource = parent::create($label, $this->getRootClass(), $propertiesValues); |
| 82 | return $resource; |
| 83 | } |
| 84 | } |