You are here

function quiz_make_new in Quiz 7

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

Makes, saves and returns a new quiz node.

Parameters

$title: The title of the new node.

Return value

New quiz node object.

1 call to quiz_make_new()
QuizQuestion::saveRelationships in question_types/quiz_question/quiz_question.core.inc
Handle the add to quiz part of the quiz_question_form

File

./quiz.module, line 3762
Quiz Module

Code

function quiz_make_new($title) {
  global $user;
  $new_node = new stdClass();
  $new_node->title = $title;
  $new_node->type = 'quiz';
  $new_node->status = 1;
  $additions = _quiz_get_node_defaults();
  foreach ($additions as $key => $value) {
    $new_node->{$key} = $value;
  }
  $new_node->quiz_open = _quiz_form_prepare_date();
  $new_node->quiz_close = _quiz_form_prepare_date(NULL, variable_get('quiz_default_close', 30));

  // Get default settings
  $settings_loaded = _quiz_load_user_settings($new_node);
  if (!$settings_loaded) {
    $new_node->def_uid = variable_get('quiz_def_uid', 1);
    _quiz_load_user_settings($new_node);
  }
  $new_node->auto_created = TRUE;
  $new_node->uid = $user->uid;
  node_save($new_node);
  if (is_numeric($new_node->nid)) {
    drupal_set_message(t('Quiz %title has been created.', array(
      '%title' => $title,
    )));
  }
  return $new_node;
}