You are here

function _quiz_load_user_settings in Quiz 6.4

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

Apply the users default settings to a quiz node.

Parameters

$node: Quiz node.

Return value

TRUE if success or FALSE if not success.

2 calls to _quiz_load_user_settings()
quiz_form in ./quiz.module
Implementation of hook_form().
quiz_make_new in ./quiz.module
Makes, saves and returns a new quiz node.

File

./quiz.module, line 3905
Quiz Module

Code

function _quiz_load_user_settings(&$node) {
  global $user;
  $sql = "SELECT * FROM {quiz_user_settings} WHERE uid = %d";

  // The def_uid property is the default user id. It is used if there are no
  // settings store for the current user.
  $res = db_query($sql, isset($node->def_uid) ? $node->def_uid : $user->uid);
  if ($res_o = db_fetch_object($res)) {
    foreach ($res_o as $key => $value) {
      if (!in_array($key, array(
        'nid',
        'vid',
        'uid',
      ))) {
        $node->{$key} = $value;
      }
    }
    $result_options = db_query('SELECT * FROM {quiz_node_result_options} WHERE nid = %d AND vid= %d', $res_o->nid, $res_o->vid);
    while ($option = db_fetch_array($result_options)) {
      $node->resultoptions[] = $option;
    }
    return TRUE;
  }
  return FALSE;
}