You are here

public static function MatchingResponse::viewsGetAnswers in Quiz 8.5

Same name and namespace in other branches
  1. 8.6 question_types/quiz_matching/src/Plugin/quiz/QuizQuestion/MatchingResponse.php \Drupal\quiz_matching\Plugin\quiz\QuizQuestion\MatchingResponse::viewsGetAnswers()
  2. 6.x question_types/quiz_matching/src/Plugin/quiz/QuizQuestion/MatchingResponse.php \Drupal\quiz_matching\Plugin\quiz\QuizQuestion\MatchingResponse::viewsGetAnswers()

Get answers for a question in a result.

This static method assists in building views for the mass export of question answers.

Overrides QuizResultAnswerEntityTrait::viewsGetAnswers

See also

views_handler_field_prerender_list for the expected return value.

File

question_types/quiz_matching/src/Plugin/quiz/QuizQuestion/MatchingResponse.php, line 113

Class

MatchingResponse
Extension of QuizQuestionResponse

Namespace

Drupal\quiz_matching\Plugin\quiz\QuizQuestion

Code

public static function viewsGetAnswers(array $result_answer_ids = array()) {
  $items = array();
  foreach ($result_answer_ids as $result_answer_id) {
    $ra = entity_load_single('quiz_result_answer', $result_answer_id);
    $question = node_load($ra->question_nid, $ra->question_vid);

    /** @var $ra_i QuizQuestionResponse */
    $ra_i = _quiz_question_response_get_instance($ra->result_id, $question);
    $matches = array();
    foreach ($question->match as $match) {
      $matches[$match['match_id']] = $match;
    }
    foreach ($ra_i
      ->getResponse() as $question_id => $answer_id) {
      if (!empty($answer_id)) {
        $items[$ra->result_id][] = array(
          'answer' => $matches[$question_id]['question'] . ': ' . $matches[$answer_id]['answer'],
        );
      }
    }
  }
  return $items;
}