When a user goes to /userpoints a report is displayed that, by default, is supposed to display each user's point balance in all categories. (The "Filter by category" selector defaults to "Display all").

In my testing, only the uncategorized points are displayed on the report.

I can change the selector to view other categories but when I choose "Display all" I see a report of uncategorized points (see attachment).

Comments

kbahey’s picture

Seems this need the tid of 'all' like we discussed in the other issue?

kmillecam’s picture

StatusFileSize
new28.67 KB
new623 bytes

This patch fixes part of the problem by removing the 'GROUP' portion of the db query. Since we're looking for a comprehensive list of points all users have in all categories, using GROUP returns a result set that's smaller than what we expect.

There's another issue though. The only way to get the complete list (after the patch is applied) is to click the /userpoints menu -- choosing "Display all" in the filter doesn't do anything.

Here's the chunk of code I modified (look for comments near the bottom).


/*
* Purpose: List the users and their point totals by all or by category
* Returns: HTML from the theme function
*/
function userpoints_list_users() {
  $tid = arg(1);

  $sql = "SELECT p.uid, u.name, p.points, p.tid, t.name as cat 
          FROM {userpoints} p INNER JOIN {users} u USING (uid) 
          LEFT JOIN {term_data} t ON p.tid = t.tid
          ";

  //Check for filtering
  if (is_numeric($tid) && $tid == 0) {
    $sql .= "WHERE p.tid IS NULL OR p.tid = ''";
    $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');
  }

  $sql_cnt = "SELECT COUNT(DISTINCT(uid)) 
              FROM {userpoints} 
              WHERE tid = %d
              ";

  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";
  }
  // Grouping causes problems when "Display all" filter is applied.
  // It doesn't seem to be necessary otherwise.
  // $sql .= " GROUP BY p.uid, u.name, p.points";
  $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);
  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', $rows, $tid, $pager_limit);
}

kmillecam’s picture

Khalid,

After I submitted the patch, I realized that "users by points" should indeed be a list of all users and a summary of the points (across all categories) that they've earned.

So, I guess two approaches/queries are necessary (similar to the 'all' solution we discussed the other day).

1) if no tid is passed, the query should include a SUM() to aggregate the category totals.

2) if a tid is passed, the existing query works to list an individual category and the points each users have earned in that category.

ilo’s picture

I guess the problem is at line 1235 of userpoints.module of the 5.x-3.2 release also..

1235 $output = drupal_get_form('userpoints_filter_cat_select', 'userpoints/', arg(3));
The filtering is not using the $tid variable passed in function definition..:
1232 function theme_userpoints_list_users(&$rows, &$tid, &$pager_limit) {

Replacing arg(3) with $tid will render the select list right solving the original problem.

It's..

1235: $output = drupal_get_form('userpoints_filter_cat_select', 'userpoints/', $tid);

Sorry, I've not patch installed in this pc..

jredding’s picture

Title: /userpoints page doesn't "Display All" categories » /userpoints page needs an ability to display SUMed categories
Category: bug » feature
StatusFileSize
new19.93 KB

ilo is correct. the "bug" is in the theme function. This should have been set to $tid so that the dropdown menu would have been set to the correct default category.

However the title suggests something different.

The Display All does in fact work as intended. ALL categories are shown but, just like the other items, the intent was not to show SUMed categories but EVERY category. The attached screen shot shows this in action and working. Version 3.2 with ilo's fix is in use (and committed to cvs).

I'm changing the category on this over to "Feature Request" as its not a bug.
I'm changing the title to properly reflect the feature request.

The feature request as I understand it is..
Add the ability to display SUMed user points (a sum of all the user points across all categories) to the /userpoints page.

To implement this.
rewrite the original SQL query in userpoints_list_users

kmillecam’s picture

Sounds good Jacob.

Thanks for taking a look at this, committing the fix, and adding this to the requested feature list.

Kevin

ilo’s picture

good work :)

berdir’s picture

Status: Active » Fixed

Sorry for spamming the participants in this issue. Due to the release of Drupal 7 and the lack of time from the maintainers, I'm closing all remaining 5.x issues for Userpoints.

Feel free to re-open this issue or create a new one for 6.x or even better 7.x if this bug is still open or feature is missing for these versions.

Status: Fixed » Closed (fixed)

Automatically closed -- issue fixed for 2 weeks with no activity.