Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
0.00% |
0 / 18 |
|
0.00% |
0 / 4 |
CRAP | |
0.00% |
0 / 1 |
| taoQtiTest_actions_OfflineRunner | |
0.00% |
0 / 18 |
|
0.00% |
0 / 4 |
42 | |
0.00% |
0 / 1 |
| init | |
0.00% |
0 / 11 |
|
0.00% |
0 / 1 |
12 | |||
| attachBranchingRulesToResponse | |
0.00% |
0 / 5 |
|
0.00% |
0 / 1 |
2 | |||
| getOfflineRunnerService | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
| getTestDefinitionSerializerService | |
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) 2019 (original work) Open Assessment Technologies SA ; |
| 19 | */ |
| 20 | |
| 21 | /** |
| 22 | * @author Péter Halász <peter@taotesting.com> |
| 23 | */ |
| 24 | |
| 25 | use oat\oatbox\service\ConfigurableService; |
| 26 | use oat\taoQtiTest\models\runner\map\TestMapBranchRuleExtender; |
| 27 | use oat\taoQtiTest\models\runner\OfflineQtiRunnerService; |
| 28 | use oat\taoQtiTest\models\runner\QtiRunnerServiceContext; |
| 29 | use oat\taoQtiTest\models\runner\TestDefinitionSerializerService; |
| 30 | |
| 31 | class taoQtiTest_actions_OfflineRunner extends taoQtiTest_actions_Runner |
| 32 | { |
| 33 | /** |
| 34 | * @throws common_Exception |
| 35 | * @return void |
| 36 | */ |
| 37 | public function init() |
| 38 | { |
| 39 | try { |
| 40 | /** @var QtiRunnerServiceContext $serviceContext */ |
| 41 | $serviceContext = $this->getRunnerService()->initServiceContext($this->getServiceContext()); |
| 42 | $response = $this->getInitResponse($serviceContext); |
| 43 | |
| 44 | if ($response['success'] === true) { |
| 45 | $response['testMap'] = $this->attachBranchingRulesToResponse($response['testMap'], $serviceContext); |
| 46 | $response['items'] = $this->getOfflineRunnerService()->getItems($serviceContext); |
| 47 | } |
| 48 | |
| 49 | $this->returnJson($response); |
| 50 | } catch (\Exception $e) { |
| 51 | $this->returnJson( |
| 52 | $this->getErrorResponse($e), |
| 53 | $this->getStatusCodeFromException($e) |
| 54 | ); |
| 55 | } |
| 56 | } |
| 57 | |
| 58 | /** |
| 59 | * Attaches the branching rules to the test map |
| 60 | * @param array $testMap |
| 61 | * @param QtiRunnerServiceContext $serviceContext |
| 62 | * @return array |
| 63 | * @throws common_exception_Error |
| 64 | * @throws common_exception_InconsistentData |
| 65 | * @throws core_kernel_persistence_Exception |
| 66 | * @throws \oat\tao\model\websource\WebsourceNotFound |
| 67 | */ |
| 68 | private function attachBranchingRulesToResponse(array $testMap, QtiRunnerServiceContext $serviceContext) |
| 69 | { |
| 70 | $serializedTestDefinition = $this->getTestDefinitionSerializerService()->getSerializedTestDefinition( |
| 71 | $serviceContext |
| 72 | ); |
| 73 | $branchRuleExtender = new TestMapBranchRuleExtender(); |
| 74 | |
| 75 | return $branchRuleExtender->getTestMapWithBranchRules($testMap, $serializedTestDefinition); |
| 76 | } |
| 77 | |
| 78 | /** |
| 79 | * @return ConfigurableService|OfflineQtiRunnerService |
| 80 | */ |
| 81 | private function getOfflineRunnerService() |
| 82 | { |
| 83 | return $this->getServiceLocator()->get(OfflineQtiRunnerService::SERVICE_ID); |
| 84 | } |
| 85 | |
| 86 | /** |
| 87 | * @return ConfigurableService|TestDefinitionSerializerService |
| 88 | */ |
| 89 | private function getTestDefinitionSerializerService() |
| 90 | { |
| 91 | return $this->getServiceLocator()->get(TestDefinitionSerializerService::SERVICE_ID); |
| 92 | } |
| 93 | } |