protected function expandQuestion($question, $questions) {
        if ($question->qtype == 'randomsamatch') {
            $subquestions = [];
            foreach ($questions as $otherquestion) {
                if ($otherquestion->qtype == 'shortanswer') {
                    foreach ($otherquestion->answers as $answer) {
                        if (intval($answer->fraction) === 1) {
                            array_push(
                                $subquestions, 
                                (object) [
                                    "id" => $answer->id,
                                    "questiontext" => $otherquestion->questiontext,
                                    "answertext" => $answer->answer
                                ]
                            );
                            // Only take the first correct answer because that's what Moodle does. 
                            break;
                        }
                    }
                } 
            }

            $question->match = (object) [
             'subquestions' => $subquestions
            ];
        }
        return $question;
    }
protected function expandQuestion($question, $questions) {
        if ($question->qtype == 'randomsamatch') {
            $subquestions = [];
            foreach ($questions as $otherquestion) {
                if ($otherquestion->qtype == 'shortanswer') {
                    foreach ($otherquestion->answers as $answer) {
                        if (intval($answer->fraction) === 1) {
                            array_push(
                                $subquestions, 
                                (object) [
                                    "id" => $answer->id,
                                    "questiontext" => $otherquestion->questiontext,
                                    "answertext" => $answer->answer
                                ]
                            );
                            // Only take the first correct answer because that's what Moodle does. 
                            break;
                        }
                    }
                } 
            }

            $question->match = (object) [
             'subquestions' => $subquestions
            ];
        }
        return $question;
    }
protected function expandQuestion ( $ question , $ questions ) { if ( $ question -> qtype == 'randomsamatch' ) { $ subquestions = [ ] ; foreach ( $ questions as $ otherquestion ) { if ( $ otherquestion -> qtype == 'shortanswer' ) { foreach ( $ otherquestion -> answers as $ answer ) { if ( intval ( $ answer -> fraction ) === 1 ) { array_push ( $ subquestions , ( object ) [ "id" => $ answer -> id , "questiontext" => $ otherquestion -> questiontext , "answertext" => $ answer -> answer ] ) ; // Only take the first correct answer because that's what Moodle does.  break ; } } } } $ question -> match = ( object ) [ 'subquestions' => $ subquestions ] ; } return $ question ; }
For certain question types, expands question data by pulling from other questions.
@param PHPObj $question
@param Array $questions
@return PHPObj $question
For certain question types expands question data by pulling from other questions .