You are here

function _quiz_save_user_settings in Quiz 6.4

Same name and namespace in other branches
  1. 8.4 quiz.module \_quiz_save_user_settings()
  2. 7 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
Implementation of hook_insert().
quiz_update in ./quiz.module
Implementation of hook_update().

File

./quiz.module, line 3932
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;
  }

  // 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;

  // Are we updating or inserting?
  $sql = 'SELECT uid FROM {quiz_user_settings} WHERE uid = %d';
  $res = db_query($sql, $node->uid);
  $update = is_numeric(db_result($res)) ? array(
    'uid',
  ) : array();
  drupal_write_record('quiz_user_settings', $node, $update);
  drupal_set_message(t('Default settings have been saved'));
}