You are here

function userpoints_admin_points in User Points 5.3

Same name and namespace in other branches
  1. 6 userpoints.module \userpoints_admin_points()
  2. 7.2 userpoints.admin.inc \userpoints_admin_points()
  3. 7 userpoints.admin.inc \userpoints_admin_points()
1 string reference to 'userpoints_admin_points'
userpoints_menu in ./userpoints.module
Implementation of hook_menu().

File

./userpoints.module, line 1182

Code

function userpoints_admin_points() {
  $tid = arg(3);
  $cat_count = count(userpoints_get_categories());
  $sql = "SELECT p.uid, u.name, p.points, p.tid, t.name as cat \n          FROM {userpoints} p INNER JOIN {users} u USING (uid) \n          LEFT JOIN {term_data} t ON p.tid = t.tid\n          ";

  //Check for filtering
  if ($tid == 0) {
    $sql .= "WHERE p.tid = 0";
    $cat = t('!Uncategorized', userpoints_translation());
  }
  elseif (is_numeric($tid)) {
    $sql .= "WHERE p.tid = %d";
    $cat = db_result(db_query("SELECT name from {term_data} WHERE tid = %d", $tid));
  }
  else {
    $cat = t('All');
  }
  drupal_set_title(t($cat) . " " . t("!points", userpoints_translation()));
  $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 = array(
    array(
      'data' => t('User'),
      'field' => 'u.name',
    ),
    array(
      'data' => t('Category'),
      'field' => 't.name',
    ),
    array(
      'data' => t('!Points', userpoints_translation()),
      'field' => 'p.points',
      'sort' => 'desc',
    ),
  );
  $sql .= tablesort_sql($header);
  $pager_limit = variable_get(USERPOINTS_REPORT_USERCOUNT, 30);
  $result = pager_query($sql, $pager_limit, 0, $sql_cnt, $tid);
  while ($data = db_fetch_object($result)) {
    if (!$data->cat) {
      $data->cat = t('!Uncategorized', userpoints_translation());
    }
    $rows[] = array(
      array(
        'data' => theme('username', $data) . "&nbsp;&nbsp;" . l("(details)", "myuserpoints/{$data->uid}"),
      ),
      array(
        'data' => $data->cat,
        'align' => 'right',
      ),
      array(
        'data' => $data->points,
        'align' => 'right',
      ),
    );
  }

  //If there is only one category there is no sense in display the category filter dropdown
  if ($cat_count > 1) {
    $output = drupal_get_form('userpoints_filter_cat_select', 'admin/user/userpoints/', arg(3));
    $output .= theme('table', $header, $rows);
    $output .= theme('pager', NULL, $pager_limit, 0);
  }
  else {
    $output = theme('table', $header, $rows);
    $output .= theme('pager', NULL, $pager_limit, 0);
  }
  return $output;
}