public static function MatchingResponse::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.
Overrides QuizQuestionResponse::viewsGetAnswers
See also
views_handler_field_prerender_list for the expected return value.
File
- question_types/
matching/ matching.classes.inc, line 553 - Matching classes.
Class
- MatchingResponse
- Extension of QuizQuestionResponse
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);
$matches = array();
foreach ($question->match as $match) {
$matches[$match['match_id']] = $match;
}
foreach ($ra_i
->getResponse() as $question_id => $answer_id) {
if (!empty($answer_id)) {
$items[$ra->result_id][] = array(
'answer' => $matches[$question_id]['question'] . ': ' . $matches[$answer_id]['answer'],
);
}
}
}
return $items;
}