You are here

public function DDLinesResponse::__construct in Quiz 7.4

Constructor

Overrides QuizQuestionResponse::__construct

File

question_types/quiz_ddlines/quiz_ddlines.classes.inc, line 312
The main classes for the drag and drop with lines question type.

Class

DDLinesResponse
Extension of QuizQuestionResponse

Code

public function __construct($result_id, stdClass $question_node, $tries = NULL) {
  parent::__construct($result_id, $question_node, $tries);

  // Is answers set in form?
  if (isset($tries)) {

    // Tries contains the answer decoded as JSON:
    // {"label_id":x,"hotspot_id":y},{...}
    $decoded = json_decode($tries);
    if (is_array($decoded)) {
      foreach ($decoded as $answer) {
        $this->user_answers[$answer->label_id] = $answer->hotspot_id;
      }
    }
  }
  else {
    $res = db_query('SELECT label_id, hotspot_id FROM {quiz_ddlines_user_answers} ua
              LEFT OUTER JOIN {quiz_ddlines_user_answer_multi} uam ON(uam.user_answer_id = ua.id)
              WHERE ua.result_id = :result_id AND ua.question_nid = :question_nid AND ua.question_vid = :question_vid', array(
      ':result_id' => $result_id,
      ':question_nid' => $this->question->nid,
      ':question_vid' => $this->question->vid,
    ));
    while ($row = $res
      ->fetch()) {
      $this->user_answers[$row->label_id] = $row->hotspot_id;
    }
  }
}