You are here

function _quiz_load_user_settings in Quiz 8.4

Same name and namespace in other branches
  1. 6.4 quiz.module \_quiz_load_user_settings()
  2. 7 quiz.module \_quiz_load_user_settings()
  3. 7.4 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_make_new in ./quiz.module
Makes, saves and returns a new quiz node.
quiz_node_insert in ./quiz.module
quiz_node_prepare_form in ./quiz.module
Implementation of hook_node_prepare_form().

File

./quiz.module, line 942
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 : \Drupal::currentUser()
    ->id();
  $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();
}