models/classes/runner/QtiRunnerService.php
public function storeItemResponse(RunnerServiceContext $context, $itemRef, $responses)
    {
        if ($context instanceof QtiRunnerServiceContext) {

            $session = $this->getCurrentAssessmentSession($context);

            try {
                \common_Logger::t('Responses sent from the client-side. The Response Processing will take place.');

                if ($context->isAdaptive()) {
                    $session->beginItemSession();
                    $session->beginAttempt();
                    $session->endAttempt($responses);

                    $assessmentItem = $session->getAssessmentItem();
                    $assessmentItemIdentifier = $assessmentItem->getIdentifier();
                    $score = $session->getVariable('SCORE');
                    $output = $context->getLastCatItemOutput();

                    if ($score !== null) {
                        $output[$assessmentItemIdentifier] = new ItemResult(
                            $assessmentItemIdentifier,
                            new ResultVariable(
                                $score->getIdentifier(),
                                BaseType::getNameByConstant($score->getBaseType()),
                                $score->getValue()->getValue(),
                                null,
                                $score->getCardinality()
                            ),
                            microtime(true)
                        );
                    } else {
                        \common_Logger::i("No 'SCORE' outcome variable for item '${assessmentItemIdentifier}' involved in an adaptive section.");
                    }

                    $context->persistLastCatItemOutput($output);

                    // Send results to TAO Results.
                    $resultTransmitter = new \taoQtiCommon_helpers_ResultTransmitter($context->getSessionManager()->getResultServer());
                    $outcomeVariables = [];

                    $hrefParts = explode('|', $assessmentItem->getHref());
                    $sessionId = $context->getTestSession()->getSessionId();
                    $itemIdentifier = $assessmentItem->getIdentifier();

                    // Deal with attempts.
                    $attempt = $context->getCatAttempts($itemIdentifier);
                    $transmissionId = "${sessionId}.${itemIdentifier}.${attempt}";

                    $attempt++;

                    foreach ($session->getAllVariables() as $var) {
                        if ($var->getIdentifier() === 'numAttempts') {
                            $var->setValue(new \qtism\common\datatypes\QtiInteger($attempt));
                        }

                        $variables[] = $var;
                    }

                    $resultTransmitter->transmitItemVariable($variables, $transmissionId, $hrefParts[0], $hrefParts[2]);
                    $context->persistCatAttempts($itemIdentifier, $attempt);

                    $context->getTestSession()->endAttempt(new State(), true);
                } else {
                    // Non adaptive case.
                    $session->endAttempt($responses, true);
                }

                return true;
            } catch (AssessmentTestSessionException $e) {
                \common_Logger::w($e->getMessage());
                return false;
            }
        } else {
            throw new \common_exception_InvalidArgumentType(
                'QtiRunnerService',
                'storeItemResponse',
                0,
                'oat\taoQtiTest\models\runner\QtiRunnerServiceContext',
                $context
            );
        }
    }
public function storeItemResponse(RunnerServiceContext $context, $itemRef, $responses)
    {
        if ($context instanceof QtiRunnerServiceContext) {

            $session = $this->getCurrentAssessmentSession($context);

            try {
                \common_Logger::t('Responses sent from the client-side. The Response Processing will take place.');

                if ($context->isAdaptive()) {
                    $session->beginItemSession();
                    $session->beginAttempt();
                    $session->endAttempt($responses);

                    $assessmentItem = $session->getAssessmentItem();
                    $assessmentItemIdentifier = $assessmentItem->getIdentifier();
                    $score = $session->getVariable('SCORE');
                    $output = $context->getLastCatItemOutput();

                    if ($score !== null) {
                        $output[$assessmentItemIdentifier] = new ItemResult(
                            $assessmentItemIdentifier,
                            new ResultVariable(
                                $score->getIdentifier(),
                                BaseType::getNameByConstant($score->getBaseType()),
                                $score->getValue()->getValue(),
                                null,
                                $score->getCardinality()
                            ),
                            microtime(true)
                        );
                    } else {
                        \common_Logger::i("No 'SCORE' outcome variable for item '${assessmentItemIdentifier}' involved in an adaptive section.");
                    }

                    $context->persistLastCatItemOutput($output);

                    // Send results to TAO Results.
                    $resultTransmitter = new \taoQtiCommon_helpers_ResultTransmitter($context->getSessionManager()->getResultServer());
                    $outcomeVariables = [];

                    $hrefParts = explode('|', $assessmentItem->getHref());
                    $sessionId = $context->getTestSession()->getSessionId();
                    $itemIdentifier = $assessmentItem->getIdentifier();

                    // Deal with attempts.
                    $attempt = $context->getCatAttempts($itemIdentifier);
                    $transmissionId = "${sessionId}.${itemIdentifier}.${attempt}";

                    $attempt++;

                    foreach ($session->getAllVariables() as $var) {
                        if ($var->getIdentifier() === 'numAttempts') {
                            $var->setValue(new \qtism\common\datatypes\QtiInteger($attempt));
                        }

                        $variables[] = $var;
                    }

                    $resultTransmitter->transmitItemVariable($variables, $transmissionId, $hrefParts[0], $hrefParts[2]);
                    $context->persistCatAttempts($itemIdentifier, $attempt);

                    $context->getTestSession()->endAttempt(new State(), true);
                } else {
                    // Non adaptive case.
                    $session->endAttempt($responses, true);
                }

                return true;
            } catch (AssessmentTestSessionException $e) {
                \common_Logger::w($e->getMessage());
                return false;
            }
        } else {
            throw new \common_exception_InvalidArgumentType(
                'QtiRunnerService',
                'storeItemResponse',
                0,
                'oat\taoQtiTest\models\runner\QtiRunnerServiceContext',
                $context
            );
        }
    }
public function storeItemResponse ( RunnerServiceContext $ context , $ itemRef , $ responses ) { if ( $ context instanceof QtiRunnerServiceContext ) { $ session = $ this -> getCurrentAssessmentSession ( $ context ) ; try { \ common_Logger :: t ( 'Responses sent from the client-side. The Response Processing will take place.' ) ; if ( $ context -> isAdaptive ( ) ) { $ session -> beginItemSession ( ) ; $ session -> beginAttempt ( ) ; $ session -> endAttempt ( $ responses ) ; $ assessmentItem = $ session -> getAssessmentItem ( ) ; $ assessmentItemIdentifier = $ assessmentItem -> getIdentifier ( ) ; $ score = $ session -> getVariable ( 'SCORE' ) ; $ output = $ context -> getLastCatItemOutput ( ) ; if ( $ score !== null ) { $ output [ $ assessmentItemIdentifier ] = new ItemResult ( $ assessmentItemIdentifier , new ResultVariable ( $ score -> getIdentifier ( ) , BaseType :: getNameByConstant ( $ score -> getBaseType ( ) ) , $ score -> getValue ( ) -> getValue ( ) , null , $ score -> getCardinality ( ) ) , microtime ( true ) ) ; } else { \ common_Logger :: i ( "No 'SCORE' outcome variable for item '${assessmentItemIdentifier}' involved in an adaptive section." ) ; } $ context -> persistLastCatItemOutput ( $ output ) ; // Send results to TAO Results. $ resultTransmitter = new \ taoQtiCommon_helpers_ResultTransmitter ( $ context -> getSessionManager ( ) -> getResultServer ( ) ) ; $ outcomeVariables = [ ] ; $ hrefParts = explode ( '|' , $ assessmentItem -> getHref ( ) ) ; $ sessionId = $ context -> getTestSession ( ) -> getSessionId ( ) ; $ itemIdentifier = $ assessmentItem -> getIdentifier ( ) ; // Deal with attempts. $ attempt = $ context -> getCatAttempts ( $ itemIdentifier ) ; $ transmissionId = "${sessionId}.${itemIdentifier}.${attempt}" ; $ attempt ++ ; foreach ( $ session -> getAllVariables ( ) as $ var ) { if ( $ var -> getIdentifier ( ) === 'numAttempts' ) { $ var -> setValue ( new \ qtism \ common \ datatypes \ QtiInteger ( $ attempt ) ) ; } $ variables [ ] = $ var ; } $ resultTransmitter -> transmitItemVariable ( $ variables , $ transmissionId , $ hrefParts [ 0 ] , $ hrefParts [ 2 ] ) ; $ context -> persistCatAttempts ( $ itemIdentifier , $ attempt ) ; $ context -> getTestSession ( ) -> endAttempt ( new State ( ) , true ) ; } else { // Non adaptive case. $ session -> endAttempt ( $ responses , true ) ; } return true ; } catch ( AssessmentTestSessionException $ e ) { \ common_Logger :: w ( $ e -> getMessage ( ) ) ; return false ; } } else { throw new \ common_exception_InvalidArgumentType ( 'QtiRunnerService' , 'storeItemResponse' , 0 , 'oat\taoQtiTest\models\runner\QtiRunnerServiceContext' , $ context ) ; } }
Stores the response of a particular item
@param RunnerServiceContext $context
@param $itemRef
@param $responses
@return boolean
@throws \common_Exception
Stores the response of a particular item