You are here

public function MultichoiceQuestion::getNodeProperties in Quiz 8.4

Implementation of getNodeProperties

Overrides QuizQuestion::getNodeProperties

See also

QuizQuestion#getNodeProperties()

File

question_types/multichoice/lib/Drupal/multichoice/MultichoiceQuestion.php, line 347
The main classes for the multichoice question type.

Class

MultichoiceQuestion
Extension of QuizQuestion.

Namespace

Drupal\multichoice

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
      ->id(),
    ':vid' => $this->node
      ->getRevisionId(),
  ))
    ->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
      ->id(),
    ':question_vid' => $this->node
      ->getRevisionId(),
  ));
  $props['alternatives'] = array();

  // init array so it can be iterated even if empty
  while ($res_arr = $res
    ->fetchAssoc()) {
    $props['alternatives'][] = $res_arr;
  }
  $this->nodeProperties = $props;
  return $props;
}