You are here

function quiz_has_been_answered in Quiz 8.4

Same name and namespace in other branches
  1. 6.4 quiz.module \quiz_has_been_answered()
  2. 7.6 quiz.module \quiz_has_been_answered()
  3. 7 quiz.module \quiz_has_been_answered()
  4. 7.4 quiz.module \quiz_has_been_answered()
  5. 7.5 quiz.module \quiz_has_been_answered()

Finds out if a quiz has been answered or not.

Return value

TRUE if there exists answers to the current question.

7 calls to quiz_has_been_answered()
QuizQuestion::saveRelationships in question_types/quiz_question/lib/Drupal/quiz_question/QuizQuestion.php
Handle the add to quiz part of the quiz_question_form
quiz_categorized_form_submit in ./quiz.admin.inc
Submit the categorized form
quiz_node_presave in ./quiz.module
Implementation of hook_node_presave().
quiz_options_form in ./quiz.pages.inc
Page callback for quiz options form
quiz_questions_form_submit in ./quiz.admin.inc
Submit function for quiz_questions.

... See full list

File

./quiz.module, line 756
Quiz Module

Code

function quiz_has_been_answered($node) {
  if ($node instanceof \stdClass && !$node->nid || !$node instanceof \stdClass && !$node
    ->id()) {
    return FALSE;
  }
  $query = db_select('quiz_node_results', 'qnr');
  $query
    ->addField('qnr', 'result_id');
  if ($node instanceof \stdClass) {
    $query
      ->condition('nid', $node->nid);
    $query
      ->condition('vid', $node->vid);
  }
  else {
    $query
      ->condition('nid', $node
      ->id());
    $query
      ->condition('vid', $node
      ->getRevisionId());
  }
  $query
    ->range(0, 1);
  return $query
    ->execute()
    ->rowCount() > 0;
}