public static function MultichoiceResponse::viewsGetAnswers in Quiz 6.x
Same name and namespace in other branches
- 8.6 question_types/quiz_multichoice/src/Plugin/quiz/QuizQuestion/MultichoiceResponse.php \Drupal\quiz_multichoice\Plugin\quiz\QuizQuestion\MultichoiceResponse::viewsGetAnswers()
- 8.5 question_types/quiz_multichoice/src/Plugin/quiz/QuizQuestion/MultichoiceResponse.php \Drupal\quiz_multichoice\Plugin\quiz\QuizQuestion\MultichoiceResponse::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_multichoice/ src/ Plugin/ quiz/ QuizQuestion/ MultichoiceResponse.php, line 181
Class
- MultichoiceResponse
- Extension of QuizQuestionResponse.
Namespace
Drupal\quiz_multichoice\Plugin\quiz\QuizQuestionCode
public static function viewsGetAnswers(array $result_answer_ids = []) : array {
$items = [];
foreach (QuizResultAnswer::loadMultiple($result_answer_ids) as $qra) {
foreach ($qra
->getResponse() as $vid) {
if ($vid) {
$paragraph = \Drupal::entityTypeManager()
->getStorage('paragraph')
->loadRevision($vid);
$answer = trim(strip_tags($paragraph
->get('multichoice_answer')->value));
$items[$qra
->get('result_id')
->getString()][] = [
'answer' => $answer,
];
}
}
}
return $items;
}