protected function getFeedbacks(AssessmentItemSession $itemSession) { $dir = $this->getDirectory($this->getRequestParameter('itemDataPath')); return QtiRunner::getFeedbacks($dir, $itemSession); }
/** * 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); } }