Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
0.00% |
0 / 17 |
|
0.00% |
0 / 3 |
CRAP | |
0.00% |
0 / 1 |
| ProctoringRunnerService | |
0.00% |
0 / 17 |
|
0.00% |
0 / 3 |
90 | |
0.00% |
0 / 1 |
| getTestContext | |
0.00% |
0 / 8 |
|
0.00% |
0 / 1 |
30 | |||
| isProctoredDelivery | |
0.00% |
0 / 4 |
|
0.00% |
0 / 1 |
6 | |||
| check | |
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) 2017 (original work) Open Assessment Technologies SA ; |
| 19 | */ |
| 20 | |
| 21 | namespace oat\taoProctoring\model\runner; |
| 22 | |
| 23 | use oat\generis\model\OntologyAwareTrait; |
| 24 | use oat\taoDelivery\model\execution\ServiceProxy; |
| 25 | use oat\taoProctoring\model\ProctorService; |
| 26 | use oat\taoQtiTest\models\runner\QtiRunnerPausedException; |
| 27 | use oat\taoQtiTest\models\runner\QtiRunnerService; |
| 28 | use oat\taoQtiTest\models\runner\RunnerServiceContext; |
| 29 | use qtism\runtime\tests\AssessmentTestSessionState; |
| 30 | |
| 31 | /** |
| 32 | * Class ProctoringRunnerService |
| 33 | * |
| 34 | * QTI implementation service for the test runner |
| 35 | * |
| 36 | * @package oat\taoProctoring\model\runner |
| 37 | */ |
| 38 | class ProctoringRunnerService extends QtiRunnerService |
| 39 | { |
| 40 | use OntologyAwareTrait; |
| 41 | |
| 42 | /** |
| 43 | * Get Test Context. |
| 44 | * |
| 45 | * @param RunnerServiceContext $context |
| 46 | * @return array |
| 47 | * @throws \common_Exception |
| 48 | * @throws \common_exception_NotFound |
| 49 | * @throws \core_kernel_persistence_Exception |
| 50 | */ |
| 51 | public function getTestContext(RunnerServiceContext $context) |
| 52 | { |
| 53 | $response = parent::getTestContext($context); |
| 54 | |
| 55 | if (isset($response['options']) && isset($response['options']['sectionPause'])) { |
| 56 | $response['securePauseStateRequired'] = $response['options']['sectionPause']; |
| 57 | } else { |
| 58 | if ($context->getTestExecutionUri()) { |
| 59 | $deliveryExecution = ServiceProxy::singleton()->getDeliveryExecution($context->getTestExecutionUri()); |
| 60 | if ($this->isProctoredDelivery($deliveryExecution->getDelivery())) { |
| 61 | $response['securePauseStateRequired'] = true; |
| 62 | } |
| 63 | } |
| 64 | } |
| 65 | |
| 66 | return $response; |
| 67 | } |
| 68 | |
| 69 | /** |
| 70 | * Check whether secure plugins must be used. |
| 71 | * |
| 72 | * @param \core_kernel_classes_Resource $delivery |
| 73 | * @return bool |
| 74 | * @throws \core_kernel_persistence_Exception |
| 75 | */ |
| 76 | private function isProctoredDelivery(\core_kernel_classes_Resource $delivery) |
| 77 | { |
| 78 | $hasProctor = $delivery->getOnePropertyValue($this->getProperty(ProctorService::ACCESSIBLE_PROCTOR)); |
| 79 | $result = $hasProctor instanceof \core_kernel_classes_Resource && |
| 80 | $hasProctor->getUri() == ProctorService::ACCESSIBLE_PROCTOR_ENABLED; |
| 81 | return $result; |
| 82 | } |
| 83 | |
| 84 | /** |
| 85 | * Check whether the test is in a runnable state. |
| 86 | * |
| 87 | * @param RunnerServiceContext $context |
| 88 | * @return bool |
| 89 | * @throws \common_Exception |
| 90 | * @throws \oat\taoQtiTest\models\runner\QtiRunnerClosedException |
| 91 | * @throws QtiRunnerPausedException |
| 92 | */ |
| 93 | public function check(RunnerServiceContext $context) |
| 94 | { |
| 95 | parent::check($context); |
| 96 | |
| 97 | $state = $context->getTestSession()->getState(); |
| 98 | |
| 99 | if ($state == AssessmentTestSessionState::SUSPENDED) { |
| 100 | throw new QtiRunnerPausedException(); |
| 101 | } |
| 102 | |
| 103 | return true; |
| 104 | } |
| 105 | } |