You are here

function _quiz_load_user_settings in Quiz 7

Same name and namespace in other branches
  1. 8.4 quiz.module \_quiz_load_user_settings()
  2. 6.4 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
Implements hook_form().
quiz_make_new in ./quiz.module
Makes, saves and returns a new quiz node.

File

./quiz.module, line 3991
Quiz Module

Code

function _quiz_load_user_settings(&$node) {
  global $user;

  // The def_uid property is the default user id. It is used if there are no
  // settings store for the current user.
  $def_uid = isset($node->def_uid) ? $node->def_uid : $user->uid;
  $query = db_select('quiz_user_settings', 'qus')
    ->fields('qus')
    ->condition('uid', $def_uid);
  $res = $query
    ->execute()
    ->fetchAssoc();
  if (!empty($res)) {
    foreach ($res as $key => $value) {
      if (!in_array($key, array(
        'nid',
        'vid',
        'uid',
      ))) {
        $node->{$key} = $value;
      }
    }

    // TODO : Reviews this later.
    $node->resultoptions[] = db_select('quiz_node_result_options', 'qnro')
      ->fields('qnro')
      ->condition('nid', $res['nid'])
      ->condition('vid', $res['vid'])
      ->execute()
      ->fetchAll();
    return TRUE;
  }
  return FALSE;
}