Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
0.00% |
0 / 93 |
|
0.00% |
0 / 9 |
CRAP | |
0.00% |
0 / 1 |
| DeliveryRunner | |
0.00% |
0 / 93 |
|
0.00% |
0 / 9 |
420 | |
0.00% |
0 / 1 |
| showControls | |
0.00% |
0 / 4 |
|
0.00% |
0 / 1 |
12 | |||
| getReturnUrl | |
0.00% |
0 / 7 |
|
0.00% |
0 / 1 |
2 | |||
| ltiReturn | |
0.00% |
0 / 28 |
|
0.00% |
0 / 1 |
6 | |||
| ltiOverview | |
0.00% |
0 / 3 |
|
0.00% |
0 / 1 |
2 | |||
| repeat | |
0.00% |
0 / 22 |
|
0.00% |
0 / 1 |
6 | |||
| thankYou | |
0.00% |
0 / 14 |
|
0.00% |
0 / 1 |
30 | |||
| feedback | |
0.00% |
0 / 2 |
|
0.00% |
0 / 1 |
2 | |||
| finishDeliveryExecution | |
0.00% |
0 / 12 |
|
0.00% |
0 / 1 |
20 | |||
| getConcurringSessionService | |
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-2023 (original work) Open Assessment Technologies SA. |
| 19 | */ |
| 20 | |
| 21 | namespace oat\ltiDeliveryProvider\controller; |
| 22 | |
| 23 | use oat\ltiDeliveryProvider\model\navigation\Command\GenerateReturnUrlCommand; |
| 24 | use oat\tao\helpers\UrlHelper; |
| 25 | use oat\tao\model\theme\ThemeServiceInterface; |
| 26 | use oat\taoDelivery\controller\DeliveryServer; |
| 27 | use oat\taoDelivery\model\execution\ServiceProxy; |
| 28 | use oat\taoLti\controller\traits\LtiModuleTrait; |
| 29 | use oat\taoLti\models\classes\LtiException; |
| 30 | use oat\taoLti\models\classes\LtiLaunchData; |
| 31 | use oat\taoLti\models\classes\LtiService; |
| 32 | use oat\taoLti\models\classes\theme\LtiHeadless; |
| 33 | use oat\ltiDeliveryProvider\model\LTIDeliveryTool; |
| 34 | use oat\taoLti\models\classes\LtiMessages\LtiErrorMessage; |
| 35 | use oat\taoDelivery\model\execution\DeliveryExecution; |
| 36 | use oat\taoDelivery\model\execution\StateServiceInterface; |
| 37 | use oat\ltiDeliveryProvider\model\navigation\LtiNavigationService; |
| 38 | use oat\taoQtiTest\model\Service\ConcurringSessionService; |
| 39 | |
| 40 | /** |
| 41 | * Called by the DeliveryTool to override DeliveryServer settings |
| 42 | * |
| 43 | * @author CRP Henri Tudor - TAO Team - {@link http://www.tao.lu} |
| 44 | * @license GPLv2 http://www.opensource.org/licenses/gpl-2.0.php |
| 45 | * @package ltiDeliveryProvider |
| 46 | */ |
| 47 | class DeliveryRunner extends DeliveryServer |
| 48 | { |
| 49 | use LtiModuleTrait; |
| 50 | |
| 51 | /** |
| 52 | * Defines if the top and bottom action menu should be displayed or not |
| 53 | * |
| 54 | * @return boolean |
| 55 | */ |
| 56 | protected function showControls() |
| 57 | { |
| 58 | $themeService = $this->getServiceManager()->get(ThemeServiceInterface::SERVICE_ID); |
| 59 | if ($themeService instanceof ThemeServiceInterface || $themeService instanceof LtiHeadless) { |
| 60 | return !$themeService->isHeadless(); |
| 61 | } |
| 62 | return false; |
| 63 | } |
| 64 | |
| 65 | protected function getReturnUrl() |
| 66 | { |
| 67 | $deliveryExecution = $this->getCurrentDeliveryExecution(); |
| 68 | |
| 69 | return _url( |
| 70 | 'ltiReturn', |
| 71 | 'DeliveryRunner', |
| 72 | 'ltiDeliveryProvider', |
| 73 | ['deliveryExecution' => $deliveryExecution->getIdentifier()] |
| 74 | ); |
| 75 | } |
| 76 | |
| 77 | public function ltiReturn() |
| 78 | { |
| 79 | $isFeedback = false; |
| 80 | $queryString = []; |
| 81 | $concurringService = $this->getConcurringSessionService(); |
| 82 | $navigation = $this->getServiceLocator()->get(LtiNavigationService::SERVICE_ID); |
| 83 | $deliveryExecution = $this->getCurrentDeliveryExecution(); |
| 84 | $launchData = LtiService::singleton()->getLtiSession()->getLaunchData(); |
| 85 | |
| 86 | if ($concurringService->isConcurringSession($deliveryExecution)) { |
| 87 | $isFeedback = true; |
| 88 | $queryString = [ |
| 89 | 'reason' => 'concurrent-test' |
| 90 | ]; |
| 91 | $concurringService->clearConcurringSession($deliveryExecution); |
| 92 | } |
| 93 | |
| 94 | $redirectUrl = $navigation->generateReturnUrl( |
| 95 | new GenerateReturnUrlCommand( |
| 96 | $launchData, |
| 97 | $deliveryExecution, |
| 98 | $isFeedback, |
| 99 | $queryString |
| 100 | ) |
| 101 | ); |
| 102 | \common_Logger::i( |
| 103 | sprintf( |
| 104 | 'Redirected from the deliveryExecution %s to %s', |
| 105 | $deliveryExecution->getIdentifier(), |
| 106 | $redirectUrl |
| 107 | ) |
| 108 | ); |
| 109 | |
| 110 | $this->redirect($redirectUrl); |
| 111 | } |
| 112 | |
| 113 | /** |
| 114 | * Shown uppon returning to a finished delivery execution |
| 115 | */ |
| 116 | public function ltiOverview() |
| 117 | { |
| 118 | $this->setData('delivery', $this->getRequestParameter('delivery')); |
| 119 | $this->setData('allowRepeat', true); |
| 120 | $this->setView('learner/overview.tpl'); |
| 121 | } |
| 122 | |
| 123 | /** |
| 124 | * @throws LtiException |
| 125 | * @throws \InterruptedActionException |
| 126 | * @throws \ResolverException |
| 127 | * @throws \common_exception_Error |
| 128 | * @throws \common_exception_IsAjaxAction |
| 129 | * @throws \oat\taoLti\models\classes\LtiVariableMissingException |
| 130 | */ |
| 131 | public function repeat() |
| 132 | { |
| 133 | $delivery = new \core_kernel_classes_Resource($this->getRequestParameter('delivery')); |
| 134 | |
| 135 | $remoteLink = LtiService::singleton()->getLtiSession()->getLtiLinkResource(); |
| 136 | $user = \common_session_SessionManager::getSession()->getUser(); |
| 137 | |
| 138 | try { |
| 139 | $newExecution = $this->getServiceLocator()->get(LTIDeliveryTool::class)->startDelivery( |
| 140 | $delivery, |
| 141 | $remoteLink, |
| 142 | $user |
| 143 | ); |
| 144 | $this->getConcurringSessionService()->pauseActiveDeliveryExecutionsForUser($newExecution); |
| 145 | $runDeliveryExecutionUrl = $this->getServiceLocator()->get(UrlHelper::class)->buildUrl( |
| 146 | 'runDeliveryExecution', |
| 147 | null, |
| 148 | null, |
| 149 | ['deliveryExecution' => $newExecution->getIdentifier()] |
| 150 | ); |
| 151 | $this->redirect($runDeliveryExecutionUrl); |
| 152 | } catch (\common_exception_Unauthorized $e) { |
| 153 | $ltiException = new LtiException( |
| 154 | $e->getMessage(), |
| 155 | LtiErrorMessage::ERROR_LAUNCH_FORBIDDEN |
| 156 | ); |
| 157 | $this->returnLtiError($ltiException); |
| 158 | } |
| 159 | } |
| 160 | |
| 161 | /** |
| 162 | * @throws LtiException |
| 163 | * @throws \common_exception_Error |
| 164 | * @throws \oat\taoLti\models\classes\LtiVariableMissingException |
| 165 | */ |
| 166 | public function thankYou() |
| 167 | { |
| 168 | $launchData = LtiService::singleton()->getLtiSession()->getLaunchData(); |
| 169 | |
| 170 | if ($launchData->hasVariable(LtiLaunchData::TOOL_CONSUMER_INSTANCE_NAME)) { |
| 171 | $this->setData('consumerLabel', $launchData->getVariable(LtiLaunchData::TOOL_CONSUMER_INSTANCE_NAME)); |
| 172 | } elseif ($launchData->hasVariable(LtiLaunchData::TOOL_CONSUMER_INSTANCE_DESCRIPTION)) { |
| 173 | $this->setData( |
| 174 | 'consumerLabel', |
| 175 | $launchData->getVariable(LtiLaunchData::TOOL_CONSUMER_INSTANCE_DESCRIPTION) |
| 176 | ); |
| 177 | } |
| 178 | |
| 179 | if ($launchData->hasReturnUrl()) { |
| 180 | $this->setData('returnUrl', $launchData->getReturnUrl()); |
| 181 | } |
| 182 | |
| 183 | if ($launchData->hasVariable(DeliveryTool::PARAM_THANKYOU_MESSAGE)) { |
| 184 | $this->setData('message', $launchData->getVariable(DeliveryTool::PARAM_THANKYOU_MESSAGE)); |
| 185 | } |
| 186 | |
| 187 | $this->setData('allowRepeat', false); |
| 188 | $this->setView('learner/thankYou.tpl'); |
| 189 | } |
| 190 | |
| 191 | public function feedback(): void |
| 192 | { |
| 193 | $this->setData('reason', $this->getRequestParameter('reason')); |
| 194 | $this->setView('learner/feedback.tpl'); |
| 195 | } |
| 196 | |
| 197 | /** |
| 198 | * Redirect user to return URL |
| 199 | */ |
| 200 | public function finishDeliveryExecution() |
| 201 | { |
| 202 | $deliveryExecution = null; |
| 203 | if ($this->hasRequestParameter('deliveryExecution')) { |
| 204 | $deliveryExecution = ServiceProxy::singleton()->getDeliveryExecution( |
| 205 | $this->getRequestParameter('deliveryExecution') |
| 206 | ); |
| 207 | if ($deliveryExecution->getState() !== DeliveryExecution::STATE_FINISHIED) { |
| 208 | $stateService = $this->getServiceLocator()->get(StateServiceInterface::SERVICE_ID); |
| 209 | $stateService->finish($deliveryExecution); |
| 210 | } |
| 211 | } |
| 212 | $redirectUrl = $deliveryExecution |
| 213 | ? $this->getServiceLocator()->get(LTIDeliveryTool::class)->getFinishUrl($deliveryExecution) |
| 214 | : $this->getReturnUrl(); |
| 215 | $this->redirect($redirectUrl); |
| 216 | } |
| 217 | |
| 218 | private function getConcurringSessionService(): ConcurringSessionService |
| 219 | { |
| 220 | return $this->getPsrContainer()->get(ConcurringSessionService::class); |
| 221 | } |
| 222 | } |