You are here

function userpoints_list_users in User Points 6

Same name and namespace in other branches
  1. 5.3 userpoints.module \userpoints_list_users()
  2. 5 userpoints.module \userpoints_list_users()
  3. 5.2 userpoints.module \userpoints_list_users()
  4. 7.2 userpoints.pages.inc \userpoints_list_users()
  5. 7 userpoints.pages.inc \userpoints_list_users()
1 string reference to 'userpoints_list_users'
userpoints_menu in ./userpoints.module
Implementation of hook_menu().

File

./userpoints.module, line 1392

Code

function userpoints_list_users() {
  $tid = arg(1);
  $sql = "SELECT p.uid, u.name, p.points, p.tid, t.name as cat\n          FROM {userpoints} p INNER JOIN {users} u ON p.uid = u.uid AND u.status = 1\n          LEFT JOIN {term_data} t ON p.tid = t.tid\n          ";

  //Check for filtering
  if (is_numeric($tid)) {
    if ($tid > 0) {
      $sql .= "WHERE p.tid = %d";
      $cat = db_result(db_query("SELECT name from {term_data} WHERE tid = %d", $tid));
    }
    else {
      $sql .= "WHERE p.tid = %d";
      $cat = t('!Uncategorized', userpoints_translation());
    }
  }
  else {
    $cat = t('All');
  }
  $sql_cnt = "SELECT COUNT(DISTINCT(uid))\n              FROM {userpoints}\n              WHERE tid = %d\n              ";
  if (variable_get(USERPOINTS_REPORT_DISPLAYZERO, 1) == 0) {

    //The user would NOT like to see users with zero points
    $sql .= " AND p.points <> 0";
    $sql_cnt .= " AND points <> 0";
  }
  $sql .= " GROUP BY p.uid, u.name, p.points, p.tid, t.name";
  $header = theme('userpoints_list_users_header');
  $sql .= tablesort_sql($header);
  $pager_limit = variable_get(USERPOINTS_REPORT_USERCOUNT, 30);
  $result = pager_query($sql, $pager_limit, 0, $sql_cnt, $tid);
  $rows = array();
  while ($data = db_fetch_object($result)) {
    $rows[] = theme('userpoints_list_users_row', $data);
  }
  drupal_set_title(t($cat) . " " . t("!points", userpoints_translation()));
  return theme('userpoints_list_users', $header, $rows, $tid, $pager_limit);
}