 question/type/randomsamatch/questiontype.php |   89 ++++++++++++++++++++++++++
 1 files changed, 89 insertions(+), 0 deletions(-)

diff --git a/question/type/randomsamatch/questiontype.php b/question/type/randomsamatch/questiontype.php
index 0bb2aa8..c3958bd 100644
--- a/question/type/randomsamatch/questiontype.php
+++ b/question/type/randomsamatch/questiontype.php
@@ -325,6 +325,95 @@ class question_randomsamatch_qtype extends question_match_qtype {
         return $answers[$question->id];
     }
 
+    function print_question_formulation_and_controls(&$question, &$state, $cmoptions, $options) {
+        global $CFG, $OUTPUT;
+        $context        = $this->get_context_by_category_id($question->category);
+        $subquestions   = $state->options->subquestions;
+        $correctanswers = $this->get_correct_responses($question, $state);
+        $nameprefix     = $question->name_prefix;
+        $answers        = array(); // Answer choices formatted ready for output.
+        $allanswers     = array(); // This and the next used to detect identical answers
+        $answerids      = array(); // and adjust ids.
+        $responses      = &$state->responses;
+
+        // Prepare a list of answers, removing duplicates.
+        foreach ($subquestions as $subquestion) {
+            foreach ($subquestion->options->answers as $ans) {
+                $allanswers[$ans->id] = $ans->answer;
+                if (!in_array($ans->answer, $answers)) {
+                    $answers[$ans->id] = strip_tags(format_string($ans->answer, false));
+                    $answerids[$ans->answer] = $ans->id;
+                }
+            }
+        }
+
+        // Fix up the ids of any responses that point the the eliminated duplicates.
+        foreach ($responses as $subquestionid => $ignored) {
+            if ($responses[$subquestionid]) {
+                $responses[$subquestionid] = $answerids[$allanswers[$responses[$subquestionid]]];
+            }
+        }
+        foreach ($correctanswers as $subquestionid => $ignored) {
+            $correctanswers[$subquestionid] = $answerids[$allanswers[$correctanswers[$subquestionid]]];
+        }
+
+        // Shuffle the answers
+        $answers = draw_rand_array($answers, count($answers));
+
+        // Print formulation
+        $questiontext = $this->format_text($question->questiontext,
+                $question->questiontextformat, $cmoptions);
+
+        // Print the input controls
+        foreach ($subquestions as $key => $subquestion) {
+            if ($subquestion->questiontext !== '' && !is_null($subquestion->questiontext)) {
+                // Subquestion text:
+                $a = new stdClass;
+                $text = quiz_rewrite_question_urls($subquestion->questiontext, 'pluginfile.php', $context->id, 'question', 'questiontext', array($state->attempt, $state->question), $subquestion->id); 
+                $a->text = $this->format_text($text, $subquestion->questiontextformat, $cmoptions);
+
+                // Drop-down list:
+                $menuname = $nameprefix.$subquestion->id;
+                $response = isset($state->responses[$subquestion->id])
+                            ? $state->responses[$subquestion->id] : '0';
+
+                $a->class = ' ';
+                $a->feedbackimg = ' ';
+
+                if ($options->readonly and $options->correct_responses) {
+                    if (isset($correctanswers[$subquestion->id])
+                            and ($correctanswers[$subquestion->id] == $response)) {
+                        $correctresponse = 1;
+                    } else {
+                        $correctresponse = 0;
+                    }
+
+                    if ($options->feedback && $response) {
+                        $a->class = question_get_feedback_class($correctresponse);
+                        $a->feedbackimg = question_get_feedback_image($correctresponse);
+                    }
+                }
+
+                $attributes = array();
+                $attributes['disabled'] = $options->readonly ? 'disabled' : null;
+                $a->control = html_writer::select($answers, $menuname, $response, array(''=>'choosedots'), $attributes);
+
+                // Neither the editing interface or the database allow to provide
+                // fedback for this question type.
+                // However (as was pointed out in bug bug 3294) the randomsamatch
+                // type which reuses this method can have feedback defined for
+                // the wrapped shortanswer questions.
+                //if ($options->feedback
+                // && !empty($subquestion->options->answers[$responses[$key]]->feedback)) {
+                //    print_comment($subquestion->options->answers[$responses[$key]]->feedback);
+                //}
+
+                $anss[] = $a;
+            }
+        }
+        include("$CFG->dirroot/question/type/match/display.html");
+    }
+    
     /**
      * @param object $question
      * @return mixed either a integer score out of 1 that the average random
