You are here

public static function TrueFalseResponse::viewsGetAnswers in Quiz 6.x

Same name and namespace in other branches
  1. 8.6 question_types/quiz_truefalse/src/Plugin/quiz/QuizQuestion/TrueFalseResponse.php \Drupal\quiz_truefalse\Plugin\quiz\QuizQuestion\TrueFalseResponse::viewsGetAnswers()
  2. 8.5 question_types/quiz_truefalse/src/Plugin/quiz/QuizQuestion/TrueFalseResponse.php \Drupal\quiz_truefalse\Plugin\quiz\QuizQuestion\TrueFalseResponse::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_truefalse/src/Plugin/quiz/QuizQuestion/TrueFalseResponse.php, line 79

Class

TrueFalseResponse
Extension of QuizQuestionResponse.

Namespace

Drupal\quiz_truefalse\Plugin\quiz\QuizQuestion

Code

public static function viewsGetAnswers(array $result_answer_ids = []) : array {
  $items = [];
  foreach (QuizResultAnswer::loadMultiple($result_answer_ids) as $qra) {
    $items[$qra
      ->get('result_id')
      ->getString()][] = [
      'answer' => $qra
        ->getResponse() ? t('True') : t('False'),
    ];
  }
  return $items;
}