You are here

class MatchingResponse in Quiz 6.3

Same name and namespace in other branches
  1. 6.6 question_types/matching/matching.classes.inc \MatchingResponse
  2. 6.4 question_types/matching/matching.classes.inc \MatchingResponse
  3. 6.5 question_types/matching/matching.classes.inc \MatchingResponse
  4. 7.6 question_types/matching/matching.classes.inc \MatchingResponse
  5. 7 question_types/matching/matching.classes.inc \MatchingResponse
  6. 7.4 question_types/matching/matching.classes.inc \MatchingResponse
  7. 7.5 question_types/matching/matching.classes.inc \MatchingResponse

Class that describes a "Directions question response". For the most part, no real scoring takes place for a direction node. However, there are a few behind-the-scenes tricks that are done here to make the quiz-taking process a little easier.

Hierarchy

Expanded class hierarchy of MatchingResponse

1 string reference to 'MatchingResponse'
matching_quiz_question_info in question_types/matching/matching.module
Implementation of hook_quiz_question_info().

File

question_types/matching/matching.classes.inc, line 217
quiz_directions.classes

View source
class MatchingResponse extends AbstractQuizQuestionResponse {
  public function __construct($rid, $question, $answer = NULL) {
    $this->rid = $rid;
    $this->question = $question;
    $this->answer = $answer;
    $this->is_correct = $this
      ->score();
  }
  public function save() {
    $user_answers = $this->answer;
    foreach ($user_answers as $key => $value) {
      $score = $key == $value ? 1 : 0;
      $sql = "INSERT INTO {quiz_matching_user_answers} (match_id, result_id, answer, score) VALUES (%d, %d, %d, %d)";

      // This is expensive need to be changed
      db_query($sql, $key, $this->rid, (int) $value, $score);
    }
  }
  public function delete() {

    //$sql = 'DELETE FROM {quiz_matching_user_answers} WHERE question_nid = %d AND question_vid = %d AND result_id = %d';

    //db_query($sql, $this->question->nid, $this->question->vid, $this->rid);
  }
  public function score() {
    $wrong_answer = 0;
    $user_answers = isset($this->answer) ? $this->answer : $this
      ->getUserAnswers();
    foreach ($user_answers as $key => $value) {
      if ($key != $value) {
        $wrong_answer++;
      }
    }
    $this->score = !empty($user_answers) && !$wrong_answer ? 1 : 0;
    return $this->score;
  }
  public function getResponse() {
    return $this->answer;
  }
  public function getUserAnswers() {
    $user_answers = array();

    // answer_id  match_id  result_id   score   answer #{quiz_matching_user_answers} fields
    $results = db_query("SELECT match_id, answer FROM {quiz_matching_user_answers} WHERE result_id = %d", $this->rid);
    while ($result = db_fetch_object($results)) {
      $user_answers[$result->match_id] = $result->answer;
    }
    return $user_answers;
  }
  public function formatReport($showpoints = TRUE, $showfeedback = TRUE) {
    $rows = $innerheader = array();

    // Build the question answers header (add blank space for IE).
    $innerheader[] = t('Match');
    if ($showpoints) {
      $innerheader[] = t('Correct Answer');
    }
    $innerheader[] = t('User Answer');
    if ($showfeedback) {
      $innerheader[] = ' ';
    }

    //if (empty($this->question->answers)) {

    //  return t('Missing question.');

    //}
    $MatchingQuestion = new MatchingQuestion($this->question);
    $correct_answers = $MatchingQuestion
      ->getCorrectAnswer();

    //$correct_answers = $this->question
    $user_answers = $this
      ->getUserAnswers();

    //print_r($correct_answers);

    //print_r($user_answers);

    //exit;
    foreach ($correct_answers as $correct_answer) {
      $id = $user_answers[$correct_answer['match_id']];
      $theme = $correct_answer['answer'] == $correct_answers[$id]['answer'] ? 'quiz_score_correct' : 'quiz_score_incorrect';
      $rows[] = array(
        'match' => check_markup($correct_answer['question'], $this->question->format),
        'correct_answer' => $showpoints ? check_plain($correct_answer['answer']) : '',
        'user_answer' => $showfeedback ? check_plain($correct_answers[$id]['answer']) : '',
        'image' => $showfeedback ? array(
          'data' => theme($theme),
          'class' => 'quiz_summary_qcell',
        ) : '',
      );
    }

    //$answer = $this->question->answers[0];

    //$correct_answer = $answer['is_correct'] ? $answer['answer'] : !$answer['answer'];

    //$user_answer = $answer['answer'];

    //if ($showpoints) {

    //  $rows[0][] = ($correct_answer ? t('True') : t('False'));
    // }

    //$rows[0][] = ($user_answer ? t('True') : t('False'));

    //if($showfeedback && !empty($this->question->feedback)) {

    //  $rows[0][] = $this->question->feedback;

    //}

    // Add the cell with the question and the answers.
    $q_output = '<div class="quiz_summary_question"><span class="quiz_question_bullet">' . t('Q:') . '</span> ' . check_markup($this->question->body) . '</div>';
    $q_output .= theme('table', $innerheader, $rows) . '<br />';
    return $q_output;
  }

}

Members

Namesort descending Modifiers Type Description Overrides
AbstractQuizQuestionResponse::$answer protected property
AbstractQuizQuestionResponse::$evaluated protected property
AbstractQuizQuestionResponse::$is_correct public property
AbstractQuizQuestionResponse::$question protected property
AbstractQuizQuestionResponse::$rid public property
AbstractQuizQuestionResponse::$score public property
AbstractQuizQuestionResponse::getReport public function Get data suitable for reporting a user's score on the question. This expects an object with the following attributes: Overrides QuizQuestionResponse::getReport
AbstractQuizQuestionResponse::getScore function Get the integer score. Overrides QuizQuestionResponse::getScore
AbstractQuizQuestionResponse::isCorrect function Check to see if the answer is marked as correct. Overrides QuizQuestionResponse::isCorrect 3
AbstractQuizQuestionResponse::isEvaluated 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. Overrides QuizQuestionResponse::isEvaluated
AbstractQuizQuestionResponse::toBareObject function Repesent the response as a stdClass object. Overrides QuizQuestionResponse::toBareObject
MatchingResponse::delete public function Delete the response. Overrides QuizQuestionResponse::delete
MatchingResponse::formatReport public function Return an HTML marked-up report for displaying the results of this question. Overrides QuizQuestionResponse::formatReport
MatchingResponse::getResponse public function Get the user's response. Overrides QuizQuestionResponse::getResponse
MatchingResponse::getUserAnswers public function
MatchingResponse::save public function Save the current response. Overrides QuizQuestionResponse::save
MatchingResponse::score public function Calculate the score for the response. This MUST set the $score instance variable. Overrides QuizQuestionResponse::score
MatchingResponse::__construct public function Create a new user response. Overrides QuizQuestionResponse::__construct