public function process_ma($quest, &$questions) {
        $question = $this->process_common($quest);
        $question->qtype = 'multichoice';
        $question = $this->add_blank_combined_feedback($question);
        $question->single = 0; // More than one answer allowed.

        $answers = $quest->responses;
        $correctanswers = array();
        foreach ($answers as $answer) {
            if ($answer->title == 'correct') {
                $answerset = $this->getpath($answer->ident[0],
                        array('and', 0, '#', 'varequal'), array(), false);
                foreach ($answerset as $ans) {
                    $correctanswers[] = $ans['#'];
                }
            }
        }
        $feedback = new stdClass();
        foreach ($quest->feedback as $fb) {
            $feedback->{$fb->ident} = trim($fb->text);
        }

        $correctanswercount = count($correctanswers);
        $fraction = 1 / $correctanswercount;
        $choiceset = $quest->RESPONSE_BLOCK->choices;
        $i = 0;
        foreach ($choiceset as $choice) {
            $question->answer[$i] = $this->cleaned_text_field(trim($choice->text));
            if (in_array($choice->ident, $correctanswers)) {
                // Correct answer.
                $question->fraction[$i] = $fraction;
                $question->feedback[$i] = $this->cleaned_text_field($feedback->correct);
            } else {
                // Wrong answer.
                $question->fraction[$i] = 0;
                $question->feedback[$i] = $this->cleaned_text_field($feedback->incorrect);
            }
            $i++;
        }

        $questions[] = $question;
    }
public function process_ma($quest, &$questions) {
        $question = $this->process_common($quest);
        $question->qtype = 'multichoice';
        $question = $this->add_blank_combined_feedback($question);
        $question->single = 0; // More than one answer allowed.

        $answers = $quest->responses;
        $correctanswers = array();
        foreach ($answers as $answer) {
            if ($answer->title == 'correct') {
                $answerset = $this->getpath($answer->ident[0],
                        array('and', 0, '#', 'varequal'), array(), false);
                foreach ($answerset as $ans) {
                    $correctanswers[] = $ans['#'];
                }
            }
        }
        $feedback = new stdClass();
        foreach ($quest->feedback as $fb) {
            $feedback->{$fb->ident} = trim($fb->text);
        }

        $correctanswercount = count($correctanswers);
        $fraction = 1 / $correctanswercount;
        $choiceset = $quest->RESPONSE_BLOCK->choices;
        $i = 0;
        foreach ($choiceset as $choice) {
            $question->answer[$i] = $this->cleaned_text_field(trim($choice->text));
            if (in_array($choice->ident, $correctanswers)) {
                // Correct answer.
                $question->fraction[$i] = $fraction;
                $question->feedback[$i] = $this->cleaned_text_field($feedback->correct);
            } else {
                // Wrong answer.
                $question->fraction[$i] = 0;
                $question->feedback[$i] = $this->cleaned_text_field($feedback->incorrect);
            }
            $i++;
        }

        $questions[] = $question;
    }
public function process_ma ( $ quest , & $ questions ) { $ question = $ this -> process_common ( $ quest ) ; $ question -> qtype = 'multichoice' ; $ question = $ this -> add_blank_combined_feedback ( $ question ) ; $ question -> single = 0 ; // More than one answer allowed. $ answers = $ quest -> responses ; $ correctanswers = array ( ) ; foreach ( $ answers as $ answer ) { if ( $ answer -> title == 'correct' ) { $ answerset = $ this -> getpath ( $ answer -> ident [ 0 ] , array ( 'and' , 0 , '#' , 'varequal' ) , array ( ) , false ) ; foreach ( $ answerset as $ ans ) { $ correctanswers [ ] = $ ans [ '#' ] ; } } } $ feedback = new stdClass ( ) ; foreach ( $ quest -> feedback as $ fb ) { $ feedback -> { $ fb -> ident } = trim ( $ fb -> text ) ; } $ correctanswercount = count ( $ correctanswers ) ; $ fraction = 1 / $ correctanswercount ; $ choiceset = $ quest -> RESPONSE_BLOCK -> choices ; $ i = 0 ; foreach ( $ choiceset as $ choice ) { $ question -> answer [ $ i ] = $ this -> cleaned_text_field ( trim ( $ choice -> text ) ) ; if ( in_array ( $ choice -> ident , $ correctanswers ) ) { // Correct answer. $ question -> fraction [ $ i ] = $ fraction ; $ question -> feedback [ $ i ] = $ this -> cleaned_text_field ( $ feedback -> correct ) ; } else { // Wrong answer. $ question -> fraction [ $ i ] = 0 ; $ question -> feedback [ $ i ] = $ this -> cleaned_text_field ( $ feedback -> incorrect ) ; } $ i ++ ; } $ questions [ ] = $ question ; }
Process Multiple Choice Questions With Multiple Answers.
Parse a multichoice multianswer rawquestion and add the result
to the array of questions already parsed.
@param object $quest rawquestion
@param array $questions array of Moodle questions already done.
Process Multiple Choice Questions With Multiple Answers . Parse a multichoice multianswer rawquestion and add the result to the array of questions already parsed .