function _quiz_question_response_get_instance in Quiz 7.5
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.4 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()
Get an instance of a quiz question response.
Get information about the class and use it to construct a new object of the appropriate type.
Parameters
int $result_id: Result id.
stdClass $question: The question node (not a QuizQuestion instance).
mixed $answer: Response to the answering form.
$nid: The Question node ID.
$vid: The Question revision ID.
Return value
QuizQuestionResponse The appropriate QuizQuestionResponse extension instance.
21 calls to _quiz_question_response_get_instance()
- LongAnswerQuestion::getAnsweringForm in question_types/
long_answer/ long_answer.classes.inc - Implementation of getAnsweringForm().
- long_answer_score_an_answer in question_types/
long_answer/ long_answer.module - Set a score for a long answer question.
- MatchingResponse::viewsGetAnswers in question_types/
matching/ matching.classes.inc - Get answers for a question in a result.
- MultichoiceResponse::viewsGetAnswers in question_types/
multichoice/ multichoice.classes.inc - Get answers for a question in a result.
- QuizGradingTestCase::testManualWeightedScore in tests/
QuizGradingTestCase.test - Test question weights.
File
- question_types/
quiz_question/ quiz_question.module, line 617 - Quiz Question module.
Code
function _quiz_question_response_get_instance($result_id, $question, $answer = NULL, $nid = NULL, $vid = NULL) {
$info = quiz_question_get_info();
// If the question node isn't set we fetch it from the QuizQuestion instance
// this response belongs to.
if (!isset($question)) {
$question = node_load($nid, $vid);
}
if (!empty($question->type)) {
$constructor = $info[$question->type]['response provider'];
}
if (empty($constructor)) {
$constructor = 'QuizQuestionResponseBroken';
$question = new stdClass();
}
$to_return = new $constructor($result_id, $question, $answer);
// All response 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);
}
$result = $to_return
->getReport();
$to_return->question->answers[$result['answer_id']] = $result;
$to_return->question->correct = $result['is_correct'];
return $to_return;
}