Ejemplo n.º 1
0
 public function testStateOutputRecord()
 {
     $sO = new taoQtiCommon_helpers_PciStateOutput();
     $sO->addVariable(new ResponseVariable('RESP1', Cardinality::RECORD, -1, new RecordContainer(array('A' => new QtiDuration('PT1S')))));
     $sO->addVariable(new ResponseVariable('RESP2', Cardinality::RECORD));
     $sO->addVariable(new ResponseVariable('RESP3', Cardinality::RECORD, -1, new RecordContainer(array('A' => new QtiPoint(1, 2), 'B' => new QtiFloat(13.37)))));
     $sO->addVariable(new OutcomeVariable('OUT1', Cardinality::RECORD, -1, new RecordContainer(array('A' => null, 'B' => new QtiInteger(23), 'C' => null, 'D' => new QtiInteger(23)))));
     $expectedArray = array();
     $expectedArray['RESP1'] = array('record' => array(array('name' => 'A', 'base' => array('duration' => 'PT1S'))));
     $expectedArray['RESP2'] = array('record' => array());
     $expectedArray['RESP3'] = array('record' => array(array('name' => 'A', 'base' => array('point' => array(1, 2))), array('name' => 'B', 'base' => array('float' => 13.37))));
     $expectedArray['OUT1'] = array('record' => array(array('name' => 'A', 'base' => null), array('name' => 'B', 'base' => array('integer' => 23)), array('name' => 'C', 'base' => null), array('name' => 'D', 'base' => array('integer' => 23))));
     $this->assertEquals($expectedArray, $sO->getOutput());
 }
 /**
  * Action called when a QTI Item embedded in a QTI Test submit responses.
  * 
  */
 public function storeItemVariableSet()
 {
     if ($this->beforeAction()) {
         // --- Deal with provided responses.
         $jsonPayload = taoQtiCommon_helpers_Utils::readJsonPayload();
         $responses = new State();
         $currentItem = $this->getTestSession()->getCurrentAssessmentItemRef();
         $currentOccurence = $this->getTestSession()->getCurrentAssessmentItemRefOccurence();
         if ($currentItem === false) {
             $msg = "Trying to store item variables but the state of the test session is INITIAL or CLOSED.\n";
             $msg .= "Session state value: " . $this->getTestSession()->getState() . "\n";
             $msg .= "Session ID: " . $this->getTestSession()->getSessionId() . "\n";
             $msg .= "JSON Payload: " . mb_substr(json_encode($jsonPayload), 0, 1000);
             common_Logger::e($msg);
         }
         $filler = new taoQtiCommon_helpers_PciVariableFiller($currentItem);
         if (is_array($jsonPayload)) {
             foreach ($jsonPayload as $id => $response) {
                 try {
                     $var = $filler->fill($id, $response);
                     // Do not take into account QTI File placeholders.
                     if (taoQtiCommon_helpers_Utils::isQtiFilePlaceHolder($var) === false) {
                         $responses->setVariable($var);
                     }
                 } catch (OutOfRangeException $e) {
                     common_Logger::d("Could not convert client-side value for variable '{$id}'.");
                 } catch (OutOfBoundsException $e) {
                     common_Logger::d("Could not find variable with identifier '{$id}' in current item.");
                 }
             }
         } else {
             common_Logger::e('Invalid json payload');
         }
         $displayFeedback = $this->getTestSession()->getCurrentSubmissionMode() !== SubmissionMode::SIMULTANEOUS;
         $stateOutput = new taoQtiCommon_helpers_PciStateOutput();
         try {
             common_Logger::i('Responses sent from the client-side. The Response Processing will take place.');
             $this->getTestSession()->endAttempt($responses, true);
             // Return the item session state to the client side.
             $itemSession = $this->getTestSession()->getAssessmentItemSessionStore()->getAssessmentItemSession($currentItem, $currentOccurence);
             foreach ($itemSession->getAllVariables() as $var) {
                 $stateOutput->addVariable($var);
             }
             $itemCompilationDirectory = $this->getDirectory($this->getRequestParameter('itemDataPath'));
             $jsonReturn = array('success' => true, 'displayFeedback' => $displayFeedback, 'itemSession' => $stateOutput->getOutput(), 'feedbacks' => array());
             if ($displayFeedback === true) {
                 $jsonReturn['feedbacks'] = QtiRunner::getFeedbacks($itemCompilationDirectory, $itemSession);
             }
             echo json_encode($jsonReturn);
         } catch (AssessmentTestSessionException $e) {
             $this->handleAssessmentTestSessionException($e);
         }
         $this->afterAction(false);
     }
 }