Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
0.00% |
0 / 100 |
|
0.00% |
0 / 6 |
CRAP | |
0.00% |
0 / 1 |
| DeliveryServer | |
0.00% |
0 / 100 |
|
0.00% |
0 / 6 |
272 | |
0.00% |
0 / 1 |
| index | |
0.00% |
0 / 6 |
|
0.00% |
0 / 1 |
12 | |||
| getReturnUrl | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
| awaitingAuthorization | |
0.00% |
0 / 57 |
|
0.00% |
0 / 1 |
20 | |||
| isAuthorized | |
0.00% |
0 / 22 |
|
0.00% |
0 / 1 |
30 | |||
| cancelExecution | |
0.00% |
0 / 13 |
|
0.00% |
0 / 1 |
6 | |||
| getDeliveryServerService | |
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) 2015 (original work) Open Assessment Technologies SA (under the project TAO-PRODUCT); |
| 19 | * |
| 20 | * |
| 21 | */ |
| 22 | |
| 23 | namespace oat\taoProctoring\controller; |
| 24 | |
| 25 | use common_Logger; |
| 26 | use common_session_SessionManager; |
| 27 | use oat\tao\model\mvc\DefaultUrlService; |
| 28 | use oat\taoDelivery\controller\DeliveryServer as DefaultDeliveryServer; |
| 29 | use oat\taoProctoring\model\DeliveryExecutionStateService; |
| 30 | use oat\taoProctoring\model\DeliveryServerService; |
| 31 | use oat\taoProctoring\model\execution\DeliveryExecution as DeliveryExecutionState; |
| 32 | use oat\taoDelivery\model\execution\DeliveryExecution; |
| 33 | |
| 34 | /** |
| 35 | * Override the default DeliveryServer Controller |
| 36 | * |
| 37 | * @package taoProctoring |
| 38 | */ |
| 39 | class DeliveryServer extends DefaultDeliveryServer |
| 40 | { |
| 41 | /** |
| 42 | * Overrides the content extension data |
| 43 | * @see {@link \taoDelivery_actions_DeliveryServer} |
| 44 | */ |
| 45 | public function index() |
| 46 | { |
| 47 | // if the test taker passes by this page, he/she cannot access to any delivery without proctor authorization, |
| 48 | // whatever the delivery execution status is. |
| 49 | $user = common_session_SessionManager::getSession()->getUser(); |
| 50 | $startedExecutions = $this->service->getResumableDeliveries($user); |
| 51 | foreach ($startedExecutions as $startedExecution) { |
| 52 | if ($startedExecution->getDelivery()->exists()) { |
| 53 | $this->getDeliveryServerService()->revoke($startedExecution); |
| 54 | } |
| 55 | } |
| 56 | |
| 57 | parent::index(); |
| 58 | } |
| 59 | |
| 60 | /** |
| 61 | * Overrides the return URL |
| 62 | * @return string the URL |
| 63 | */ |
| 64 | protected function getReturnUrl() |
| 65 | { |
| 66 | return $this->getServiceManager()->get(DefaultUrlService::SERVICE_ID)->getUrl('ProctoringDeliveryServer'); |
| 67 | } |
| 68 | |
| 69 | /** |
| 70 | * The awaiting authorization screen |
| 71 | */ |
| 72 | public function awaitingAuthorization() |
| 73 | { |
| 74 | $deliveryExecution = $this->getCurrentDeliveryExecution(); |
| 75 | $deliveryExecutionStateService = $this->getServiceManager()->get(DeliveryExecutionStateService::SERVICE_ID); |
| 76 | $executionState = $deliveryExecution->getState()->getUri(); |
| 77 | |
| 78 | $runDeliveryUrl = _url( |
| 79 | 'runDeliveryExecution', |
| 80 | null, |
| 81 | null, |
| 82 | [ |
| 83 | 'deliveryExecution' => $deliveryExecution->getIdentifier(), |
| 84 | ] |
| 85 | ); |
| 86 | |
| 87 | // if the test is in progress, first pause it to avoid inconsistent storage state |
| 88 | if (DeliveryExecutionState::STATE_ACTIVE == $executionState) { |
| 89 | //do not remove these comments, this is used to generate the translation in .po file |
| 90 | // __('System generated pause.'); |
| 91 | $deliveryExecutionStateService->pauseExecution($deliveryExecution, [ |
| 92 | 'reasons' => ['category' => 'System'], |
| 93 | 'comment' => 'System generated pause.', |
| 94 | ]); |
| 95 | } |
| 96 | |
| 97 | $states = [DeliveryExecutionState::STATE_FINISHED, DeliveryExecutionState::STATE_TERMINATED]; |
| 98 | |
| 99 | // we need to change the state of the delivery execution |
| 100 | if (!in_array($executionState, $states)) { |
| 101 | if (DeliveryExecutionState::STATE_AUTHORIZED !== $executionState) { |
| 102 | $deliveryExecutionStateService->waitExecution($deliveryExecution); |
| 103 | } |
| 104 | |
| 105 | $this->setData('deliveryExecution', $deliveryExecution->getIdentifier()); |
| 106 | $this->setData('deliveryLabel', addslashes($deliveryExecution->getLabel())); |
| 107 | $this->setData('returnUrl', $this->getReturnUrl()); |
| 108 | $this->setData( |
| 109 | 'cancelUrl', |
| 110 | _url( |
| 111 | 'cancelExecution', |
| 112 | 'DeliveryServer', |
| 113 | 'taoProctoring', |
| 114 | [ |
| 115 | 'deliveryExecution' => $deliveryExecution->getIdentifier(), |
| 116 | ] |
| 117 | ) |
| 118 | ); |
| 119 | $this->setData('cancelable', $deliveryExecutionStateService->isCancelable($deliveryExecution)); |
| 120 | $this->setData('userLabel', common_session_SessionManager::getSession()->getUserLabel()); |
| 121 | $this->setData('client_config_url', $this->getClientConfigUrl()); |
| 122 | $this->setData('showControls', true); |
| 123 | $this->setData('runDeliveryUrl', $runDeliveryUrl); |
| 124 | |
| 125 | //set template |
| 126 | $this->setData( |
| 127 | 'homeUrl', |
| 128 | $this->getServiceManager()->get(DefaultUrlService::SERVICE_ID)->getUrl('ProctoringHome') |
| 129 | ); |
| 130 | $this->setData( |
| 131 | 'logout', |
| 132 | $this->getServiceManager()->get(DefaultUrlService::SERVICE_ID)->getUrl('ProctoringLogout') |
| 133 | ); |
| 134 | $this->setData('content-template', 'DeliveryServer/awaiting.tpl'); |
| 135 | $this->setData('content-extension', 'taoProctoring'); |
| 136 | $this->setData('title', __('TAO: User Authorization')); |
| 137 | $this->setView('DeliveryServer/layout.tpl', 'taoDelivery'); |
| 138 | } else { |
| 139 | // inconsistent state |
| 140 | common_Logger::i( |
| 141 | get_called_class() |
| 142 | . '::awaitingAuthorization(): cannot wait authorization for delivery execution ' |
| 143 | . $deliveryExecution->getIdentifier() . ' with state ' . $executionState |
| 144 | ); |
| 145 | |
| 146 | return $this->redirect($this->getReturnUrl()); |
| 147 | } |
| 148 | } |
| 149 | |
| 150 | /** |
| 151 | * The action called to check if the requested delivery execution has been authorized by the proctor |
| 152 | */ |
| 153 | public function isAuthorized() |
| 154 | { |
| 155 | $deliveryExecution = $this->getCurrentDeliveryExecution(); |
| 156 | $executionState = $deliveryExecution->getState()->getUri(); |
| 157 | |
| 158 | $authorized = false; |
| 159 | $success = true; |
| 160 | $message = null; |
| 161 | |
| 162 | // reacts to a few particular states |
| 163 | switch ($executionState) { |
| 164 | case DeliveryExecutionState::STATE_AUTHORIZED: |
| 165 | $authorized = true; |
| 166 | break; |
| 167 | |
| 168 | case DeliveryExecutionState::STATE_TERMINATED: |
| 169 | case DeliveryExecutionState::STATE_FINISHED: |
| 170 | $success = false; |
| 171 | $message = __('The assessment has been terminated. You cannot interact with it anymore.'); |
| 172 | break; |
| 173 | |
| 174 | case DeliveryExecutionState::STATE_PAUSED: |
| 175 | $success = false; |
| 176 | // phpcs:disable Generic.Files.LineLength |
| 177 | $message = __('The assessment has been suspended. To resume your assessment, please relaunch it and contact your proctor if required.'); |
| 178 | // phpcs:enable Generic.Files.LineLength |
| 179 | |
| 180 | break; |
| 181 | } |
| 182 | |
| 183 | $this->returnJson(array( |
| 184 | 'authorized' => $authorized, |
| 185 | 'success' => $success, |
| 186 | 'message' => $message |
| 187 | )); |
| 188 | } |
| 189 | |
| 190 | /** |
| 191 | * Cancel delivery authorization request. |
| 192 | */ |
| 193 | public function cancelExecution() |
| 194 | { |
| 195 | |
| 196 | $deliveryExecution = $this->getCurrentDeliveryExecution(); |
| 197 | /** @var DeliveryExecutionStateService $deliveryExecutionStateService */ |
| 198 | $deliveryExecutionStateService = $this->getServiceManager()->get(DeliveryExecutionStateService::SERVICE_ID); |
| 199 | $reason = [ |
| 200 | 'reasons' => ['category' => 'Examinee', 'subCategory' => 'Navigation'], |
| 201 | ]; |
| 202 | if ($deliveryExecution->getState()->getUri() === DeliveryExecutionState::STATE_AUTHORIZED) { |
| 203 | // phpcs:disable Generic.Files.LineLength |
| 204 | $reason['comment'] = __('Automatically reset by the system due to the test taker choosing not to proceed with the authorized test.'); |
| 205 | // phpcs:enable Generic.Files.LineLength |
| 206 | } else { |
| 207 | // phpcs:disable Generic.Files.LineLength |
| 208 | $reason['comment'] = __('Automatically reset by the system due to authorization request being cancelled by test taker.'); |
| 209 | // phpcs:enable Generic.Files.LineLength |
| 210 | } |
| 211 | $deliveryExecutionStateService->cancelExecution( |
| 212 | $deliveryExecution, |
| 213 | $reason |
| 214 | ); |
| 215 | return $this->redirect($this->getReturnUrl()); |
| 216 | } |
| 217 | |
| 218 | /** |
| 219 | * @return DeliveryServerService |
| 220 | */ |
| 221 | protected function getDeliveryServerService() |
| 222 | { |
| 223 | return $this->getServiceLocator()->get(DeliveryServerService::SERVICE_ID); |
| 224 | } |
| 225 | } |