You are here

function _quiz_save_user_settings in Quiz 7

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

Fetch settings from a node and save them as the users default settings.

Parameters

$node: Quiz node.

3 calls to _quiz_save_user_settings()
quiz_admin_node_form_submit in ./quiz.admin.inc
Submit function for quiz_admin_node_form
quiz_insert in ./quiz.module
Implements hook_insert().
quiz_update in ./quiz.module
Implements hook_update().

File

./quiz.module, line 4024
Quiz Module

Code

function _quiz_save_user_settings($node) {
  global $user;

  // We do not save settings if the node has been created by the system,
  // or if the user haven't requested it
  $node = (object) $node;
  if (isset($node->auto_created) || !isset($node->remember_settings) || !$node->remember_settings) {
    return FALSE;
  }
  db_merge('quiz_user_settings')
    ->key(array(
    'uid' => $user->uid,
  ))
    ->fields(array(
    'uid' => isset($node->uid) ? $node->uid : $node->save_def_uid,
    'nid' => $node->nid,
    'vid' => $node->vid,
    'aid' => isset($node->aid) ? $node->aid : 0,
    'pass_rate' => $node->pass_rate,
    'summary_pass' => $node->summary_pass['value'],
    'summary_pass_format' => $node->summary_pass['format'],
    'summary_default' => $node->summary_default['value'],
    'summary_default_format' => $node->summary_default['format'],
    'randomization' => $node->randomization,
    'backwards_navigation' => $node->backwards_navigation,
    'keep_results' => $node->keep_results,
    'repeat_until_correct' => $node->repeat_until_correct,
    'feedback_time' => $node->feedback_time,
    'display_feedback' => $node->display_feedback,
    'takes' => $node->takes,
    'show_attempt_stats' => $node->show_attempt_stats,
    'time_limit' => isset($node->time_limit) ? $node->time_limit : 0,
    'quiz_always' => $node->quiz_always,
    'has_userpoints' => isset($node->has_userpoints) ? $node->has_userpoints : 0,
    'allow_skipping' => $node->allow_skipping,
    'allow_resume' => $node->allow_resume,
    'allow_jumping' => $node->allow_jumping,
  ))
    ->execute();

  /*
  // We're going to use drupal_write_record so we have to set the uid correctly first.
  // This is just temporary. We're not changing the nodes stored uid!
  $node->uid = isset($node->save_def_uid) ? $node->save_def_uid : $user->uid;
  $node->aid = isset($node->aid) ? $node->aid : '';
  // Are we updating or inserting?
  $res = db_query('SELECT uid FROM {quiz_user_settings} WHERE uid = :uid', array(':uid' => $node->uid));
  $update = is_numeric($res->fetchField()) ? array('uid') : array();
  drupal_write_record('quiz_user_settings', $node, $update);
  */
  drupal_set_message(t('Default settings have been saved'));
}