/** * 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); } }
protected function getFeedbacks(AssessmentItemSession $itemSession) { $dir = $this->getDirectory($this->getRequestParameter('itemDataPath')); return QtiRunner::getFeedbacks($dir, $itemSession); }
/** * Get the feedback to be displayed on an AssessmentItemSession * * @param tao_models_classes_service_StorageDirectory $directory * @param \qtism\runtime\tests\AssessmentItemSession $itemSession * @return array */ public static function getFeedbacks(tao_models_classes_service_StorageDirectory $directory, AssessmentItemSession $itemSession) { $returnValue = array(); $feedbackClasses = array('modalFeedback', 'feedbackInline', 'feedbackBlock'); $elements = self::getContentVariableElements($directory); $outcomes = array(); foreach ($elements as $data) { if (empty($data['qtiClass']) === false && in_array($data['qtiClass'], $feedbackClasses)) { $feedbackIdentifier = $data['attributes']['identifier']; $outcomeIdentifier = $data['attributes']['outcomeIdentifier']; if (!isset($outcomes[$outcomeIdentifier])) { $outcomes[$outcomeIdentifier] = array(); } $outcomes[$outcomeIdentifier][$feedbackIdentifier] = $data; } } foreach ($itemSession->getAllVariables() as $var) { $identifier = $var->getIdentifier(); if (isset($outcomes[$identifier])) { $feedbacks = $outcomes[$identifier]; $feedbackIds = QtiRunner::getVariableValues($var); foreach ($feedbackIds as $feedbackId) { if (isset($feedbacks[$feedbackId])) { $data = $feedbacks[$feedbackId]; $returnValue[$data['serial']] = $data; } } } } return $returnValue; }