Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
0.00% |
0 / 17 |
|
0.00% |
0 / 2 |
CRAP | |
0.00% |
0 / 1 |
| LtiModuleTrait | |
0.00% |
0 / 17 |
|
0.00% |
0 / 2 |
56 | |
0.00% |
0 / 1 |
| returnLtiError | |
0.00% |
0 / 12 |
|
0.00% |
0 / 1 |
30 | |||
| getLtiReturnUrl | |
0.00% |
0 / 5 |
|
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) 2016 (original work) Open Assessment Technologies SA (under the project TAO-PRODUCT); |
| 19 | * |
| 20 | */ |
| 21 | |
| 22 | namespace oat\taoLti\controller\traits; |
| 23 | |
| 24 | use oat\taoLti\models\classes\LtiException; |
| 25 | use oat\taoLti\models\classes\LtiLaunchData; |
| 26 | use oat\taoLti\models\classes\LtiMessages\LtiErrorMessage; |
| 27 | use tao_helpers_Request; |
| 28 | use common_exception_IsAjaxAction; |
| 29 | use oat\tao\model\routing\FlowController; |
| 30 | |
| 31 | trait LtiModuleTrait |
| 32 | { |
| 33 | /** |
| 34 | * Returns an error page |
| 35 | * |
| 36 | * Ignore the parameter returnLink as LTI session always |
| 37 | * require a way for the consumer to return to his platform |
| 38 | * |
| 39 | * @param LtiException $error error to show |
| 40 | * @param boolean $returnLink |
| 41 | * @throws LtiException |
| 42 | * @throws \InterruptedActionException |
| 43 | * @throws \ResolverException |
| 44 | * @throws \common_exception_Error |
| 45 | * @throws \oat\taoLti\models\classes\LtiVariableMissingException |
| 46 | * @throws common_exception_IsAjaxAction |
| 47 | * @see \tao_actions_CommonModule::returnError() |
| 48 | */ |
| 49 | protected function returnLtiError(LtiException $error, $returnLink = true) |
| 50 | { |
| 51 | // full trace of the error |
| 52 | \common_Logger::e($error->__toString()); |
| 53 | |
| 54 | if (tao_helpers_Request::isAjax()) { |
| 55 | throw new common_exception_IsAjaxAction(__CLASS__ . '::' . __FUNCTION__); |
| 56 | } else { |
| 57 | $launchData = LtiLaunchData::fromRequest(\common_http_Request::currentRequest()); |
| 58 | |
| 59 | if ($launchData->hasReturnUrl() && $error->getCode() != LtiErrorMessage::ERROR_UNAUTHORIZED) { |
| 60 | $flowController = new FlowController(); |
| 61 | $flowController->redirect($this->getLtiReturnUrl($launchData, $error)); |
| 62 | } |
| 63 | |
| 64 | // In regard of the IMS LTI standard, we have to show a back button that refer to the |
| 65 | // launch_presentation_return_url url param. So we have to retrieve this parameter before trying to start |
| 66 | // the session |
| 67 | $consumerLabel = $launchData->getToolConsumerName(); |
| 68 | if (!is_null($consumerLabel)) { |
| 69 | $this->setData('consumerLabel', $consumerLabel); |
| 70 | } |
| 71 | |
| 72 | $this->setData('message', $error->getMessage()); |
| 73 | $this->setView('error.tpl', 'taoLti'); |
| 74 | } |
| 75 | } |
| 76 | |
| 77 | /** |
| 78 | * @param LtiLaunchData $launchData |
| 79 | * @param LtiException $error |
| 80 | * @return string |
| 81 | * @throws LtiException |
| 82 | */ |
| 83 | private function getLtiReturnUrl(LtiLaunchData $launchData, LtiException $error) |
| 84 | { |
| 85 | $baseUrl = $launchData->getReturnUrl(); |
| 86 | $url = $baseUrl |
| 87 | . (parse_url($baseUrl, PHP_URL_QUERY) ? '&' : '?') |
| 88 | . http_build_query($error->getLtiMessage()->getUrlParams()); |
| 89 | |
| 90 | return $url; |
| 91 | } |
| 92 | } |