You are here

public function QuizQuestionEntityTrait::hasBeenAnswered in Quiz 6.x

Same name and namespace in other branches
  1. 8.6 src/Entity/QuizQuestionEntityTrait.php \Drupal\quiz\Entity\QuizQuestionEntityTrait::hasBeenAnswered()
  2. 8.5 src/Entity/QuizQuestionEntityTrait.php \Drupal\quiz\Entity\QuizQuestionEntityTrait::hasBeenAnswered()

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

bool TRUE if question has been answered or is about to be answered...

File

src/Entity/QuizQuestionEntityTrait.php, line 58

Class

QuizQuestionEntityTrait
A trait all Quiz question strongly typed entity bundles must use.

Namespace

Drupal\quiz\Entity

Code

public function hasBeenAnswered() {
  $result = \Drupal::entityQuery('quiz_result_answer')
    ->condition('question_vid', $this
    ->getRevisionId())
    ->range(0, 1)
    ->execute();
  return !empty($result);
}