You are here

public function MultichoiceQuestion::getNodeProperties in Quiz 7.4

Same name and namespace in other branches
  1. 6.4 question_types/multichoice/multichoice.classes.inc \MultichoiceQuestion::getNodeProperties()
  2. 7.6 question_types/multichoice/multichoice.classes.inc \MultichoiceQuestion::getNodeProperties()
  3. 7 question_types/multichoice/multichoice.classes.inc \MultichoiceQuestion::getNodeProperties()
  4. 7.5 question_types/multichoice/multichoice.classes.inc \MultichoiceQuestion::getNodeProperties()

Implementation of getNodeProperties

Overrides QuizQuestion::getNodeProperties

See also

QuizQuestion#getNodeProperties()

File

question_types/multichoice/multichoice.classes.inc, line 360
The main classes for the multichoice question type.

Class

MultichoiceQuestion
Extension of QuizQuestion.

Code

public function getNodeProperties() {
  if (isset($this->nodeProperties) && !empty($this->nodeProperties)) {
    return $this->nodeProperties;
  }
  $props = parent::getNodeProperties();
  $res_a = db_query('SELECT choice_multi, choice_random, choice_boolean FROM {quiz_multichoice_properties}
            WHERE nid = :nid AND vid = :vid', array(
    ':nid' => $this->node->nid,
    ':vid' => $this->node->vid,
  ))
    ->fetchAssoc();
  if (is_array($res_a)) {
    $props = array_merge($props, $res_a);
  }

  // Load the answers
  $res = db_query('SELECT id, answer, answer_format, feedback_if_chosen, feedback_if_chosen_format,
            feedback_if_not_chosen, feedback_if_not_chosen_format, score_if_chosen, score_if_not_chosen
            FROM {quiz_multichoice_answers}
            WHERE question_nid = :question_nid AND question_vid = :question_vid
            ORDER BY id', array(
    ':question_nid' => $this->node->nid,
    ':question_vid' => $this->node->vid,
  ));
  $props['alternatives'] = array();

  // init array so it can be iterated even if empty
  while ($res_arr = $res
    ->fetchAssoc()) {
    $props['alternatives'][] = array(
      'id' => $res_arr['id'],
      'answer' => array(
        'value' => $res_arr['answer'],
        'format' => $res_arr['answer_format'],
      ),
      'feedback_if_chosen' => array(
        'value' => $res_arr['feedback_if_chosen'],
        'format' => $res_arr['feedback_if_chosen_format'],
      ),
      'feedback_if_not_chosen' => array(
        'value' => $res_arr['feedback_if_not_chosen'],
        'format' => $res_arr['feedback_if_not_chosen_format'],
      ),
      'score_if_chosen' => $res_arr['score_if_chosen'],
      'score_if_not_chosen' => $res_arr['score_if_not_chosen'],
    );
  }
  $this->nodeProperties = $props;
  return $props;
}