function _quiz_question_response_get_instance in Quiz 6.4
Same name and namespace in other branches
- 8.6 question_types/quiz_question/quiz_question.module \_quiz_question_response_get_instance()
- 8.4 question_types/quiz_question/quiz_question.module \_quiz_question_response_get_instance()
- 8.5 question_types/quiz_question/quiz_question.module \_quiz_question_response_get_instance()
- 6.6 question_types/quiz_question/quiz_question.module \_quiz_question_response_get_instance()
- 6.3 question_types/quiz_question/quiz_question.module \_quiz_question_response_get_instance()
- 6.5 question_types/quiz_question/quiz_question.module \_quiz_question_response_get_instance()
- 7.6 question_types/quiz_question/quiz_question.module \_quiz_question_response_get_instance()
- 7 question_types/quiz_question/quiz_question.module \_quiz_question_response_get_instance()
- 7.4 question_types/quiz_question/quiz_question.module \_quiz_question_response_get_instance()
- 7.5 question_types/quiz_question/quiz_question.module \_quiz_question_response_get_instance()
Get an instance of a quiz question responce.
Get information about the class and use it to construct a new object of the appropriate type.
Parameters
$rid: Result id
$question: The question node(not a QuizQuestion instance)
$answer: Resonce to the answering form.
$nid: Question node id
$vid: Question node version id
Return value
The appropriate QuizQuestionResponce extension instance
5 calls to _quiz_question_response_get_instance()
- quiz_question_delete_result in question_types/
quiz_question/ quiz_question.module - Implementation of hook_delete_result
- quiz_question_evaluate_question in question_types/
quiz_question/ quiz_question.module - Implementation of Quiz's hook_evaluate_question().
- quiz_question_get_report in question_types/
quiz_question/ quiz_question.module - Imlementation of hook_get_report().
- quiz_question_quiz_question_score in question_types/
quiz_question/ quiz_question.module - Implementation of hook_quiz_question_score().
- quiz_question_report_form in question_types/
quiz_question/ quiz_question.module - Returns a result report for a question response.
File
- question_types/
quiz_question/ quiz_question.module, line 668 - Quiz Question module. This module provides the basic facilities for adding quiz question types to a quiz.
Code
function _quiz_question_response_get_instance($rid, $question, $answer = NULL, $nid = NULL, $vid = NULL) {
// We cache responses to improve performance
static $quiz_responses = array();
if (is_object($question) && isset($quiz_responses[$rid][$question->vid])) {
// We refresh the question node in case it has been changed since we cached the response
$quiz_responses[$rid][$question->vid]
->refreshQuestionNode($question);
if ($quiz_responses[$rid][$question->vid]->is_skipped !== FALSE) {
// Return a cached instance of the response
return $quiz_responses[$rid][$question->vid];
}
}
elseif (isset($quiz_responses[$rid][$vid])) {
if ($quiz_responses[$rid][$vid]->is_skipped !== FALSE) {
// Return a cached instance of the response
return $quiz_responses[$rid][$vid];
}
}
if (!isset($quiz_responses[$rid])) {
// Prepare to cache responses for this result id
$quiz_responses[$rid] = array();
}
// If the question node isn't set we fetch it from the QuizQuestion instance this responce belongs to
if (!isset($question)) {
$dummy_node = new stdClass();
$dummy_node->nid = $nid;
$dummy_node->vid = $vid;
$question = _quiz_question_get_instance($dummy_node, TRUE)->node;
}
if (!$question) {
return FALSE;
}
$info = _quiz_question_get_implementations();
$constructor = $info[$question->type]['response provider'];
$to_return = new $constructor($rid, $question, $answer);
// All responce classes must extend QuizQuestionResponse
if (!$to_return instanceof QuizQuestionResponse) {
drupal_set_message(t('The question-response isn\'t a QuizQuestionResponse. It needs to extend the QuizQuestionResponse interface, or extend the abstractQuizQuestionResponse class.'), 'error', FALSE);
}
// Cache the responce instance
$quiz_responses[$rid][$question->vid] = $to_return;
return $to_return;
}