/** * Do the move * @param RunnerServiceContext $context * @param mixed $ref * @return boolean * @throws \common_Exception */ public function move(RunnerServiceContext $context, $ref) { $session = $context->getTestSession(); $session->skip(); $session->moveNext(); return true; }
/** * Gets the rubrics according to the current session state * The content is directly rendered into the page * @param RunnerServiceContext $context * @return mixed */ public function getRubrics(RunnerServiceContext $context) { // TODO: make a better implementation for rubrics loading. /* @var AssessmentTestSession $session */ $session = $context->getTestSession(); $compilationDirs = $context->getCompilationDirectory(); // -- variables used in the included rubric block templates. // base path (base URI to be used for resource inclusion). $basePathVarName = TAOQTITEST_BASE_PATH_NAME; ${$basePathVarName} = $compilationDirs['public']->getPublicAccessUrl(); // state name (the variable to access to get the state of the assessmentTestSession). $stateName = TAOQTITEST_RENDERING_STATE_NAME; ${$stateName} = $session; // views name (the variable to be accessed for the visibility of rubric blocks). $viewsName = TAOQTITEST_VIEWS_NAME; ${$viewsName} = array(View::CANDIDATE); ob_start(); foreach ($session->getRoute()->current()->getRubricBlockRefs() as $rubric) { $data = $compilationDirs['private']->read($rubric->getHref()); $tmpFile = \tao_helpers_File::createTempDir() . basename($rubric->getHref()); file_put_contents($tmpFile, $data); include $tmpFile; unlink($tmpFile); } $rubrics = ob_get_contents(); ob_end_clean(); return $rubrics; }
/** * Do the move * @param RunnerServiceContext $context * @param mixed $ref * @return boolean * @throws \common_Exception */ public function move(RunnerServiceContext $context, $ref) { /* @var AssessmentTestSession $session */ $session = $context->getTestSession(); $nextPosition = $session->getRoute()->getPosition() + 1; QtiRunnerNavigation::checkTimedSectionExit($context, $nextPosition); $session->moveNext(); return true; }
/** * Returns the options related to the current test context * @param RunnerServiceContext $context The test context * @return mixed */ public function getOptions(RunnerServiceContext $context) { $session = $context->getTestSession(); // Comment allowed? Skipping allowed? Logout or Exit allowed ? $options = ['allowComment' => \taoQtiTest_helpers_TestRunnerUtils::doesAllowComment($session), 'allowSkipping' => \taoQtiTest_helpers_TestRunnerUtils::doesAllowSkipping($session), 'exitButton' => \taoQtiTest_helpers_TestRunnerUtils::doesAllowExit($session), 'logoutButton' => \taoQtiTest_helpers_TestRunnerUtils::doesAllowLogout($session)]; // get the options from the categories owned by the current item $categories = \taoQtiTest_helpers_TestRunnerUtils::getCategories($session); $prefixCategory = 'x-tao-option-'; $prefixCategoryLen = strlen($prefixCategory); foreach ($categories as $category) { if (!strncmp($category, $prefixCategory, $prefixCategoryLen)) { // extract the option name from the category, transform to camelCase if needed $optionName = lcfirst(str_replace(' ', '', ucwords(strtr(substr($category, $prefixCategoryLen), ['-' => ' ', '_' => ' '])))); // the options added by the categories are just flags $options[$optionName] = true; } } return $options; }
/** * Builds the map of an assessment test * @param RunnerServiceContext $context The test context * @param RunnerConfig $config The runner config * @return mixed */ public function getMap(RunnerServiceContext $context, RunnerConfig $config) { $map = ['parts' => [], 'jumps' => []]; // get config for the sequence number option $reviewConfig = $config->getConfigValue('review'); $checkInformational = $config->getConfigValue('checkInformational'); $forceTitles = !empty($reviewConfig['forceTitle']); $uniqueTitle = isset($reviewConfig['itemTitle']) ? $reviewConfig['itemTitle'] : '%d'; /* @var AssessmentTestSession $session */ $session = $context->getTestSession(); if ($session->isRunning() !== false) { $route = $session->getRoute(); $store = $session->getAssessmentItemSessionStore(); $routeItems = $route->getAllRouteItems(); $offset = $route->getRouteItemPosition($routeItems[0]); $offsetPart = 0; $offsetSection = 0; $lastPart = null; $lastSection = null; /** @var \qtism\runtime\tests\RouteItem $routeItem */ foreach ($routeItems as $routeItem) { // access the item reference $itemRef = $routeItem->getAssessmentItemRef(); $occurrence = $routeItem->getOccurence(); // get the jump definition $itemSession = $store->getAssessmentItemSession($itemRef, $occurrence); // load item infos $testPart = $routeItem->getTestPart(); $partId = $testPart->getIdentifier(); $section = $routeItem->getAssessmentSection(); $sectionId = $section->getIdentifier(); $itemId = $itemRef->getIdentifier(); $itemUri = strstr($itemRef->getHref(), '|', true); $item = new \core_kernel_classes_Resource($itemUri); if ($lastPart != $partId) { $offsetPart = 0; $lastPart = $partId; } if ($lastSection != $sectionId) { $offsetSection = 0; $lastSection = $sectionId; } if ($forceTitles) { $label = sprintf($uniqueTitle, $offsetSection + 1); } else { $label = $item->getLabel(); } $itemInfos = ['id' => $itemId, 'uri' => $itemUri, 'label' => $label, 'position' => $offset, 'positionInPart' => $offsetPart, 'positionInSection' => $offsetSection, 'index' => $offsetSection + 1, 'occurrence' => $occurrence, 'remainingAttempts' => $itemSession->getRemainingAttempts(), 'answered' => TestRunnerUtils::isItemCompleted($routeItem, $itemSession), 'flagged' => TestRunnerUtils::getItemFlag($session, $routeItem), 'viewed' => $itemSession->isPresented()]; if ($checkInformational) { $itemInfos['informational'] = TestRunnerUtils::isItemInformational($routeItem, $itemSession); } // update the map $map['jumps'][] = ['identifier' => $itemId, 'section' => $sectionId, 'part' => $partId, 'position' => $offset, 'uri' => $itemUri]; if (!isset($map['parts'][$partId])) { $map['parts'][$partId]['id'] = $partId; $map['parts'][$partId]['label'] = $partId; $map['parts'][$partId]['position'] = $offset; $map['parts'][$partId]['isLinear'] = $testPart->getNavigationMode() == NavigationMode::LINEAR; } if (!isset($map['parts'][$partId]['sections'][$sectionId])) { $map['parts'][$partId]['sections'][$sectionId]['id'] = $sectionId; $map['parts'][$partId]['sections'][$sectionId]['label'] = $section->getTitle(); $map['parts'][$partId]['sections'][$sectionId]['position'] = $offset; } $map['parts'][$partId]['sections'][$sectionId]['items'][$itemId] = $itemInfos; // update the stats $this->updateStats($map, $itemInfos); $this->updateStats($map['parts'][$partId], $itemInfos); $this->updateStats($map['parts'][$partId]['sections'][$sectionId], $itemInfos); $offset++; $offsetPart++; $offsetSection++; } } return $map; }
/** * Do the move * @param RunnerServiceContext $context * @param mixed $ref * @return boolean * @throws \common_Exception */ public function move(RunnerServiceContext $context, $ref) { $context->getTestSession()->moveNextAssessmentSection(); return true; }
/** * Sets the test session * @param mixed $testSession * @throws \common_exception_InvalidArgumentType */ public function setTestSession($testSession) { if ($testSession instanceof TestSession) { parent::setTestSession($testSession); } else { throw new \common_exception_InvalidArgumentType('QtiRunnerServiceContext', 'setTestSession', 0, 'oat\\taoQtiTest\\models\\runner\\session\\TestSession', $testSession); } }