*/ use oat\oatbox\service\ConfigurableService; use oat\taoQtiTest\models\runner\map\TestMapBranchRuleExtender; use oat\taoQtiTest\models\runner\OfflineQtiRunnerService; use oat\taoQtiTest\models\runner\QtiRunnerServiceContext; use oat\taoQtiTest\models\runner\TestDefinitionSerializerService; class taoQtiTest_actions_OfflineRunner extends taoQtiTest_actions_Runner { /** * @throws common_Exception * @return void */ public function init() { try { /** @var QtiRunnerServiceContext $serviceContext */ $serviceContext = $this->getRunnerService()->initServiceContext($this->getServiceContext()); $response = $this->getInitResponse($serviceContext); if ($response['success'] === true) { $response['testMap'] = $this->attachBranchingRulesToResponse($response['testMap'], $serviceContext); $response['items'] = $this->getOfflineRunnerService()->getItems($serviceContext); } $this->returnJson($response); } catch (\Exception $e) { $this->returnJson( $this->getErrorResponse($e), $this->getErrorCode($e) ); } } /** * Attaches the branching rules to the test map * @param array $testMap * @param QtiRunnerServiceContext $serviceContext * @return array * @throws common_exception_Error * @throws common_exception_InconsistentData * @throws core_kernel_persistence_Exception * @throws \oat\tao\model\websource\WebsourceNotFound */ private function attachBranchingRulesToResponse(array $testMap, QtiRunnerServiceContext $serviceContext) { $serializedTestDefinition = $this->getTestDefinitionSerializerService()->getSerializedTestDefinition($serviceContext); $branchRuleExtender = new TestMapBranchRuleExtender(); return $branchRuleExtender->getTestMapWithBranchRules($testMap, $serializedTestDefinition); } /** * @return ConfigurableService|OfflineQtiRunnerService */ private function getOfflineRunnerService() { return $this->getServiceLocator()->get(OfflineQtiRunnerService::SERVICE_ID); } /** * @return ConfigurableService|TestDefinitionSerializerService */ private function getTestDefinitionSerializerService() { return $this->getServiceLocator()->get(TestDefinitionSerializerService::SERVICE_ID); } }