public static function MatchingResponse::viewsGetAnswers in Quiz 6.x
Same name and namespace in other branches
- 8.6 question_types/quiz_matching/src/Plugin/quiz/QuizQuestion/MatchingResponse.php \Drupal\quiz_matching\Plugin\quiz\QuizQuestion\MatchingResponse::viewsGetAnswers()
- 8.5 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 132
Class
- MatchingResponse
- Extension of QuizQuestionResponse
Namespace
Drupal\quiz_matching\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 $paragraph) {
/* @var $paragraph Drupal\paragraphs\Entity\Paragraph */
$q_vid = $paragraph
->get('matching_user_question')->value;
$qp = \Drupal::entityTypeManager()
->getStorage('paragraph')
->loadRevision($q_vid);
$a_vid = $paragraph
->get('matching_user_answer')->value;
if ($a_vid) {
$qa = \Drupal::entityTypeManager()
->getStorage('paragraph')
->loadRevision($a_vid);
}
if ($qa) {
$items[$qra
->get('result_id')
->getString()][] = array(
'answer' => $qp
->get('matching_question')->value . ': ' . $qa
->get('matching_answer')->value,
);
}
}
}
return $items;
}