Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
0.00% |
0 / 26 |
|
0.00% |
0 / 5 |
CRAP | |
0.00% |
0 / 1 |
| RestService | |
0.00% |
0 / 26 |
|
0.00% |
0 / 5 |
90 | |
0.00% |
0 / 1 |
| getCrudService | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
| get | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
| getUserId | |
0.00% |
0 / 15 |
|
0.00% |
0 / 1 |
30 | |||
| getParametersAliases | |
0.00% |
0 / 8 |
|
0.00% |
0 / 1 |
2 | |||
| getParametersRequirements | |
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) 2013 (original work) Open Assessment Technologies SA (under the project TAO-PRODUCT); |
| 19 | * |
| 20 | * |
| 21 | */ |
| 22 | |
| 23 | namespace oat\taoLti\controller; |
| 24 | |
| 25 | use oat\generis\model\OntologyRdfs; |
| 26 | use oat\taoLti\models\classes\LtiRestApiService; |
| 27 | use oat\tao\model\oauth\DataStore; |
| 28 | |
| 29 | class RestService extends \tao_actions_CommonRestModule |
| 30 | { |
| 31 | public const LTI_USER_ID = 'lti_user_id'; |
| 32 | public const LTI_CONSUMER_KEY = 'lti_consumer_key'; |
| 33 | |
| 34 | /** |
| 35 | * @return LtiRestApiService |
| 36 | */ |
| 37 | protected function getCrudService() |
| 38 | { |
| 39 | return $this->propagate(LtiRestApiService::singleton()); |
| 40 | } |
| 41 | |
| 42 | /** |
| 43 | * @param null $uri |
| 44 | * @return mixed|void |
| 45 | * @throws \common_exception_NoImplementation |
| 46 | */ |
| 47 | public function get($uri = null) |
| 48 | { |
| 49 | throw new \common_exception_NoImplementation(); |
| 50 | } |
| 51 | |
| 52 | /** |
| 53 | * End point to get common user uri by lti user id |
| 54 | * @throws \common_exception_NotImplemented |
| 55 | */ |
| 56 | public function getUserId() |
| 57 | { |
| 58 | try { |
| 59 | $parameters = $this->getParameters(); |
| 60 | if (!isset($parameters[self::LTI_USER_ID])) { |
| 61 | throw new \common_exception_MissingParameter(self::LTI_USER_ID, __FUNCTION__); |
| 62 | } |
| 63 | if (!isset($parameters[self::LTI_CONSUMER_KEY])) { |
| 64 | throw new \common_exception_MissingParameter(self::LTI_CONSUMER_KEY, __FUNCTION__); |
| 65 | } |
| 66 | |
| 67 | $id = $parameters[self::LTI_USER_ID]; |
| 68 | $key = $parameters[self::LTI_CONSUMER_KEY]; |
| 69 | |
| 70 | $data = $this->getCrudService->getUserId($id, $key); |
| 71 | if (!$data) { |
| 72 | \common_Logger::i('Id ' . $id . ' is not found.'); |
| 73 | throw new \common_exception_NotFound('No data found for the given id.'); |
| 74 | } |
| 75 | |
| 76 | $this->returnSuccess($data); |
| 77 | } catch (\Exception $e) { |
| 78 | \common_Logger::w($e->getMessage()); |
| 79 | $this->returnFailure($e); |
| 80 | } |
| 81 | } |
| 82 | |
| 83 | /** |
| 84 | * Optionally a specific rest controller may declare |
| 85 | * aliases for parameters used for the rest communication |
| 86 | */ |
| 87 | protected function getParametersAliases() |
| 88 | { |
| 89 | return [ |
| 90 | 'user_id' => self::LTI_USER_ID, |
| 91 | 'oauth_consumer_key' => self::LTI_CONSUMER_KEY, |
| 92 | 'label' => OntologyRdfs::RDFS_LABEL, |
| 93 | 'oauth-key' => DataStore::PROPERTY_OAUTH_KEY, |
| 94 | 'oauth-secret' => DataStore::PROPERTY_OAUTH_SECRET, |
| 95 | 'oauth-callback-url' => DataStore::PROPERTY_OAUTH_CALLBACK, |
| 96 | ]; |
| 97 | } |
| 98 | |
| 99 | /** |
| 100 | * Return array of required parameters sorted by http method |
| 101 | * @return array |
| 102 | */ |
| 103 | protected function getParametersRequirements() |
| 104 | { |
| 105 | return []; |
| 106 | } |
| 107 | } |