public static function MultichoiceResponse::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/
multichoice/ multichoice.classes.inc, line 1023 - Multichoice classes.
Class
- MultichoiceResponse
- Extension of QuizQuestionResponse.
Code
public static function viewsGetAnswers(array $result_answer_ids = array()) {
$ras = entity_load('quiz_result_answer', $result_answer_ids);
$items = array();
$nids = db_select('quiz_node_results_answers', 'qra')
->fields('qra', array(
'question_nid',
))
->condition('result_answer_id', $result_answer_ids)
->execute()
->fetchAllKeyed(0, 0);
$nodes = node_load_multiple($nids);
foreach ($ras as $ra) {
$question = $nodes[$ra->question_nid];
/* @var $ra_i QuizQuestionResponse */
$ra_i = _quiz_question_response_get_instance($ra->result_id, $question);
$alternatives = array();
foreach ($question->alternatives as $alternative) {
$alternatives[$alternative['id']] = $alternative;
}
foreach ($ra_i
->getResponse() as $answer_id) {
if (!empty($answer_id)) {
$items[$ra->result_id][] = array(
'answer' => $alternatives[$answer_id]['answer']['value'],
);
}
}
}
return $items;
}