You are here

public function QuizQuestion::hasBeenAnswered in Quiz 8.4

Finds out if a question has been answered or not

This function also returns TRUE if a quiz that this question belongs to have been answered. Even if the question itself haven't been answered. This is because the question might have been rendered and a user is about to answer it...

Return value

true if question has been answered or is about to be answered...

1 call to QuizQuestion::hasBeenAnswered()
QuizQuestion::getNodeForm in question_types/quiz_question/lib/Drupal/quiz_question/QuizQuestion.php
Returns a node form to quiz_question_form

File

question_types/quiz_question/lib/Drupal/quiz_question/QuizQuestion.php, line 630
Classes used in the Quiz Question module.

Class

QuizQuestion
A base implementation of a quiz_question, adding a layer of abstraction between the node API, quiz API and the question types.

Namespace

Drupal\quiz_question

Code

public function hasBeenAnswered() {
  if (!$this->node
    ->getRevisionId()) {
    return FALSE;
  }
  $answered = db_query_range('SELECT 1 FROM {quiz_node_results} qnres
            JOIN {quiz_node_relationship} qnrel ON (qnres.vid = qnrel.parent_vid)
            WHERE qnrel.child_vid = :child_vid', 0, 1, array(
    ':child_vid' => $this->node
      ->getRevisionId(),
  ))
    ->fetch();
  return $answered ? TRUE : FALSE;
}