You are here

function quiz_create_rid in Quiz 8.4

Same name and namespace in other branches
  1. 6.4 quiz.module \quiz_create_rid()
  2. 7 quiz.module \quiz_create_rid()
  3. 7.4 quiz.module \quiz_create_rid()

Creates a unique id to be used when storing results for a quiz taker.

Parameters

$quiz: The quiz node.

Return value

$rid The result id.

2 calls to quiz_create_rid()
quiz_take_quiz in ./quiz.module
Handles quiz taking.
_quiz_take_quiz_init in ./quiz.module

File

./quiz.module, line 2371
Quiz Module

Code

function quiz_create_rid($quiz) {
  $rid = db_insert('quiz_node_results')
    ->fields(array(
    'nid' => $quiz
      ->id(),
    'vid' => $quiz
      ->getRevisionId(),
    'uid' => \Drupal::currentUser()
      ->id(),
    'time_start' => REQUEST_TIME,
  ))
    ->execute();
  if (!is_numeric($rid)) {
    form_set_error(t('There was a problem starting the @quiz. Please try again later.', array(
      '@quiz' => QUIZ_NAME,
    ), array(
      'langcode' => 'error',
    )), $form_state);
    return FALSE;
  }
  return $rid;
}