You are here

function qformat_blackboard_6::process_ma in Quiz 6.5

Same name and namespace in other branches
  1. 6.6 includes/moodle/question/format/blackboard_6/format.php \qformat_blackboard_6::process_ma()
1 call to qformat_blackboard_6::process_ma()
qformat_blackboard_6::readquestions in includes/moodle/question/format/blackboard_6/format.php
Parses an array of lines into an array of questions, where each item is a question object as defined by readquestion(). Questions are defined as anything between blank lines.

File

includes/moodle/question/format/blackboard_6/format.php, line 739

Class

qformat_blackboard_6

Code

function process_ma($quest, &$questions) {
  $question = $this
    ->process_common($quest);

  // copied this from process_mc
  $question->qtype = MULTICHOICE;
  $question->single = 0;

  // More than one answer allowed
  $answers = $quest->responses;
  $correct_answers = array();
  foreach ($answers as $answer) {
    if ($answer->title == 'correct') {
      $answerset = $answer->ident[0]['and'][0]['#']['varequal'];
      foreach ($answerset as $ans) {
        $correct_answers[] = $ans['#'];
      }
    }
  }
  foreach ($quest->feedback as $fb) {
    $feedback->{$fb->ident} = addslashes(trim($fb->text));
  }
  $correct_answer_count = count($correct_answers);
  $choiceset = $quest->RESPONSE_BLOCK->choices;
  $i = 0;
  foreach ($choiceset as $choice) {
    $question->answer[$i] = addslashes(trim($choice->text));
    if (in_array($choice->ident, $correct_answers)) {

      // correct answer
      $question->fraction[$i] = floor(100000 / $correct_answer_count) / 100000;

      // strange behavior if we have more than 5 decimal places
      $question->feedback[$i] = $feedback->correct;
    }
    else {

      // wrong answer
      $question->fraction[$i] = 0;
      $question->feedback[$i] = $feedback->incorrect;
    }
    $i++;
  }
  $questions[] = $question;
}