class MatchingResponse in Quiz 7.6
Same name and namespace in other branches
- 6.6 question_types/matching/matching.classes.inc \MatchingResponse
- 6.3 question_types/matching/matching.classes.inc \MatchingResponse
- 6.4 question_types/matching/matching.classes.inc \MatchingResponse
- 6.5 question_types/matching/matching.classes.inc \MatchingResponse
- 7 question_types/matching/matching.classes.inc \MatchingResponse
- 7.4 question_types/matching/matching.classes.inc \MatchingResponse
- 7.5 question_types/matching/matching.classes.inc \MatchingResponse
Extension of QuizQuestionResponse
Hierarchy
- class \QuizQuestionResponse
- class \MatchingResponse
Expanded class hierarchy of MatchingResponse
1 string reference to 'MatchingResponse'
- matching_quiz_question_info in question_types/
matching/ matching.module - Implements hook_quiz_question_info().
File
- question_types/
matching/ matching.classes.inc, line 431 - matching.classes
View source
class MatchingResponse extends QuizQuestionResponse {
/**
* Constructor
*/
public function __construct($result_id, stdClass $question_node, $answer = NULL) {
parent::__construct($result_id, $question_node, $answer);
if (!isset($answer)) {
$res = db_query('SELECT ua.answer, score, ua.match_id FROM {quiz_matching_user_answers} ua
JOIN {quiz_matching_node} n ON n.match_id = ua.match_id
WHERE n.nid = :nid AND n.vid = :vid AND ua.result_id = :result_id', array(
':nid' => $question_node->nid,
':vid' => $question_node->vid,
':result_id' => $result_id,
));
$this->answer = array();
while ($obj = $res
->fetch()) {
$this->answer[$obj->match_id] = $obj->answer;
}
}
$this->is_correct = $this
->isCorrect();
}
/**
* Implementation of save
*
* @see QuizQuestionResponse#save()
*/
public function save() {
if (!isset($this->answer) || !is_array($this->answer)) {
return;
}
$insert = db_insert('quiz_matching_user_answers')
->fields(array(
'match_id',
'result_id',
'answer',
'score',
));
foreach ($this->answer as $key => $value) {
$insert
->values(array(
'match_id' => $key,
'result_id' => $this->result_id,
'answer' => (int) $value,
'score' => $key == $value ? 1 : 0,
));
}
$insert
->execute();
}
/**
* Implementation of delete
*
* @see QuizQuestionResponse#delete()
*/
public function delete() {
$match_id = db_query('SELECT match_id FROM {quiz_matching_node} WHERE nid = :nid AND vid = :vid', array(
':nid' => $this->question->nid,
':vid' => $this->question->vid,
))
->fetchCol();
db_delete('quiz_matching_user_answers')
->condition('match_id', is_array($match_id) ? $match_id : array(
0,
), 'IN')
->condition('result_id', $this->result_id)
->execute();
}
/**
* Implementation of score
*
* @see QuizQuestionResponse#score()
*/
public function score() {
$wrong_answer = 0;
$correct_answer = 0;
$user_answers = isset($this->answer['answer']) ? $this->answer['answer'] : $this->answer;
$MatchingQuestion = new MatchingQuestion($this->question);
$correct_answers = $MatchingQuestion
->getCorrectAnswer();
foreach ((array) $user_answers as $key => $value) {
if ($value != 0 && $correct_answers[$key]['answer'] == $correct_answers[$value]['answer']) {
$correct_answer++;
}
elseif ($value == 0 || $value == 'def') {
}
else {
$wrong_answer++;
}
}
$score = $correct_answer;
if ($this->question->choice_penalty) {
$score -= $wrong_answer;
}
return $score < 0 ? 0 : $score;
}
/**
* Implementation of getResponse
*
* @see QuizQuestionResponse#getResponse()
*/
public function getResponse() {
return $this->answer;
}
/**
* Implementation of getReportFormResponse
*/
public function getFeedbackValues() {
$data = array();
$answers = $this->question->answers[0]['answer'];
$solution = $this->quizQuestion
->getSubquestions();
foreach ($this->question->match as $match) {
$data[] = array(
'choice' => $match['question'],
'attempt' => !empty($answers[$match['match_id']]) ? $solution[1][$answers[$match['match_id']]] : '',
'correct' => $answers[$match['match_id']] == $match['match_id'] ? theme('quiz_answer_result', array(
'type' => 'correct',
)) : theme('quiz_answer_result', array(
'type' => 'incorrect',
)),
'score' => $answers[$match['match_id']] == $match['match_id'] ? 1 : 0,
'answer_feedback' => $match['feedback'],
'question_feedback' => 'Question feedback',
'solution' => $solution[1][$match['match_id']],
'quiz_feedback' => "Quiz feedback",
);
}
return $data;
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
MatchingResponse:: |
public | function |
Implementation of delete Overrides QuizQuestionResponse:: |
|
MatchingResponse:: |
public | function |
Implementation of getReportFormResponse Overrides QuizQuestionResponse:: |
|
MatchingResponse:: |
public | function |
Implementation of getResponse Overrides QuizQuestionResponse:: |
|
MatchingResponse:: |
public | function |
Implementation of save Overrides QuizQuestionResponse:: |
|
MatchingResponse:: |
public | function |
Implementation of score Overrides QuizQuestionResponse:: |
|
MatchingResponse:: |
public | function |
Constructor Overrides QuizQuestionResponse:: |
|
QuizQuestionResponse:: |
protected | property | ||
QuizQuestionResponse:: |
protected | property | ||
QuizQuestionResponse:: |
protected | property | ||
QuizQuestionResponse:: |
public | property | ||
QuizQuestionResponse:: |
public | property | ||
QuizQuestionResponse:: |
public | property | ||
QuizQuestionResponse:: |
public | property | ||
QuizQuestionResponse:: |
protected | property | ||
QuizQuestionResponse:: |
protected | property | 8 | |
QuizQuestionResponse:: |
public | function | Can the quiz taker view the requested review? | |
QuizQuestionResponse:: |
public | function | Returns a renderable array of question feedback. | |
QuizQuestionResponse:: |
protected | function | Utility function that returns the format of the node body | |
QuizQuestionResponse:: |
public | function | Returns stored max score if it exists, if not the max score is calculated and returned. | |
QuizQuestionResponse:: |
function | |||
QuizQuestionResponse:: |
public | function | Get data suitable for reporting a user's score on the question. This expects an object with the following attributes: | |
QuizQuestionResponse:: |
public | function | Creates the report form for the admin pages, and for when a user gets feedback after answering questions. | 2 |
QuizQuestionResponse:: |
public | function | 2 | |
QuizQuestionResponse:: |
public | function | Implementation of getReportFormScore | |
QuizQuestionResponse:: |
public | function | Get the submit function for the reportForm | 2 |
QuizQuestionResponse:: |
public | function | Get the validate function for the reportForm | 2 |
QuizQuestionResponse:: |
function | Returns stored score if it exists, if not the score is calculated and returned. | ||
QuizQuestionResponse:: |
function | Check to see if the answer is marked as correct. | 2 | |
QuizQuestionResponse:: |
public | function | Indicate whether the response has been evaluated (scored) yet. Questions that require human scoring (e.g. essays) may need to manually toggle this. | |
QuizQuestionResponse:: |
public | function | Validates response from a quiz taker. If the response isn't valid the quiz taker won't be allowed to proceed. | |
QuizQuestionResponse:: |
public | function | Used to refresh this instances question node in case drupal has changed it. | |
QuizQuestionResponse:: |
public | function | Set the target result ID for this Question response. | |
QuizQuestionResponse:: |
function | Represent the response as a stdClass object. |