/** * Add a PendingResponse object to the store. * * @param \qtism\runtime\tests\PendingResponses $pendingResponses */ public function addPendingResponses(PendingResponses $pendingResponses) { $map = $this->getAssessmentItemRefMap(); $itemRef = $pendingResponses->getAssessmentItemRef(); if (isset($map[$itemRef]) === false) { $map[$itemRef] = array(); } $entry = $map[$itemRef]; $entry[$pendingResponses->getOccurence()] = $pendingResponses; $map[$itemRef] = $entry; $this->getAllPendingResponses()->attach($pendingResponses); }
/** * Write a PendingResponses object in the current binary stream. * * @param AssessmentTestSeeker $seeker An AssessmentTestSeeker object from where positions in the assessmentTest tree will be pulled out. * @param PendingResponses $pendingResponses The read PendingResponses object. * @throws QtiBinaryStreamAccessException */ public function writePendingResponses(AssessmentTestSeeker $seeker, PendingResponses $pendingResponses) { try { $state = $pendingResponses->getState(); $itemRef = $pendingResponses->getAssessmentItemRef(); $occurence = $pendingResponses->getOccurence(); // Write the state. $responseDeclarations = $itemRef->getResponseDeclarations(); $varCount = count($state); $this->writeTinyInt($varCount); foreach ($state as $responseVariable) { $respId = $responseVariable->getIdentifier(); if (isset($responseDeclarations[$respId]) === true) { $this->writeShort($seeker->seekPosition($responseDeclarations[$respId])); $this->writeVariableValue($responseVariable); } else { $msg = "No response variable with identifier '{$respId}' found in related assessmentItemRef."; throw new QtiBinaryStreamAccessException($msg, $this, QtiBinaryStreamAccessException::PENDING_RESPONSES); } } // Write the assessmentItemRef. $this->writeShort($seeker->seekPosition($itemRef)); // Write the occurence number. $this->writeTinyInt($occurence); } catch (BinaryStreamAccessException $e) { $msg = "An error occured while reading some pending responses."; throw new QtiBinaryStreamAccessException($msg, $this, QtiBinaryStreamAccessException::PENDING_RESPONSES, $e); } catch (OutOfBoundsException $e) { $msg = "A QTI component position could not be found in the assessmentTest tree structure."; throw new QtiBinaryStreamAccessException($msg, $this, QtiBinaryStreamAccessException::PENDING_RESPONSES, $e); } }