You are here

public static function QuizQuestionResponse::viewsGetAnswers in Quiz 7.5

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 QuizQuestionResponse::viewsGetAnswers()
MatchingResponse::viewsGetAnswers in question_types/matching/matching.classes.inc
Get answers for a question in a result.
MultichoiceResponse::viewsGetAnswers in question_types/multichoice/multichoice.classes.inc
Get answers for a question in a result.
TrueFalseResponse::viewsGetAnswers in question_types/truefalse/truefalse.classes.inc
Get answers for a question in a result.

File

question_types/quiz_question/quiz_question.core.inc, line 915
Classes used in the Quiz Question module.

Class

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

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;
}