You are here

function quiz_create_rid in Quiz 7

Same name and namespace in other branches
  1. 8.4 quiz.module \quiz_create_rid()
  2. 6.4 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.

Related topics

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 2682
Quiz Module

Code

function quiz_create_rid($quiz) {
  $rid = db_insert('quiz_node_results')
    ->fields(array(
    'nid' => $quiz->nid,
    'vid' => $quiz->vid,
    'uid' => $GLOBALS['user']->uid,
    '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',
    )));
    return FALSE;
  }
  return $rid;
}