/**
  * Save session metadata.
  * 
  * @param array $metaData Meta data array to be saved.
  * @param RouteItem $routeItem item for which data will be saved
  * @param string $assessmentSectionId section id for which data will be saved
  * Example:
  * array(
  *   'TEST' => array('TEST_EXIT_CODE' => 'IC'),
  *   'SECTION' => array('SECTION_EXIT_CODE' => 701),
  * )
  */
 public function save(array $metaData, RouteItem $routeItem = null, $assessmentSectionId = null)
 {
     $testUri = $this->session->getTest()->getUri();
     $resultServer = \taoResultServer_models_classes_ResultServerStateFull::singleton();
     foreach ($metaData as $type => $data) {
         foreach ($data as $key => $value) {
             $metaVariable = $this->getVariable($key, $value);
             if (strcasecmp($type, 'ITEM') === 0) {
                 if ($routeItem === null) {
                     $itemRef = $this->session->getCurrentAssessmentItemRef();
                     $occurence = $this->session->getCurrentAssessmentItemRefOccurence();
                 } else {
                     $itemRef = $routeItem->getAssessmentItemRef();
                     $occurence = $routeItem->getOccurence();
                 }
                 $itemUri = $this->getItemUri($itemRef);
                 $sessionId = $this->session->getSessionId();
                 $transmissionId = "{$sessionId}.{$itemRef}.{$occurence}";
                 $resultServer->storeItemVariable($testUri, $itemUri, $metaVariable, $transmissionId);
             } elseif (strcasecmp($type, 'TEST') === 0) {
                 $resultServer->storeTestVariable($testUri, $metaVariable, $this->session->getSessionId());
             } elseif (strcasecmp($type, 'SECTION') === 0) {
                 //suffix section variables with _{SECTION_IDENTIFIER}
                 if ($assessmentSectionId === null) {
                     $assessmentSectionId = $this->session->getCurrentAssessmentSection()->getIdentifier();
                 }
                 $metaVariable->setIdentifier($key . '_' . $assessmentSectionId);
                 $resultServer->storeTestVariable($testUri, $metaVariable, $this->session->getSessionId());
             }
         }
     }
 }
 /**
  * Checks if the current session can be exited
  *
  * @param AssessmentTestSession $session
  * @return bool
  */
 public static function doesAllowExit(AssessmentTestSession $session)
 {
     $categories = $session->getCurrentAssessmentItemRef()->getCategories();
     $config = common_ext_ExtensionsManager::singleton()->getExtensionById('taoQtiTest')->getConfig('testRunner');
     $exitButton = isset($config['exitButton']) && $config['exitButton'];
     return $exitButton && $categories->contains('x-tao-option-exit');
 }
 /**
  * Get the URI referencing the current Assessment Item (in the knowledge base)
  * to be presented to the candidate.
  * 
  * @param AssessmentTestSession $session An AssessmentTestSession object.
  * @return string A URI.
  */
 public static function getCurrentItemUri(AssessmentTestSession $session)
 {
     $href = $session->getCurrentAssessmentItemRef()->getHref();
     $parts = explode('|', $href);
     return $parts[0];
 }
 /**
  * Get the array of available categories for the current itemRef
  * 
  * @param \qtism\runtime\tests\AssessmentTestSession $session
  * @return array
  */
 public static function getCategories(AssessmentTestSession $session)
 {
     return $session->getCurrentAssessmentItemRef()->getCategories()->getArrayCopy();
 }