You are here

function _quiz_save_user_settings in Quiz 7.4

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

Code

function _quiz_save_user_settings($node) {
  global $user;
  $node = (object) $node;

  // We do not save settings if the node has been created by the system,
  // or if the user haven't requested it
  if (isset($node->auto_created) || !isset($node->remember_settings) || !$node->remember_settings) {
    return FALSE;
  }
  $summary_pass_format = filter_fallback_format();
  if (isset($node->summary_pass['format']) && !empty($node->summary_pass['format'])) {
    $summary_pass_format = $node->summary_pass['format'];
  }
  $summary_default_format = filter_fallback_format();
  if (isset($node->summary_default['format']) && !empty($node->summary_default['format'])) {
    $summary_default_format = $node->summary_default['format'];
  }
  db_merge('quiz_user_settings')
    ->key(array(
    'uid' => $user->uid,
  ))
    ->fields(array(
    'uid' => $user->uid,
    'nid' => $node->nid,
    'vid' => $node->vid,
    'aid' => isset($node->aid) ? $node->aid : 0,
    'pass_rate' => $node->pass_rate,
    'summary_pass' => isset($node->summary_pass['value']) ? $node->summary_pass['value'] : '',
    'summary_pass_format' => $summary_pass_format,
    'summary_default' => $node->summary_default['value'],
    'summary_default_format' => $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,
    'show_passed' => $node->show_passed,
  ))
    ->execute();
  drupal_set_message(t('Default settings have been saved'));
}