You are here

public function MatchingQuestion::getNodeView in Quiz 8.4

Implementation of getNodeView

Overrides QuizQuestion::getNodeView

See also

QuizQuestion#getNodeView()

File

question_types/matching/lib/Drupal/matching/MatchingQuestion.php, line 178
The main classes for the matching question type.

Class

MatchingQuestion
Extension of QuizQuestion.

Namespace

Drupal\matching

Code

public function getNodeView() {
  $content = parent::getNodeView();
  list($matches, $select_option) = $this
    ->getSubquestions();
  $subquestions = array();
  if ($this
    ->viewCanRevealCorrect()) {
    foreach ($matches as $match) {
      $subquestions[] = array(
        'question' => $match['question'],
        'correct' => $match['answer'],
        'feedback' => $match['feedback'],
      );
    }
  }
  else {

    // shuffle the answer column
    foreach ($matches as $match) {
      $sub_qs[] = $match['question'];
      $sub_as[] = $match['answer'];
    }
    shuffle($sub_as);
    foreach ($sub_qs as $i => $sub_q) {
      $subquestions[] = array(
        'question' => $sub_q,
        'random' => $sub_as[$i],
      );
    }
  }
  $content['answers'] = array(
    '#markup' => theme('matching_match_node_view', array(
      'subquestions' => $subquestions,
    )),
    '#weight' => 2,
  );
  return $content;
}