You are here

public static function QuizResultAnswerEntityTrait::viewsGetAnswers in Quiz 8.6

Same name and namespace in other branches
  1. 8.5 src/Entity/QuizResultAnswerEntityTrait.php \Drupal\quiz\Entity\QuizResultAnswerEntityTrait::viewsGetAnswers()
  2. 6.x src/Entity/QuizResultAnswerEntityTrait.php \Drupal\quiz\Entity\QuizResultAnswerEntityTrait::viewsGetAnswers()

Get answers for a question in a result.

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

It is not as easy as instantiating all the question responses and returning the answer. To do this in views scalably we have to gather the data carefully.

This base method provides a very poor way of gathering the data.

See also

views_handler_field_prerender_list for the expected return value.

MultichoiceResponse::viewsGetAnswers() for a correct approach

TrueFalseResponse::viewsGetAnswers() for a correct approach

3 methods override QuizResultAnswerEntityTrait::viewsGetAnswers()
MatchingResponse::viewsGetAnswers in question_types/quiz_matching/src/Plugin/quiz/QuizQuestion/MatchingResponse.php
Get answers for a question in a result.
MultichoiceResponse::viewsGetAnswers in question_types/quiz_multichoice/src/Plugin/quiz/QuizQuestion/MultichoiceResponse.php
Get answers for a question in a result.
TrueFalseResponse::viewsGetAnswers in question_types/quiz_truefalse/src/Plugin/quiz/QuizQuestion/TrueFalseResponse.php
Get answers for a question in a result.

File

src/Entity/QuizResultAnswerEntityTrait.php, line 268

Class

QuizResultAnswerEntityTrait
Each question type must store its own response data and be able to calculate a score for that data.

Namespace

Drupal\quiz\Entity

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);
    $items[$ra->result_id][] = array(
      'answer' => $ra_i
        ->getResponse(),
    );
  }
  return $items;
}