public function matchStatement($translatorevent, $questionAttempt, $question) {

        $translatorevent['interaction_type'] = 'matching';

        $targets = [];
        $sources = [];
        $correctResponses = [];
        $responseTargetsPos = [];
        $responseSourcesPos = [];

        foreach ($question->match->subquestions as $subquestion) {
            $target = strip_tags($subquestion->questiontext);
            $source = strip_tags($subquestion->answertext);
            $targetId = 'moodle_quiz_question_target_'.$subquestion->id;
            $sourceId = 'moodle_quiz_question_source_'.$subquestion->id;
            $targets[$targetId] = $target;
            $sources[$sourceId] = $source;
            array_push(
                $correctResponses, 
                $sourceId.'[.]'.$targetId
            );

            // Get the positions of the target and source within the response string.
            $responseTargetsPos[strpos($questionAttempt->responsesummary, $target)] = $targetId;
            $responseSourcesPos[strpos($questionAttempt->responsesummary, $source)] = $sourceId;
        }

        // Get ordered and indexed lists of target and source.
        ksort($responseTargetsPos);
        $responseTargets = array_values($responseTargetsPos);
        ksort($responseSourcesPos);
        $responseSources = array_values($responseSourcesPos);

        $translatorevent['attempt_response'] = '';
        if (count($responseTargets) == count($responseSources) && count($responseTargets) > 0) {
            $responses = [];
            foreach ($responseTargets as $index => $targetId) {
                array_push(
                    $responses,
                    $responseSources[$index].'[.]'.$targetId
                );
            }
            $translatorevent['attempt_response'] = implode('[,]', $responses);
        }

        $translatorevent['interaction_target'] = $targets;
        $translatorevent['interaction_source'] = $sources;
        $translatorevent['interaction_correct_responses'] = [implode('[,]', $correctResponses)];

        return $translatorevent;
    }
public function matchStatement($translatorevent, $questionAttempt, $question) {

        $translatorevent['interaction_type'] = 'matching';

        $targets = [];
        $sources = [];
        $correctResponses = [];
        $responseTargetsPos = [];
        $responseSourcesPos = [];

        foreach ($question->match->subquestions as $subquestion) {
            $target = strip_tags($subquestion->questiontext);
            $source = strip_tags($subquestion->answertext);
            $targetId = 'moodle_quiz_question_target_'.$subquestion->id;
            $sourceId = 'moodle_quiz_question_source_'.$subquestion->id;
            $targets[$targetId] = $target;
            $sources[$sourceId] = $source;
            array_push(
                $correctResponses, 
                $sourceId.'[.]'.$targetId
            );

            // Get the positions of the target and source within the response string.
            $responseTargetsPos[strpos($questionAttempt->responsesummary, $target)] = $targetId;
            $responseSourcesPos[strpos($questionAttempt->responsesummary, $source)] = $sourceId;
        }

        // Get ordered and indexed lists of target and source.
        ksort($responseTargetsPos);
        $responseTargets = array_values($responseTargetsPos);
        ksort($responseSourcesPos);
        $responseSources = array_values($responseSourcesPos);

        $translatorevent['attempt_response'] = '';
        if (count($responseTargets) == count($responseSources) && count($responseTargets) > 0) {
            $responses = [];
            foreach ($responseTargets as $index => $targetId) {
                array_push(
                    $responses,
                    $responseSources[$index].'[.]'.$targetId
                );
            }
            $translatorevent['attempt_response'] = implode('[,]', $responses);
        }

        $translatorevent['interaction_target'] = $targets;
        $translatorevent['interaction_source'] = $sources;
        $translatorevent['interaction_correct_responses'] = [implode('[,]', $correctResponses)];

        return $translatorevent;
    }
public function matchStatement ( $ translatorevent , $ questionAttempt , $ question ) { $ translatorevent [ 'interaction_type' ] = 'matching' ; $ targets = [ ] ; $ sources = [ ] ; $ correctResponses = [ ] ; $ responseTargetsPos = [ ] ; $ responseSourcesPos = [ ] ; foreach ( $ question -> match -> subquestions as $ subquestion ) { $ target = strip_tags ( $ subquestion -> questiontext ) ; $ source = strip_tags ( $ subquestion -> answertext ) ; $ targetId = 'moodle_quiz_question_target_' . $ subquestion -> id ; $ sourceId = 'moodle_quiz_question_source_' . $ subquestion -> id ; $ targets [ $ targetId ] = $ target ; $ sources [ $ sourceId ] = $ source ; array_push ( $ correctResponses , $ sourceId . '[.]' . $ targetId ) ; // Get the positions of the target and source within the response string. $ responseTargetsPos [ strpos ( $ questionAttempt -> responsesummary , $ target ) ] = $ targetId ; $ responseSourcesPos [ strpos ( $ questionAttempt -> responsesummary , $ source ) ] = $ sourceId ; } // Get ordered and indexed lists of target and source. ksort ( $ responseTargetsPos ) ; $ responseTargets = array_values ( $ responseTargetsPos ) ; ksort ( $ responseSourcesPos ) ; $ responseSources = array_values ( $ responseSourcesPos ) ; $ translatorevent [ 'attempt_response' ] = '' ; if ( count ( $ responseTargets ) == count ( $ responseSources ) && count ( $ responseTargets ) > 0 ) { $ responses = [ ] ; foreach ( $ responseTargets as $ index => $ targetId ) { array_push ( $ responses , $ responseSources [ $ index ] . '[.]' . $ targetId ) ; } $ translatorevent [ 'attempt_response' ] = implode ( '[,]' , $ responses ) ; } $ translatorevent [ 'interaction_target' ] = $ targets ; $ translatorevent [ 'interaction_source' ] = $ sources ; $ translatorevent [ 'interaction_correct_responses' ] = [ implode ( '[,]' , $ correctResponses ) ] ; return $ translatorevent ; }
Add data specifc to matching question types to a translator event.
@param [String => Mixed] $translatorevent
@param PHPObj $questionAttempt
@param PHPObj $question
@return [String => Mixed]
Add data specifc to matching question types to a translator event .