You are here

function _quiz_load_user_settings in Quiz 7.4

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 quiz.module \_quiz_load_user_settings()

Returns the users default settings.

Parameters

$node: Quiz node.

$uid: (optional) The uid of the user to get the settings for. Defaults to the current user (NULL).

Return value

An array of settings. The array is empty in case no settings are available.

4 calls to _quiz_load_user_settings()
quiz_admin_node_form in ./quiz.admin.inc
Renders the quiz node form for the admin pages
quiz_insert in ./quiz.module
Implements hook_insert().
quiz_make_new in ./quiz.module
Makes, saves and returns a new quiz node.
quiz_node_prepare in ./quiz.module
Implementation of hook_node_prepare().

File

./quiz.module, line 4287
Quiz Module

Code

function _quiz_load_user_settings($uid = NULL) {

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

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